@perses-dev/prometheus-plugin 0.46.0-rc1 → 0.47.0-rc0
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/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +3 -3
- package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +12 -11
- package/dist/cjs/plugins/prometheus-variables.js +9 -9
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +4 -4
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.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 +13 -12
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/dist/plugins/prometheus-variables.d.ts.map +1 -1
- package/dist/plugins/prometheus-variables.js +10 -10
- package/dist/plugins/prometheus-variables.js.map +1 -1
- package/package.json +6 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -32,8 +32,8 @@ const PrometheusTimeSeriesQuery = {
|
|
|
32
32
|
}),
|
|
33
33
|
dependsOn: (spec)=>{
|
|
34
34
|
// Variables can be used in the query and/or in the legend format string
|
|
35
|
-
const queryVariables = (0, _pluginsystem.
|
|
36
|
-
const legendVariables = (0, _pluginsystem.
|
|
35
|
+
const queryVariables = (0, _pluginsystem.parseVariables)(spec.query);
|
|
36
|
+
const legendVariables = (0, _pluginsystem.parseVariables)(spec.seriesNameFormat || '');
|
|
37
37
|
const allVariables = [
|
|
38
38
|
...new Set([
|
|
39
39
|
...queryVariables,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -38,9 +38,11 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
38
38
|
var _datasource_plugin_spec_scrapeInterval;
|
|
39
39
|
const datasourceScrapeInterval = Math.trunc((0, _datefns.milliseconds)((0, _core.parseDurationString)((_datasource_plugin_spec_scrapeInterval = datasource.plugin.spec.scrapeInterval) !== null && _datasource_plugin_spec_scrapeInterval !== void 0 ? _datasource_plugin_spec_scrapeInterval : _types.DEFAULT_SCRAPE_INTERVAL)) / 1000);
|
|
40
40
|
var _getDurationStringSeconds;
|
|
41
|
+
// Min step is the lower bound of the interval between data points
|
|
42
|
+
// If no value is provided for it, it should default to the scrape interval of the datasource
|
|
41
43
|
const minStep = (_getDurationStringSeconds = (0, _model.getDurationStringSeconds)(// resolve any variable that may have been provided
|
|
42
44
|
// TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here
|
|
43
|
-
(0, _pluginsystem.
|
|
45
|
+
(0, _pluginsystem.replaceVariables)(spec.minStep, context.variableState))) !== null && _getDurationStringSeconds !== void 0 ? _getDurationStringSeconds : datasourceScrapeInterval;
|
|
44
46
|
const timeRange = (0, _model.getPrometheusTimeRange)(context.timeRange);
|
|
45
47
|
const step = (0, _model.getRangeStep)(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution
|
|
46
48
|
// Align the time range so that it's a multiple of the step
|
|
@@ -50,22 +52,21 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
50
52
|
const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
|
|
51
53
|
start = alignedStart;
|
|
52
54
|
end = alignedEnd;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
query = (0, _pluginsystem.replaceTemplateVariable)(spec.query, '__interval', (0, _core.formatDuration)((0, _core.msToPrometheusDuration)(intervalMs)));
|
|
55
|
+
// Replace variable placeholders in PromQL query
|
|
56
|
+
const intervalMs = step * 1000; // step is in seconds
|
|
57
|
+
let query = (0, _pluginsystem.replaceVariable)(spec.query, '__interval_ms', intervalMs.toString());
|
|
58
|
+
query = (0, _pluginsystem.replaceVariable)(spec.query, '__interval', (0, _core.formatDuration)((0, _core.msToPrometheusDuration)(intervalMs)));
|
|
58
59
|
const scrapeIntervalMs = minStep * 1000;
|
|
59
60
|
// The $__rate_interval variable is meant to be used in the rate function.
|
|
60
61
|
// It is defined as max($__interval + Scrape interval, 4 * Scrape interval), where Scrape interval is the Min step setting (a setting per PromQL query),
|
|
61
62
|
// if any is set, and otherwise the Scrape interval as set in the Prometheus datasource
|
|
62
63
|
const rateIntervalMs = Math.max(intervalMs + scrapeIntervalMs, 4 * scrapeIntervalMs);
|
|
63
|
-
query = (0, _pluginsystem.
|
|
64
|
-
query = (0, _pluginsystem.
|
|
64
|
+
query = (0, _pluginsystem.replaceVariable)(query, '__rate_interval', (0, _core.formatDuration)((0, _core.msToPrometheusDuration)(rateIntervalMs)));
|
|
65
|
+
query = (0, _pluginsystem.replaceVariables)(query, context.variableState);
|
|
65
66
|
let seriesNameFormat = spec.seriesNameFormat;
|
|
66
|
-
// if series name format is defined, replace
|
|
67
|
+
// if series name format is defined, replace variable placeholders in series name format
|
|
67
68
|
if (seriesNameFormat) {
|
|
68
|
-
seriesNameFormat = (0, _pluginsystem.
|
|
69
|
+
seriesNameFormat = (0, _pluginsystem.replaceVariables)(seriesNameFormat, context.variableState);
|
|
69
70
|
}
|
|
70
71
|
var _spec_datasource1;
|
|
71
72
|
// Get the datasource, using the default Prom Datasource if one isn't specified in the query
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -249,7 +249,7 @@ const PrometheusLabelNamesVariable = {
|
|
|
249
249
|
getVariableOptions: async (spec, ctx)=>{
|
|
250
250
|
var _spec_datasource;
|
|
251
251
|
const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : _model.DEFAULT_PROM);
|
|
252
|
-
const match = spec.matchers ? spec.matchers.map((m)=>(0, _pluginsystem.
|
|
252
|
+
const match = spec.matchers ? spec.matchers.map((m)=>(0, _pluginsystem.replaceVariables)(m, ctx.variables)) : undefined;
|
|
253
253
|
const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
|
|
254
254
|
const { data: options } = await client.labelNames({
|
|
255
255
|
'match[]': match,
|
|
@@ -262,7 +262,7 @@ const PrometheusLabelNamesVariable = {
|
|
|
262
262
|
dependsOn: (spec)=>{
|
|
263
263
|
var _spec_matchers;
|
|
264
264
|
return {
|
|
265
|
-
variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>(0, _pluginsystem.
|
|
265
|
+
variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>(0, _pluginsystem.parseVariables)(m)).flat()) || []
|
|
266
266
|
};
|
|
267
267
|
},
|
|
268
268
|
OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
|
|
@@ -273,10 +273,10 @@ const PrometheusLabelValuesVariable = {
|
|
|
273
273
|
const pluginDef = spec;
|
|
274
274
|
var _spec_datasource;
|
|
275
275
|
const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : _model.DEFAULT_PROM);
|
|
276
|
-
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _pluginsystem.
|
|
276
|
+
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _pluginsystem.replaceVariables)(m, ctx.variables)) : undefined;
|
|
277
277
|
const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
|
|
278
278
|
const { data: options } = await client.labelValues({
|
|
279
|
-
labelName: (0, _pluginsystem.
|
|
279
|
+
labelName: (0, _pluginsystem.replaceVariables)(pluginDef.labelName, ctx.variables),
|
|
280
280
|
'match[]': match,
|
|
281
281
|
...timeRange
|
|
282
282
|
});
|
|
@@ -287,7 +287,7 @@ const PrometheusLabelValuesVariable = {
|
|
|
287
287
|
dependsOn: (spec)=>{
|
|
288
288
|
var _spec_matchers;
|
|
289
289
|
return {
|
|
290
|
-
variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>(0, _pluginsystem.
|
|
290
|
+
variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>(0, _pluginsystem.parseVariables)(m)).flat().concat((0, _pluginsystem.parseVariables)(spec.labelName))) || []
|
|
291
291
|
};
|
|
292
292
|
},
|
|
293
293
|
OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
|
|
@@ -301,9 +301,9 @@ const PrometheusPromQLVariable = {
|
|
|
301
301
|
const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : _model.DEFAULT_PROM);
|
|
302
302
|
// TODO we may want to manage a range query as well.
|
|
303
303
|
const { data: options } = await client.instantQuery({
|
|
304
|
-
query: (0, _pluginsystem.
|
|
304
|
+
query: (0, _pluginsystem.replaceVariables)(spec.expr, ctx.variables)
|
|
305
305
|
});
|
|
306
|
-
const labelName = (0, _pluginsystem.
|
|
306
|
+
const labelName = (0, _pluginsystem.replaceVariables)(spec.labelName, ctx.variables);
|
|
307
307
|
let values = [];
|
|
308
308
|
if ((options === null || options === void 0 ? void 0 : options.resultType) === 'matrix') {
|
|
309
309
|
values = capturingMatrix(options, labelName);
|
|
@@ -316,7 +316,7 @@ const PrometheusPromQLVariable = {
|
|
|
316
316
|
},
|
|
317
317
|
dependsOn: (spec)=>{
|
|
318
318
|
return {
|
|
319
|
-
variables: (0, _pluginsystem.
|
|
319
|
+
variables: (0, _pluginsystem.parseVariables)(spec.expr).concat((0, _pluginsystem.parseVariables)(spec.labelName))
|
|
320
320
|
};
|
|
321
321
|
},
|
|
322
322
|
OptionsEditorComponent: PrometheusPromQLVariableEditor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusTimeSeriesQuery.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"PrometheusTimeSeriesQuery.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,qBAAqB,EAAkB,MAAM,2BAA2B,CAAC;AAGlF,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,qBAAqB,CAAC,6BAA6B,CAgB1F,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -10,7 +10,7 @@
|
|
|
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 {
|
|
13
|
+
import { parseVariables } from '@perses-dev/plugin-system';
|
|
14
14
|
import { getTimeSeriesData } from './get-time-series-data';
|
|
15
15
|
import { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';
|
|
16
16
|
/**
|
|
@@ -24,8 +24,8 @@ import { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEdit
|
|
|
24
24
|
}),
|
|
25
25
|
dependsOn: (spec)=>{
|
|
26
26
|
// Variables can be used in the query and/or in the legend format string
|
|
27
|
-
const queryVariables =
|
|
28
|
-
const legendVariables =
|
|
27
|
+
const queryVariables = parseVariables(spec.query);
|
|
28
|
+
const legendVariables = parseVariables(spec.seriesNameFormat || '');
|
|
29
29
|
const allVariables = [
|
|
30
30
|
...new Set([
|
|
31
31
|
...queryVariables,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"sourcesContent":["// Copyright 2024 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 { TimeSeriesQueryPlugin, parseVariables } from '@perses-dev/plugin-system';\nimport { getTimeSeriesData } from './get-time-series-data';\nimport { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\n/**\n * The core Prometheus TimeSeriesQuery plugin for Perses.\n */\nexport const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec> = {\n getTimeSeriesData,\n OptionsEditorComponent: PrometheusTimeSeriesQueryEditor,\n createInitialOptions: () => ({\n query: '',\n datasource: undefined,\n }),\n dependsOn: (spec) => {\n // Variables can be used in the query and/or in the legend format string\n const queryVariables = parseVariables(spec.query);\n const legendVariables = parseVariables(spec.seriesNameFormat || '');\n const allVariables = [...new Set([...queryVariables, ...legendVariables])];\n return {\n variables: allVariables,\n };\n },\n};\n"],"names":["parseVariables","getTimeSeriesData","PrometheusTimeSeriesQueryEditor","PrometheusTimeSeriesQuery","OptionsEditorComponent","createInitialOptions","query","datasource","undefined","dependsOn","spec","queryVariables","legendVariables","seriesNameFormat","allVariables","Set","variables"],"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,SAAgCA,cAAc,QAAQ,4BAA4B;AAClF,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,+BAA+B,QAAQ,oCAAoC;AAGpF;;CAEC,GACD,OAAO,MAAMC,4BAAkF;IAC7FF;IACAG,wBAAwBF;IACxBG,sBAAsB,IAAO,CAAA;YAC3BC,OAAO;YACPC,YAAYC;QACd,CAAA;IACAC,WAAW,CAACC;QACV,wEAAwE;QACxE,MAAMC,iBAAiBX,eAAeU,KAAKJ,KAAK;QAChD,MAAMM,kBAAkBZ,eAAeU,KAAKG,gBAAgB,IAAI;QAChE,MAAMC,eAAe;eAAI,IAAIC,IAAI;mBAAIJ;mBAAmBC;aAAgB;SAAE;QAC1E,OAAO;YACLI,WAAWF;QACb;IACF;AACF,EAAE"}
|
|
@@ -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":"AAuBA,OAAO,EAAE,qBAAqB,
|
|
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":"AAuBA,OAAO,EAAE,qBAAqB,EAAqC,MAAM,2BAA2B,CAAC;AAerG,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CA4GvG,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { formatDuration, msToPrometheusDuration, parseDurationString } from '@perses-dev/core';
|
|
14
|
-
import {
|
|
14
|
+
import { replaceVariables, replaceVariable } from '@perses-dev/plugin-system';
|
|
15
15
|
import { fromUnixTime, milliseconds } from 'date-fns';
|
|
16
16
|
import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, DEFAULT_PROM } from '../../model';
|
|
17
17
|
import { getFormattedPrometheusSeriesName } from '../../utils';
|
|
@@ -28,9 +28,11 @@ export const getTimeSeriesData = async (spec, context)=>{
|
|
|
28
28
|
var _datasource_plugin_spec_scrapeInterval;
|
|
29
29
|
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);
|
|
30
30
|
var _getDurationStringSeconds;
|
|
31
|
+
// Min step is the lower bound of the interval between data points
|
|
32
|
+
// If no value is provided for it, it should default to the scrape interval of the datasource
|
|
31
33
|
const minStep = (_getDurationStringSeconds = getDurationStringSeconds(// resolve any variable that may have been provided
|
|
32
34
|
// TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here
|
|
33
|
-
|
|
35
|
+
replaceVariables(spec.minStep, context.variableState))) !== null && _getDurationStringSeconds !== void 0 ? _getDurationStringSeconds : datasourceScrapeInterval;
|
|
34
36
|
const timeRange = getPrometheusTimeRange(context.timeRange);
|
|
35
37
|
const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution
|
|
36
38
|
// Align the time range so that it's a multiple of the step
|
|
@@ -40,22 +42,21 @@ export const getTimeSeriesData = async (spec, context)=>{
|
|
|
40
42
|
const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
|
|
41
43
|
start = alignedStart;
|
|
42
44
|
end = alignedEnd;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
query = replaceTemplateVariable(spec.query, '__interval', formatDuration(msToPrometheusDuration(intervalMs)));
|
|
45
|
+
// Replace variable placeholders in PromQL query
|
|
46
|
+
const intervalMs = step * 1000; // step is in seconds
|
|
47
|
+
let query = replaceVariable(spec.query, '__interval_ms', intervalMs.toString());
|
|
48
|
+
query = replaceVariable(spec.query, '__interval', formatDuration(msToPrometheusDuration(intervalMs)));
|
|
48
49
|
const scrapeIntervalMs = minStep * 1000;
|
|
49
50
|
// The $__rate_interval variable is meant to be used in the rate function.
|
|
50
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),
|
|
51
52
|
// if any is set, and otherwise the Scrape interval as set in the Prometheus datasource
|
|
52
53
|
const rateIntervalMs = Math.max(intervalMs + scrapeIntervalMs, 4 * scrapeIntervalMs);
|
|
53
|
-
query =
|
|
54
|
-
query =
|
|
54
|
+
query = replaceVariable(query, '__rate_interval', formatDuration(msToPrometheusDuration(rateIntervalMs)));
|
|
55
|
+
query = replaceVariables(query, context.variableState);
|
|
55
56
|
let seriesNameFormat = spec.seriesNameFormat;
|
|
56
|
-
// if series name format is defined, replace
|
|
57
|
+
// if series name format is defined, replace variable placeholders in series name format
|
|
57
58
|
if (seriesNameFormat) {
|
|
58
|
-
seriesNameFormat =
|
|
59
|
+
seriesNameFormat = replaceVariables(seriesNameFormat, context.variableState);
|
|
59
60
|
}
|
|
60
61
|
var _spec_datasource1;
|
|
61
62
|
// Get the datasource, using the default Prom Datasource if one isn't specified in the query
|
|
@@ -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 {\n DatasourceSpec,\n DurationString,\n formatDuration,\n msToPrometheusDuration,\n Notice,\n parseDurationString,\n TimeSeries,\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 MatrixData,\n VectorData,\n ScalarData,\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 let response;\n switch (context.mode) {\n case 'instant':\n response = await client.instantQuery({\n query,\n time: end,\n });\n break;\n case 'range':\n default:\n response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n break;\n }\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data;\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: buildTimeSeries(result, query, seriesNameFormat),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n\nfunction buildVectorData(data: VectorData, query: string, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, value } = res;\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: [parseValueTuple(value)],\n formattedName,\n labels: metric,\n };\n });\n}\n\nfunction buildMatrixData(data: MatrixData, query: string, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, values } = res;\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}\n\nfunction buildScalarData(data: ScalarData, query: string, seriesNameFormat: string | undefined): TimeSeries[] {\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, {}, seriesNameFormat);\n return [\n {\n name,\n values: [parseValueTuple(data.result)],\n formattedName,\n },\n ];\n}\n\nfunction buildTimeSeries(\n data: MatrixData | VectorData | ScalarData | undefined,\n query: string,\n seriesNameFormat?: string\n): TimeSeries[] {\n if (!data) {\n return [];\n }\n\n const resultType = data.resultType;\n\n switch (resultType) {\n case 'vector':\n return buildVectorData(data, query, seriesNameFormat);\n case 'matrix':\n return buildMatrixData(data, query, seriesNameFormat);\n case 'scalar':\n return buildScalarData(data, query, seriesNameFormat);\n default:\n console.warn('Unknown result type', resultType, data);\n return [];\n }\n}\n"],"names":["formatDuration","msToPrometheusDuration","parseDurationString","replaceTemplateVariables","replaceTemplateVariable","fromUnixTime","milliseconds","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getFormattedPrometheusSeriesName","DEFAULT_SCRAPE_INTERVAL","getTimeSeriesData","spec","context","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","response","mode","instantQuery","time","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","buildTimeSeries","metadata","executedQueryString","buildVectorData","map","res","metric","value","name","formattedName","values","labels","buildMatrixData","buildScalarData","resultType","console","warn"],"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,SAGEA,cAAc,EACdC,sBAAsB,EAEtBC,mBA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,QAAQA,OAAON,GAAG,CAAC9D;YACnBmE;YACAE,QAAQL;QACV;IACF;AACF;AAEA,SAASO,gBAAgBvB,IAAgB,EAAEtC,KAAa,EAAE6B,gBAAoC;IAC5F,MAAM,EAAE2B,IAAI,EAAEC,aAAa,EAAE,GAAG9D,iCAAiCK,OAAO,CAAC,GAAG6B;IAC5E,OAAO;QACL;YACE2B;YACAE,QAAQ;gBAACpE,gBAAgBgD,KAAKD,MAAM;aAAE;YACtCoB;QACF;KACD;AACH;AAEA,SAAST,gBACPV,IAAsD,EACtDtC,KAAa,EACb6B,gBAAyB;IAEzB,IAAI,CAACS,MAAM;QACT,OAAO,EAAE;IACX;IAEA,MAAMwB,aAAaxB,KAAKwB,UAAU;IAElC,OAAQA;QACN,KAAK;YACH,OAAOX,gBAAgBb,MAAMtC,OAAO6B;QACtC,KAAK;YACH,OAAO+B,gBAAgBtB,MAAMtC,OAAO6B;QACtC,KAAK;YACH,OAAOgC,gBAAgBvB,MAAMtC,OAAO6B;QACtC;YACEkC,QAAQC,IAAI,CAAC,uBAAuBF,YAAYxB;YAChD,OAAO,EAAE;IACb;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 2024 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 TimeSeries,\n TimeSeriesData,\n} from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceVariables, replaceVariable } 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 MatrixData,\n VectorData,\n ScalarData,\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 // Min step is the lower bound of the interval between data points\n // If no value is provided for it, it should default to the scrape interval of the datasource\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 replaceVariables(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 variable placeholders in PromQL query\n const intervalMs = step * 1000; // step is in seconds\n let query = replaceVariable(spec.query, '__interval_ms', intervalMs.toString());\n query = replaceVariable(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 = replaceVariable(query, '__rate_interval', formatDuration(msToPrometheusDuration(rateIntervalMs)));\n query = replaceVariables(query, context.variableState);\n\n let seriesNameFormat = spec.seriesNameFormat;\n // if series name format is defined, replace variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceVariables(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 let response;\n switch (context.mode) {\n case 'instant':\n response = await client.instantQuery({\n query,\n time: end,\n });\n break;\n case 'range':\n default:\n response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n break;\n }\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data;\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: buildTimeSeries(result, query, seriesNameFormat),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n\nfunction buildVectorData(data: VectorData, query: string, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, value } = res;\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: [parseValueTuple(value)],\n formattedName,\n labels: metric,\n };\n });\n}\n\nfunction buildMatrixData(data: MatrixData, query: string, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, values } = res;\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}\n\nfunction buildScalarData(data: ScalarData, query: string, seriesNameFormat: string | undefined): TimeSeries[] {\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, {}, seriesNameFormat);\n return [\n {\n name,\n values: [parseValueTuple(data.result)],\n formattedName,\n },\n ];\n}\n\nfunction buildTimeSeries(\n data: MatrixData | VectorData | ScalarData | undefined,\n query: string,\n seriesNameFormat?: string\n): TimeSeries[] {\n if (!data) {\n return [];\n }\n\n const resultType = data.resultType;\n\n switch (resultType) {\n case 'vector':\n return buildVectorData(data, query, seriesNameFormat);\n case 'matrix':\n return buildMatrixData(data, query, seriesNameFormat);\n case 'scalar':\n return buildScalarData(data, query, seriesNameFormat);\n default:\n console.warn('Unknown result type', resultType, data);\n return [];\n }\n}\n"],"names":["formatDuration","msToPrometheusDuration","parseDurationString","replaceVariables","replaceVariable","fromUnixTime","milliseconds","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getFormattedPrometheusSeriesName","DEFAULT_SCRAPE_INTERVAL","getTimeSeriesData","spec","context","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","response","mode","instantQuery","time","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","buildTimeSeries","metadata","executedQueryString","buildVectorData","map","res","metric","value","name","formattedName","values","labels","buildMatrixData","buildScalarData","resultType","console","warn"],"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,SAGEA,cAAc,EACdC,sBAAsB,EAEtBC,mBAAmB,QAGd,mBAAmB;AAC1B,SAAgCC,gBAAgB,EAAEC,eAAe,QAAQ,4BAA4B;AACrG,SAASC,YAAY,EAAEC,YAAY,QAAQ,WAAW;AACtD,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,QAIP,cAAc;AACrB,SAASC,gCAAgC,QAAQ,cAAc;AAC/D,SAASC,uBAAuB,QAAkC,WAAW;AAG7E,OAAO,MAAMC,oBAA+F,OAC1GC,MACAC;IAEA,IAAID,KAAKE,KAAK,KAAKC,aAAaH,KAAKE,KAAK,KAAK,QAAQF,KAAKE,KAAK,KAAK,IAAI;QACxE,+EAA+E;QAC/E,OAAO;YAAEE,QAAQ,EAAE;QAAC;IACtB;QAGEJ;IADF,MAAMK,aAAc,MAAMJ,QAAQK,eAAe,CAACC,aAAa,CAC7DP,CAAAA,mBAAAA,KAAKK,UAAU,cAAfL,8BAAAA,mBAAmBJ;QAGcS;IADnC,MAAMG,2BAA2BC,KAAKC,KAAK,CACzCnB,aAAaJ,oBAAoBkB,CAAAA,yCAAAA,WAAWM,MAAM,CAACX,IAAI,CAACY,cAAc,cAArCP,oDAAAA,yCAAyCP,4BAA4B;QAMtGL;IAHF,kEAAkE;IAClE,6FAA6F;IAC7F,MAAMoB,UACJpB,CAAAA,4BAAAA,yBACE,mDAAmD;IAC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E,QAAQ;gBAACpE,gBAAgBiE;aAAO;YAChCE;YACAE,QAAQL;QACV;IACF;AACF;AAEA,SAASM,gBAAgBtB,IAAgB,EAAEtC,KAAa,EAAE6B,gBAAoC;IAC5F,OAAOS,KAAKD,MAAM,CAACe,GAAG,CAAC,CAACC;QACtB,MAAM,EAAEC,MAAM,EAAEI,MAAM,EAAE,GAAGL;QAE3B,wGAAwG;QACxG,MAAM,EAAEG,IAAI,EAAEC,aAAa,EAAE,GAAG9D,iCAAiCK,OAAOsD,QAAQzB;QAEhF,OAAO;YACL2B;YACAE,QAAQA,OAAON,GAAG,CAAC9D;YACnBmE;YACAE,QAAQL;QACV;IACF;AACF;AAEA,SAASO,gBAAgBvB,IAAgB,EAAEtC,KAAa,EAAE6B,gBAAoC;IAC5F,MAAM,EAAE2B,IAAI,EAAEC,aAAa,EAAE,GAAG9D,iCAAiCK,OAAO,CAAC,GAAG6B;IAC5E,OAAO;QACL;YACE2B;YACAE,QAAQ;gBAACpE,gBAAgBgD,KAAKD,MAAM;aAAE;YACtCoB;QACF;KACD;AACH;AAEA,SAAST,gBACPV,IAAsD,EACtDtC,KAAa,EACb6B,gBAAyB;IAEzB,IAAI,CAACS,MAAM;QACT,OAAO,EAAE;IACX;IAEA,MAAMwB,aAAaxB,KAAKwB,UAAU;IAElC,OAAQA;QACN,KAAK;YACH,OAAOX,gBAAgBb,MAAMtC,OAAO6B;QACtC,KAAK;YACH,OAAO+B,gBAAgBtB,MAAMtC,OAAO6B;QACtC,KAAK;YACH,OAAOgC,gBAAgBvB,MAAMtC,OAAO6B;QACtC;YACEkC,QAAQC,IAAI,CAAC,uBAAuBF,YAAYxB;YAChD,OAAO,EAAE;IACb;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAML,cAAc,EAIf,MAAM,2BAA2B,CAAC;AAcnC,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AA+LjB,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAgB5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,
|
|
1
|
+
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAML,cAAc,EAIf,MAAM,2BAA2B,CAAC;AAcnC,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AA+LjB,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAgB5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CA4B9F,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,+BAA+B,CAwBpF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { DatasourceSelect, useDatasourceClient,
|
|
14
|
+
import { DatasourceSelect, useDatasourceClient, parseVariables, replaceVariables } from '@perses-dev/plugin-system';
|
|
15
15
|
import { FormControl, InputLabel, Stack, TextField } from '@mui/material';
|
|
16
16
|
import { produce } from 'immer';
|
|
17
17
|
import { DEFAULT_PROM, getPrometheusTimeRange, isDefaultPromSelector, isPrometheusDatasourceSelector, PROM_DATASOURCE_KIND } from '../model';
|
|
@@ -228,7 +228,7 @@ export const PrometheusLabelNamesVariable = {
|
|
|
228
228
|
getVariableOptions: async (spec, ctx)=>{
|
|
229
229
|
var _spec_datasource;
|
|
230
230
|
const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
|
|
231
|
-
const match = spec.matchers ? spec.matchers.map((m)=>
|
|
231
|
+
const match = spec.matchers ? spec.matchers.map((m)=>replaceVariables(m, ctx.variables)) : undefined;
|
|
232
232
|
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
233
233
|
const { data: options } = await client.labelNames({
|
|
234
234
|
'match[]': match,
|
|
@@ -241,7 +241,7 @@ export const PrometheusLabelNamesVariable = {
|
|
|
241
241
|
dependsOn: (spec)=>{
|
|
242
242
|
var _spec_matchers;
|
|
243
243
|
return {
|
|
244
|
-
variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>
|
|
244
|
+
variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>parseVariables(m)).flat()) || []
|
|
245
245
|
};
|
|
246
246
|
},
|
|
247
247
|
OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
|
|
@@ -252,10 +252,10 @@ export const PrometheusLabelValuesVariable = {
|
|
|
252
252
|
const pluginDef = spec;
|
|
253
253
|
var _spec_datasource;
|
|
254
254
|
const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
|
|
255
|
-
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>
|
|
255
|
+
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceVariables(m, ctx.variables)) : undefined;
|
|
256
256
|
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
257
257
|
const { data: options } = await client.labelValues({
|
|
258
|
-
labelName:
|
|
258
|
+
labelName: replaceVariables(pluginDef.labelName, ctx.variables),
|
|
259
259
|
'match[]': match,
|
|
260
260
|
...timeRange
|
|
261
261
|
});
|
|
@@ -266,7 +266,7 @@ export const PrometheusLabelValuesVariable = {
|
|
|
266
266
|
dependsOn: (spec)=>{
|
|
267
267
|
var _spec_matchers;
|
|
268
268
|
return {
|
|
269
|
-
variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>
|
|
269
|
+
variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>parseVariables(m)).flat().concat(parseVariables(spec.labelName))) || []
|
|
270
270
|
};
|
|
271
271
|
},
|
|
272
272
|
OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
|
|
@@ -280,9 +280,9 @@ export const PrometheusPromQLVariable = {
|
|
|
280
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
|
-
query:
|
|
283
|
+
query: replaceVariables(spec.expr, ctx.variables)
|
|
284
284
|
});
|
|
285
|
-
const labelName =
|
|
285
|
+
const labelName = replaceVariables(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,7 +295,7 @@ export const PrometheusPromQLVariable = {
|
|
|
295
295
|
},
|
|
296
296
|
dependsOn: (spec)=>{
|
|
297
297
|
return {
|
|
298
|
-
variables:
|
|
298
|
+
variables: parseVariables(spec.expr).concat(parseVariables(spec.labelName))
|
|
299
299
|
};
|
|
300
300
|
},
|
|
301
301
|
OptionsEditorComponent: PrometheusPromQLVariableEditor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/prometheus-variables.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.\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n VariablePlugin,\n parseTemplateVariables,\n replaceTemplateVariables,\n GetVariableOptionsContext,\n} from '@perses-dev/plugin-system';\nimport { FormControl, InputLabel, Stack, TextField } from '@mui/material';\nimport { produce } from 'immer';\nimport {\n DEFAULT_PROM,\n getPrometheusTimeRange,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n VectorData,\n} from '../model';\nimport { PromQLEditor } from '../components';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\nimport { MatcherEditor } from './MatcherEditor';\n\nfunction PrometheusLabelValuesVariableEditor(props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n readOnly={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <TextField\n label=\"Label Name\"\n required\n value={props.value.labelName}\n onChange={(e) => {\n props.onChange({ ...props.value, labelName: e.target.value });\n }}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n />\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n isReadonly={props.isReadonly}\n />\n </Stack>\n );\n}\n\nfunction PrometheusLabelNamesVariableEditor(props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n disabled={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n isReadonly={props.isReadonly}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\n}\n\nfunction PrometheusPromQLVariableEditor(props: OptionsEditorProps<PrometheusPromQLVariableOptions>) {\n const { onChange, value } = 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\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n disabled={props.isReadonly}\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={value.expr}\n onChange={(query) => {\n props.onChange({ ...props.value, expr: query });\n }}\n readOnly={props.isReadonly}\n width=\"100%\"\n />\n <TextField\n label=\"Label Name\"\n value={props.value.labelName}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n onChange={(e) => {\n props.onChange({ ...props.value, labelName: e.target.value });\n }}\n />\n </Stack>\n );\n}\n\nfunction capturingMatrix(matrix: MatrixData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of matrix.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\nfunction capturingVector(vector: VectorData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of vector.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\n/**\n * Takes a list of strings and returns a list of VariableOptions\n */\nconst stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n\nexport const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelNamesVariableOptions, ctx: GetVariableOptionsContext) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = spec.matchers ? spec.matchers.map((m) => replaceTemplateVariables(m, ctx.variables)) : undefined;\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelNames({ 'match[]': match, ...timeRange });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelNamesVariableOptions) => {\n return { variables: spec.matchers?.map((m) => parseTemplateVariables(m)).flat() || [] };\n },\n OptionsEditorComponent: PrometheusLabelNamesVariableEditor,\n createInitialOptions: () => ({}),\n};\n\nexport const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelValuesVariableOptions, ctx: GetVariableOptionsContext) => {\n const pluginDef = spec;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = pluginDef.matchers\n ? pluginDef.matchers.map((m) => replaceTemplateVariables(m, ctx.variables))\n : undefined;\n\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues({\n labelName: replaceTemplateVariables(pluginDef.labelName, ctx.variables),\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelValuesVariableOptions) => {\n return {\n variables:\n spec.matchers\n ?.map((m) => parseTemplateVariables(m))\n .flat()\n .concat(parseTemplateVariables(spec.labelName)) || [],\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ labelName: '' }),\n};\n\nexport const PrometheusPromQLVariable: VariablePlugin<PrometheusPromQLVariableOptions> = {\n getVariableOptions: async (spec: PrometheusPromQLVariableOptions, ctx: GetVariableOptionsContext) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n // TODO we may want to manage a range query as well.\n const { data: options } = await client.instantQuery({\n query: replaceTemplateVariables(spec.expr, ctx.variables),\n });\n const labelName = replaceTemplateVariables(spec.labelName, ctx.variables);\n let values: string[] = [];\n if (options?.resultType === 'matrix') {\n values = capturingMatrix(options, labelName);\n } else if (options?.resultType === 'vector') {\n values = capturingVector(options, labelName);\n }\n\n return {\n data: stringArrayToVariableOptions(values),\n };\n },\n dependsOn: (spec: PrometheusPromQLVariableOptions) => {\n return { variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.labelName)) };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', labelName: '' }),\n};\n"],"names":["DatasourceSelect","useDatasourceClient","parseTemplateVariables","replaceTemplateVariables","FormControl","InputLabel","Stack","TextField","produce","DEFAULT_PROM","getPrometheusTimeRange","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","PromQLEditor","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","handleDatasourceChange","next","draft","undefined","Error","spacing","margin","id","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","labelName","e","target","InputProps","matchers","PrometheusLabelNamesVariableEditor","disabled","PrometheusPromQLVariableEditor","data","client","promURL","options","datasourceUrl","completeConfig","remote","url","expr","query","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","datasourceStore","getDatasourceClient","match","m","variables","timeRange","labelNames","dependsOn","flat","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","concat","PrometheusPromQLVariable","instantQuery","resultType"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,s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AAC/C,EAAE;AAEF,OAAO,MAAMqD,2BAA4E;IACvFlB,oBAAoB,OAAOC,MAAuCC;YACeD;QAA/E,MAAM3B,SAA2B,MAAM4B,IAAIC,eAAe,CAACC,mBAAmB,CAACH,CAAAA,mBAAAA,KAAKpD,UAAU,cAAfoD,8BAAAA,mBAAmB/D;QAClG,oDAAoD;QACpD,MAAM,EAAEmC,MAAMG,OAAO,EAAE,GAAG,MAAMF,OAAO6C,YAAY,CAAC;YAClDrC,OAAOlD,yBAAyBqE,KAAKpB,IAAI,EAAEqB,IAAIK,SAAS;QAC1D;QACA,MAAM1C,YAAYjC,yBAAyBqE,KAAKpC,SAAS,EAAEqC,IAAIK,SAAS;QACxE,IAAIb,SAAmB,EAAE;QACzB,IAAIlB,CAAAA,oBAAAA,8BAAAA,QAAS4C,UAAU,MAAK,UAAU;YACpC1B,SAASV,gBAAgBR,SAASX;QACpC,OAAO,IAAIW,CAAAA,oBAAAA,8BAAAA,QAAS4C,UAAU,MAAK,UAAU;YAC3C1B,SAASC,gBAAgBnB,SAASX;QACpC;QAEA,OAAO;YACLQ,MAAMwB,6BAA6BH;QACrC;IACF;IACAgB,WAAW,CAACT;QACV,OAAO;YAAEM,WAAW5E,uBAAuBsE,KAAKpB,IAAI,EAAEoC,MAAM,CAACtF,uBAAuBsE,KAAKpC,SAAS;QAAG;IACvG;IACA+C,wBAAwBxC;IACxByC,sBAAsB,IAAO,CAAA;YAAEhC,MAAM;YAAIhB,WAAW;QAAG,CAAA;AACzD,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/prometheus-variables.tsx"],"sourcesContent":["// Copyright 2024 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.\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n VariablePlugin,\n parseVariables,\n replaceVariables,\n GetVariableOptionsContext,\n} from '@perses-dev/plugin-system';\nimport { FormControl, InputLabel, Stack, TextField } from '@mui/material';\nimport { produce } from 'immer';\nimport {\n DEFAULT_PROM,\n getPrometheusTimeRange,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n VectorData,\n} from '../model';\nimport { PromQLEditor } from '../components';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\nimport { MatcherEditor } from './MatcherEditor';\n\nfunction PrometheusLabelValuesVariableEditor(props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n readOnly={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <TextField\n label=\"Label Name\"\n required\n value={props.value.labelName}\n onChange={(e) => {\n props.onChange({ ...props.value, labelName: e.target.value });\n }}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n />\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n isReadonly={props.isReadonly}\n />\n </Stack>\n );\n}\n\nfunction PrometheusLabelNamesVariableEditor(props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n disabled={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n isReadonly={props.isReadonly}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\n}\n\nfunction PrometheusPromQLVariableEditor(props: OptionsEditorProps<PrometheusPromQLVariableOptions>) {\n const { onChange, value } = 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\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n disabled={props.isReadonly}\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={value.expr}\n onChange={(query) => {\n props.onChange({ ...props.value, expr: query });\n }}\n readOnly={props.isReadonly}\n width=\"100%\"\n />\n <TextField\n label=\"Label Name\"\n value={props.value.labelName}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n onChange={(e) => {\n props.onChange({ ...props.value, labelName: e.target.value });\n }}\n />\n </Stack>\n );\n}\n\nfunction capturingMatrix(matrix: MatrixData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of matrix.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\nfunction capturingVector(vector: VectorData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of vector.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\n/**\n * Takes a list of strings and returns a list of VariableOptions\n */\nconst stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n\nexport const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelNamesVariableOptions, ctx: GetVariableOptionsContext) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = spec.matchers ? spec.matchers.map((m) => replaceVariables(m, ctx.variables)) : undefined;\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelNames({ 'match[]': match, ...timeRange });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelNamesVariableOptions) => {\n return { variables: spec.matchers?.map((m) => parseVariables(m)).flat() || [] };\n },\n OptionsEditorComponent: PrometheusLabelNamesVariableEditor,\n createInitialOptions: () => ({}),\n};\n\nexport const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelValuesVariableOptions, ctx: GetVariableOptionsContext) => {\n const pluginDef = spec;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = pluginDef.matchers ? pluginDef.matchers.map((m) => replaceVariables(m, ctx.variables)) : undefined;\n\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues({\n labelName: replaceVariables(pluginDef.labelName, ctx.variables),\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelValuesVariableOptions) => {\n return {\n variables:\n spec.matchers\n ?.map((m) => parseVariables(m))\n .flat()\n .concat(parseVariables(spec.labelName)) || [],\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ labelName: '' }),\n};\n\nexport const PrometheusPromQLVariable: VariablePlugin<PrometheusPromQLVariableOptions> = {\n getVariableOptions: async (spec: PrometheusPromQLVariableOptions, ctx: GetVariableOptionsContext) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n // TODO we may want to manage a range query as well.\n const { data: options } = await client.instantQuery({\n query: replaceVariables(spec.expr, ctx.variables),\n });\n const labelName = replaceVariables(spec.labelName, ctx.variables);\n let values: string[] = [];\n if (options?.resultType === 'matrix') {\n values = capturingMatrix(options, labelName);\n } else if (options?.resultType === 'vector') {\n values = capturingVector(options, labelName);\n }\n\n return {\n data: stringArrayToVariableOptions(values),\n };\n },\n dependsOn: (spec: PrometheusPromQLVariableOptions) => {\n return { variables: parseVariables(spec.expr).concat(parseVariables(spec.labelName)) };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', labelName: '' }),\n};\n"],"names":["DatasourceSelect","useDatasourceClient","parseVariables","replaceVariables","FormControl","InputLabel","Stack","TextField","produce","DEFAULT_PROM","getPrometheusTimeRange","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","PromQLEditor","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","handleDatasourceChange","next","draft","undefined","Error","spacing","margin","id","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","labelName","e","target","InputProps","matchers","PrometheusLabelNamesVariableEditor","disabled","PrometheusPromQLVariableEditor","data","client","promURL","options","datasourceUrl","completeConfig","remote","url","expr","query","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","datasourceStore","getDatasourceClient","match","m","variables","timeRange","labelNames","dependsOn","flat","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","concat","PrometheusPromQLVariable","instantQuery","resultType"],"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;;AACjC,SACEA,gBAAgB,EAGhBC,mBAAmB,EAGnBC,cAAc,EACdC,gBAAgB,QAEX,4BAA4B;AACnC,SAASC,WAAW,EAAEC,UAAU,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC1E,SAASC,OAAO,QAAQ,QAAQ;AAChC,SACEC,YAAY,EACZC,sBAAsB,EACtBC,qBAAqB,EACrBC,8BAA8B,EAE9BC,oBAAoB,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K,SAAS;QAClD;QACA,MAAM1C,YAAYjC,iBAAiBqE,KAAKpC,SAAS,EAAEqC,IAAIK,SAAS;QAChE,IAAIb,SAAmB,EAAE;QACzB,IAAIlB,CAAAA,oBAAAA,8BAAAA,QAAS4C,UAAU,MAAK,UAAU;YACpC1B,SAASV,gBAAgBR,SAASX;QACpC,OAAO,IAAIW,CAAAA,oBAAAA,8BAAAA,QAAS4C,UAAU,MAAK,UAAU;YAC3C1B,SAASC,gBAAgBnB,SAASX;QACpC;QAEA,OAAO;YACLQ,MAAMwB,6BAA6BH;QACrC;IACF;IACAgB,WAAW,CAACT;QACV,OAAO;YAAEM,WAAW5E,eAAesE,KAAKpB,IAAI,EAAEoC,MAAM,CAACtF,eAAesE,KAAKpC,SAAS;QAAG;IACvF;IACA+C,wBAAwBxC;IACxByC,sBAAsB,IAAO,CAAA;YAAEhC,MAAM;YAAIhB,WAAW;QAAG,CAAA;AACzD,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/prometheus-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.0-rc0",
|
|
4
4
|
"description": "Prometheus plugin for Perses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -31,13 +31,14 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@lezer/highlight": "^1.0.0",
|
|
33
33
|
"@lezer/lr": "^1.2.0",
|
|
34
|
-
"@perses-dev/components": "0.
|
|
35
|
-
"@perses-dev/core": "0.
|
|
36
|
-
"@perses-dev/plugin-system": "0.
|
|
34
|
+
"@perses-dev/components": "0.47.0-rc0",
|
|
35
|
+
"@perses-dev/core": "0.47.0-rc0",
|
|
36
|
+
"@perses-dev/plugin-system": "0.47.0-rc0",
|
|
37
37
|
"@prometheus-io/codemirror-promql": "^0.43.0",
|
|
38
38
|
"@uiw/react-codemirror": "^4.19.1",
|
|
39
39
|
"date-fns": "^2.28.0",
|
|
40
|
-
"immer": "^9.0.15"
|
|
40
|
+
"immer": "^9.0.15",
|
|
41
|
+
"react-hook-form": "^7.46.1"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
44
|
"react": "^17.0.2 || ^18.0.0"
|