Opentsdb: Add variables to select when interacting with the metric select (#78558)

add variables to select when interacting with the metric select
This commit is contained in:
Brendan O'Handley 2023-11-23 06:32:35 -05:00 committed by GitHub
parent 58a0ff7459
commit 7cf173b651
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -16,8 +16,16 @@ const setup = (propOverrides?: Object) => {
aggregator: 'avg',
alias: 'alias',
};
const varQuery: OpenTsdbQuery = {
metric: '$variable',
refId: 'A',
aggregator: 'avg',
alias: 'alias',
};
const props: MetricSectionProps = {
query,
query: !propOverrides ? query : varQuery,
onChange: onChange,
onRunQuery: onRunQuery,
suggestMetrics: suggestMetrics,
@ -42,6 +50,11 @@ describe('MetricSection', () => {
setup();
expect(screen.getByText('cpu')).toBeInTheDocument();
});
it('should display variables in the metrics select', () => {
setup({ variables: true });
expect(screen.getByText('$variable')).toBeInTheDocument();
});
});
describe('metric aggregator', () => {

View File

@ -93,12 +93,21 @@ export function OpenTsdbQueryEditor({
}
function getTextValues(metrics: Array<{ text: string }>) {
return metrics.map((value: { text: string }) => {
const variables = datasource.getVariables().map((value) => {
return {
value: textUtil.escapeHtml(value),
description: value,
};
});
const values = metrics.map((value: { text: string }) => {
return {
value: textUtil.escapeHtml(value.text),
description: value.text,
};
});
return variables.concat(values);
}
return (

View File

@ -550,6 +550,10 @@ export default class OpenTsDatasource extends DataSourceApi<OpenTsdbQuery, OpenT
});
}
getVariables(): string[] {
return this.templateSrv.getVariables().map((v) => `$${v.name}`);
}
mapMetricsToTargets(metrics: any, options: any, tsdbVersion: number) {
let interpolatedTagValue, arrTagV;
return _map(metrics, (metricData) => {