2017-12-20 05:33:33 -06:00
|
|
|
import _ from 'lodash';
|
2019-11-27 17:45:35 -06:00
|
|
|
import {
|
|
|
|
DataFrame,
|
|
|
|
DataQueryRequest,
|
2020-03-23 23:46:31 -05:00
|
|
|
DataQueryResponse,
|
2019-11-27 17:45:35 -06:00
|
|
|
DataSourceApi,
|
2020-03-23 23:46:31 -05:00
|
|
|
dateMath,
|
2020-03-18 07:00:14 -05:00
|
|
|
QueryResultMetaStat,
|
2020-03-23 23:46:31 -05:00
|
|
|
ScopedVars,
|
|
|
|
toDataFrame,
|
2020-07-08 04:05:20 -05:00
|
|
|
TimeRange,
|
2019-11-27 17:45:35 -06:00
|
|
|
} from '@grafana/data';
|
2017-12-20 05:33:33 -06:00
|
|
|
import { isVersionGtOrEq, SemVersion } from 'app/core/utils/version';
|
2017-12-08 17:48:39 -06:00
|
|
|
import gfunc from './gfunc';
|
2020-01-21 03:08:07 -06:00
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
2019-07-05 06:26:14 -05:00
|
|
|
import { TemplateSrv } from 'app/features/templating/template_srv';
|
2020-03-18 07:00:14 -05:00
|
|
|
// Types
|
|
|
|
import { GraphiteOptions, GraphiteQuery, GraphiteType, MetricTankRequestMeta } from './types';
|
|
|
|
import { getRollupNotice, getRuntimeConsolidationNotice } from 'app/plugins/datasource/graphite/meta';
|
2020-06-04 06:44:48 -05:00
|
|
|
import { getSearchFilterScopedVar } from '../../../features/variables/utils';
|
2019-10-08 10:01:20 -05:00
|
|
|
|
2019-11-27 17:45:35 -06:00
|
|
|
export class GraphiteDatasource extends DataSourceApi<GraphiteQuery, GraphiteOptions> {
|
2019-07-05 06:26:14 -05:00
|
|
|
basicAuth: string;
|
|
|
|
url: string;
|
|
|
|
name: string;
|
|
|
|
graphiteVersion: any;
|
|
|
|
supportsTags: boolean;
|
2019-11-08 03:38:10 -06:00
|
|
|
isMetricTank: boolean;
|
2020-03-18 07:00:14 -05:00
|
|
|
rollupIndicatorEnabled: boolean;
|
2019-07-05 06:26:14 -05:00
|
|
|
cacheTimeout: any;
|
|
|
|
withCredentials: boolean;
|
2019-07-05 09:46:46 -05:00
|
|
|
funcDefs: any = null;
|
2020-07-08 04:05:20 -05:00
|
|
|
funcDefsPromise: Promise<any> | null = null;
|
2019-07-05 06:26:14 -05:00
|
|
|
_seriesRefLetters: string;
|
|
|
|
|
|
|
|
/** @ngInject */
|
2020-01-21 03:08:07 -06:00
|
|
|
constructor(instanceSettings: any, private templateSrv: TemplateSrv) {
|
2019-11-27 17:45:35 -06:00
|
|
|
super(instanceSettings);
|
2019-07-05 06:26:14 -05:00
|
|
|
this.basicAuth = instanceSettings.basicAuth;
|
|
|
|
this.url = instanceSettings.url;
|
|
|
|
this.name = instanceSettings.name;
|
|
|
|
this.graphiteVersion = instanceSettings.jsonData.graphiteVersion || '0.9';
|
2019-11-08 03:38:10 -06:00
|
|
|
this.isMetricTank = instanceSettings.jsonData.graphiteType === GraphiteType.Metrictank;
|
2019-07-05 06:26:14 -05:00
|
|
|
this.supportsTags = supportsTags(this.graphiteVersion);
|
|
|
|
this.cacheTimeout = instanceSettings.cacheTimeout;
|
2020-03-18 07:00:14 -05:00
|
|
|
this.rollupIndicatorEnabled = instanceSettings.jsonData.rollupIndicatorEnabled;
|
2019-07-05 06:26:14 -05:00
|
|
|
this.withCredentials = instanceSettings.withCredentials;
|
|
|
|
this.funcDefs = null;
|
|
|
|
this.funcDefsPromise = null;
|
|
|
|
this._seriesRefLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
}
|
|
|
|
|
|
|
|
getQueryOptionsInfo() {
|
2017-08-31 07:05:52 -05:00
|
|
|
return {
|
2017-12-19 09:06:54 -06:00
|
|
|
maxDataPoints: true,
|
|
|
|
cacheTimeout: true,
|
|
|
|
links: [
|
2017-08-31 07:05:52 -05:00
|
|
|
{
|
2017-12-20 05:33:33 -06:00
|
|
|
text: 'Help',
|
2017-12-21 01:39:31 -06:00
|
|
|
url: 'http://docs.grafana.org/features/datasources/graphite/#using-graphite-in-grafana',
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
|
|
|
],
|
2017-08-31 07:05:52 -05:00
|
|
|
};
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2017-08-31 07:05:52 -05:00
|
|
|
|
2019-11-08 03:38:10 -06:00
|
|
|
async query(options: DataQueryRequest<GraphiteQuery>): Promise<DataQueryResponse> {
|
2018-08-29 07:27:29 -05:00
|
|
|
const graphOptions = {
|
2020-07-08 04:05:20 -05:00
|
|
|
from: this.translateTime(options.range.raw.from, false, options.timezone),
|
|
|
|
until: this.translateTime(options.range.raw.to, true, options.timezone),
|
2016-03-22 15:27:53 -05:00
|
|
|
targets: options.targets,
|
2019-11-08 03:38:10 -06:00
|
|
|
format: (options as any).format,
|
2016-03-22 15:27:53 -05:00
|
|
|
cacheTimeout: options.cacheTimeout || this.cacheTimeout,
|
2017-12-20 05:33:33 -06:00
|
|
|
maxDataPoints: options.maxDataPoints,
|
2016-03-22 15:27:53 -05:00
|
|
|
};
|
|
|
|
|
2018-08-29 07:27:29 -05:00
|
|
|
const params = this.buildGraphiteParams(graphOptions, options.scopedVars);
|
2016-03-22 15:27:53 -05:00
|
|
|
if (params.length === 0) {
|
2019-12-05 03:04:03 -06:00
|
|
|
return Promise.resolve({ data: [] });
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
2016-03-22 15:27:53 -05:00
|
|
|
|
2019-11-08 03:38:10 -06:00
|
|
|
if (this.isMetricTank) {
|
|
|
|
params.push('meta=true');
|
|
|
|
}
|
|
|
|
|
2018-08-29 07:27:29 -05:00
|
|
|
const httpOptions: any = {
|
2017-12-20 05:33:33 -06:00
|
|
|
method: 'POST',
|
|
|
|
url: '/render',
|
|
|
|
data: params.join('&'),
|
2016-06-16 03:48:26 -05:00
|
|
|
headers: {
|
2017-12-20 05:33:33 -06:00
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
},
|
2016-06-16 03:48:26 -05:00
|
|
|
};
|
2016-03-22 15:27:53 -05:00
|
|
|
|
2018-05-28 08:57:12 -05:00
|
|
|
this.addTracingHeaders(httpOptions, options);
|
|
|
|
|
2016-06-16 03:48:26 -05:00
|
|
|
if (options.panelId) {
|
2017-12-20 05:33:33 -06:00
|
|
|
httpOptions.requestId = this.name + '.panelId.' + options.panelId;
|
2016-03-22 15:27:53 -05:00
|
|
|
}
|
|
|
|
|
2019-11-08 03:38:10 -06:00
|
|
|
return this.doGraphiteRequest(httpOptions).then(this.convertResponseToDataFrames);
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
addTracingHeaders(httpOptions: { headers: any }, options: { dashboardId: any; panelId: any }) {
|
2018-08-29 07:27:29 -05:00
|
|
|
const proxyMode = !this.url.match(/^http/);
|
2018-05-28 08:57:12 -05:00
|
|
|
if (proxyMode) {
|
|
|
|
httpOptions.headers['X-Dashboard-Id'] = options.dashboardId;
|
|
|
|
httpOptions.headers['X-Panel-Id'] = options.panelId;
|
|
|
|
}
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2018-05-28 08:57:12 -05:00
|
|
|
|
2020-01-10 00:59:23 -06:00
|
|
|
convertResponseToDataFrames = (result: any): DataQueryResponse => {
|
2019-11-08 03:38:10 -06:00
|
|
|
const data: DataFrame[] = [];
|
2017-12-19 09:06:54 -06:00
|
|
|
if (!result || !result.data) {
|
2019-11-08 03:38:10 -06:00
|
|
|
return { data };
|
2017-12-19 09:06:54 -06:00
|
|
|
}
|
2020-03-18 07:00:14 -05:00
|
|
|
|
2019-11-08 03:38:10 -06:00
|
|
|
// Series are either at the root or under a node called 'series'
|
|
|
|
const series = result.data.series || result.data;
|
2020-03-18 07:00:14 -05:00
|
|
|
|
2019-11-08 03:38:10 -06:00
|
|
|
if (!_.isArray(series)) {
|
|
|
|
throw { message: 'Missing series in result', data: result };
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let i = 0; i < series.length; i++) {
|
|
|
|
const s = series[i];
|
2020-03-18 07:00:14 -05:00
|
|
|
|
Field: getFieldTitle as field / series display identity and use it in all field name matchers & field / series name displays (#24024)
* common title handling
* show labels
* update comment
* Update changelog for v7.0.0-beta1 (#24007)
Co-Authored-By: Marcus Efraimsson <marcus.efraimsson@gmail.com>
Co-Authored-By: Andrej Ocenas <mr.ocenas@gmail.com>
Co-Authored-By: Hugo Häggmark <hugo.haggmark@grafana.com>
Co-authored-by: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com>
* verify-repo-update: Fix Dockerfile.deb (#24030)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* CircleCI: Upgrade build pipeline tool (#24021)
* CircleCI: Upgrade build pipeline tool
* Devenv: ignore enterprise (#24037)
* Add header icon to Add data source page (#24033)
* latest.json: Update testing version (#24038)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Fix login page redirected from password reset (#24032)
* Storybook: Rewrite stories to CSF (#23989)
* ColorPicker to CSF format
* Convert stories to CSF
* Do not export ClipboardButton
* Update ConfirmButton
* Remove unused imports
* Fix feedback
* changelog enterprise 7.0.0-beta1 (#24039)
* CircleCI: Bump grafana/build-container revision (#24043)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Changelog: Updates changelog with more feature details (#24040)
* Changelog: Updates changelog with more feature details
* spell fix
* spell fix
* Updates
* Readme update
* Updates
* Select: fixes so component loses focus on selecting value or pressing outside of input. (#24008)
* changed the value container to a class component to get it to work with focus (maybe something with context?).
* added e2e tests to verify that the select focus is working as it should.
* fixed according to feedback.
* updated snapshot.
* Devenv: add remote renderer to grafana (#24050)
* NewPanelEditor: minor UI twekas (#24042)
* Forward ref for tabs, use html props
* Inspect: add inspect label to drawer title
* Add tooltips to sidebar pane tabs, copy changes
* Remove unused import
* Place tooltips over tabs
* Inspector: dont show transformations select if there is only one data frame
* Review
* Changelog: Add a breaking change (#24051)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* CircleCI: Unpin grafana/docs-base (#24054)
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
* Search: close overlay on Esc press (#24003)
* Search: Close on Esc
* Search: Increase bottom padding for the last item in section
* Search: Move closing search to keybindingsSrv
* Search: Fix folder view
* Search: Do not move folders if already in folder
* Docs: Adds deprecation notice to changelog and docs for scripted dashboards (#24060)
* Update CHANGELOG.md (#24047)
Fix typo
Co-authored-by: Daniel Lee <dan.limerick@gmail.com>
* Documentation: Alternative Team Sync Wording (#23960)
* Alternative wording for team sync docs
Signed-off-by: Joe Elliott <number101010@gmail.com>
* Update docs/sources/auth/team-sync.md
Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
* Fix misspell issues (#23905)
* Fix misspell issues
See,
$ golangci-lint run --timeout 10m --disable-all -E misspell ./...
Signed-off-by: Mario Trangoni <mjtrangoni@gmail.com>
* Fix codespell issues
See,
$ codespell -S './.git*' -L 'uint,thru,pres,unknwon,serie,referer,uptodate,durationm'
Signed-off-by: Mario Trangoni <mjtrangoni@gmail.com>
* ci please?
* non-empty commit - ci?
* Trigger build
Co-authored-by: bergquist <carl.bergquist@gmail.com>
Co-authored-by: Kyle Brandt <kyle@grafana.com>
* fix compile error
* better series display
* better display
* now with prometheus and loki
* a few more tests
* Improvements and tests
* thinking
* More advanced and smart default title generation
* Another fix
* Progress but dam this will be hard
* Reverting the time series Value field name change
* revert revert going in circles
* add a field state object
* Use state title when converting back to legacy format
* Improved the join (series to columsn) transformer
* Got tests running again
* Rewrite of seriesToColums that simplifies and fixing tests
* Fixed the tricky problem of multiple time field when not used in join
* Prometheus: Restoring prometheus formatting
* Graphite: Disable Grafana's series naming
* fixed imports
* Fixed tests and made rename transform change title instead
* Fixing more tests
* fix more tests
* fixed import issue
* Fixed more circular dependencies
* Renamed to getFieldTitle
* More rename
* Review feedback
* Fix for showing field title in calculate field transformer
* fieldOverride: Make it clear that state title after applying defaults & overrides
* Fixed ts issue
* Update packages/grafana-ui/src/components/TransformersUI/OrganizeFieldsTransformerEditor.tsx
Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>
Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>
Co-authored-by: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com>
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
Co-authored-by: Leonard Gram <leo@xlson.com>
Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
Co-authored-by: Alexander Zobnin <alexanderzobnin@gmail.com>
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
Co-authored-by: Richard Hartmann <RichiH@users.noreply.github.com>
Co-authored-by: Daniel Lee <dan.limerick@gmail.com>
Co-authored-by: Joe Elliott <joe.elliott@grafana.com>
Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
Co-authored-by: Mario Trangoni <mario@mariotrangoni.de>
Co-authored-by: bergquist <carl.bergquist@gmail.com>
Co-authored-by: Kyle Brandt <kyle@grafana.com>
2020-05-07 03:42:03 -05:00
|
|
|
// Disables Grafana own series naming
|
|
|
|
s.title = s.target;
|
|
|
|
|
2019-11-08 03:38:10 -06:00
|
|
|
for (let y = 0; y < s.datapoints.length; y++) {
|
|
|
|
s.datapoints[y][1] *= 1000;
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
2020-03-18 07:00:14 -05:00
|
|
|
|
2019-11-08 03:38:10 -06:00
|
|
|
const frame = toDataFrame(s);
|
|
|
|
|
|
|
|
// Metrictank metadata
|
|
|
|
if (s.meta) {
|
|
|
|
frame.meta = {
|
2020-01-10 00:59:23 -06:00
|
|
|
custom: {
|
2020-03-18 07:00:14 -05:00
|
|
|
requestMetaList: result.data.meta, // info for the whole request
|
|
|
|
seriesMetaList: s.meta, // Array of metadata
|
2020-01-10 00:59:23 -06:00
|
|
|
},
|
2019-11-08 03:38:10 -06:00
|
|
|
};
|
2020-03-18 07:00:14 -05:00
|
|
|
|
|
|
|
if (this.rollupIndicatorEnabled) {
|
|
|
|
const rollupNotice = getRollupNotice(s.meta);
|
|
|
|
const runtimeNotice = getRuntimeConsolidationNotice(s.meta);
|
|
|
|
|
|
|
|
if (rollupNotice) {
|
|
|
|
frame.meta.notices = [rollupNotice];
|
|
|
|
} else if (runtimeNotice) {
|
|
|
|
frame.meta.notices = [runtimeNotice];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// only add the request stats to the first frame
|
|
|
|
if (i === 0 && result.data.meta.stats) {
|
|
|
|
frame.meta.stats = this.getRequestStats(result.data.meta);
|
|
|
|
}
|
2019-11-08 03:38:10 -06:00
|
|
|
}
|
2020-03-18 07:00:14 -05:00
|
|
|
|
2019-11-08 03:38:10 -06:00
|
|
|
data.push(frame);
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
2020-03-18 07:00:14 -05:00
|
|
|
|
2019-11-08 03:38:10 -06:00
|
|
|
return { data };
|
2020-01-10 00:59:23 -06:00
|
|
|
};
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2020-03-18 07:00:14 -05:00
|
|
|
getRequestStats(meta: MetricTankRequestMeta): QueryResultMetaStat[] {
|
|
|
|
const stats: QueryResultMetaStat[] = [];
|
|
|
|
|
|
|
|
for (const key in meta.stats) {
|
|
|
|
let unit: string | undefined = undefined;
|
|
|
|
|
|
|
|
if (key.endsWith('.ms')) {
|
|
|
|
unit = 'ms';
|
|
|
|
}
|
|
|
|
|
2020-05-12 06:52:53 -05:00
|
|
|
stats.push({ displayName: key, value: meta.stats[key], unit });
|
2020-03-18 07:00:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return stats;
|
|
|
|
}
|
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
parseTags(tagString: string) {
|
2019-07-05 09:46:46 -05:00
|
|
|
let tags: string[] = [];
|
2017-12-20 05:33:33 -06:00
|
|
|
tags = tagString.split(',');
|
2017-10-07 03:31:39 -05:00
|
|
|
if (tags.length === 1) {
|
2017-12-20 05:33:33 -06:00
|
|
|
tags = tagString.split(' ');
|
|
|
|
if (tags[0] === '') {
|
2017-10-07 03:31:39 -05:00
|
|
|
tags = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tags;
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2017-10-07 03:31:39 -05:00
|
|
|
|
2020-01-24 02:50:09 -06:00
|
|
|
interpolateVariablesInQueries(queries: GraphiteQuery[], scopedVars: ScopedVars): GraphiteQuery[] {
|
2019-10-08 10:01:20 -05:00
|
|
|
let expandedQueries = queries;
|
|
|
|
if (queries && queries.length > 0) {
|
|
|
|
expandedQueries = queries.map(query => {
|
|
|
|
const expandedQuery = {
|
|
|
|
...query,
|
|
|
|
datasource: this.name,
|
2020-07-08 04:05:20 -05:00
|
|
|
target: this.templateSrv.replace(query.target ?? '', scopedVars),
|
2019-10-08 10:01:20 -05:00
|
|
|
};
|
|
|
|
return expandedQuery;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return expandedQueries;
|
|
|
|
}
|
|
|
|
|
2019-11-27 17:45:35 -06:00
|
|
|
annotationQuery(options: any) {
|
2016-02-02 05:52:43 -06:00
|
|
|
// Graphite metric as annotation
|
|
|
|
if (options.annotation.target) {
|
2019-07-05 06:26:14 -05:00
|
|
|
const target = this.templateSrv.replace(options.annotation.target, {}, 'glob');
|
2019-11-08 03:38:10 -06:00
|
|
|
const graphiteQuery = ({
|
2020-07-08 04:05:20 -05:00
|
|
|
range: options.range,
|
2016-02-02 05:52:43 -06:00
|
|
|
targets: [{ target: target }],
|
2017-12-20 05:33:33 -06:00
|
|
|
format: 'json',
|
|
|
|
maxDataPoints: 100,
|
2019-11-08 03:38:10 -06:00
|
|
|
} as unknown) as DataQueryRequest<GraphiteQuery>;
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2019-12-04 11:07:11 -06:00
|
|
|
return this.query(graphiteQuery).then(result => {
|
2018-08-29 07:27:29 -05:00
|
|
|
const list = [];
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2018-08-30 02:03:11 -05:00
|
|
|
for (let i = 0; i < result.data.length; i++) {
|
2018-08-29 07:27:29 -05:00
|
|
|
const target = result.data[i];
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2019-12-04 11:07:11 -06:00
|
|
|
for (let y = 0; y < target.length; y++) {
|
2020-05-12 01:33:45 -05:00
|
|
|
const time = target.fields[0].values.get(y);
|
|
|
|
const value = target.fields[1].values.get(y);
|
2019-12-04 11:07:11 -06:00
|
|
|
|
|
|
|
if (!value) {
|
2017-12-19 09:06:54 -06:00
|
|
|
continue;
|
|
|
|
}
|
2016-02-02 05:52:43 -06:00
|
|
|
|
|
|
|
list.push({
|
|
|
|
annotation: options.annotation,
|
2019-12-04 11:07:11 -06:00
|
|
|
time,
|
|
|
|
title: target.name,
|
2016-02-02 05:52:43 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Graphite event as annotation
|
2019-07-05 06:26:14 -05:00
|
|
|
const tags = this.templateSrv.replace(options.annotation.tags);
|
2020-07-08 04:05:20 -05:00
|
|
|
return this.events({ range: options.range, tags: tags }).then((results: any) => {
|
2018-08-29 07:27:29 -05:00
|
|
|
const list = [];
|
2018-08-30 02:03:11 -05:00
|
|
|
for (let i = 0; i < results.data.length; i++) {
|
2018-08-29 07:27:29 -05:00
|
|
|
const e = results.data[i];
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2018-08-30 02:03:11 -05:00
|
|
|
let tags = e.tags;
|
2017-12-21 01:39:31 -06:00
|
|
|
if (_.isString(e.tags)) {
|
|
|
|
tags = this.parseTags(e.tags);
|
2017-10-07 03:31:39 -05:00
|
|
|
}
|
|
|
|
|
2017-12-21 01:39:31 -06:00
|
|
|
list.push({
|
|
|
|
annotation: options.annotation,
|
|
|
|
time: e.when * 1000,
|
|
|
|
title: e.what,
|
|
|
|
tags: tags,
|
|
|
|
text: e.data,
|
|
|
|
});
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
2017-12-21 01:39:31 -06:00
|
|
|
|
|
|
|
return list;
|
|
|
|
});
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2020-07-08 04:05:20 -05:00
|
|
|
events(options: { range: TimeRange; tags: any; timezone?: any }) {
|
2016-02-02 05:52:43 -06:00
|
|
|
try {
|
2018-08-30 02:03:11 -05:00
|
|
|
let tags = '';
|
2016-02-02 05:52:43 -06:00
|
|
|
if (options.tags) {
|
2017-12-20 05:33:33 -06:00
|
|
|
tags = '&tags=' + options.tags;
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
|
|
|
return this.doGraphiteRequest({
|
2017-12-20 05:33:33 -06:00
|
|
|
method: 'GET',
|
2017-12-19 09:06:54 -06:00
|
|
|
url:
|
2017-12-20 05:33:33 -06:00
|
|
|
'/events/get_data?from=' +
|
2020-07-08 04:05:20 -05:00
|
|
|
this.translateTime(options.range.raw.from, false, options.timezone) +
|
2017-12-20 05:33:33 -06:00
|
|
|
'&until=' +
|
2020-07-08 04:05:20 -05:00
|
|
|
this.translateTime(options.range.raw.to, true, options.timezone) +
|
2017-12-20 05:33:33 -06:00
|
|
|
tags,
|
2016-02-02 05:52:43 -06:00
|
|
|
});
|
|
|
|
} catch (err) {
|
2019-12-05 03:04:03 -06:00
|
|
|
return Promise.reject(err);
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2019-11-27 17:45:35 -06:00
|
|
|
targetContainsTemplate(target: GraphiteQuery) {
|
2020-07-08 04:05:20 -05:00
|
|
|
return this.templateSrv.variableExists(target.target ?? '');
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2016-10-11 09:00:59 -05:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
translateTime(date: any, roundUp: any, timezone: any) {
|
2016-02-02 05:52:43 -06:00
|
|
|
if (_.isString(date)) {
|
2017-12-20 05:33:33 -06:00
|
|
|
if (date === 'now') {
|
|
|
|
return 'now';
|
|
|
|
} else if (date.indexOf('now-') >= 0 && date.indexOf('/') === -1) {
|
2016-02-02 05:52:43 -06:00
|
|
|
date = date.substring(3);
|
2017-12-20 05:33:33 -06:00
|
|
|
date = date.replace('m', 'min');
|
|
|
|
date = date.replace('M', 'mon');
|
2016-02-02 05:52:43 -06:00
|
|
|
return date;
|
|
|
|
}
|
2019-02-11 05:04:27 -06:00
|
|
|
date = dateMath.parse(date, roundUp, timezone);
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// graphite' s from filter is exclusive
|
|
|
|
// here we step back one minute in order
|
|
|
|
// to guarantee that we get all the data that
|
|
|
|
// exists for the specified range
|
|
|
|
if (roundUp) {
|
2017-12-20 05:33:33 -06:00
|
|
|
if (date.get('s')) {
|
2019-09-20 07:37:03 -05:00
|
|
|
date.add(1, 's');
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
|
|
|
} else if (roundUp === false) {
|
2017-12-20 05:33:33 -06:00
|
|
|
if (date.get('s')) {
|
2019-09-20 07:37:03 -05:00
|
|
|
date.subtract(1, 's');
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return date.unix();
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2020-03-18 07:00:14 -05:00
|
|
|
metricFindQuery(query: string, optionalOptions?: any) {
|
2019-07-05 06:26:14 -05:00
|
|
|
const options: any = optionalOptions || {};
|
2019-11-03 23:43:03 -06:00
|
|
|
let interpolatedQuery = this.templateSrv.replace(
|
|
|
|
query,
|
|
|
|
getSearchFilterScopedVar({ query, wildcardChar: '', options: optionalOptions })
|
|
|
|
);
|
2017-07-31 10:21:15 -05:00
|
|
|
|
2017-12-27 14:32:15 -06:00
|
|
|
// special handling for tag_values(<tag>[,<expression>]*), this is used for template variables
|
|
|
|
let matches = interpolatedQuery.match(/^tag_values\(([^,]+)((, *[^,]+)*)\)$/);
|
|
|
|
if (matches) {
|
|
|
|
const expressions = [];
|
|
|
|
const exprRegex = /, *([^,]+)/g;
|
2018-09-05 03:53:58 -05:00
|
|
|
let match = exprRegex.exec(matches[2]);
|
|
|
|
while (match !== null) {
|
2017-12-27 14:32:15 -06:00
|
|
|
expressions.push(match[1]);
|
2018-09-05 03:53:58 -05:00
|
|
|
match = exprRegex.exec(matches[2]);
|
2017-12-27 14:32:15 -06:00
|
|
|
}
|
|
|
|
options.limit = 10000;
|
|
|
|
return this.getTagValuesAutoComplete(expressions, matches[1], undefined, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
// special handling for tags(<expression>[,<expression>]*), this is used for template variables
|
|
|
|
matches = interpolatedQuery.match(/^tags\(([^,]*)((, *[^,]+)*)\)$/);
|
|
|
|
if (matches) {
|
|
|
|
const expressions = [];
|
|
|
|
if (matches[1]) {
|
|
|
|
expressions.push(matches[1]);
|
|
|
|
const exprRegex = /, *([^,]+)/g;
|
2018-09-05 03:53:58 -05:00
|
|
|
let match = exprRegex.exec(matches[2]);
|
|
|
|
while (match !== null) {
|
2017-12-27 14:32:15 -06:00
|
|
|
expressions.push(match[1]);
|
2018-09-05 03:53:58 -05:00
|
|
|
match = exprRegex.exec(matches[2]);
|
2017-12-27 14:32:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
options.limit = 10000;
|
|
|
|
return this.getTagsAutoComplete(expressions, undefined, options);
|
|
|
|
}
|
|
|
|
|
2019-11-03 23:43:03 -06:00
|
|
|
interpolatedQuery = this.templateSrv.replace(
|
|
|
|
query,
|
|
|
|
getSearchFilterScopedVar({ query, wildcardChar: '*', options: optionalOptions })
|
|
|
|
);
|
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
const httpOptions: any = {
|
2019-06-28 08:21:32 -05:00
|
|
|
method: 'POST',
|
2017-12-20 05:33:33 -06:00
|
|
|
url: '/metrics/find',
|
2019-06-28 08:21:32 -05:00
|
|
|
params: {},
|
|
|
|
data: `query=${interpolatedQuery}`,
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
2017-07-31 10:21:15 -05:00
|
|
|
},
|
|
|
|
// for cancellations
|
2017-12-20 05:33:33 -06:00
|
|
|
requestId: options.requestId,
|
2017-07-31 10:21:15 -05:00
|
|
|
};
|
|
|
|
|
2017-12-27 14:32:15 -06:00
|
|
|
if (options.range) {
|
2019-02-11 05:04:27 -06:00
|
|
|
httpOptions.params.from = this.translateTime(options.range.from, false, options.timezone);
|
|
|
|
httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
return this.doGraphiteRequest(httpOptions).then((results: any) => {
|
2017-07-31 10:21:15 -05:00
|
|
|
return _.map(results.data, metric => {
|
2016-02-02 05:52:43 -06:00
|
|
|
return {
|
|
|
|
text: metric.text,
|
2017-12-20 05:33:33 -06:00
|
|
|
expandable: metric.expandable ? true : false,
|
2016-02-02 05:52:43 -06:00
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
getTags(optionalOptions: any) {
|
2018-08-26 10:14:40 -05:00
|
|
|
const options = optionalOptions || {};
|
2017-10-04 11:46:18 -05:00
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
const httpOptions: any = {
|
2017-12-20 05:33:33 -06:00
|
|
|
method: 'GET',
|
|
|
|
url: '/tags',
|
2017-10-04 11:46:18 -05:00
|
|
|
// for cancellations
|
2017-12-20 05:33:33 -06:00
|
|
|
requestId: options.requestId,
|
2017-10-04 11:46:18 -05:00
|
|
|
};
|
|
|
|
|
2017-12-27 14:32:15 -06:00
|
|
|
if (options.range) {
|
2019-02-11 05:04:27 -06:00
|
|
|
httpOptions.params.from = this.translateTime(options.range.from, false, options.timezone);
|
|
|
|
httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
|
2017-10-04 11:46:18 -05:00
|
|
|
}
|
|
|
|
|
2019-07-05 09:46:46 -05:00
|
|
|
return this.doGraphiteRequest(httpOptions).then((results: any) => {
|
2017-10-04 11:46:18 -05:00
|
|
|
return _.map(results.data, tag => {
|
|
|
|
return {
|
|
|
|
text: tag.tag,
|
2017-12-20 05:33:33 -06:00
|
|
|
id: tag.id,
|
2017-10-04 11:46:18 -05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2017-10-04 11:46:18 -05:00
|
|
|
|
2019-11-27 17:45:35 -06:00
|
|
|
getTagValues(options: any = {}) {
|
2018-08-26 10:14:40 -05:00
|
|
|
const httpOptions: any = {
|
2017-12-20 05:33:33 -06:00
|
|
|
method: 'GET',
|
2019-11-27 17:45:35 -06:00
|
|
|
url: '/tags/' + this.templateSrv.replace(options.key),
|
2017-10-04 11:46:18 -05:00
|
|
|
// for cancellations
|
2017-12-20 05:33:33 -06:00
|
|
|
requestId: options.requestId,
|
2017-10-04 11:46:18 -05:00
|
|
|
};
|
|
|
|
|
2017-12-27 14:32:15 -06:00
|
|
|
if (options.range) {
|
2019-02-11 05:04:27 -06:00
|
|
|
httpOptions.params.from = this.translateTime(options.range.from, false, options.timezone);
|
|
|
|
httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
|
2017-10-04 11:46:18 -05:00
|
|
|
}
|
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
return this.doGraphiteRequest(httpOptions).then((results: any) => {
|
2017-10-04 11:46:18 -05:00
|
|
|
if (results.data && results.data.values) {
|
|
|
|
return _.map(results.data.values, value => {
|
|
|
|
return {
|
|
|
|
text: value.value,
|
2017-12-20 05:33:33 -06:00
|
|
|
id: value.id,
|
2017-10-04 11:46:18 -05:00
|
|
|
};
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
});
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2017-10-04 11:46:18 -05:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
getTagsAutoComplete(expressions: any[], tagPrefix: any, optionalOptions: any) {
|
2018-08-26 10:14:40 -05:00
|
|
|
const options = optionalOptions || {};
|
2017-12-27 14:32:15 -06:00
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
const httpOptions: any = {
|
2017-12-20 05:33:33 -06:00
|
|
|
method: 'GET',
|
|
|
|
url: '/tags/autoComplete/tags',
|
2017-10-27 05:15:54 -05:00
|
|
|
params: {
|
2019-07-05 06:26:14 -05:00
|
|
|
expr: _.map(expressions, expression => this.templateSrv.replace((expression || '').trim())),
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2017-12-27 14:32:15 -06:00
|
|
|
// for cancellations
|
|
|
|
requestId: options.requestId,
|
2017-10-27 05:15:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
if (tagPrefix) {
|
|
|
|
httpOptions.params.tagPrefix = tagPrefix;
|
|
|
|
}
|
2017-12-27 14:32:15 -06:00
|
|
|
if (options.limit) {
|
|
|
|
httpOptions.params.limit = options.limit;
|
|
|
|
}
|
|
|
|
if (options.range) {
|
2019-02-11 05:04:27 -06:00
|
|
|
httpOptions.params.from = this.translateTime(options.range.from, false, options.timezone);
|
|
|
|
httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
|
2017-12-27 14:32:15 -06:00
|
|
|
}
|
2017-10-27 05:15:54 -05:00
|
|
|
|
2019-07-05 09:46:46 -05:00
|
|
|
return this.doGraphiteRequest(httpOptions).then((results: any) => {
|
2017-10-27 05:15:54 -05:00
|
|
|
if (results.data) {
|
2017-12-19 09:06:54 -06:00
|
|
|
return _.map(results.data, tag => {
|
2017-10-27 05:15:54 -05:00
|
|
|
return { text: tag };
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
});
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2017-10-27 05:15:54 -05:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
getTagValuesAutoComplete(expressions: any[], tag: any, valuePrefix: any, optionalOptions: any) {
|
2018-08-26 10:14:40 -05:00
|
|
|
const options = optionalOptions || {};
|
2017-12-27 14:32:15 -06:00
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
const httpOptions: any = {
|
2017-12-20 05:33:33 -06:00
|
|
|
method: 'GET',
|
|
|
|
url: '/tags/autoComplete/values',
|
2017-10-27 05:15:54 -05:00
|
|
|
params: {
|
2019-07-05 06:26:14 -05:00
|
|
|
expr: _.map(expressions, expression => this.templateSrv.replace((expression || '').trim())),
|
|
|
|
tag: this.templateSrv.replace((tag || '').trim()),
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2017-12-27 14:32:15 -06:00
|
|
|
// for cancellations
|
|
|
|
requestId: options.requestId,
|
2017-10-27 05:15:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
if (valuePrefix) {
|
|
|
|
httpOptions.params.valuePrefix = valuePrefix;
|
|
|
|
}
|
2017-12-27 14:32:15 -06:00
|
|
|
if (options.limit) {
|
|
|
|
httpOptions.params.limit = options.limit;
|
|
|
|
}
|
|
|
|
if (options.range) {
|
2019-02-11 05:04:27 -06:00
|
|
|
httpOptions.params.from = this.translateTime(options.range.from, false, options.timezone);
|
|
|
|
httpOptions.params.until = this.translateTime(options.range.to, true, options.timezone);
|
2017-12-27 14:32:15 -06:00
|
|
|
}
|
2017-10-27 05:15:54 -05:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
return this.doGraphiteRequest(httpOptions).then((results: any) => {
|
2017-10-27 05:15:54 -05:00
|
|
|
if (results.data) {
|
2017-12-19 09:06:54 -06:00
|
|
|
return _.map(results.data, value => {
|
2017-10-27 05:15:54 -05:00
|
|
|
return { text: value };
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
});
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2017-10-27 05:15:54 -05:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
getVersion(optionalOptions: any) {
|
2018-08-26 10:14:40 -05:00
|
|
|
const options = optionalOptions || {};
|
2017-12-27 14:32:15 -06:00
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
const httpOptions = {
|
2017-12-20 05:33:33 -06:00
|
|
|
method: 'GET',
|
2018-01-12 06:07:50 -06:00
|
|
|
url: '/version',
|
2017-12-27 14:32:15 -06:00
|
|
|
requestId: options.requestId,
|
2017-10-20 08:25:19 -05:00
|
|
|
};
|
|
|
|
|
2017-12-19 09:06:54 -06:00
|
|
|
return this.doGraphiteRequest(httpOptions)
|
2019-07-05 06:26:14 -05:00
|
|
|
.then((results: any) => {
|
2017-12-19 09:06:54 -06:00
|
|
|
if (results.data) {
|
2018-08-26 10:14:40 -05:00
|
|
|
const semver = new SemVersion(results.data);
|
2017-12-20 05:33:33 -06:00
|
|
|
return semver.isValid() ? results.data : '';
|
2017-12-19 09:06:54 -06:00
|
|
|
}
|
2017-12-20 05:33:33 -06:00
|
|
|
return '';
|
2017-12-19 09:06:54 -06:00
|
|
|
})
|
|
|
|
.catch(() => {
|
2017-12-20 05:33:33 -06:00
|
|
|
return '';
|
2017-12-19 09:06:54 -06:00
|
|
|
});
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2017-10-20 08:25:19 -05:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
createFuncInstance(funcDef: any, options?: any) {
|
2017-12-08 17:48:39 -06:00
|
|
|
return gfunc.createFuncInstance(funcDef, options, this.funcDefs);
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2017-12-08 17:48:39 -06:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
getFuncDef(name: string) {
|
2017-12-08 17:48:39 -06:00
|
|
|
return gfunc.getFuncDef(name, this.funcDefs);
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2017-12-08 17:48:39 -06:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
waitForFuncDefsLoaded() {
|
2018-01-12 05:31:27 -06:00
|
|
|
return this.getFuncDefs();
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2017-12-08 17:48:39 -06:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
getFuncDefs() {
|
2018-01-12 05:31:27 -06:00
|
|
|
if (this.funcDefsPromise !== null) {
|
|
|
|
return this.funcDefsPromise;
|
2017-12-08 17:48:39 -06:00
|
|
|
}
|
|
|
|
|
2018-01-12 05:31:27 -06:00
|
|
|
if (!supportsFunctionIndex(this.graphiteVersion)) {
|
|
|
|
this.funcDefs = gfunc.getFuncDefs(this.graphiteVersion);
|
|
|
|
this.funcDefsPromise = Promise.resolve(this.funcDefs);
|
|
|
|
return this.funcDefsPromise;
|
2017-12-08 17:48:39 -06:00
|
|
|
}
|
|
|
|
|
2018-08-26 10:14:40 -05:00
|
|
|
const httpOptions = {
|
2017-12-08 17:48:39 -06:00
|
|
|
method: 'GET',
|
|
|
|
url: '/functions',
|
|
|
|
};
|
|
|
|
|
2018-01-12 05:31:27 -06:00
|
|
|
this.funcDefsPromise = this.doGraphiteRequest(httpOptions)
|
2019-07-05 06:26:14 -05:00
|
|
|
.then((results: any) => {
|
2017-12-08 17:48:39 -06:00
|
|
|
if (results.status !== 200 || typeof results.data !== 'object') {
|
2018-01-12 05:31:27 -06:00
|
|
|
this.funcDefs = gfunc.getFuncDefs(this.graphiteVersion);
|
2018-01-16 17:04:59 -06:00
|
|
|
} else {
|
|
|
|
this.funcDefs = gfunc.parseFuncDefs(results.data);
|
2017-12-08 17:48:39 -06:00
|
|
|
}
|
2018-01-12 05:31:27 -06:00
|
|
|
return this.funcDefs;
|
2017-12-08 17:48:39 -06:00
|
|
|
})
|
2019-07-05 09:46:46 -05:00
|
|
|
.catch((err: any) => {
|
2018-01-12 05:31:27 -06:00
|
|
|
console.log('Fetching graphite functions error', err);
|
|
|
|
this.funcDefs = gfunc.getFuncDefs(this.graphiteVersion);
|
|
|
|
return this.funcDefs;
|
2017-12-08 17:48:39 -06:00
|
|
|
});
|
2018-01-11 10:21:02 -06:00
|
|
|
|
2018-01-12 05:31:27 -06:00
|
|
|
return this.funcDefsPromise;
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2017-12-08 17:48:39 -06:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
testDatasource() {
|
2019-11-08 03:38:10 -06:00
|
|
|
const query = ({
|
2018-04-05 11:11:35 -05:00
|
|
|
panelId: 3,
|
|
|
|
rangeRaw: { from: 'now-1h', to: 'now' },
|
|
|
|
targets: [{ target: 'constantLine(100)' }],
|
|
|
|
maxDataPoints: 300,
|
2019-11-08 03:38:10 -06:00
|
|
|
} as unknown) as DataQueryRequest<GraphiteQuery>;
|
2018-09-04 10:02:32 -05:00
|
|
|
return this.query(query).then(() => {
|
2017-12-20 05:33:33 -06:00
|
|
|
return { status: 'success', message: 'Data source is working' };
|
2016-02-02 05:52:43 -06:00
|
|
|
});
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
doGraphiteRequest(options: {
|
|
|
|
method?: string;
|
|
|
|
url: any;
|
|
|
|
requestId?: any;
|
|
|
|
withCredentials?: any;
|
|
|
|
headers?: any;
|
|
|
|
inspect?: any;
|
|
|
|
}) {
|
2016-02-02 05:52:43 -06:00
|
|
|
if (this.basicAuth || this.withCredentials) {
|
|
|
|
options.withCredentials = true;
|
|
|
|
}
|
|
|
|
if (this.basicAuth) {
|
|
|
|
options.headers = options.headers || {};
|
|
|
|
options.headers.Authorization = this.basicAuth;
|
|
|
|
}
|
|
|
|
|
|
|
|
options.url = this.url + options.url;
|
2017-12-20 05:33:33 -06:00
|
|
|
options.inspect = { type: 'graphite' };
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2020-01-21 03:08:07 -06:00
|
|
|
return getBackendSrv().datasourceRequest(options);
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2020-03-18 07:00:14 -05:00
|
|
|
buildGraphiteParams(options: any, scopedVars?: ScopedVars): string[] {
|
2018-09-03 04:00:46 -05:00
|
|
|
const graphiteOptions = ['from', 'until', 'rawData', 'format', 'maxDataPoints', 'cacheTimeout'];
|
|
|
|
const cleanOptions = [],
|
2019-07-05 09:46:46 -05:00
|
|
|
targets: any = {};
|
2018-08-30 02:03:11 -05:00
|
|
|
let target, targetValue, i;
|
2018-08-29 07:27:29 -05:00
|
|
|
const regex = /\#([A-Z])/g;
|
|
|
|
const intervalFormatFixRegex = /'(\d+)m'/gi;
|
2018-08-30 02:03:11 -05:00
|
|
|
let hasTargets = false;
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
options['format'] = 'json';
|
2016-02-02 05:52:43 -06:00
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
function fixIntervalFormat(match: any) {
|
2017-12-20 05:33:33 -06:00
|
|
|
return match.replace('m', 'min').replace('M', 'mon');
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < options.targets.length; i++) {
|
|
|
|
target = options.targets[i];
|
|
|
|
if (!target.target) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!target.refId) {
|
|
|
|
target.refId = this._seriesRefLetters[i];
|
|
|
|
}
|
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
targetValue = this.templateSrv.replace(target.target, scopedVars);
|
2017-12-21 01:39:31 -06:00
|
|
|
targetValue = targetValue.replace(intervalFormatFixRegex, fixIntervalFormat);
|
2016-02-02 05:52:43 -06:00
|
|
|
targets[target.refId] = targetValue;
|
|
|
|
}
|
|
|
|
|
2019-07-05 06:26:14 -05:00
|
|
|
function nestedSeriesRegexReplacer(match: any, g1: string | number) {
|
2016-07-14 03:29:22 -05:00
|
|
|
return targets[g1] || match;
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < options.targets.length; i++) {
|
|
|
|
target = options.targets[i];
|
|
|
|
if (!target.target) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
targetValue = targets[target.refId];
|
|
|
|
targetValue = targetValue.replace(regex, nestedSeriesRegexReplacer);
|
|
|
|
targets[target.refId] = targetValue;
|
|
|
|
|
|
|
|
if (!target.hide) {
|
|
|
|
hasTargets = true;
|
2018-09-03 04:00:46 -05:00
|
|
|
cleanOptions.push('target=' + encodeURIComponent(targetValue));
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-04 10:02:32 -05:00
|
|
|
_.each(options, (value, key) => {
|
2018-09-03 04:00:46 -05:00
|
|
|
if (_.indexOf(graphiteOptions, key) === -1) {
|
2017-12-19 09:06:54 -06:00
|
|
|
return;
|
|
|
|
}
|
2016-02-02 05:52:43 -06:00
|
|
|
if (value) {
|
2018-09-03 04:00:46 -05:00
|
|
|
cleanOptions.push(key + '=' + encodeURIComponent(value));
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!hasTargets) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2018-09-03 04:00:46 -05:00
|
|
|
return cleanOptions;
|
2019-07-05 06:26:14 -05:00
|
|
|
}
|
2016-02-02 05:52:43 -06:00
|
|
|
}
|
2017-10-20 03:23:14 -05:00
|
|
|
|
|
|
|
function supportsTags(version: string): boolean {
|
2017-12-20 05:33:33 -06:00
|
|
|
return isVersionGtOrEq(version, '1.1');
|
2017-10-20 03:23:14 -05:00
|
|
|
}
|
2017-12-08 17:48:39 -06:00
|
|
|
|
|
|
|
function supportsFunctionIndex(version: string): boolean {
|
|
|
|
return isVersionGtOrEq(version, '1.1');
|
|
|
|
}
|