Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown for resource types #53

Merged
merged 1 commit into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 1.6.2

* Use a dropdown for resource types

Version 1.6.1

* Allow to have different attributes for templating
Expand Down
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = function(grunt) {
removeComments: false,
noImplicitAny: false,
moduleResolution: "node",
lib: ["dom", "es2015", "es5", "es6"],
typeRoots: ["node_modules/@types"],
}
},
Expand Down
27 changes: 26 additions & 1 deletion dist/datasource.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/datasource.js.map

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions dist/partials/query.editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<div class="gf-form-inline">
<div class="gf-form max-width" ng-if="['resource', 'resource_search', 'resource_aggregation', 'dynamic_aggregates'].indexOf(ctrl.target.queryMode) >= 0">
<label class="gf-form-label query-keyword width-8">Resource type</label>
<input type="text" class="gf-form-input width-12" ng-model="ctrl.target.resource_type" spellcheck='false' data-min-length=0 ng-model-onblur ng-keyup="cancel($event)" ng-change="ctrl.refresh()">
<div class="gf-form-select-wrapper">
<select class="gf-form-input gf-size-auto" ng-model="ctrl.target.resource_type" ng-options="f for f in ctrl.resource_types" ng-change="ctrl.refresh()"></select>
</div>
<label class="gf-form-label query-keyword width-8" ng-if="['resource_search'].indexOf(ctrl.target.queryMode) >= 0">Metric regex</label>
<label class="gf-form-label query-keyword width-8" ng-if="['resource_search', 'dynamic_aggregates'].indexOf(ctrl.target.queryMode) < 0">Metric name</label>
<input ng-if="['dynamic_aggregates'].indexOf(ctrl.target.queryMode) < 0" type="text" class="gf-form-input" ng-model="ctrl.target.metric_name" bs-typeahead="ctrl.suggestMetricNames" spellcheck='false' placeholder="metric" data-min-length=0 ng-model-onblur ng-keyup="cancel($event)" ng-change="ctrl.refresh()">
Expand Down Expand Up @@ -47,11 +49,11 @@
</div>
<div class="gf-form" ng-if="['dynamic_aggregates'].indexOf(ctrl.target.queryMode) < 0">
<label class="gf-form-label query-keyword width-8">Aggregator</label>
<gf-form-dropdown css-class="width-12" allow-custom="true" model="ctrl.target.aggregator" get-options="ctrl.getAggregators()" on-change="ctrl.setAggregator($option)"></gf-form-dropdown>
<gf-form-dropdown css-class="width-12" allow-custom="true" model="ctrl.target.aggregator" get-options="ctrl.getAggregators(false)" on-change="ctrl.setAggregator($option)"></gf-form-dropdown>
</div>
<div class="gf-form" ng-if="['resource_aggregation'].indexOf(ctrl.target.queryMode) >= 0">
<label class="gf-form-label query-keyword width-8">Reaggregator</label>
<gf-form-dropdown css-class="width-12" allow-custom="true" model="ctrl.target.reaggregator" get-options="ctrl.getAggregators()" on-change="ctrl.setReaggregator($option)"></gf-form-dropdown>
<gf-form-dropdown css-class="width-12" allow-custom="true" model="ctrl.target.reaggregator" get-options="ctrl.getAggregators(true)" on-change="ctrl.setReaggregator($option)"></gf-form-dropdown>
</div>
<div class="gf-form max-width-20" ng-if="['resource_aggregation', 'dynamic_aggregates'].indexOf(ctrl.target.queryMode) >= 0">
<label class="gf-form-label query-keyword width-16">Percent of needed overlap</label>
Expand Down
16 changes: 13 additions & 3 deletions dist/query_ctrl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/query_ctrl.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions dist/specs/gnocchi-datasource-specs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/specs/gnocchi-datasource-specs.js.map

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export default class GnocchiDatasource {
roles: string;
url: string;
keystone_endpoint: string;
resource_types: any;

constructor(instanceSettings, private $q, private backendSrv, private templateSrv) {
this.type = 'gnocchi';
this.name = instanceSettings.name;
this.supportMetrics = true;
this.version = null;
this.resource_types = [];

this.default_headers = {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -181,7 +183,11 @@ export default class GnocchiDatasource {
var measures_req = _.merge({}, default_measures_req);
measures_req.url = 'v1/aggregation/metric';
measures_req.params.metric = _.keysIn(metrics);
measures_req.params.reaggregation = target.reaggregator;
if (target.reaggregator !== "none") {
measures_req.params.reaggregation = target.reaggregator;
} else {
measures_req.params.reaggregation = null;
}
measures_req.params.fill = target.fill;
if (target.needed_overlap === undefined) {
measures_req.params.needed_overlap = 0;
Expand Down Expand Up @@ -483,6 +489,24 @@ export default class GnocchiDatasource {
/// Utils
//////////////////////

getResourceTypes() {
var deferred = this.$q.defer();
if (this.resource_types.length === 0) {
this.resource_types = ["generic"];
this._gnocchi_request({url: 'v1/resource_type'}).then((result) => {
_.map(result, (item) => {
if (item["name"] !== "generic") {
this.resource_types.push(item["name"]);
}
});
deferred.resolve(this.resource_types);
});
} else {
deferred.resolve(this.resource_types);
}
return deferred.promise;
}

requireVersion(version) {
// this.version is a sum of 3 int where:
// major * 1000000
Expand Down
Loading