Browse Source

Merge pull request #1 from hastic/134-send-datasource-request-on-anomaly-create

Send datasource request on anomaly create
master
Alexey Velikiy 7 years ago committed by GitHub
parent
commit
c67e8e8d20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/controllers/anomaly_controller.ts
  2. 7
      src/model/datasource.ts
  3. 16
      src/module.ts
  4. 6
      src/services/anomaly_service.ts

8
src/controllers/anomaly_controller.ts

@ -4,7 +4,8 @@ import {
AnomalyKey, AnomalyType, AnomalyKey, AnomalyType,
AnomalyTypesSet, AnomalySegment, AnomalySegmentsSearcher, AnomalySermentPair AnomalyTypesSet, AnomalySegment, AnomalySegmentsSearcher, AnomalySermentPair
} from '../model/anomaly'; } from '../model/anomaly';
import { MetricExpanded } from '../model/metric' import { MetricExpanded } from '../model/metric';
import { DatasourceRequest } from '../model/datasource';
import { Segment, SegmentKey } from '../model/segment'; import { Segment, SegmentKey } from '../model/segment';
import { SegmentsSet } from '../model/segment_set'; import { SegmentsSet } from '../model/segment_set';
import { SegmentArray } from '../model/segment_array'; import { SegmentArray } from '../model/segment_array';
@ -65,13 +66,14 @@ export class AnomalyController {
this._savingNewAnomalyType = false; this._savingNewAnomalyType = false;
} }
async saveNewAnomalyType(metricExpanded: MetricExpanded, panelId: number) { async saveNewAnomalyType(metricExpanded: MetricExpanded, datasourceRequest: DatasourceRequest, panelId: number) {
this._savingNewAnomalyType = true; this._savingNewAnomalyType = true;
await this._anomalyService.postNewAnomalyType(metricExpanded, this._newAnomalyType, panelId); await this._anomalyService.postNewAnomalyType(metricExpanded, datasourceRequest, this._newAnomalyType, panelId);
this._anomalyTypesSet.addAnomalyType(this._newAnomalyType); this._anomalyTypesSet.addAnomalyType(this._newAnomalyType);
this._creatingNewAnomalyType = false; this._creatingNewAnomalyType = false;
this._savingNewAnomalyType = false; this._savingNewAnomalyType = false;
this.runAnomalyTypeAlertEnabledWaiter(this._newAnomalyType); this.runAnomalyTypeAlertEnabledWaiter(this._newAnomalyType);
this._runAnomalyTypeStatusWaiter(this._newAnomalyType);
} }
get creatingAnomalyType() { return this._creatingNewAnomalyType; } get creatingAnomalyType() { return this._creatingNewAnomalyType; }

7
src/model/datasource.ts

@ -0,0 +1,7 @@
export type DatasourceRequest = {
method: string,
data: Object,
params: Object,
type: string,
url: string
}

16
src/module.ts

@ -7,6 +7,7 @@ import { GraphRenderer } from './graph_renderer';
import { GraphLegend } from './graph_legend'; import { GraphLegend } from './graph_legend';
import { DataProcessor } from './data_processor'; import { DataProcessor } from './data_processor';
import { Metric, MetricExpanded } from './model/metric'; import { Metric, MetricExpanded } from './model/metric';
import { DatasourceRequest } from './model/datasource';
import { AnomalyKey, AnomalyType } from './model/anomaly'; import { AnomalyKey, AnomalyType } from './model/anomaly';
import { AnomalyService } from './services/anomaly_service'; import { AnomalyService } from './services/anomaly_service';
import { AnomalyController } from './controllers/anomaly_controller'; import { AnomalyController } from './controllers/anomaly_controller';
@ -38,8 +39,9 @@ class GraphCtrl extends MetricsPanelCtrl {
subTabIndex: number; subTabIndex: number;
processor: DataProcessor; processor: DataProcessor;
datasourceRequest: DatasourceRequest;
backendURL: string; backendURL: string;
analyticsTypes: Array<String> = ['Anomaly detection', 'Pettern Detection (not implemented yet)']; analyticsTypes: Array<String> = ['Anomaly detection', 'Pattern Detection (not implemented yet)'];
anomalyTypes = []; // TODO: remove it later. Only for alert tab anomalyTypes = []; // TODO: remove it later. Only for alert tab
anomalyController: AnomalyController; anomalyController: AnomalyController;
@ -172,6 +174,16 @@ class GraphCtrl extends MetricsPanelCtrl {
this.render(this.seriesList); this.render(this.seriesList);
this.$scope.$digest(); this.$scope.$digest();
}); });
appEvents.on('ds-request-response', data => {
let requestConfig = data.config;
this.datasourceRequest = {
url: requestConfig.url,
type: requestConfig.inspect.type,
method: requestConfig.method,
data: requestConfig.data,
params: requestConfig.params
};
});
this.anomalyController.fetchAnomalyTypesStatuses(); this.anomalyController.fetchAnomalyTypesStatuses();
@ -472,8 +484,10 @@ class GraphCtrl extends MetricsPanelCtrl {
} }
async saveAnomalyType() { async saveAnomalyType() {
this.refresh();
await this.anomalyController.saveNewAnomalyType( await this.anomalyController.saveNewAnomalyType(
new MetricExpanded(this.panel.datasource, this.panel.targets), new MetricExpanded(this.panel.datasource, this.panel.targets),
this.datasourceRequest,
this.panel.id this.panel.id
); );
this.$scope.$digest(); this.$scope.$digest();

6
src/services/anomaly_service.ts

@ -1,5 +1,6 @@
import { Segment, SegmentKey } from '../model/segment'; import { Segment, SegmentKey } from '../model/segment';
import { MetricExpanded } from '../model/metric'; import { MetricExpanded } from '../model/metric';
import { DatasourceRequest } from '../model/datasource';
import { SegmentsSet } from '../model/segment_set'; import { SegmentsSet } from '../model/segment_set';
import { AnomalyKey, AnomalyType, AnomalySegment } from '../model/anomaly'; import { AnomalyKey, AnomalyType, AnomalySegment } from '../model/anomaly';
@ -11,13 +12,14 @@ export class AnomalyService {
constructor(private _backendURL: string, private _backendSrv: BackendSrv) { constructor(private _backendURL: string, private _backendSrv: BackendSrv) {
} }
async postNewAnomalyType(metric: MetricExpanded, newAnomalyType: AnomalyType, panelId: number) { async postNewAnomalyType(metric: MetricExpanded, datasourceRequest: DatasourceRequest, newAnomalyType: AnomalyType, panelId: number) {
return this._backendSrv.post( return this._backendSrv.post(
this._backendURL + '/anomalies', this._backendURL + '/anomalies',
{ {
name: newAnomalyType.name, name: newAnomalyType.name,
metric: metric.toJSON(), metric: metric.toJSON(),
panelUrl: window.location.origin + window.location.pathname + `?panelId=${panelId}&fullscreen` panelUrl: window.location.origin + window.location.pathname + `?panelId=${panelId}&fullscreen`,
datasource: datasourceRequest
} }
) )
}; };

Loading…
Cancel
Save