stackdriver: wip annotation support

This commit is contained in:
Daniel Lee
2018-09-27 15:17:35 +02:00
parent 26d9e9243a
commit 03b43ab769
10 changed files with 165 additions and 67 deletions

View File

@@ -0,0 +1,32 @@
import _ from 'lodash';
import './query_filter_ctrl';
export class StackdriverAnnotationsQueryCtrl {
static templateUrl = 'partials/annotations.editor.html';
annotation: any;
datasource: any;
defaultDropdownValue = 'Select Metric';
defaultServiceValue = 'All Services';
defaults = {
project: {
id: 'default',
name: 'loading project...',
},
metricType: this.defaultDropdownValue,
metricService: this.defaultServiceValue,
metric: '',
filters: [],
metricKind: '',
valueType: '',
};
/** @ngInject */
constructor() {
this.annotation.target = this.annotation.target || {};
this.annotation.target.refId = 'annotationQuery';
_.defaultsDeep(this.annotation.target, this.defaults);
}
}

View File

@@ -1,14 +1,11 @@
import StackdriverDatasource from './datasource';
import { StackdriverQueryCtrl } from './query_ctrl';
import { StackdriverConfigCtrl } from './config_ctrl';
// class AnnotationsQueryCtrl {
// static templateUrl = 'partials/annotations.editor.html';
// }
import { StackdriverAnnotationsQueryCtrl } from './annotations_query_ctrl';
export {
StackdriverDatasource as Datasource,
StackdriverQueryCtrl as QueryCtrl,
StackdriverConfigCtrl as ConfigCtrl,
// AnnotationsQueryCtrl,
StackdriverAnnotationsQueryCtrl as AnnotationsQueryCtrl,
};

View File

@@ -1,13 +1,16 @@
<div class="gf-form-group">
<stackdriver-filter target="ctrl.annotation.target" refresh="ctrl.refresh()" datasource="ctrl.datasource"
default-dropdown-value="ctrl.defaultDropdownValue" default-service-value="ctrl.defaultServiceValue" hide-group-bys="true"></stackdriver-filter>
<div class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label width-12">Graphite query</span>
<input type="text" class="gf-form-input" ng-model='ctrl.annotation.target' placeholder="Example: statsd.application.counters.*.count"></input>
<span class="gf-form-label query-keyword width-9">Title</span>
<input type="text" class="gf-form-input width-20" ng-model="ctrl.annotation.target.title" />
</div>
<h5 class="section-heading">Or</h5>
<div class="gf-form">
<span class="gf-form-label width-12">Graphite events tags</span>
<input type="text" class="gf-form-input" ng-model='ctrl.annotation.tags' placeholder="Example: event_tag_name"></input>
<span class="gf-form-label query-keyword width-9">Text</span>
<input type="text" class="gf-form-input width-20" ng-model="ctrl.annotation.target.text" />
</div>
<div class="gf-form gf-form--grow">
<div class="gf-form-label gf-form-label--grow"></div>
</div>
</div>

View File

@@ -1,5 +1,6 @@
<query-editor-row query-ctrl="ctrl" has-text-edit-mode="false">
<stackdriver-filter target="ctrl.target" refresh="ctrl.refresh()" datasource="ctrl.datasource" default-dropdown-value="ctrl.defaultDropdownValue" default-service-value="ctrl.defaultServiceValue"></stackdriver-filter>
<stackdriver-filter target="ctrl.target" refresh="ctrl.refresh()" datasource="ctrl.datasource" default-dropdown-value="ctrl.defaultDropdownValue"
default-service-value="ctrl.defaultServiceValue"></stackdriver-filter>
<stackdriver-aggregation target="ctrl.target" alignment-period="ctrl.lastQueryMeta.alignmentPeriod" refresh="ctrl.refresh()"></stackdriver-aggregation>
<div class="gf-form-inline">
<div class="gf-form">

View File

@@ -4,11 +4,6 @@
<gf-form-dropdown model="ctrl.service" get-options="ctrl.services" class="min-width-20" disabled type="text"
allow-custom="true" lookup-text="true" css-class="min-width-12" on-change="ctrl.onServiceChange(ctrl.service)"></gf-form-dropdown>
</div>
<div class="gf-form gf-form--grow">
<div class="gf-form-label gf-form-label--grow"></div>
</div>
</div>
<div class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label width-9">Metric</span>
<gf-form-dropdown model="ctrl.metricType" get-options="ctrl.metrics" class="min-width-20" disabled type="text"
@@ -29,7 +24,7 @@
<div class="gf-form-label gf-form-label--grow"></div>
</div>
</div>
<div class="gf-form-inline">
<div class="gf-form-inline" ng-hide="ctrl.$scope.hideGroupBys">
<div class="gf-form">
<span class="gf-form-label query-keyword width-9">Group By</span>
<div class="gf-form" ng-repeat="segment in ctrl.groupBySegments">

View File

@@ -4,7 +4,7 @@
"id": "stackdriver",
"metrics": true,
"alerting": true,
"annotations": false,
"annotations": true,
"state": "beta",
"queryOptions": {
"maxDataPoints": true,

View File

@@ -16,6 +16,7 @@ export class StackdriverFilter {
refresh: '&',
defaultDropdownValue: '<',
defaultServiceValue: '<',
hideGroupBys: '<',
},
};
}
@@ -54,15 +55,18 @@ export class StackdriverFilterCtrl {
.then(this.loadMetricDescriptors.bind(this))
.then(this.getLabels.bind(this));
this.initSegments();
this.initSegments($scope.hideGroupBys);
}
initSegments() {
this.groupBySegments = this.target.aggregation.groupBys.map(groupBy => {
return this.uiSegmentSrv.getSegmentForValue(groupBy);
});
initSegments(hideGroupBys: boolean) {
if (!hideGroupBys) {
this.groupBySegments = this.target.aggregation.groupBys.map(groupBy => {
return this.uiSegmentSrv.getSegmentForValue(groupBy);
});
this.ensurePlusButton(this.groupBySegments);
}
this.removeSegment = this.uiSegmentSrv.newSegment({ fake: true, value: '-- remove group by --' });
this.ensurePlusButton(this.groupBySegments);
this.filterSegments = new FilterSegments(
this.uiSegmentSrv,
@@ -142,7 +146,11 @@ export class StackdriverFilterCtrl {
this.resourceLabels = data.results[this.target.refId].meta.resourceLabels;
resolve();
} catch (error) {
console.log(error.data.message);
if (error.data && error.data.message) {
console.log(error.data.message);
} else {
console.log(error);
}
appEvents.emit('alert-error', ['Error', 'Error loading metric labels for ' + this.target.metricType]);
resolve();
}