[v9.5.x] InfluxDB: Interpolate retention policies (#69299)
InfluxDB: Interpolate retention policies (#69202)
Interpolate retention policies
(cherry picked from commit f610e37aec)
Co-authored-by: ismail simsek <ismailsimsek09@gmail.com>
This commit is contained in:
co-authored by
ismail simsek
parent
8f9c2e6198
commit
4e6fd701f7
@@ -2,7 +2,7 @@ import { css } from '@emotion/css';
|
|||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { useAsync } from 'react-use';
|
import { useAsync } from 'react-use';
|
||||||
|
|
||||||
import { GrafanaTheme2 } from '@grafana/data';
|
import { GrafanaTheme2, TypedVariableModel } from '@grafana/data';
|
||||||
import { getTemplateSrv } from '@grafana/runtime';
|
import { getTemplateSrv } from '@grafana/runtime';
|
||||||
import { InlineLabel, SegmentSection, useStyles2 } from '@grafana/ui';
|
import { InlineLabel, SegmentSection, useStyles2 } from '@grafana/ui';
|
||||||
|
|
||||||
@@ -42,19 +42,31 @@ type Props = {
|
|||||||
datasource: InfluxDatasource;
|
datasource: InfluxDatasource;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getTemplateVariableOptions() {
|
function wrapRegex(v: TypedVariableModel): string {
|
||||||
|
return `/^$${v.name}$/`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function wrapPure(v: TypedVariableModel): string {
|
||||||
|
return `$${v.name}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTemplateVariableOptions(wrapper: (v: TypedVariableModel) => string) {
|
||||||
return (
|
return (
|
||||||
getTemplateSrv()
|
getTemplateSrv()
|
||||||
.getVariables()
|
.getVariables()
|
||||||
// we make them regex-params, i'm not 100% sure why.
|
// we make them regex-params, i'm not 100% sure why.
|
||||||
// probably because this way multi-value variables work ok too.
|
// probably because this way multi-value variables work ok too.
|
||||||
.map((v) => `/^$${v.name}$/`)
|
.map(wrapper)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to make it easy to call this from the widget-render-code
|
// helper function to make it easy to call this from the widget-render-code
|
||||||
function withTemplateVariableOptions(optionsPromise: Promise<string[]>, filter?: string): Promise<string[]> {
|
function withTemplateVariableOptions(
|
||||||
let templateVariableOptions = getTemplateVariableOptions();
|
optionsPromise: Promise<string[]>,
|
||||||
|
wrapper: (v: TypedVariableModel) => string,
|
||||||
|
filter?: string
|
||||||
|
): Promise<string[]> {
|
||||||
|
let templateVariableOptions = getTemplateVariableOptions(wrapper);
|
||||||
if (filter) {
|
if (filter) {
|
||||||
templateVariableOptions = templateVariableOptions.filter((tvo) => tvo.indexOf(filter) > -1);
|
templateVariableOptions = templateVariableOptions.filter((tvo) => tvo.indexOf(filter) > -1);
|
||||||
}
|
}
|
||||||
@@ -149,7 +161,12 @@ export const Editor = (props: Props): JSX.Element => {
|
|||||||
<FromSection
|
<FromSection
|
||||||
policy={policy ?? retentionPolicies[0]}
|
policy={policy ?? retentionPolicies[0]}
|
||||||
measurement={measurement}
|
measurement={measurement}
|
||||||
getPolicyOptions={() => getAllPolicies(datasource)}
|
getPolicyOptions={() =>
|
||||||
|
withTemplateVariableOptions(
|
||||||
|
allTagKeys.then((keys) => getAllPolicies(datasource)),
|
||||||
|
wrapPure
|
||||||
|
)
|
||||||
|
}
|
||||||
getMeasurementOptions={(filter) =>
|
getMeasurementOptions={(filter) =>
|
||||||
withTemplateVariableOptions(
|
withTemplateVariableOptions(
|
||||||
allTagKeys.then((keys) =>
|
allTagKeys.then((keys) =>
|
||||||
@@ -159,6 +176,7 @@ export const Editor = (props: Props): JSX.Element => {
|
|||||||
datasource
|
datasource
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
wrapRegex,
|
||||||
filter
|
filter
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -175,7 +193,8 @@ export const Editor = (props: Props): JSX.Element => {
|
|||||||
withTemplateVariableOptions(
|
withTemplateVariableOptions(
|
||||||
allTagKeys.then((keys) =>
|
allTagKeys.then((keys) =>
|
||||||
getTagValues(key, measurement, policy, filterTags(query.tags ?? [], keys), datasource)
|
getTagValues(key, measurement, policy, filterTags(query.tags ?? [], keys), datasource)
|
||||||
)
|
),
|
||||||
|
wrapRegex
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -200,10 +200,13 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
|||||||
this.retentionPolicies = allPolicies;
|
this.retentionPolicies = allPolicies;
|
||||||
const policyFixedRequests = {
|
const policyFixedRequests = {
|
||||||
...request,
|
...request,
|
||||||
targets: request.targets.map((t) => ({
|
targets: request.targets.map((t) => {
|
||||||
...t,
|
t.policy = t.policy ? this.templateSrv.replace(t.policy, {}, 'regex') : '';
|
||||||
policy: replaceHardCodedRetentionPolicy(t.policy, this.retentionPolicies),
|
return {
|
||||||
})),
|
...t,
|
||||||
|
policy: replaceHardCodedRetentionPolicy(t.policy, this.retentionPolicies),
|
||||||
|
};
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
return this._query(policyFixedRequests);
|
return this._query(policyFixedRequests);
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user