Browse Source

Send datasource request on anomaly create

master
rozetko 7 years ago
parent
commit
08f4f9bb7c
  1. 7
      src/controllers/anomaly_controller.ts
  2. 7
      src/model/datasource.ts
  3. 16
      src/module.ts
  4. 6
      src/services/anomaly_service.ts

7
src/controllers/anomaly_controller.ts

@ -4,7 +4,8 @@ import {
AnomalyKey, AnomalyType,
AnomalyTypesSet, AnomalySegment, AnomalySegmentsSearcher, AnomalySermentPair
} 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 { SegmentsSet } from '../model/segment_set';
import { SegmentArray } from '../model/segment_array';
@ -65,9 +66,9 @@ export class AnomalyController {
this._savingNewAnomalyType = false;
}
async saveNewAnomalyType(metricExpanded: MetricExpanded, panelId: number) {
async saveNewAnomalyType(metricExpanded: MetricExpanded, datasourceRequest: DatasourceRequest, panelId: number) {
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._creatingNewAnomalyType = false;
this._savingNewAnomalyType = false;

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 { DataProcessor } from './data_processor';
import { Metric, MetricExpanded } from './model/metric';
import { DatasourceRequest } from './model/datasource';
import { AnomalyKey, AnomalyType } from './model/anomaly';
import { AnomalyService } from './services/anomaly_service';
import { AnomalyController } from './controllers/anomaly_controller';
@ -38,8 +39,9 @@ class GraphCtrl extends MetricsPanelCtrl {
subTabIndex: number;
processor: DataProcessor;
datasourceRequest: DatasourceRequest;
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
anomalyController: AnomalyController;
@ -172,6 +174,16 @@ class GraphCtrl extends MetricsPanelCtrl {
this.render(this.seriesList);
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();
@ -472,8 +484,10 @@ class GraphCtrl extends MetricsPanelCtrl {
}
async saveAnomalyType() {
this.refresh();
await this.anomalyController.saveNewAnomalyType(
new MetricExpanded(this.panel.datasource, this.panel.targets),
this.datasourceRequest,
this.panel.id
);
this.$scope.$digest();

6
src/services/anomaly_service.ts

@ -1,5 +1,6 @@
import { Segment, SegmentKey } from '../model/segment';
import { MetricExpanded } from '../model/metric';
import { DatasourceRequest } from '../model/datasource';
import { SegmentsSet } from '../model/segment_set';
import { AnomalyKey, AnomalyType, AnomalySegment } from '../model/anomaly';
@ -11,13 +12,14 @@ export class AnomalyService {
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(
this._backendURL + '/anomalies',
{
name: newAnomalyType.name,
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