Browse Source

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

Send datasource request on anomaly create
master
Alexey Velikiy 6 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. 22
      src/module.ts
  4. 6
      src/services/anomaly_service.ts

8
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,13 +66,14 @@ 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;
this.runAnomalyTypeAlertEnabledWaiter(this._newAnomalyType);
this._runAnomalyTypeStatusWaiter(this._newAnomalyType);
}
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
}

22
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;
@ -135,8 +137,8 @@ class GraphCtrl extends MetricsPanelCtrl {
/** @ngInject */
constructor(
$scope, $injector, private annotationsSrv,
private keybindingSrv, private backendSrv,
$scope, $injector, private annotationsSrv,
private keybindingSrv, private backendSrv,
private popoverSrv, private contextSrv
) {
super($scope, $injector);
@ -172,7 +174,17 @@ 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