Commit 6114f63d by Alexander Zobnin

graphite: auto detect version

parent 89aea278
const versionPattern = /(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z\.]+))?/;
import _ from 'lodash';
const versionPattern = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z\.]+))?/;
export class SemVersion {
major: number;
......@@ -20,6 +22,10 @@ export class SemVersion {
let compared = new SemVersion(version);
return !(this.major < compared.major || this.minor < compared.minor || this.patch < compared.patch);
}
isValid(): boolean {
return _.isNumber(this.major);
}
}
export function isVersionGtOrEq(a: string, b: string): boolean {
......
......@@ -2,12 +2,26 @@
export class GraphiteConfigCtrl {
static templateUrl = 'public/app/plugins/datasource/graphite/partials/config.html';
datasourceSrv: any;
current: any;
/** @ngInject */
constructor($scope) {
constructor($scope, datasourceSrv) {
this.datasourceSrv = datasourceSrv;
this.current.jsonData = this.current.jsonData || {};
this.current.jsonData.graphiteVersion = this.current.jsonData.graphiteVersion || '0.9';
this.autoDetectGraphiteVersion();
}
autoDetectGraphiteVersion() {
this.datasourceSrv.loadDatasource(this.current.name)
.then((ds) => {
return ds.getVersion();
}).then((version) => {
this.graphiteVersions.push({name: version, value: version});
this.current.jsonData.graphiteVersion = version;
});
}
graphiteVersions = [
......
......@@ -2,7 +2,7 @@
import _ from 'lodash';
import * as dateMath from 'app/core/utils/datemath';
import {isVersionGtOrEq} from 'app/core/utils/version';
import {isVersionGtOrEq, SemVersion} from 'app/core/utils/version';
/** @ngInject */
export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv) {
......@@ -273,6 +273,23 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
});
};
this.getVersion = function() {
let httpOptions = {
method: 'GET',
url: '/version/_', // Prevent last / trimming
};
return this.doGraphiteRequest(httpOptions).then(results => {
if (results.data) {
let semver = new SemVersion(results.data);
return semver.isValid() ? results.data : '';
}
return '';
}).catch(() => {
return '';
});
};
this.testDatasource = function() {
return this.metricFindQuery('*').then(function () {
return { status: "success", message: "Data source is working"};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment