@perses-dev/prometheus-plugin 0.0.0-snapshot-panel-extra-content-2-2767e21 → 0.0.0-snapshot-scatter-chart-embed-8efdfab
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/PromQL.js +9 -7
- package/dist/cjs/components/index.js +10 -8
- package/dist/cjs/index.js +33 -19
- package/dist/cjs/model/index.js +15 -13
- package/dist/cjs/model/parse-sample-values.js +6 -2
- package/dist/cjs/model/prometheus-client.js +40 -5
- package/dist/cjs/model/prometheus-selectors.js +12 -4
- package/dist/cjs/model/templating.js +7 -5
- package/dist/cjs/model/time.js +14 -8
- package/dist/cjs/plugins/MatcherEditor.js +13 -11
- package/dist/cjs/plugins/PrometheusDatasourceEditor.js +612 -0
- package/dist/cjs/plugins/prometheus-datasource.js +58 -6
- package/dist/cjs/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.js +88 -0
- package/dist/cjs/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.js +123 -0
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +10 -8
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +48 -50
- package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +41 -21
- package/dist/cjs/plugins/prometheus-time-series-query/index.js +10 -8
- package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +42 -9
- package/dist/cjs/plugins/prometheus-variables.js +60 -54
- package/dist/cjs/plugins/types.js +7 -0
- package/dist/cjs/plugins/variable.js +9 -7
- package/dist/cjs/utils/index.js +10 -8
- package/dist/cjs/utils/utils.js +12 -6
- package/dist/components/PromQL.js.map +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/parse-sample-values.js.map +1 -1
- package/dist/model/prometheus-client.d.ts +4 -0
- package/dist/model/prometheus-client.d.ts.map +1 -1
- package/dist/model/prometheus-client.js +24 -0
- package/dist/model/prometheus-client.js.map +1 -1
- package/dist/model/prometheus-selectors.js.map +1 -1
- package/dist/model/templating.js.map +1 -1
- package/dist/model/time.js +1 -1
- package/dist/model/time.js.map +1 -1
- package/dist/plugins/MatcherEditor.js.map +1 -1
- package/dist/plugins/PrometheusDatasourceEditor.d.ts +9 -0
- package/dist/plugins/PrometheusDatasourceEditor.d.ts.map +1 -0
- package/dist/plugins/PrometheusDatasourceEditor.js +560 -0
- package/dist/plugins/PrometheusDatasourceEditor.js.map +1 -0
- package/dist/plugins/prometheus-datasource.d.ts +1 -5
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
- package/dist/plugins/prometheus-datasource.js +56 -6
- package/dist/plugins/prometheus-datasource.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.d.ts +21 -0
- package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.js +80 -0
- package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.d.ts +21 -0
- package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.js +115 -0
- package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +43 -47
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +34 -16
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +10 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js +36 -8
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts +2 -2
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
- package/dist/plugins/prometheus-variables.js +27 -27
- package/dist/plugins/prometheus-variables.js.map +1 -1
- package/dist/plugins/types.d.ts +9 -2
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/plugins/types.js +1 -1
- package/dist/plugins/types.js.map +1 -1
- package/dist/plugins/variable.js +2 -2
- package/dist/plugins/variable.js.map +1 -1
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js +3 -3
- package/dist/utils/utils.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { produce } from 'immer';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { produce } from 'immer';\nimport { DatasourceSelectProps, useDatasource, useDatasourceClient } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PrometheusClient } from '../../model';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport {\n PrometheusTimeSeriesQueryEditorProps,\n useQueryState,\n useFormatState,\n useMinStepState,\n} from './query-editor-model';\nimport { DashboardPrometheusTimeSeriesQueryEditor } from './DashboardPrometheusTimeSeriesQueryEditor';\nimport { ExplorePrometheusTimeSeriesQueryEditor } from './ExplorePrometheusTimeSeriesQueryEditor';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value, isExplore } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n const { data: datasourceResource } = useDatasource(selectedDatasource);\n\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\n const { minStep, handleMinStepChange, handleMinStepBlur } = useMinStepState(props);\n const minStepPlaceholder =\n minStep ??\n (datasourceResource && (datasourceResource?.plugin.spec as PrometheusDatasourceSpec).scrapeInterval) ??\n DEFAULT_SCRAPE_INTERVAL;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n if (isExplore) {\n return (\n <ExplorePrometheusTimeSeriesQueryEditor\n selectedDatasource={selectedDatasource}\n handleDatasourceChange={handleDatasourceChange}\n promURL={promURL}\n query={query}\n handleQueryChange={handleQueryChange}\n handleQueryBlur={handleQueryBlur}\n format={format}\n handleFormatChange={handleFormatChange}\n handleFormatBlur={handleFormatBlur}\n minStepPlaceholder={minStepPlaceholder}\n minStep={minStep}\n handleMinStepChange={handleMinStepChange}\n handleMinStepBlur={handleMinStepBlur}\n />\n );\n }\n\n return (\n <DashboardPrometheusTimeSeriesQueryEditor\n selectedDatasource={selectedDatasource}\n handleDatasourceChange={handleDatasourceChange}\n promURL={promURL}\n query={query}\n handleQueryChange={handleQueryChange}\n handleQueryBlur={handleQueryBlur}\n format={format}\n handleFormatChange={handleFormatChange}\n handleFormatBlur={handleFormatBlur}\n minStepPlaceholder={minStepPlaceholder}\n minStep={minStep}\n handleMinStepChange={handleMinStepChange}\n handleMinStepBlur={handleMinStepBlur}\n />\n );\n}\n"],"names":["produce","useDatasource","useDatasourceClient","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","DEFAULT_SCRAPE_INTERVAL","useQueryState","useFormatState","useMinStepState","DashboardPrometheusTimeSeriesQueryEditor","ExplorePrometheusTimeSeriesQueryEditor","PrometheusTimeSeriesQueryEditor","props","onChange","value","isExplore","datasource","selectedDatasource","data","client","promURL","options","datasourceUrl","datasourceResource","query","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","minStep","handleMinStepChange","handleMinStepBlur","minStepPlaceholder","plugin","spec","scrapeInterval","handleDatasourceChange","next","draft","nextDatasource","undefined","Error"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,OAAO,QAAQ,QAAQ;AAChC,SAAgCC,aAAa,EAAEC,mBAAmB,QAAQ,4BAA4B;AACtG,SAASC,YAAY,EAAEC,qBAAqB,EAAEC,8BAA8B,QAA0B,cAAc;AACpH,SAASC,uBAAuB,QAAkC,WAAW;AAC7E,SAEEC,aAAa,EACbC,cAAc,EACdC,eAAe,QACV,uBAAuB;AAC9B,SAASC,wCAAwC,QAAQ,6CAA6C;AACtG,SAASC,sCAAsC,QAAQ,2CAA2C;AAElG;;CAEC,GACD,OAAO,SAASC,gCAAgCC,KAA2C;IACzF,MAAM,EAAEC,SAAQ,EAAEC,MAAK,EAAEC,UAAS,EAAE,GAAGH;IACvC,MAAM,EAAEI,WAAU,EAAE,GAAGF;IACvB,MAAMG,qBAAqBD,uBAAAA,wBAAAA,aAAcd;IAEzC,MAAM,EAAEgB,MAAMC,OAAM,EAAE,GAAGlB,oBAAsCgB;IAC/D,MAAMG,UAAUD,mBAAAA,oBAAAA,KAAAA,IAAAA,OAAQE,QAAQC;IAChC,MAAM,EAAEJ,MAAMK,mBAAkB,EAAE,GAAGvB,cAAciB;IAEnD,MAAM,EAAEO,MAAK,EAAEC,kBAAiB,EAAEC,gBAAe,EAAE,GAAGpB,cAAcM;IACpE,MAAM,EAAEe,OAAM,EAAEC,mBAAkB,EAAEC,iBAAgB,EAAE,GAAGtB,eAAeK;IACxE,MAAM,EAAEkB,QAAO,EAAEC,oBAAmB,EAAEC,kBAAiB,EAAE,GAAGxB,gBAAgBI;QAE1EkB;IADF,MAAMG,qBACJH,CAAAA,OAAAA,oBAAAA,qBAAAA,UACCP,sBAAsB,CAACA,+BAAAA,gCAAAA,KAAAA,IAAAA,mBAAoBW,OAAOC,IAAgC,EAAEC,4BADrFN,kBAAAA,OAEAzB;IAEF,MAAMgC,yBAA4D,CAACC;QACjE,IAAIlC,+BAA+BkC,OAAO;YACxCzB,SACEd,QAAQe,OAAO,CAACyB;gBACd,sFAAsF;gBACtF,MAAMC,iBAAiBrC,sBAAsBmC,QAAQG,YAAYH;gBACjEC,MAAMvB,aAAawB;YACrB;YAEF;QACF;QAEA,MAAM,IAAIE,MAAM;IAClB;IAEA,IAAI3B,WAAW;QACb,qBACE,KAACL;YACCO,oBAAoBA;YACpBoB,wBAAwBA;YACxBjB,SAASA;YACTI,OAAOA;YACPC,mBAAmBA;YACnBC,iBAAiBA;YACjBC,QAAQA;YACRC,oBAAoBA;YACpBC,kBAAkBA;YAClBI,oBAAoBA;YACpBH,SAASA;YACTC,qBAAqBA;YACrBC,mBAAmBA;;IAGzB;IAEA,qBACE,KAACvB;QACCQ,oBAAoBA;QACpBoB,wBAAwBA;QACxBjB,SAASA;QACTI,OAAOA;QACPC,mBAAmBA;QACnBC,iBAAiBA;QACjBC,QAAQA;QACRC,oBAAoBA;QACpBC,kBAAkBA;QAClBI,oBAAoBA;QACpBH,SAASA;QACTC,qBAAqBA;QACrBC,mBAAmBA;;AAGzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,qBAAqB,EAAqD,MAAM,2BAA2B,CAAC;AAYrH,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CA0GvG,CAAC"}
|
|
@@ -10,21 +10,30 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { formatDuration, msToPrometheusDuration, parseDurationString } from '@perses-dev/core';
|
|
14
|
+
import { replaceTemplateVariables, replaceTemplateVariable } from '@perses-dev/plugin-system';
|
|
15
|
+
import { fromUnixTime, milliseconds } from 'date-fns';
|
|
15
16
|
import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, DEFAULT_PROM } from '../../model';
|
|
16
17
|
import { getFormattedPrometheusSeriesName } from '../../utils';
|
|
18
|
+
import { DEFAULT_SCRAPE_INTERVAL } from '../types';
|
|
17
19
|
export const getTimeSeriesData = async (spec, context)=>{
|
|
18
|
-
var
|
|
20
|
+
var _response_data;
|
|
19
21
|
if (spec.query === undefined || spec.query === null || spec.query === '') {
|
|
20
22
|
// Do not make a request to the backend, instead return an empty TimeSeriesData
|
|
21
23
|
return {
|
|
22
24
|
series: []
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
|
-
|
|
27
|
+
var _spec_datasource;
|
|
28
|
+
const datasource = await context.datasourceStore.getDatasource((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
|
|
29
|
+
var _datasource_plugin_spec_scrapeInterval;
|
|
30
|
+
const datasourceScrapeInterval = Math.trunc(milliseconds(parseDurationString((_datasource_plugin_spec_scrapeInterval = datasource.plugin.spec.scrapeInterval) !== null && _datasource_plugin_spec_scrapeInterval !== void 0 ? _datasource_plugin_spec_scrapeInterval : DEFAULT_SCRAPE_INTERVAL)) / 1000);
|
|
31
|
+
var _getDurationStringSeconds;
|
|
32
|
+
const minStep = (_getDurationStringSeconds = getDurationStringSeconds(// resolve any variable that may have been provided
|
|
33
|
+
// TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here
|
|
34
|
+
replaceTemplateVariables(spec.minStep, context.variableState))) !== null && _getDurationStringSeconds !== void 0 ? _getDurationStringSeconds : datasourceScrapeInterval;
|
|
26
35
|
const timeRange = getPrometheusTimeRange(context.timeRange);
|
|
27
|
-
const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs);
|
|
36
|
+
const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution
|
|
28
37
|
// Align the time range so that it's a multiple of the step
|
|
29
38
|
let { start , end } = timeRange;
|
|
30
39
|
const utcOffsetSec = new Date().getTimezoneOffset() * 60;
|
|
@@ -32,17 +41,26 @@ export const getTimeSeriesData = async (spec, context)=>{
|
|
|
32
41
|
const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
|
|
33
42
|
start = alignedStart;
|
|
34
43
|
end = alignedEnd;
|
|
44
|
+
var _context_suggestedStepMs;
|
|
35
45
|
// Replace template variable placeholders in PromQL query
|
|
36
|
-
|
|
46
|
+
const intervalMs = (_context_suggestedStepMs = context.suggestedStepMs) !== null && _context_suggestedStepMs !== void 0 ? _context_suggestedStepMs : step * 1000; // Step is in seconds
|
|
47
|
+
let query = replaceTemplateVariable(spec.query, '__interval_ms', intervalMs.toString());
|
|
48
|
+
query = replaceTemplateVariable(spec.query, '__interval', formatDuration(msToPrometheusDuration(intervalMs)));
|
|
49
|
+
const scrapeIntervalMs = minStep * 1000;
|
|
50
|
+
// The $__rate_interval variable is meant to be used in the rate function.
|
|
51
|
+
// It is defined as max($__interval + Scrape interval, 4 * Scrape interval), where Scrape interval is the Min step setting (a setting per PromQL query),
|
|
52
|
+
// if any is set, and otherwise the Scrape interval as set in the Prometheus datasource
|
|
53
|
+
const rateIntervalMs = Math.max(intervalMs + scrapeIntervalMs, 4 * scrapeIntervalMs);
|
|
54
|
+
query = replaceTemplateVariable(query, '__rate_interval', formatDuration(msToPrometheusDuration(rateIntervalMs)));
|
|
37
55
|
query = replaceTemplateVariables(query, context.variableState);
|
|
38
|
-
let seriesNameFormat = spec.
|
|
56
|
+
let seriesNameFormat = spec.seriesNameFormat;
|
|
39
57
|
// if series name format is defined, replace template variable placeholders in series name format
|
|
40
58
|
if (seriesNameFormat) {
|
|
41
59
|
seriesNameFormat = replaceTemplateVariables(seriesNameFormat, context.variableState);
|
|
42
60
|
}
|
|
43
|
-
var
|
|
61
|
+
var _spec_datasource1;
|
|
44
62
|
// Get the datasource, using the default Prom Datasource if one isn't specified in the query
|
|
45
|
-
const client = await context.datasourceStore.getDatasourceClient((
|
|
63
|
+
const client = await context.datasourceStore.getDatasourceClient((_spec_datasource1 = spec.datasource) !== null && _spec_datasource1 !== void 0 ? _spec_datasource1 : DEFAULT_PROM);
|
|
46
64
|
// Make the request to Prom
|
|
47
65
|
const response = await client.rangeQuery({
|
|
48
66
|
query,
|
|
@@ -50,16 +68,16 @@ export const getTimeSeriesData = async (spec, context)=>{
|
|
|
50
68
|
end,
|
|
51
69
|
step
|
|
52
70
|
});
|
|
53
|
-
var
|
|
71
|
+
var _response_data_result;
|
|
54
72
|
// TODO: What about error responses from Prom that have a response body?
|
|
55
|
-
const result = (
|
|
73
|
+
const result = (_response_data_result = (_response_data = response.data) === null || _response_data === void 0 ? void 0 : _response_data.result) !== null && _response_data_result !== void 0 ? _response_data_result : [];
|
|
56
74
|
// Custom display for response header warnings, configurable error responses display coming next
|
|
57
75
|
const notices = [];
|
|
58
76
|
if (response.status === 'success') {
|
|
59
|
-
var
|
|
60
|
-
const warnings = (
|
|
61
|
-
var
|
|
62
|
-
const warningMessage = (
|
|
77
|
+
var _response_warnings;
|
|
78
|
+
const warnings = (_response_warnings = response.warnings) !== null && _response_warnings !== void 0 ? _response_warnings : [];
|
|
79
|
+
var _warnings_;
|
|
80
|
+
const warningMessage = (_warnings_ = warnings[0]) !== null && _warnings_ !== void 0 ? _warnings_ : '';
|
|
63
81
|
if (warningMessage !== '') {
|
|
64
82
|
notices.push({
|
|
65
83
|
type: 'warning',
|
|
@@ -77,7 +95,7 @@ export const getTimeSeriesData = async (spec, context)=>{
|
|
|
77
95
|
stepMs: step * 1000,
|
|
78
96
|
series: result.map((value)=>{
|
|
79
97
|
const { metric , values } = value;
|
|
80
|
-
// Account for
|
|
98
|
+
// Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.
|
|
81
99
|
const { name , formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);
|
|
82
100
|
return {
|
|
83
101
|
name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n DatasourceSpec,\n DurationString,\n formatDuration,\n msToPrometheusDuration,\n Notice,\n parseDurationString,\n TimeSeriesData,\n} from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceTemplateVariables, replaceTemplateVariable } from '@perses-dev/plugin-system';\nimport { fromUnixTime, milliseconds } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const datasource = (await context.datasourceStore.getDatasource(\n spec.datasource ?? DEFAULT_PROM\n )) as DatasourceSpec<PrometheusDatasourceSpec>;\n const datasourceScrapeInterval = Math.trunc(\n milliseconds(parseDurationString(datasource.plugin.spec.scrapeInterval ?? DEFAULT_SCRAPE_INTERVAL)) / 1000\n );\n\n const minStep =\n getDurationStringSeconds(\n // resolve any variable that may have been provided\n // TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here\n replaceTemplateVariables(spec.minStep as string, context.variableState) as DurationString\n ) ?? datasourceScrapeInterval;\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n // Replace template variable placeholders in PromQL query\n const intervalMs = context.suggestedStepMs ?? step * 1000; // Step is in seconds\n let query = replaceTemplateVariable(spec.query, '__interval_ms', intervalMs.toString());\n query = replaceTemplateVariable(spec.query, '__interval', formatDuration(msToPrometheusDuration(intervalMs)));\n\n const scrapeIntervalMs = minStep * 1000;\n // The $__rate_interval variable is meant to be used in the rate function.\n // It is defined as max($__interval + Scrape interval, 4 * Scrape interval), where Scrape interval is the Min step setting (a setting per PromQL query),\n // if any is set, and otherwise the Scrape interval as set in the Prometheus datasource\n const rateIntervalMs = Math.max(intervalMs + scrapeIntervalMs, 4 * scrapeIntervalMs);\n query = replaceTemplateVariable(query, '__rate_interval', formatDuration(msToPrometheusDuration(rateIntervalMs)));\n query = replaceTemplateVariables(query, context.variableState);\n\n let seriesNameFormat = spec.seriesNameFormat;\n // if series name format is defined, replace template variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceTemplateVariables(seriesNameFormat, context.variableState);\n }\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n\n // Make the request to Prom\n const response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data?.result ?? [];\n\n // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n series: result.map((value) => {\n const { metric, values } = value;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n labels: metric,\n };\n }),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n"],"names":["formatDuration","msToPrometheusDuration","parseDurationString","replaceTemplateVariables","replaceTemplateVariable","fromUnixTime","milliseconds","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getFormattedPrometheusSeriesName","DEFAULT_SCRAPE_INTERVAL","getTimeSeriesData","spec","context","response","query","undefined","series","datasource","datasourceStore","getDatasource","datasourceScrapeInterval","Math","trunc","plugin","scrapeInterval","minStep","variableState","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","floor","alignedStart","intervalMs","toString","scrapeIntervalMs","rateIntervalMs","max","seriesNameFormat","client","getDatasourceClient","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","map","value","metric","values","name","formattedName","labels","metadata","executedQueryString"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './PrometheusTimeSeriesQuery';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './PrometheusTimeSeriesQuery';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,8BAA8B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
2
|
+
import { DurationString } from '@perses-dev/core';
|
|
2
3
|
import { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';
|
|
3
4
|
export declare type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;
|
|
4
5
|
/**
|
|
@@ -13,11 +14,19 @@ export declare function useQueryState(props: PrometheusTimeSeriesQueryEditorProp
|
|
|
13
14
|
handleQueryBlur: () => void;
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
16
|
-
* Hook to manage `
|
|
17
|
+
* Hook to manage `seriesNameFormat` state to ensure panel preview does not rerender until text input is blurred
|
|
17
18
|
*/
|
|
18
19
|
export declare function useFormatState(props: PrometheusTimeSeriesQueryEditorProps): {
|
|
19
20
|
format: string | undefined;
|
|
20
21
|
handleFormatChange: (e: string) => void;
|
|
21
22
|
handleFormatBlur: () => void;
|
|
22
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Hook to manage `minStep` state to ensure panel preview does not rerender until text input is blurred
|
|
26
|
+
*/
|
|
27
|
+
export declare function useMinStepState(props: PrometheusTimeSeriesQueryEditorProps): {
|
|
28
|
+
minStep: `${number}y` | `${number}w` | `${number}d` | `${number}h` | `${number}m` | `${number}s` | `${number}ms` | `${number}s${number}ms` | `${number}m${number}ms` | `${number}m${number}s` | `${number}m${number}s${number}ms` | `${number}h${number}ms` | `${number}h${number}s` | `${number}h${number}s${number}ms` | `${number}h${number}m` | `${number}h${number}m${number}ms` | `${number}h${number}m${number}s` | `${number}h${number}m${number}s${number}ms` | `${number}d${number}ms` | `${number}d${number}s` | `${number}d${number}s${number}ms` | `${number}d${number}m` | `${number}d${number}m${number}ms` | `${number}d${number}m${number}s` | `${number}d${number}m${number}s${number}ms` | `${number}d${number}h` | `${number}d${number}h${number}ms` | `${number}d${number}h${number}s` | `${number}d${number}h${number}s${number}ms` | `${number}d${number}h${number}m` | `${number}d${number}h${number}m${number}ms` | `${number}d${number}h${number}m${number}s` | `${number}d${number}h${number}m${number}s${number}ms` | `${number}w${number}ms` | `${number}w${number}s` | `${number}w${number}s${number}ms` | `${number}w${number}m` | `${number}w${number}m${number}ms` | `${number}w${number}m${number}s` | `${number}w${number}m${number}s${number}ms` | `${number}w${number}h` | `${number}w${number}h${number}ms` | `${number}w${number}h${number}s` | `${number}w${number}h${number}s${number}ms` | `${number}w${number}h${number}m` | `${number}w${number}h${number}m${number}ms` | `${number}w${number}h${number}m${number}s` | `${number}w${number}h${number}m${number}s${number}ms` | `${number}w${number}d` | `${number}w${number}d${number}ms` | `${number}w${number}d${number}s` | `${number}w${number}d${number}s${number}ms` | `${number}w${number}d${number}m` | `${number}w${number}d${number}m${number}ms` | `${number}w${number}d${number}m${number}s` | `${number}w${number}d${number}m${number}s${number}ms` | `${number}w${number}d${number}h` | `${number}w${number}d${number}h${number}ms` | `${number}w${number}d${number}h${number}s` | `${number}w${number}d${number}h${number}s${number}ms` | `${number}w${number}d${number}h${number}m` | `${number}w${number}d${number}h${number}m${number}ms` | `${number}w${number}d${number}h${number}m${number}s` | `${number}w${number}d${number}h${number}m${number}s${number}ms` | `${number}y${number}ms` | `${number}y${number}s` | `${number}y${number}s${number}ms` | `${number}y${number}m` | `${number}y${number}m${number}ms` | `${number}y${number}m${number}s` | `${number}y${number}m${number}s${number}ms` | `${number}y${number}h` | `${number}y${number}h${number}ms` | `${number}y${number}h${number}s` | `${number}y${number}h${number}s${number}ms` | `${number}y${number}h${number}m` | `${number}y${number}h${number}m${number}ms` | `${number}y${number}h${number}m${number}s` | `${number}y${number}h${number}m${number}s${number}ms` | `${number}y${number}d` | `${number}y${number}d${number}ms` | `${number}y${number}d${number}s` | `${number}y${number}d${number}s${number}ms` | `${number}y${number}d${number}m` | `${number}y${number}d${number}m${number}ms` | `${number}y${number}d${number}m${number}s` | `${number}y${number}d${number}m${number}s${number}ms` | `${number}y${number}d${number}h` | `${number}y${number}d${number}h${number}ms` | `${number}y${number}d${number}h${number}s` | `${number}y${number}d${number}h${number}s${number}ms` | `${number}y${number}d${number}h${number}m` | `${number}y${number}d${number}h${number}m${number}ms` | `${number}y${number}d${number}h${number}m${number}s` | `${number}y${number}d${number}h${number}m${number}s${number}ms` | `${number}y${number}w` | `${number}y${number}w${number}ms` | `${number}y${number}w${number}s` | `${number}y${number}w${number}s${number}ms` | `${number}y${number}w${number}m` | `${number}y${number}w${number}m${number}ms` | `${number}y${number}w${number}m${number}s` | `${number}y${number}w${number}m${number}s${number}ms` | `${number}y${number}w${number}h` | `${number}y${number}w${number}h${number}ms` | `${number}y${number}w${number}h${number}s` | `${number}y${number}w${number}h${number}s${number}ms` | `${number}y${number}w${number}h${number}m` | `${number}y${number}w${number}h${number}m${number}ms` | `${number}y${number}w${number}h${number}m${number}s` | `${number}y${number}w${number}h${number}m${number}s${number}ms` | `${number}y${number}w${number}d` | `${number}y${number}w${number}d${number}ms` | `${number}y${number}w${number}d${number}s` | `${number}y${number}w${number}d${number}s${number}ms` | `${number}y${number}w${number}d${number}m` | `${number}y${number}w${number}d${number}m${number}ms` | `${number}y${number}w${number}d${number}m${number}s` | `${number}y${number}w${number}d${number}m${number}s${number}ms` | `${number}y${number}w${number}d${number}h` | `${number}y${number}w${number}d${number}h${number}ms` | `${number}y${number}w${number}d${number}h${number}s` | `${number}y${number}w${number}d${number}h${number}s${number}ms` | `${number}y${number}w${number}d${number}h${number}m` | `${number}y${number}w${number}d${number}h${number}m${number}ms` | `${number}y${number}w${number}d${number}h${number}m${number}s` | `${number}y${number}w${number}d${number}h${number}m${number}s${number}ms` | undefined;
|
|
29
|
+
handleMinStepChange: (e: DurationString) => void;
|
|
30
|
+
handleMinStepBlur: () => void;
|
|
31
|
+
};
|
|
23
32
|
//# sourceMappingURL=query-editor-model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-editor-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,oBAAY,oCAAoC,GAAG,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AAErG;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,oCAAoC;;2BAezC,MAAM;;EAgBrC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,oCAAoC;;4BAYzC,MAAM;;EAetC"}
|
|
1
|
+
{"version":3,"file":"query-editor-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,oBAAY,oCAAoC,GAAG,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AAErG;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,oCAAoC;;2BAezC,MAAM;;EAgBrC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,oCAAoC;;4BAYzC,MAAM;;EAetC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oCAAoC;;6BAYzC,cAAc;;EAe/C"}
|
|
@@ -47,25 +47,25 @@ import { produce } from 'immer';
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
|
-
* Hook to manage `
|
|
50
|
+
* Hook to manage `seriesNameFormat` state to ensure panel preview does not rerender until text input is blurred
|
|
51
51
|
*/ export function useFormatState(props) {
|
|
52
52
|
const { onChange , value } = props;
|
|
53
53
|
// TODO: reusable hook or helper util instead of duplicating from useQueryState
|
|
54
|
-
const [format, setFormat] = useState(value.
|
|
55
|
-
const [lastSyncedFormat, setLastSyncedFormat] = useState(value.
|
|
56
|
-
if (value.
|
|
57
|
-
setFormat(value.
|
|
58
|
-
setLastSyncedFormat(value.
|
|
54
|
+
const [format, setFormat] = useState(value.seriesNameFormat);
|
|
55
|
+
const [lastSyncedFormat, setLastSyncedFormat] = useState(value.seriesNameFormat);
|
|
56
|
+
if (value.seriesNameFormat !== lastSyncedFormat) {
|
|
57
|
+
setFormat(value.seriesNameFormat);
|
|
58
|
+
setLastSyncedFormat(value.seriesNameFormat);
|
|
59
59
|
}
|
|
60
60
|
// Update our local state as the user types
|
|
61
61
|
const handleFormatChange = (e)=>{
|
|
62
62
|
setFormat(e);
|
|
63
63
|
};
|
|
64
|
-
// Propagate changes to the panel preview component when
|
|
64
|
+
// Propagate changes to the panel preview component when seriesNameFormat TextField is blurred
|
|
65
65
|
const handleFormatBlur = ()=>{
|
|
66
66
|
setLastSyncedFormat(format);
|
|
67
67
|
onChange(produce(value, (draft)=>{
|
|
68
|
-
draft.
|
|
68
|
+
draft.seriesNameFormat = format;
|
|
69
69
|
}));
|
|
70
70
|
};
|
|
71
71
|
return {
|
|
@@ -74,5 +74,33 @@ import { produce } from 'immer';
|
|
|
74
74
|
handleFormatBlur
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Hook to manage `minStep` state to ensure panel preview does not rerender until text input is blurred
|
|
79
|
+
*/ export function useMinStepState(props) {
|
|
80
|
+
const { onChange , value } = props;
|
|
81
|
+
// TODO: reusable hook or helper util instead of duplicating from useQueryState
|
|
82
|
+
const [minStep, setMinStep] = useState(value.minStep);
|
|
83
|
+
const [lastSyncedMinStep, setLastSyncedMinStep] = useState(value.minStep);
|
|
84
|
+
if (value.minStep !== lastSyncedMinStep) {
|
|
85
|
+
setMinStep(value.minStep);
|
|
86
|
+
setLastSyncedMinStep(value.minStep);
|
|
87
|
+
}
|
|
88
|
+
// Update our local state as the user types
|
|
89
|
+
const handleMinStepChange = (e)=>{
|
|
90
|
+
setMinStep(e);
|
|
91
|
+
};
|
|
92
|
+
// Propagate changes to the panel preview component when minStep TextField is blurred
|
|
93
|
+
const handleMinStepBlur = ()=>{
|
|
94
|
+
setLastSyncedMinStep(minStep);
|
|
95
|
+
onChange(produce(value, (draft)=>{
|
|
96
|
+
draft.minStep = minStep;
|
|
97
|
+
}));
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
minStep,
|
|
101
|
+
handleMinStepChange,
|
|
102
|
+
handleMinStepBlur
|
|
103
|
+
};
|
|
104
|
+
}
|
|
77
105
|
|
|
78
106
|
//# sourceMappingURL=query-editor-model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useState } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\n/**\n * A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with\n * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those\n * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview\n * every time the user types.\n */\nexport function useQueryState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // Local copy of the query's value\n const [query, setQuery] = useState(value.query);\n\n // This is basically \"getDerivedStateFromProps\" to make sure if spec's value changes external to this component,\n // we render with the latest value\n const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);\n if (value.query !== lastSyncedQuery) {\n setQuery(value.query);\n setLastSyncedQuery(value.query);\n }\n\n // Update our local state's copy as the user types\n const handleQueryChange = (e: string) => {\n setQuery(e);\n };\n\n // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the\n // PanelPreview\n const handleQueryBlur = () => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n\n/**\n * Hook to manage `
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useState } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { DurationString } from '@perses-dev/core';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\n/**\n * A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with\n * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those\n * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview\n * every time the user types.\n */\nexport function useQueryState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // Local copy of the query's value\n const [query, setQuery] = useState(value.query);\n\n // This is basically \"getDerivedStateFromProps\" to make sure if spec's value changes external to this component,\n // we render with the latest value\n const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);\n if (value.query !== lastSyncedQuery) {\n setQuery(value.query);\n setLastSyncedQuery(value.query);\n }\n\n // Update our local state's copy as the user types\n const handleQueryChange = (e: string) => {\n setQuery(e);\n };\n\n // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the\n // PanelPreview\n const handleQueryBlur = () => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n\n/**\n * Hook to manage `seriesNameFormat` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useFormatState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [format, setFormat] = useState(value.seriesNameFormat);\n const [lastSyncedFormat, setLastSyncedFormat] = useState(value.seriesNameFormat);\n if (value.seriesNameFormat !== lastSyncedFormat) {\n setFormat(value.seriesNameFormat);\n setLastSyncedFormat(value.seriesNameFormat);\n }\n\n // Update our local state as the user types\n const handleFormatChange = (e: string) => {\n setFormat(e);\n };\n\n // Propagate changes to the panel preview component when seriesNameFormat TextField is blurred\n const handleFormatBlur = () => {\n setLastSyncedFormat(format);\n onChange(\n produce(value, (draft) => {\n draft.seriesNameFormat = format;\n })\n );\n };\n\n return { format, handleFormatChange, handleFormatBlur };\n}\n\n/**\n * Hook to manage `minStep` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useMinStepState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [minStep, setMinStep] = useState(value.minStep);\n const [lastSyncedMinStep, setLastSyncedMinStep] = useState(value.minStep);\n if (value.minStep !== lastSyncedMinStep) {\n setMinStep(value.minStep);\n setLastSyncedMinStep(value.minStep);\n }\n\n // Update our local state as the user types\n const handleMinStepChange = (e: DurationString) => {\n setMinStep(e);\n };\n\n // Propagate changes to the panel preview component when minStep TextField is blurred\n const handleMinStepBlur = () => {\n setLastSyncedMinStep(minStep);\n onChange(\n produce(value, (draft) => {\n draft.minStep = minStep;\n })\n );\n };\n\n return { minStep, handleMinStepChange, handleMinStepBlur };\n}\n"],"names":["useState","produce","useQueryState","props","onChange","value","query","setQuery","lastSyncedQuery","setLastSyncedQuery","handleQueryChange","e","handleQueryBlur","draft","useFormatState","format","setFormat","seriesNameFormat","lastSyncedFormat","setLastSyncedFormat","handleFormatChange","handleFormatBlur","useMinStepState","minStep","setMinStep","lastSyncedMinStep","setLastSyncedMinStep","handleMinStepChange","handleMinStepBlur"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,QAAQ,QAAQ,QAAQ;AACjC,SAASC,OAAO,QAAQ,QAAQ;AAOhC;;;;;CAKC,GACD,OAAO,SAASC,cAAcC,KAA2C;IACvE,MAAM,EAAEC,SAAQ,EAAEC,MAAK,EAAE,GAAGF;IAE5B,kCAAkC;IAClC,MAAM,CAACG,OAAOC,SAAS,GAAGP,SAASK,MAAMC;IAEzC,gHAAgH;IAChH,kCAAkC;IAClC,MAAM,CAACE,iBAAiBC,mBAAmB,GAAGT,SAASK,MAAMC;IAC7D,IAAID,MAAMC,UAAUE,iBAAiB;QACnCD,SAASF,MAAMC;QACfG,mBAAmBJ,MAAMC;IAC3B;IAEA,kDAAkD;IAClD,MAAMI,oBAAoB,CAACC;QACzBJ,SAASI;IACX;IAEA,iHAAiH;IACjH,eAAe;IACf,MAAMC,kBAAkB;QACtBH,mBAAmBH;QACnBF,SACEH,QAAQI,OAAO,CAACQ;YACdA,MAAMP,QAAQA;QAChB;IAEJ;IAEA,OAAO;QAAEA;QAAOI;QAAmBE;IAAgB;AACrD;AAEA;;CAEC,GACD,OAAO,SAASE,eAAeX,KAA2C;IACxE,MAAM,EAAEC,SAAQ,EAAEC,MAAK,EAAE,GAAGF;IAE5B,+EAA+E;IAC/E,MAAM,CAACY,QAAQC,UAAU,GAAGhB,SAASK,MAAMY;IAC3C,MAAM,CAACC,kBAAkBC,oBAAoB,GAAGnB,SAASK,MAAMY;IAC/D,IAAIZ,MAAMY,qBAAqBC,kBAAkB;QAC/CF,UAAUX,MAAMY;QAChBE,oBAAoBd,MAAMY;IAC5B;IAEA,2CAA2C;IAC3C,MAAMG,qBAAqB,CAACT;QAC1BK,UAAUL;IACZ;IAEA,8FAA8F;IAC9F,MAAMU,mBAAmB;QACvBF,oBAAoBJ;QACpBX,SACEH,QAAQI,OAAO,CAACQ;YACdA,MAAMI,mBAAmBF;QAC3B;IAEJ;IAEA,OAAO;QAAEA;QAAQK;QAAoBC;IAAiB;AACxD;AAEA;;CAEC,GACD,OAAO,SAASC,gBAAgBnB,KAA2C;IACzE,MAAM,EAAEC,SAAQ,EAAEC,MAAK,EAAE,GAAGF;IAE5B,+EAA+E;IAC/E,MAAM,CAACoB,SAASC,WAAW,GAAGxB,SAASK,MAAMkB;IAC7C,MAAM,CAACE,mBAAmBC,qBAAqB,GAAG1B,SAASK,MAAMkB;IACjE,IAAIlB,MAAMkB,YAAYE,mBAAmB;QACvCD,WAAWnB,MAAMkB;QACjBG,qBAAqBrB,MAAMkB;IAC7B;IAEA,2CAA2C;IAC3C,MAAMI,sBAAsB,CAAChB;QAC3Ba,WAAWb;IACb;IAEA,qFAAqF;IACrF,MAAMiB,oBAAoB;QACxBF,qBAAqBH;QACrBnB,SACEH,QAAQI,OAAO,CAACQ;YACdA,MAAMU,UAAUA;QAClB;IAEJ;IAEA,OAAO;QAAEA;QAASI;QAAqBC;IAAkB;AAC3D"}
|
|
@@ -5,8 +5,8 @@ import { PrometheusDatasourceSelector, TemplateString } from '../../model';
|
|
|
5
5
|
*/
|
|
6
6
|
export interface PrometheusTimeSeriesQuerySpec {
|
|
7
7
|
query: TemplateString;
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
seriesNameFormat?: string;
|
|
9
|
+
minStep?: DurationString;
|
|
10
10
|
resolution?: number;
|
|
11
11
|
datasource?: PrometheusDatasourceSelector;
|
|
12
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-series-query-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,cAAc,CAAC;IACtB,
|
|
1
|
+
{"version":3,"file":"time-series-query-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,cAAc,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport { PrometheusDatasourceSelector, TemplateString } from '../../model';\n\n/**\n * The spec/options for the PrometheusTimeSeriesQuery plugin.\n */\nexport interface PrometheusTimeSeriesQuerySpec {\n query: TemplateString;\n
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport { PrometheusDatasourceSelector, TemplateString } from '../../model';\n\n/**\n * The spec/options for the PrometheusTimeSeriesQuery plugin.\n */\nexport interface PrometheusTimeSeriesQuerySpec {\n query: TemplateString;\n seriesNameFormat?: string;\n minStep?: DurationString;\n resolution?: number;\n datasource?: PrometheusDatasourceSelector;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAYC"}
|
|
@@ -31,7 +31,7 @@ function PrometheusLabelValuesVariableEditor(props) {
|
|
|
31
31
|
}
|
|
32
32
|
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
33
33
|
};
|
|
34
|
-
var
|
|
34
|
+
var _props_value_matchers;
|
|
35
35
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
36
36
|
spacing: 2,
|
|
37
37
|
children: [
|
|
@@ -55,11 +55,11 @@ function PrometheusLabelValuesVariableEditor(props) {
|
|
|
55
55
|
/*#__PURE__*/ _jsx(TextField, {
|
|
56
56
|
label: "Label Name",
|
|
57
57
|
required: true,
|
|
58
|
-
value: props.value.
|
|
58
|
+
value: props.value.labelName,
|
|
59
59
|
onChange: (e)=>{
|
|
60
60
|
props.onChange({
|
|
61
61
|
...props.value,
|
|
62
|
-
|
|
62
|
+
labelName: e.target.value
|
|
63
63
|
});
|
|
64
64
|
},
|
|
65
65
|
InputProps: {
|
|
@@ -67,7 +67,7 @@ function PrometheusLabelValuesVariableEditor(props) {
|
|
|
67
67
|
}
|
|
68
68
|
}),
|
|
69
69
|
/*#__PURE__*/ _jsx(MatcherEditor, {
|
|
70
|
-
matchers: (
|
|
70
|
+
matchers: (_props_value_matchers = props.value.matchers) !== null && _props_value_matchers !== void 0 ? _props_value_matchers : [],
|
|
71
71
|
onChange: (e)=>{
|
|
72
72
|
props.onChange({
|
|
73
73
|
...props.value,
|
|
@@ -93,7 +93,7 @@ function PrometheusLabelNamesVariableEditor(props) {
|
|
|
93
93
|
}
|
|
94
94
|
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
95
95
|
};
|
|
96
|
-
var
|
|
96
|
+
var _props_value_matchers;
|
|
97
97
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
98
98
|
spacing: 2,
|
|
99
99
|
children: [
|
|
@@ -115,7 +115,7 @@ function PrometheusLabelNamesVariableEditor(props) {
|
|
|
115
115
|
]
|
|
116
116
|
}),
|
|
117
117
|
/*#__PURE__*/ _jsx(MatcherEditor, {
|
|
118
|
-
matchers: (
|
|
118
|
+
matchers: (_props_value_matchers = props.value.matchers) !== null && _props_value_matchers !== void 0 ? _props_value_matchers : [],
|
|
119
119
|
isReadonly: props.isReadonly,
|
|
120
120
|
onChange: (e)=>{
|
|
121
121
|
props.onChange({
|
|
@@ -181,34 +181,34 @@ function PrometheusPromQLVariableEditor(props) {
|
|
|
181
181
|
}),
|
|
182
182
|
/*#__PURE__*/ _jsx(TextField, {
|
|
183
183
|
label: "Label Name",
|
|
184
|
-
value: props.value.
|
|
184
|
+
value: props.value.labelName,
|
|
185
185
|
InputProps: {
|
|
186
186
|
readOnly: props.isReadonly
|
|
187
187
|
},
|
|
188
188
|
onChange: (e)=>{
|
|
189
189
|
props.onChange({
|
|
190
190
|
...props.value,
|
|
191
|
-
|
|
191
|
+
labelName: e.target.value
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
194
|
})
|
|
195
195
|
]
|
|
196
196
|
});
|
|
197
197
|
}
|
|
198
|
-
function capturingMatrix(matrix,
|
|
198
|
+
function capturingMatrix(matrix, labelName) {
|
|
199
199
|
const captured = new Set();
|
|
200
200
|
for (const sample of matrix.result){
|
|
201
|
-
const value = sample.metric[
|
|
201
|
+
const value = sample.metric[labelName];
|
|
202
202
|
if (value !== undefined) {
|
|
203
203
|
captured.add(value);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
return Array.from(captured.values());
|
|
207
207
|
}
|
|
208
|
-
function capturingVector(vector,
|
|
208
|
+
function capturingVector(vector, labelName) {
|
|
209
209
|
const captured = new Set();
|
|
210
210
|
for (const sample of vector.result){
|
|
211
|
-
const value = sample.metric[
|
|
211
|
+
const value = sample.metric[labelName];
|
|
212
212
|
if (value !== undefined) {
|
|
213
213
|
captured.add(value);
|
|
214
214
|
}
|
|
@@ -226,8 +226,8 @@ function capturingVector(vector, label_name) {
|
|
|
226
226
|
};
|
|
227
227
|
export const PrometheusLabelNamesVariable = {
|
|
228
228
|
getVariableOptions: async (spec, ctx)=>{
|
|
229
|
-
var
|
|
230
|
-
const client = await ctx.datasourceStore.getDatasourceClient((
|
|
229
|
+
var _spec_datasource;
|
|
230
|
+
const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
|
|
231
231
|
const match = spec.matchers ? spec.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
|
|
232
232
|
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
233
233
|
const { data: options } = await client.labelNames({
|
|
@@ -239,9 +239,9 @@ export const PrometheusLabelNamesVariable = {
|
|
|
239
239
|
};
|
|
240
240
|
},
|
|
241
241
|
dependsOn: (spec)=>{
|
|
242
|
-
var
|
|
242
|
+
var _spec_matchers;
|
|
243
243
|
return {
|
|
244
|
-
variables: ((
|
|
244
|
+
variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>parseTemplateVariables(m)).flat()) || []
|
|
245
245
|
};
|
|
246
246
|
},
|
|
247
247
|
OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
|
|
@@ -250,12 +250,12 @@ export const PrometheusLabelNamesVariable = {
|
|
|
250
250
|
export const PrometheusLabelValuesVariable = {
|
|
251
251
|
getVariableOptions: async (spec, ctx)=>{
|
|
252
252
|
const pluginDef = spec;
|
|
253
|
-
var
|
|
254
|
-
const client = await ctx.datasourceStore.getDatasourceClient((
|
|
253
|
+
var _spec_datasource;
|
|
254
|
+
const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
|
|
255
255
|
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
|
|
256
256
|
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
257
257
|
const { data: options } = await client.labelValues({
|
|
258
|
-
labelName: replaceTemplateVariables(pluginDef.
|
|
258
|
+
labelName: replaceTemplateVariables(pluginDef.labelName, ctx.variables),
|
|
259
259
|
'match[]': match,
|
|
260
260
|
...timeRange
|
|
261
261
|
});
|
|
@@ -264,25 +264,25 @@ export const PrometheusLabelValuesVariable = {
|
|
|
264
264
|
};
|
|
265
265
|
},
|
|
266
266
|
dependsOn: (spec)=>{
|
|
267
|
-
var
|
|
267
|
+
var _spec_matchers;
|
|
268
268
|
return {
|
|
269
|
-
variables: ((
|
|
269
|
+
variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>parseTemplateVariables(m)).flat().concat(parseTemplateVariables(spec.labelName))) || []
|
|
270
270
|
};
|
|
271
271
|
},
|
|
272
272
|
OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
|
|
273
273
|
createInitialOptions: ()=>({
|
|
274
|
-
|
|
274
|
+
labelName: ''
|
|
275
275
|
})
|
|
276
276
|
};
|
|
277
277
|
export const PrometheusPromQLVariable = {
|
|
278
278
|
getVariableOptions: async (spec, ctx)=>{
|
|
279
|
-
var
|
|
280
|
-
const client = await ctx.datasourceStore.getDatasourceClient((
|
|
279
|
+
var _spec_datasource;
|
|
280
|
+
const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
|
|
281
281
|
// TODO we may want to manage a range query as well.
|
|
282
282
|
const { data: options } = await client.instantQuery({
|
|
283
283
|
query: replaceTemplateVariables(spec.expr, ctx.variables)
|
|
284
284
|
});
|
|
285
|
-
const labelName = replaceTemplateVariables(spec.
|
|
285
|
+
const labelName = replaceTemplateVariables(spec.labelName, ctx.variables);
|
|
286
286
|
let values = [];
|
|
287
287
|
if ((options === null || options === void 0 ? void 0 : options.resultType) === 'matrix') {
|
|
288
288
|
values = capturingMatrix(options, labelName);
|
|
@@ -295,13 +295,13 @@ export const PrometheusPromQLVariable = {
|
|
|
295
295
|
},
|
|
296
296
|
dependsOn: (spec)=>{
|
|
297
297
|
return {
|
|
298
|
-
variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.
|
|
298
|
+
variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.labelName))
|
|
299
299
|
};
|
|
300
300
|
},
|
|
301
301
|
OptionsEditorComponent: PrometheusPromQLVariableEditor,
|
|
302
302
|
createInitialOptions: ()=>({
|
|
303
303
|
expr: '',
|
|
304
|
-
|
|
304
|
+
labelName: ''
|
|
305
305
|
})
|
|
306
306
|
};
|
|
307
307
|
|