Skip to content

Commit

Permalink
Use utility function from grafana/data for v7.2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
oberschlauberger committed Sep 29, 2020
1 parent cf3d8f2 commit 823a5be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 11 additions & 2 deletions dist/datasource.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-ignore
var data_1 = require("@grafana/data");
// @ts-ignore
var kbn = require("app/core/utils/kbn");
var ApmDatasource = /** @class */ (function () {
function ApmDatasource(instanceSettings, $q, backendSrv, templateSrv) {
Expand All @@ -14,6 +16,12 @@ var ApmDatasource = /** @class */ (function () {
if (window.DOMParser) {
this.parser = new DOMParser();
}
if (!data_1.rangeUtil.intervalToSeconds) {
this.intervalToSeconds = kbn.interval_to_seconds;
}
else {
this.intervalToSeconds = data_1.rangeUtil.intervalToSeconds;
}
}
ApmDatasource.prototype.query = function (options) {
var _this = this;
Expand Down Expand Up @@ -55,7 +63,7 @@ var ApmDatasource = /** @class */ (function () {
"SOAPAction": "getMetricData",
"Content-Type": "text/xml"
};
var dataFrequencyInSeconds = kbn.interval_to_seconds(dataFrequency);
var dataFrequencyInSeconds = _this.intervalToSeconds(dataFrequency);
dataFrequencyInSeconds = dataFrequencyInSeconds - (dataFrequencyInSeconds % 15);
if (dataFrequencyInSeconds == 0) {
dataFrequencyInSeconds = 15;
Expand Down Expand Up @@ -241,7 +249,8 @@ var ApmDatasource = /** @class */ (function () {
});
grafanaResponse.data.push({
target: metric,
datapoints: metrics[metric]
datapoints: metrics[metric],
refId: metric
});
});
grafanaResponse.data.sort(function (a, b) { return +(a.target > b.target) || -(a.target < b.target); });
Expand Down
15 changes: 13 additions & 2 deletions src/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @ts-ignore
import { rangeUtil } from '@grafana/data';
// @ts-ignore
import * as kbn from 'app/core/utils/kbn';
import ApmRawQuery from './apmrawquery'

Expand All @@ -10,6 +12,8 @@ export class ApmDatasource {
soapHead: string = '<soapenv:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:met=\"http://metricslist.webservicesimpl.server.introscope.wily.com\"><soapenv:Header/><soapenv:Body>';
soapTail: string= '</soapenv:Body></soapenv:Envelope>';

private intervalToSeconds: (interval: string) => any;

constructor(instanceSettings, private $q, private backendSrv, private templateSrv) {

this.url = instanceSettings.url;
Expand All @@ -18,6 +22,12 @@ export class ApmDatasource {
if ((<any>window).DOMParser) {
this.parser = new DOMParser();
}

if (!rangeUtil.intervalToSeconds) {
this.intervalToSeconds = kbn.interval_to_seconds;
} else {
this.intervalToSeconds = rangeUtil.intervalToSeconds;
}
}

query(options) {
Expand Down Expand Up @@ -70,7 +80,7 @@ export class ApmDatasource {
"Content-Type": "text/xml"
};

let dataFrequencyInSeconds = kbn.interval_to_seconds(dataFrequency)
let dataFrequencyInSeconds = this.intervalToSeconds(dataFrequency)
dataFrequencyInSeconds = dataFrequencyInSeconds - (dataFrequencyInSeconds % 15);
if (dataFrequencyInSeconds == 0) {
dataFrequencyInSeconds = 15;
Expand Down Expand Up @@ -277,7 +287,8 @@ export class ApmDatasource {
})
grafanaResponse.data.push({
target: metric,
datapoints: metrics[metric]
datapoints: metrics[metric],
refId: metric
});
})

Expand Down

0 comments on commit 823a5be

Please sign in to comment.