Skip to content

Commit

Permalink
Merge pull request ceph#44985 from rhcs-dashboard/dashboard-turns-tel…
Browse files Browse the repository at this point in the history
…emetry-off

mgr/dashboard: dashboard turns telemetry off when configuring report

Reviewed-by: Nizamudeen A <[email protected]>
Reviewed-by: Alfonso Martínez <[email protected]>
Reviewed-by: Yaarit Hatuka <[email protected]>
Reviewed-by: Laura Flores <[email protected]>
  • Loading branch information
yuriw authored Feb 21, 2022
2 parents 9ddf7fa + 15211a6 commit 66f1984
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,19 @@
i18n-placeholder>
</div>
</div>
<div class="form-group row">
<label class="cd-col-form-label"
for="organization"
i18n>Organization</label>
<div class="cd-col-form-input">
<input id="organization"
class="form-control"
type="text"
formControlName="organization"
placeholder="Organization name"
i18n-placeholder>
</div>
</div>
</ng-container>
<legend i18n>Advanced Settings</legend>
<div class="form-group row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,28 @@ describe('TelemetryComponent', () => {
fixture.debugElement.nativeElement.querySelector('input[id=contact]');
const getDescriptionField = () =>
fixture.debugElement.nativeElement.querySelector('input[id=description]');
const checkVisibility = () => {
if (component.showContactInfo) {
expect(getContactField()).toBeTruthy();
expect(getDescriptionField()).toBeTruthy();
} else {
expect(getContactField()).toBeFalsy();
expect(getDescriptionField()).toBeFalsy();
}
};

// Initially hidden.
expect(getContactField()).toBeFalsy();
expect(getDescriptionField()).toBeFalsy();
// Initial check.
checkVisibility();

// Show fields.
// toggle fields.
component.toggleIdent();
fixture.detectChanges();
expect(getContactField()).toBeTruthy();
expect(getDescriptionField()).toBeTruthy();
checkVisibility();

// Hide fields.
// toggle fields again.
component.toggleIdent();
fixture.detectChanges();
expect(getContactField()).toBeFalsy();
expect(getDescriptionField()).toBeFalsy();
checkVisibility();
});

it('should set module enability to true correctly', () => {
Expand All @@ -120,16 +126,6 @@ describe('TelemetryComponent', () => {
});
});

it('should update the Telemetry configuration', () => {
component.updateConfig();
const req = httpTesting.expectOne('api/mgr/module/telemetry');
expect(req.request.method).toBe('PUT');
expect(req.request.body).toEqual({
config: {}
});
req.flush({});
});

it('should disable the Telemetry module', () => {
const message = 'Module disabled message.';
const followUpFunc = function () {
Expand Down Expand Up @@ -305,14 +301,22 @@ describe('TelemetryComponent', () => {

it('should submit', () => {
component.onSubmit();
const req = httpTesting.expectOne('api/telemetry');
expect(req.request.method).toBe('PUT');
expect(req.request.body).toEqual({
const req1 = httpTesting.expectOne('api/telemetry');
expect(req1.request.method).toBe('PUT');
expect(req1.request.body).toEqual({
enable: true,
license_name: 'sharing-1-0'
});
req.flush({});
expect(router.navigate).toHaveBeenCalledWith(['']);
req1.flush({});
const req2 = httpTesting.expectOne({
url: 'api/mgr/module/telemetry',
method: 'PUT'
});
expect(req2.request.body).toEqual({
config: {}
});
req2.flush({});
expect(router.url).toBe('/');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class TelemetryComponent extends CdForm implements OnInit {
licenseAgrmt = false;
moduleEnabled: boolean;
options: Object = {};
newConfig: Object = {};
configResp: object = {};
previewForm: CdFormGroup;
requiredFields = [
'channel_basic',
Expand All @@ -35,14 +37,16 @@ export class TelemetryComponent extends CdForm implements OnInit {
'interval',
'proxy',
'contact',
'description'
'description',
'organization'
];
contactInfofields = ['contact', 'description', 'organization'];
report: object = undefined;
reportId: number = undefined;
sendToUrl = '';
sendToDeviceUrl = '';
step = 1;
showContactInfo = false;
showContactInfo: boolean;

constructor(
public actionLabels: ActionLabelsI18n,
Expand All @@ -67,10 +71,11 @@ export class TelemetryComponent extends CdForm implements OnInit {
this.moduleEnabled = configResp['enabled'];
this.sendToUrl = configResp['url'];
this.sendToDeviceUrl = configResp['device_url'];
this.showContactInfo = configResp['channel_ident'];
this.options = _.pick(resp[0], this.requiredFields);
const configs = _.pick(configResp, this.requiredFields);
this.configResp = _.pick(configResp, this.requiredFields);
this.createConfigForm();
this.configForm.setValue(configs);
this.configForm.setValue(this.configResp);
this.loadingReady();
},
(_error) => {
Expand Down Expand Up @@ -176,13 +181,31 @@ export class TelemetryComponent extends CdForm implements OnInit {
return result;
}

private updateReportFromConfig(updatedConfig: Object = {}) {
// update channels
const availableChannels: string[] = this.report['report']['channels_available'];
const updatedChannels = [];
for (const channel of availableChannels) {
const key = `channel_${channel}`;
if (updatedConfig[key]) {
updatedChannels.push(channel);
}
}
this.report['report']['channels'] = updatedChannels;
// update contactInfo
for (const contactInfofield of this.contactInfofields) {
this.report['report'][contactInfofield] = updatedConfig[contactInfofield];
}
}

private getReport() {
this.loadingStart();

this.telemetryService.getReport().subscribe(
(resp: object) => {
this.report = resp;
this.reportId = resp['report']['report_id'];
this.updateReportFromConfig(this.newConfig);
this.createPreviewForm();
this.loadingReady();
this.step++;
Expand All @@ -197,31 +220,25 @@ export class TelemetryComponent extends CdForm implements OnInit {
this.showContactInfo = !this.showContactInfo;
}

updateConfig() {
const config = {};
_.forEach(Object.values(this.options), (option) => {
buildReport() {
this.newConfig = {};
for (const option of Object.values(this.options)) {
const control = this.configForm.get(option.name);
// Append the option only if the value has been modified.
if (control.dirty && control.valid) {
config[option.name] = control.value;
}
});
this.mgrModuleService.updateConfig('telemetry', config).subscribe(
() => {
this.disableModule(
$localize`Your settings have been applied successfully. \
Due to privacy/legal reasons the Telemetry module is now disabled until you \
complete the next step and accept the license.`,
() => {
this.getReport();
}
);
},
() => {
// Reset the 'Submit' button.
// Append the option only if they are valid
if (control.valid) {
this.newConfig[option.name] = control.value;
} else {
this.configForm.setErrors({ cdSubmitButton: true });
return;
}
);
}
// reset contact info field if ident channel is off
if (!this.newConfig['channel_ident']) {
for (const contactInfofield of this.contactInfofields) {
this.newConfig[contactInfofield] = '';
}
}
this.getReport();
}

disableModule(message: string = null, followUpFunc: Function = null) {
Expand All @@ -239,25 +256,52 @@ export class TelemetryComponent extends CdForm implements OnInit {
}

next() {
if (this.configForm.pristine) {
this.getReport();
} else {
this.updateConfig();
}
this.buildReport();
}

back() {
this.step--;
}

onSubmit() {
this.telemetryService.enable().subscribe(() => {
this.telemetryNotificationService.setVisibility(false);
this.notificationService.show(
NotificationType.success,
$localize`The Telemetry module has been configured and activated successfully.`
);
this.router.navigate(['']);
getChangedConfig() {
const updatedConfig = {};
_.forEach(this.requiredFields, (configField) => {
if (!_.isEqual(this.configResp[configField], this.newConfig[configField])) {
updatedConfig[configField] = this.newConfig[configField];
}
});
return updatedConfig;
}

onSubmit() {
const updatedConfig = this.getChangedConfig();
const observables = [
this.telemetryService.enable(),
this.mgrModuleService.updateConfig('telemetry', updatedConfig)
];

observableForkJoin(observables).subscribe(
() => {
this.telemetryNotificationService.setVisibility(false);
this.notificationService.show(
NotificationType.success,
$localize`The Telemetry module has been configured and activated successfully.`
);
},
() => {
this.telemetryNotificationService.setVisibility(false);
this.notificationService.show(
NotificationType.error,
$localize`An Error occurred while updating the Telemetry module configuration.\
Please Try again`
);
// Reset the 'Update' button.
this.previewForm.setErrors({ cdSubmitButton: true });
},
() => {
this.newConfig = {};
this.router.navigate(['']);
}
);
}
}

0 comments on commit 66f1984

Please sign in to comment.