@perses-dev/prometheus-plugin 0.53.4 → 0.55.0
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/__mf/css/async/1339.d3010b86.css +1 -0
- package/__mf/css/async/1576.d3010b86.css +1 -0
- package/__mf/css/async/4576.d3010b86.css +1 -0
- package/__mf/js/{Prometheus.780ccd9b.js → Prometheus.f0d65264.js} +3 -3
- package/__mf/js/async/1339.194207db.js +1 -0
- package/__mf/js/async/212.5fcca998.js +1 -0
- package/__mf/js/async/2178.0f075947.js +2 -0
- package/__mf/js/async/2472.2134f9f7.js +22 -0
- package/__mf/js/async/3749.3ecd9372.js +1 -0
- package/__mf/js/async/{4075.88e3f633.js → 4075.dab1b7b8.js} +1 -1
- package/__mf/js/async/{4238.422a1b1c.js → 4238.c48b1950.js} +1 -1
- package/__mf/js/async/4421.6ebf935f.js +1 -0
- package/__mf/js/async/4576.f42daf99.js +1 -0
- package/__mf/js/async/6341.70ddfbe9.js +7 -0
- package/__mf/js/async/6620.5a15a075.js +2 -0
- package/__mf/js/async/684.4495f632.js +1 -0
- package/__mf/js/async/8164.bb3d3363.js +1 -0
- package/__mf/js/async/8706.08030938.js +1 -0
- package/__mf/js/async/{2675.27451820.js → 9010.bdb2ef97.js} +1 -1
- package/__mf/js/async/__federation_expose_PrometheusDatasource.dcb93aae.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusExplorer.9ab5666d.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.0f7697ac.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.cd804473.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.4c376d6b.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.d4984d73.js +1 -0
- package/__mf/js/{main.34d1997e.js → main.d76b840e.js} +3 -3
- package/lib/cjs/explore/PrometheusExplorer.js +7 -2
- package/lib/cjs/model/prometheus-client.js +4 -2
- package/lib/cjs/plugins/PrometheusLabelNamesVariable.js +8 -2
- package/lib/cjs/plugins/PrometheusLabelValuesVariable.js +10 -2
- package/lib/cjs/plugins/PrometheusPromQLVariable.js +10 -2
- package/lib/cjs/plugins/prometheus-datasource.js +21 -14
- package/lib/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +3 -3
- package/lib/cjs/plugins/prometheus-variables.js +9 -8
- package/lib/explore/PrometheusExplorer.d.ts.map +1 -1
- package/lib/explore/PrometheusExplorer.js +7 -2
- package/lib/explore/PrometheusExplorer.js.map +1 -1
- package/lib/model/prometheus-client.d.ts +8 -7
- package/lib/model/prometheus-client.d.ts.map +1 -1
- package/lib/model/prometheus-client.js +4 -2
- package/lib/model/prometheus-client.js.map +1 -1
- package/lib/model/prometheus-selectors.d.ts +2 -2
- package/lib/model/prometheus-selectors.d.ts.map +1 -1
- package/lib/model/prometheus-selectors.js.map +1 -1
- package/lib/plugins/PrometheusLabelNamesVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusLabelNamesVariable.js +10 -4
- package/lib/plugins/PrometheusLabelNamesVariable.js.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.js +12 -4
- package/lib/plugins/PrometheusLabelValuesVariable.js.map +1 -1
- package/lib/plugins/PrometheusPromQLVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusPromQLVariable.js +12 -4
- package/lib/plugins/PrometheusPromQLVariable.js.map +1 -1
- package/lib/plugins/prometheus-datasource.d.ts.map +1 -1
- package/lib/plugins/prometheus-datasource.js +21 -14
- package/lib/plugins/prometheus-datasource.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.js +3 -3
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/lib/plugins/prometheus-variables.d.ts.map +1 -1
- package/lib/plugins/prometheus-variables.js +10 -9
- package/lib/plugins/prometheus-variables.js.map +1 -1
- package/lib/plugins/types.d.ts +2 -1
- package/lib/plugins/types.d.ts.map +1 -1
- package/lib/plugins/types.js.map +1 -1
- package/mf-manifest.json +104 -98
- package/mf-stats.json +107 -101
- package/package.json +7 -7
- package/__mf/css/async/1576.dacad691.css +0 -1
- package/__mf/css/async/2188.dacad691.css +0 -1
- package/__mf/css/async/2341.dacad691.css +0 -1
- package/__mf/js/async/212.69f85c2b.js +0 -1
- package/__mf/js/async/2188.d2c5eadd.js +0 -1
- package/__mf/js/async/2275.95fa6219.js +0 -7
- package/__mf/js/async/3391.eced295d.js +0 -73
- package/__mf/js/async/4323.fdf7d039.js +0 -1
- package/__mf/js/async/4368.38ebfc12.js +0 -2
- package/__mf/js/async/4421.b5492f46.js +0 -1
- package/__mf/js/async/6714.fd02e782.js +0 -2
- package/__mf/js/async/684.f7b5c16e.js +0 -1
- package/__mf/js/async/7239.2619666a.js +0 -1
- package/__mf/js/async/8706.70f829fc.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusDatasource.8b4b16ca.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusExplorer.8faab52f.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.baed70be.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.86fed903.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.8eb55b7f.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.66df70ad.js +0 -1
- /package/__mf/js/async/{4368.38ebfc12.js.LICENSE.txt → 2178.0f075947.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{3391.eced295d.js.LICENSE.txt → 2472.2134f9f7.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{2275.95fa6219.js.LICENSE.txt → 6341.70ddfbe9.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{6714.fd02e782.js.LICENSE.txt → 6620.5a15a075.js.LICENSE.txt} +0 -0
|
@@ -13,7 +13,8 @@ const _model = require("../model");
|
|
|
13
13
|
const _prometheusvariables = require("./prometheus-variables");
|
|
14
14
|
const PrometheusPromQLVariable = {
|
|
15
15
|
getVariableOptions: async (spec, ctx)=>{
|
|
16
|
-
const
|
|
16
|
+
const datasourceSelector = (0, _pluginsystem.datasourceSelectValueToSelector)(spec.datasource ?? _model.DEFAULT_PROM, ctx.variables, await ctx.datasourceStore.listDatasourceSelectItems(_model.PROM_DATASOURCE_KIND)) ?? _model.DEFAULT_PROM;
|
|
17
|
+
const client = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);
|
|
17
18
|
// TODO we may want to manage a range query as well.
|
|
18
19
|
const { data: options } = await client.instantQuery({
|
|
19
20
|
query: (0, _pluginsystem.replaceVariables)(spec.expr, ctx.variables)
|
|
@@ -30,8 +31,15 @@ const PrometheusPromQLVariable = {
|
|
|
30
31
|
};
|
|
31
32
|
},
|
|
32
33
|
dependsOn: (spec)=>{
|
|
34
|
+
const exprVariables = (0, _pluginsystem.parseVariables)(spec.expr);
|
|
35
|
+
const labelVariables = (0, _pluginsystem.parseVariables)(spec.labelName);
|
|
36
|
+
const datasourceVariables = spec.datasource && (0, _pluginsystem.isVariableDatasource)(spec.datasource) ? (0, _pluginsystem.parseVariables)(spec.datasource) : [];
|
|
33
37
|
return {
|
|
34
|
-
variables:
|
|
38
|
+
variables: [
|
|
39
|
+
...exprVariables,
|
|
40
|
+
...labelVariables,
|
|
41
|
+
...datasourceVariables
|
|
42
|
+
]
|
|
35
43
|
};
|
|
36
44
|
},
|
|
37
45
|
OptionsEditorComponent: _prometheusvariables.PrometheusPromQLVariableEditor,
|
|
@@ -42,33 +42,40 @@ const _PrometheusDatasourceEditor = require("./PrometheusDatasourceEditor");
|
|
|
42
42
|
datasourceUrl,
|
|
43
43
|
headers: specHeaders
|
|
44
44
|
}),
|
|
45
|
-
instantQuery: (params, headers)=>(0, _model.instantQuery)(params, {
|
|
45
|
+
instantQuery: (params, headers, abortSignal)=>(0, _model.instantQuery)(params, {
|
|
46
46
|
datasourceUrl,
|
|
47
|
-
headers: headers ?? specHeaders
|
|
47
|
+
headers: headers ?? specHeaders,
|
|
48
|
+
abortSignal
|
|
48
49
|
}),
|
|
49
|
-
rangeQuery: (params, headers)=>(0, _model.rangeQuery)(params, {
|
|
50
|
+
rangeQuery: (params, headers, abortSignal)=>(0, _model.rangeQuery)(params, {
|
|
50
51
|
datasourceUrl,
|
|
51
|
-
headers: headers ?? specHeaders
|
|
52
|
+
headers: headers ?? specHeaders,
|
|
53
|
+
abortSignal
|
|
52
54
|
}),
|
|
53
|
-
labelNames: (params, headers)=>(0, _model.labelNames)(params, {
|
|
55
|
+
labelNames: (params, headers, abortSignal)=>(0, _model.labelNames)(params, {
|
|
54
56
|
datasourceUrl,
|
|
55
|
-
headers: headers ?? specHeaders
|
|
57
|
+
headers: headers ?? specHeaders,
|
|
58
|
+
abortSignal
|
|
56
59
|
}),
|
|
57
|
-
labelValues: (params, headers)=>(0, _model.labelValues)(params, {
|
|
60
|
+
labelValues: (params, headers, abortSignal)=>(0, _model.labelValues)(params, {
|
|
58
61
|
datasourceUrl,
|
|
59
|
-
headers: headers ?? specHeaders
|
|
62
|
+
headers: headers ?? specHeaders,
|
|
63
|
+
abortSignal
|
|
60
64
|
}),
|
|
61
|
-
metricMetadata: (params, headers)=>(0, _model.metricMetadata)(params, {
|
|
65
|
+
metricMetadata: (params, headers, abortSignal)=>(0, _model.metricMetadata)(params, {
|
|
62
66
|
datasourceUrl,
|
|
63
|
-
headers: headers ?? specHeaders
|
|
67
|
+
headers: headers ?? specHeaders,
|
|
68
|
+
abortSignal
|
|
64
69
|
}),
|
|
65
|
-
series: (params, headers)=>(0, _model.series)(params, {
|
|
70
|
+
series: (params, headers, abortSignal)=>(0, _model.series)(params, {
|
|
66
71
|
datasourceUrl,
|
|
67
|
-
headers: headers ?? specHeaders
|
|
72
|
+
headers: headers ?? specHeaders,
|
|
73
|
+
abortSignal
|
|
68
74
|
}),
|
|
69
|
-
parseQuery: (params, headers)=>(0, _model.parseQuery)(params, {
|
|
75
|
+
parseQuery: (params, headers, abortSignal)=>(0, _model.parseQuery)(params, {
|
|
70
76
|
datasourceUrl,
|
|
71
|
-
headers: headers ?? specHeaders
|
|
77
|
+
headers: headers ?? specHeaders,
|
|
78
|
+
abortSignal
|
|
72
79
|
})
|
|
73
80
|
};
|
|
74
81
|
};
|
|
@@ -27,7 +27,7 @@ const _model = require("../../model");
|
|
|
27
27
|
const _utils = require("../../utils");
|
|
28
28
|
const _types = require("../types");
|
|
29
29
|
const _replaceprombuiltinvariables = require("./replace-prom-builtin-variables");
|
|
30
|
-
const getTimeSeriesData = async (spec, context)=>{
|
|
30
|
+
const getTimeSeriesData = async (spec, context, abortSignal)=>{
|
|
31
31
|
if (spec.query === undefined || spec.query === null || spec.query === '') {
|
|
32
32
|
// Do not make a request to the backend, instead return an empty TimeSeriesData
|
|
33
33
|
return {
|
|
@@ -79,7 +79,7 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
79
79
|
response = await client.instantQuery({
|
|
80
80
|
query,
|
|
81
81
|
time: end
|
|
82
|
-
});
|
|
82
|
+
}, undefined, abortSignal);
|
|
83
83
|
break;
|
|
84
84
|
case 'range':
|
|
85
85
|
default:
|
|
@@ -88,7 +88,7 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
88
88
|
start,
|
|
89
89
|
end,
|
|
90
90
|
step
|
|
91
|
-
});
|
|
91
|
+
}, undefined, abortSignal);
|
|
92
92
|
break;
|
|
93
93
|
}
|
|
94
94
|
// TODO: What about error responses from Prom that have a response body?
|
|
@@ -54,10 +54,10 @@ function PrometheusLabelValuesVariableEditor(props) {
|
|
|
54
54
|
const [labelValue, setLabelValue] = (0, _react.useState)(props.value.labelName);
|
|
55
55
|
const [matchersValues, setMatchersValues] = (0, _react.useState)(props.value.matchers ?? []);
|
|
56
56
|
const handleDatasourceChange = (0, _react.useCallback)((next)=>{
|
|
57
|
-
if ((0, _model.isPrometheusDatasourceSelector)(next)) {
|
|
57
|
+
if ((0, _pluginsystem.isVariableDatasource)(next) || (0, _model.isPrometheusDatasourceSelector)(next)) {
|
|
58
58
|
onChange((0, _immer.produce)(value, (draft)=>{
|
|
59
59
|
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
60
|
-
draft.datasource = (0, _model.isDefaultPromSelector)(next) ? undefined : next;
|
|
60
|
+
draft.datasource = !(0, _pluginsystem.isVariableDatasource)(next) && (0, _model.isDefaultPromSelector)(next) ? undefined : next;
|
|
61
61
|
}));
|
|
62
62
|
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
|
|
63
63
|
...value,
|
|
@@ -127,10 +127,10 @@ function PrometheusLabelNamesVariableEditor(props) {
|
|
|
127
127
|
const selectedDatasource = datasource ?? _model.DEFAULT_PROM;
|
|
128
128
|
const [matchersValues, setMatchersValues] = (0, _react.useState)(props.value.matchers ?? []);
|
|
129
129
|
const handleDatasourceChange = (0, _react.useCallback)((next)=>{
|
|
130
|
-
if ((0, _model.isPrometheusDatasourceSelector)(next)) {
|
|
130
|
+
if ((0, _pluginsystem.isVariableDatasource)(next) || (0, _model.isPrometheusDatasourceSelector)(next)) {
|
|
131
131
|
onChange((0, _immer.produce)(value, (draft)=>{
|
|
132
132
|
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
133
|
-
draft.datasource = (0, _model.isDefaultPromSelector)(next) ? undefined : next;
|
|
133
|
+
draft.datasource = !(0, _pluginsystem.isVariableDatasource)(next) && (0, _model.isDefaultPromSelector)(next) ? undefined : next;
|
|
134
134
|
}));
|
|
135
135
|
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
|
|
136
136
|
...value,
|
|
@@ -180,15 +180,16 @@ function PrometheusLabelNamesVariableEditor(props) {
|
|
|
180
180
|
}
|
|
181
181
|
function PrometheusPromQLVariableEditor(props) {
|
|
182
182
|
const { onChange, value, value: { datasource }, queryHandlerSettings } = props;
|
|
183
|
-
const
|
|
183
|
+
const datasourceSelectValue = datasource ?? _model.DEFAULT_PROM;
|
|
184
|
+
const selectedDatasource = (0, _pluginsystem.useDatasourceSelectValueToSelector)(datasourceSelectValue, _model.PROM_DATASOURCE_KIND);
|
|
184
185
|
const { data: client } = (0, _pluginsystem.useDatasourceClient)(selectedDatasource);
|
|
185
186
|
const promURL = client?.options.datasourceUrl;
|
|
186
187
|
const [labelValue, setLableValue] = (0, _react.useState)(props.value.labelName);
|
|
187
188
|
const handleDatasourceChange = (0, _react.useCallback)((next)=>{
|
|
188
|
-
if ((0, _model.isPrometheusDatasourceSelector)(next)) {
|
|
189
|
+
if ((0, _pluginsystem.isVariableDatasource)(next) || (0, _model.isPrometheusDatasourceSelector)(next)) {
|
|
189
190
|
onChange((0, _immer.produce)(value, (draft)=>{
|
|
190
191
|
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
191
|
-
draft.datasource = (0, _model.isDefaultPromSelector)(next) ? undefined : next;
|
|
192
|
+
draft.datasource = !(0, _pluginsystem.isVariableDatasource)(next) && (0, _model.isDefaultPromSelector)(next) ? undefined : next;
|
|
192
193
|
}));
|
|
193
194
|
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
|
|
194
195
|
...value,
|
|
@@ -237,7 +238,7 @@ function PrometheusPromQLVariableEditor(props) {
|
|
|
237
238
|
margin: "dense",
|
|
238
239
|
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DatasourceSelect, {
|
|
239
240
|
datasourcePluginKind: _model.PROM_DATASOURCE_KIND,
|
|
240
|
-
value:
|
|
241
|
+
value: datasourceSelectValue,
|
|
241
242
|
onChange: handleDatasourceChange,
|
|
242
243
|
labelId: "prom-datasource-label",
|
|
243
244
|
label: "Prometheus Datasource",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusExplorer.d.ts","sourceRoot":"","sources":["../../../src/explore/PrometheusExplorer.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"PrometheusExplorer.d.ts","sourceRoot":"","sources":["../../../src/explore/PrometheusExplorer.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AA0ErC,wBAAgB,kBAAkB,IAAI,YAAY,CAoDjD"}
|
|
@@ -19,6 +19,9 @@ import { Panel } from '@perses-dev/dashboards';
|
|
|
19
19
|
import { DEFAULT_PROM } from '../model/prometheus-selectors';
|
|
20
20
|
import { PrometheusMetricsFinder } from './PrometheusMetricsFinder';
|
|
21
21
|
const PANEL_PREVIEW_HEIGHT = 700;
|
|
22
|
+
const FILTERED_QUERY_PLUGINS = [
|
|
23
|
+
'PrometheusTimeSeriesQuery'
|
|
24
|
+
];
|
|
22
25
|
function TimeSeriesPanel({ queries }) {
|
|
23
26
|
const { width, ref: boxRef } = useResizeObserver();
|
|
24
27
|
const height = PANEL_PREVIEW_HEIGHT;
|
|
@@ -144,7 +147,8 @@ export function PrometheusExplorer() {
|
|
|
144
147
|
tab,
|
|
145
148
|
queries: state
|
|
146
149
|
}),
|
|
147
|
-
queries: queries
|
|
150
|
+
queries: queries,
|
|
151
|
+
filteredQueryPlugins: FILTERED_QUERY_PLUGINS
|
|
148
152
|
}),
|
|
149
153
|
/*#__PURE__*/ _jsx(MetricDataTable, {
|
|
150
154
|
queries: queries
|
|
@@ -161,7 +165,8 @@ export function PrometheusExplorer() {
|
|
|
161
165
|
tab,
|
|
162
166
|
queries: state
|
|
163
167
|
}),
|
|
164
|
-
queries: queries
|
|
168
|
+
queries: queries,
|
|
169
|
+
filteredQueryPlugins: FILTERED_QUERY_PLUGINS
|
|
165
170
|
}),
|
|
166
171
|
/*#__PURE__*/ _jsx(TimeSeriesPanel, {
|
|
167
172
|
queries: queries
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/explore/PrometheusExplorer.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.\n\nimport { QueryDefinition } from '@perses-dev/core';\nimport { Box, Stack, Tab, Tabs } from '@mui/material';\nimport { DataQueriesProvider, MultiQueryEditor, useSuggestedStepMs } from '@perses-dev/plugin-system';\nimport { useExplorerManagerContext } from '@perses-dev/explore';\nimport useResizeObserver from 'use-resize-observer';\nimport { Panel } from '@perses-dev/dashboards';\nimport { ReactElement } from 'react';\nimport { DEFAULT_PROM } from '../model/prometheus-selectors';\nimport { FinderQueryParams } from './PrometheusMetricsFinder/types';\nimport { PrometheusMetricsFinder } from './PrometheusMetricsFinder';\n\ninterface MetricsExplorerQueryParams extends FinderQueryParams {\n tab?: string;\n queries?: QueryDefinition[];\n}\n\nconst PANEL_PREVIEW_HEIGHT = 700;\n\nfunction TimeSeriesPanel({ queries }: { queries: QueryDefinition[] }): ReactElement {\n const { width, ref: boxRef } = useResizeObserver();\n const height = PANEL_PREVIEW_HEIGHT;\n\n const suggestedStepMs = useSuggestedStepMs(width);\n\n // map TimeSeriesQueryDefinition to Definition<UnknownSpec>\n const definitions = queries.length\n ? queries.map((query) => {\n return {\n kind: query.spec.plugin.kind,\n spec: query.spec.plugin.spec,\n };\n })\n : [];\n\n return (\n <Box ref={boxRef} height={height}>\n <DataQueriesProvider definitions={definitions} options={{ suggestedStepMs, mode: 'range' }}>\n <Panel\n panelOptions={{\n hideHeader: true,\n }}\n definition={{\n kind: 'Panel',\n spec: { queries: queries, display: { name: '' }, plugin: { kind: 'TimeSeriesChart', spec: {} } },\n }}\n />\n </DataQueriesProvider>\n </Box>\n );\n}\n\nfunction MetricDataTable({ queries }: { queries: QueryDefinition[] }): ReactElement {\n const height = PANEL_PREVIEW_HEIGHT;\n\n // map TimeSeriesQueryDefinition to Definition<UnknownSpec>\n const definitions = queries.map((query) => {\n return {\n kind: query.spec.plugin.kind,\n spec: query.spec.plugin.spec,\n };\n });\n\n return (\n <Box height={height}>\n <DataQueriesProvider definitions={definitions} options={{ mode: 'instant' }}>\n <Panel\n panelOptions={{\n hideHeader: true,\n }}\n definition={{\n kind: 'Panel',\n spec: { queries: queries, display: { name: '' }, plugin: { kind: 'TimeSeriesTable', spec: {} } },\n }}\n />\n </DataQueriesProvider>\n </Box>\n );\n}\n\nexport function PrometheusExplorer(): ReactElement {\n const {\n data: { tab = 'table', queries = [], datasource = DEFAULT_PROM, filters = [], exploredMetric = undefined },\n setData,\n } = useExplorerManagerContext<MetricsExplorerQueryParams>();\n\n return (\n <Stack gap={2} sx={{ width: '100%' }}>\n <Tabs\n value={tab}\n onChange={(_, state) => setData({ tab: state, queries })}\n variant=\"scrollable\"\n sx={{ borderBottom: 1, borderColor: 'divider' }}\n >\n <Tab value=\"table\" label=\"Table\" />\n <Tab value=\"graph\" label=\"Graph\" />\n <Tab value=\"finder\" label=\"Finder\" />\n </Tabs>\n <Stack gap={1}>\n {tab === 'table' && (\n <Stack>\n <MultiQueryEditor\n queryTypes={['TimeSeriesQuery']}\n onChange={(state) => setData({ tab, queries: state })}\n queries={queries}\n />\n <MetricDataTable queries={queries} />\n </Stack>\n )}\n {tab === 'graph' && (\n <Stack>\n <MultiQueryEditor\n queryTypes={['TimeSeriesQuery']}\n onChange={(state) => setData({ tab, queries: state })}\n queries={queries}\n />\n <TimeSeriesPanel queries={queries} />\n </Stack>\n )}\n {tab === 'finder' && (\n <Stack>\n <PrometheusMetricsFinder\n onChange={(state) => setData({ tab, ...state })}\n value={{ datasource, filters, exploredMetric }}\n />\n </Stack>\n )}\n </Stack>\n </Stack>\n );\n}\n"],"names":["Box","Stack","Tab","Tabs","DataQueriesProvider","MultiQueryEditor","useSuggestedStepMs","useExplorerManagerContext","useResizeObserver","Panel","DEFAULT_PROM","PrometheusMetricsFinder","PANEL_PREVIEW_HEIGHT","TimeSeriesPanel","queries","width","ref","boxRef","height","suggestedStepMs","definitions","length","map","query","kind","spec","plugin","options","mode","panelOptions","hideHeader","definition","display","name","MetricDataTable","PrometheusExplorer","data","tab","datasource","filters","exploredMetric","undefined","setData","gap","sx","value","onChange","_","state","variant","borderBottom","borderColor","label","queryTypes"],"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;;AAGjC,SAASA,GAAG,EAAEC,KAAK,EAAEC,GAAG,EAAEC,IAAI,QAAQ,gBAAgB;AACtD,SAASC,mBAAmB,EAAEC,gBAAgB,EAAEC,kBAAkB,QAAQ,4BAA4B;AACtG,SAASC,yBAAyB,QAAQ,sBAAsB;AAChE,OAAOC,uBAAuB,sBAAsB;AACpD,SAASC,KAAK,QAAQ,yBAAyB;AAE/C,SAASC,YAAY,QAAQ,gCAAgC;AAE7D,SAASC,uBAAuB,QAAQ,4BAA4B;AAOpE,MAAMC,uBAAuB;
|
|
1
|
+
{"version":3,"sources":["../../../src/explore/PrometheusExplorer.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.\n\nimport { QueryDefinition } from '@perses-dev/core';\nimport { Box, Stack, Tab, Tabs } from '@mui/material';\nimport { DataQueriesProvider, MultiQueryEditor, useSuggestedStepMs } from '@perses-dev/plugin-system';\nimport { useExplorerManagerContext } from '@perses-dev/explore';\nimport useResizeObserver from 'use-resize-observer';\nimport { Panel } from '@perses-dev/dashboards';\nimport { ReactElement } from 'react';\nimport { DEFAULT_PROM } from '../model/prometheus-selectors';\nimport { FinderQueryParams } from './PrometheusMetricsFinder/types';\nimport { PrometheusMetricsFinder } from './PrometheusMetricsFinder';\n\ninterface MetricsExplorerQueryParams extends FinderQueryParams {\n tab?: string;\n queries?: QueryDefinition[];\n}\n\nconst PANEL_PREVIEW_HEIGHT = 700;\nconst FILTERED_QUERY_PLUGINS = ['PrometheusTimeSeriesQuery'];\n\nfunction TimeSeriesPanel({ queries }: { queries: QueryDefinition[] }): ReactElement {\n const { width, ref: boxRef } = useResizeObserver();\n const height = PANEL_PREVIEW_HEIGHT;\n\n const suggestedStepMs = useSuggestedStepMs(width);\n\n // map TimeSeriesQueryDefinition to Definition<UnknownSpec>\n const definitions = queries.length\n ? queries.map((query) => {\n return {\n kind: query.spec.plugin.kind,\n spec: query.spec.plugin.spec,\n };\n })\n : [];\n\n return (\n <Box ref={boxRef} height={height}>\n <DataQueriesProvider definitions={definitions} options={{ suggestedStepMs, mode: 'range' }}>\n <Panel\n panelOptions={{\n hideHeader: true,\n }}\n definition={{\n kind: 'Panel',\n spec: { queries: queries, display: { name: '' }, plugin: { kind: 'TimeSeriesChart', spec: {} } },\n }}\n />\n </DataQueriesProvider>\n </Box>\n );\n}\n\nfunction MetricDataTable({ queries }: { queries: QueryDefinition[] }): ReactElement {\n const height = PANEL_PREVIEW_HEIGHT;\n\n // map TimeSeriesQueryDefinition to Definition<UnknownSpec>\n const definitions = queries.map((query) => {\n return {\n kind: query.spec.plugin.kind,\n spec: query.spec.plugin.spec,\n };\n });\n\n return (\n <Box height={height}>\n <DataQueriesProvider definitions={definitions} options={{ mode: 'instant' }}>\n <Panel\n panelOptions={{\n hideHeader: true,\n }}\n definition={{\n kind: 'Panel',\n spec: { queries: queries, display: { name: '' }, plugin: { kind: 'TimeSeriesTable', spec: {} } },\n }}\n />\n </DataQueriesProvider>\n </Box>\n );\n}\n\nexport function PrometheusExplorer(): ReactElement {\n const {\n data: { tab = 'table', queries = [], datasource = DEFAULT_PROM, filters = [], exploredMetric = undefined },\n setData,\n } = useExplorerManagerContext<MetricsExplorerQueryParams>();\n\n return (\n <Stack gap={2} sx={{ width: '100%' }}>\n <Tabs\n value={tab}\n onChange={(_, state) => setData({ tab: state, queries })}\n variant=\"scrollable\"\n sx={{ borderBottom: 1, borderColor: 'divider' }}\n >\n <Tab value=\"table\" label=\"Table\" />\n <Tab value=\"graph\" label=\"Graph\" />\n <Tab value=\"finder\" label=\"Finder\" />\n </Tabs>\n <Stack gap={1}>\n {tab === 'table' && (\n <Stack>\n <MultiQueryEditor\n queryTypes={['TimeSeriesQuery']}\n onChange={(state) => setData({ tab, queries: state })}\n queries={queries}\n filteredQueryPlugins={FILTERED_QUERY_PLUGINS}\n />\n <MetricDataTable queries={queries} />\n </Stack>\n )}\n {tab === 'graph' && (\n <Stack>\n <MultiQueryEditor\n queryTypes={['TimeSeriesQuery']}\n onChange={(state) => setData({ tab, queries: state })}\n queries={queries}\n filteredQueryPlugins={FILTERED_QUERY_PLUGINS}\n />\n <TimeSeriesPanel queries={queries} />\n </Stack>\n )}\n {tab === 'finder' && (\n <Stack>\n <PrometheusMetricsFinder\n onChange={(state) => setData({ tab, ...state })}\n value={{ datasource, filters, exploredMetric }}\n />\n </Stack>\n )}\n </Stack>\n </Stack>\n );\n}\n"],"names":["Box","Stack","Tab","Tabs","DataQueriesProvider","MultiQueryEditor","useSuggestedStepMs","useExplorerManagerContext","useResizeObserver","Panel","DEFAULT_PROM","PrometheusMetricsFinder","PANEL_PREVIEW_HEIGHT","FILTERED_QUERY_PLUGINS","TimeSeriesPanel","queries","width","ref","boxRef","height","suggestedStepMs","definitions","length","map","query","kind","spec","plugin","options","mode","panelOptions","hideHeader","definition","display","name","MetricDataTable","PrometheusExplorer","data","tab","datasource","filters","exploredMetric","undefined","setData","gap","sx","value","onChange","_","state","variant","borderBottom","borderColor","label","queryTypes","filteredQueryPlugins"],"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;;AAGjC,SAASA,GAAG,EAAEC,KAAK,EAAEC,GAAG,EAAEC,IAAI,QAAQ,gBAAgB;AACtD,SAASC,mBAAmB,EAAEC,gBAAgB,EAAEC,kBAAkB,QAAQ,4BAA4B;AACtG,SAASC,yBAAyB,QAAQ,sBAAsB;AAChE,OAAOC,uBAAuB,sBAAsB;AACpD,SAASC,KAAK,QAAQ,yBAAyB;AAE/C,SAASC,YAAY,QAAQ,gCAAgC;AAE7D,SAASC,uBAAuB,QAAQ,4BAA4B;AAOpE,MAAMC,uBAAuB;AAC7B,MAAMC,yBAAyB;IAAC;CAA4B;AAE5D,SAASC,gBAAgB,EAAEC,OAAO,EAAkC;IAClE,MAAM,EAAEC,KAAK,EAAEC,KAAKC,MAAM,EAAE,GAAGV;IAC/B,MAAMW,SAASP;IAEf,MAAMQ,kBAAkBd,mBAAmBU;IAE3C,2DAA2D;IAC3D,MAAMK,cAAcN,QAAQO,MAAM,GAC9BP,QAAQQ,GAAG,CAAC,CAACC;QACX,OAAO;YACLC,MAAMD,MAAME,IAAI,CAACC,MAAM,CAACF,IAAI;YAC5BC,MAAMF,MAAME,IAAI,CAACC,MAAM,CAACD,IAAI;QAC9B;IACF,KACA,EAAE;IAEN,qBACE,KAAC1B;QAAIiB,KAAKC;QAAQC,QAAQA;kBACxB,cAAA,KAACf;YAAoBiB,aAAaA;YAAaO,SAAS;gBAAER;gBAAiBS,MAAM;YAAQ;sBACvF,cAAA,KAACpB;gBACCq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;wBAAQO,OAAM;;kCACzB,KAACnD;wBAAI4C,OAAM;wBAAQO,OAAM;;kCACzB,KAACnD;wBAAI4C,OAAM;wBAASO,OAAM;;;;0BAE5B,MAACpD;gBAAM2C,KAAK;;oBACTN,QAAQ,yBACP,MAACrC;;0CACC,KAACI;gCACCiD,YAAY;oCAAC;iCAAkB;gCAC/BP,UAAU,CAACE,QAAUN,QAAQ;wCAAEL;wCAAKvB,SAASkC;oCAAM;gCACnDlC,SAASA;gCACTwC,sBAAsB1C;;0CAExB,KAACsB;gCAAgBpB,SAASA;;;;oBAG7BuB,QAAQ,yBACP,MAACrC;;0CACC,KAACI;gCACCiD,YAAY;oCAAC;iCAAkB;gCAC/BP,UAAU,CAACE,QAAUN,QAAQ;wCAAEL;wCAAKvB,SAASkC;oCAAM;gCACnDlC,SAASA;gCACTwC,sBAAsB1C;;0CAExB,KAACC;gCAAgBC,SAASA;;;;oBAG7BuB,QAAQ,0BACP,KAACrC;kCACC,cAAA,KAACU;4BACCoC,UAAU,CAACE,QAAUN,QAAQ;oCAAEL;oCAAK,GAAGW,KAAK;gCAAC;4BAC7CH,OAAO;gCAAEP;gCAAYC;gCAASC;4BAAe;;;;;;;AAO3D"}
|
|
@@ -7,17 +7,18 @@ interface PrometheusClientOptions {
|
|
|
7
7
|
}
|
|
8
8
|
export interface PrometheusClient extends DatasourceClient {
|
|
9
9
|
options: PrometheusClientOptions;
|
|
10
|
-
instantQuery(params: InstantQueryRequestParameters, headers?: RequestHeaders): Promise<InstantQueryResponse>;
|
|
11
|
-
rangeQuery(params: RangeQueryRequestParameters, headers?: RequestHeaders): Promise<RangeQueryResponse>;
|
|
12
|
-
labelNames(params: LabelNamesRequestParameters, headers?: RequestHeaders): Promise<LabelNamesResponse>;
|
|
13
|
-
labelValues(params: LabelValuesRequestParameters, headers?: RequestHeaders): Promise<LabelValuesResponse>;
|
|
14
|
-
metricMetadata(params: MetricMetadataRequestParameters, headers?: RequestHeaders): Promise<MetricMetadataResponse>;
|
|
15
|
-
series(params: SeriesRequestParameters, headers?: RequestHeaders): Promise<SeriesResponse>;
|
|
16
|
-
parseQuery(params: ParseQueryRequestParameters, headers?: RequestHeaders): Promise<ParseQueryResponse>;
|
|
10
|
+
instantQuery(params: InstantQueryRequestParameters, headers?: RequestHeaders, signal?: AbortSignal): Promise<InstantQueryResponse>;
|
|
11
|
+
rangeQuery(params: RangeQueryRequestParameters, headers?: RequestHeaders, signal?: AbortSignal): Promise<RangeQueryResponse>;
|
|
12
|
+
labelNames(params: LabelNamesRequestParameters, headers?: RequestHeaders, signal?: AbortSignal): Promise<LabelNamesResponse>;
|
|
13
|
+
labelValues(params: LabelValuesRequestParameters, headers?: RequestHeaders, signal?: AbortSignal): Promise<LabelValuesResponse>;
|
|
14
|
+
metricMetadata(params: MetricMetadataRequestParameters, headers?: RequestHeaders, signal?: AbortSignal): Promise<MetricMetadataResponse>;
|
|
15
|
+
series(params: SeriesRequestParameters, headers?: RequestHeaders, signal?: AbortSignal): Promise<SeriesResponse>;
|
|
16
|
+
parseQuery(params: ParseQueryRequestParameters, headers?: RequestHeaders, signal?: AbortSignal): Promise<ParseQueryResponse>;
|
|
17
17
|
}
|
|
18
18
|
export interface QueryOptions {
|
|
19
19
|
datasourceUrl: string;
|
|
20
20
|
headers?: RequestHeaders;
|
|
21
|
+
abortSignal?: AbortSignal;
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* Calls the `/-/healthy` endpoint to check if the datasource is healthy.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAoB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,+BAA+B,EAC/B,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,2BAA2B,EAC3B,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EAEf,MAAM,aAAa,CAAC;AAErB,UAAU,uBAAuB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,OAAO,EAAE,uBAAuB,CAAC;IACjC,YAAY,
|
|
1
|
+
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAoB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,+BAA+B,EAC/B,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,2BAA2B,EAC3B,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EAEf,MAAM,aAAa,CAAC;AAErB,UAAU,uBAAuB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,OAAO,EAAE,uBAAuB,CAAC;IACjC,YAAY,CACV,MAAM,EAAE,6BAA6B,EACrC,OAAO,CAAC,EAAE,cAAc,EACxB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACjC,UAAU,CACR,MAAM,EAAE,2BAA2B,EACnC,OAAO,CAAC,EAAE,cAAc,EACxB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC/B,UAAU,CACR,MAAM,EAAE,2BA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,CAAC,CAE7B;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,4BAA4B,EACpC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,mBAAmB,CAAC,CAa9B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,+BAA+B,EACvC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,sBAAsB,CAAC,CAGjC;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,uBAAuB,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAG3G;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,2BAA2B,EACnC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,kBAAkB,CAAC,CAG7B;AAsED;;GAEG;AACH,wBAAsB,YAAY,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAI1F"}
|
|
@@ -18,7 +18,8 @@ import { fetch, fetchJson } from '@perses-dev/core';
|
|
|
18
18
|
const url = `${queryOptions.datasourceUrl}/-/healthy`;
|
|
19
19
|
try {
|
|
20
20
|
const resp = await fetch(url, {
|
|
21
|
-
headers: queryOptions.headers
|
|
21
|
+
headers: queryOptions.headers,
|
|
22
|
+
signal: queryOptions.abortSignal
|
|
22
23
|
});
|
|
23
24
|
return resp.status === 200;
|
|
24
25
|
} catch {
|
|
@@ -88,7 +89,7 @@ function fetchWithGet(apiURI, params, queryOptions) {
|
|
|
88
89
|
});
|
|
89
90
|
}
|
|
90
91
|
function fetchWithPost(apiURI, params, queryOptions) {
|
|
91
|
-
const { datasourceUrl, headers } = queryOptions;
|
|
92
|
+
const { datasourceUrl, headers, abortSignal: signal } = queryOptions;
|
|
92
93
|
const url = `${datasourceUrl}${apiURI}`;
|
|
93
94
|
const init = {
|
|
94
95
|
method: 'POST',
|
|
@@ -96,6 +97,7 @@ function fetchWithPost(apiURI, params, queryOptions) {
|
|
|
96
97
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
97
98
|
...headers
|
|
98
99
|
},
|
|
100
|
+
signal,
|
|
99
101
|
body: createSearchParams(params)
|
|
100
102
|
};
|
|
101
103
|
return fetchResults(url, init);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/prometheus-client.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 { fetch, fetchJson, RequestHeaders } from '@perses-dev/core';\nimport { DatasourceClient } from '@perses-dev/plugin-system';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n ParseQueryRequestParameters,\n ParseQueryResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n SeriesRequestParameters,\n SeriesResponse,\n SuccessResponse,\n} from './api-types';\n\ninterface PrometheusClientOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\nexport interface PrometheusClient extends DatasourceClient {\n options: PrometheusClientOptions;\n instantQuery(params: InstantQueryRequestParameters, headers?: RequestHeaders): Promise<InstantQueryResponse>;\n rangeQuery(params: RangeQueryRequestParameters, headers?: RequestHeaders): Promise<RangeQueryResponse>;\n labelNames(params: LabelNamesRequestParameters, headers?: RequestHeaders): Promise<LabelNamesResponse>;\n labelValues(params: LabelValuesRequestParameters, headers?: RequestHeaders): Promise<LabelValuesResponse>;\n metricMetadata(params: MetricMetadataRequestParameters, headers?: RequestHeaders): Promise<MetricMetadataResponse>;\n series(params: SeriesRequestParameters, headers?: RequestHeaders): Promise<SeriesResponse>;\n parseQuery(params: ParseQueryRequestParameters, headers?: RequestHeaders): Promise<ParseQueryResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\n/**\n * Calls the `/-/healthy` endpoint to check if the datasource is healthy.\n */\nexport function healthCheck(queryOptions: QueryOptions) {\n return async (): Promise<boolean> => {\n const url = `${queryOptions.datasourceUrl}/-/healthy`;\n\n try {\n const resp = await fetch(url, { headers: queryOptions.headers });\n return resp.status === 200;\n } catch {\n return false;\n }\n };\n}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(\n params: InstantQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<InstantQueryResponse> {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(\n params: RangeQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<RangeQueryResponse> {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(\n params: LabelNamesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelNamesResponse> {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(\n params: LabelValuesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelValuesResponse> {\n const { labelName, ...searchParams } = params;\n\n // In case label name is empty, we'll receive a 404, so we can replace it by an empty list, which is less confusing.\n // Note that an empty list is the prometheus result if the label does not exist.\n if (labelName.length === 0) {\n return new Promise((resolve) => {\n resolve({ data: [] as string[] } as SuccessResponse<string[]>);\n });\n }\n\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function metricMetadata(\n params: MetricMetadataRequestParameters,\n queryOptions: QueryOptions\n): Promise<MetricMetadataResponse> {\n const apiURI = `/api/v1/metadata`;\n return fetchWithGet<MetricMetadataRequestParameters, MetricMetadataResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/series` endpoint to finding series by label matchers.\n */\nexport function series(params: SeriesRequestParameters, queryOptions: QueryOptions): Promise<SeriesResponse> {\n const apiURI = `/api/v1/series`;\n return fetchWithPost<SeriesRequestParameters, SeriesResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/parse_query` to parse the given promQL expresion into an abstract syntax tree (AST).\n */\nexport function parseQuery(\n params: ParseQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<ParseQueryResponse> {\n const apiURI = `/api/v1/parse_query`;\n return fetchWithPost<ParseQueryRequestParameters, ParseQueryResponse>(apiURI, params, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers } = queryOptions;\n\n let url = `${datasourceUrl}${apiURI}`;\n const urlParams = createSearchParams(params).toString();\n if (urlParams !== '') {\n url += `?${urlParams}`;\n }\n return fetchJson<TResponse>(url, { method: 'GET', headers });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers } = queryOptions;\n\n const url = `${datasourceUrl}${apiURI}`;\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n ...headers,\n },\n body: createSearchParams(params),\n };\n return fetchResults<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T): URLSearchParams {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n\n/**\n * Fetch JSON and parse warnings for query inspector\n */\nexport async function fetchResults<T>(...args: Parameters<typeof global.fetch>): Promise<T> {\n const response = await fetch(...args);\n const json: T = await response.json();\n return { ...json, rawResponse: response };\n}\n"],"names":["fetch","fetchJson","healthCheck","queryOptions","url","datasourceUrl","resp","headers","status","instantQuery","params","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","length","Promise","resolve","data","apiURI","encodeURIComponent","fetchWithGet","metricMetadata","series","parseQuery","urlParams","createSearchParams","toString","method","init","body","fetchResults","URLSearchParams","key","value","undefined","append","val","args","response","json","rawResponse"],"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,KAAK,EAAEC,SAAS,QAAwB,mBAAmB;AAyCpE;;CAEC,GACD,OAAO,SAASC,YAAYC,YAA0B;IACpD,OAAO;QACL,MAAMC,MAAM,GAAGD,aAAaE,aAAa,CAAC,UAAU,CAAC;QAErD,IAAI;YACF,MAAMC,OAAO,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C,OAAO;QAAE,GAAGA,IAAI;QAAEC,aAAaF;IAAS;AAC1C"}
|
|
1
|
+
{"version":3,"sources":["../../../src/model/prometheus-client.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 { fetch, fetchJson, RequestHeaders } from '@perses-dev/core';\nimport { DatasourceClient } from '@perses-dev/plugin-system';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n ParseQueryRequestParameters,\n ParseQueryResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n SeriesRequestParameters,\n SeriesResponse,\n SuccessResponse,\n} from './api-types';\n\ninterface PrometheusClientOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\nexport interface PrometheusClient extends DatasourceClient {\n options: PrometheusClientOptions;\n instantQuery(\n params: InstantQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<InstantQueryResponse>;\n rangeQuery(\n params: RangeQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<RangeQueryResponse>;\n labelNames(\n params: LabelNamesRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<LabelNamesResponse>;\n labelValues(\n params: LabelValuesRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<LabelValuesResponse>;\n metricMetadata(\n params: MetricMetadataRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<MetricMetadataResponse>;\n series(params: SeriesRequestParameters, headers?: RequestHeaders, signal?: AbortSignal): Promise<SeriesResponse>;\n parseQuery(\n params: ParseQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<ParseQueryResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n abortSignal?: AbortSignal;\n}\n\n/**\n * Calls the `/-/healthy` endpoint to check if the datasource is healthy.\n */\nexport function healthCheck(queryOptions: QueryOptions) {\n return async (): Promise<boolean> => {\n const url = `${queryOptions.datasourceUrl}/-/healthy`;\n\n try {\n const resp = await fetch(url, { headers: queryOptions.headers, signal: queryOptions.abortSignal });\n return resp.status === 200;\n } catch {\n return false;\n }\n };\n}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(\n params: InstantQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<InstantQueryResponse> {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(\n params: RangeQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<RangeQueryResponse> {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(\n params: LabelNamesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelNamesResponse> {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(\n params: LabelValuesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelValuesResponse> {\n const { labelName, ...searchParams } = params;\n\n // In case label name is empty, we'll receive a 404, so we can replace it by an empty list, which is less confusing.\n // Note that an empty list is the prometheus result if the label does not exist.\n if (labelName.length === 0) {\n return new Promise((resolve) => {\n resolve({ data: [] as string[] } as SuccessResponse<string[]>);\n });\n }\n\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function metricMetadata(\n params: MetricMetadataRequestParameters,\n queryOptions: QueryOptions\n): Promise<MetricMetadataResponse> {\n const apiURI = `/api/v1/metadata`;\n return fetchWithGet<MetricMetadataRequestParameters, MetricMetadataResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/series` endpoint to finding series by label matchers.\n */\nexport function series(params: SeriesRequestParameters, queryOptions: QueryOptions): Promise<SeriesResponse> {\n const apiURI = `/api/v1/series`;\n return fetchWithPost<SeriesRequestParameters, SeriesResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/parse_query` to parse the given promQL expresion into an abstract syntax tree (AST).\n */\nexport function parseQuery(\n params: ParseQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<ParseQueryResponse> {\n const apiURI = `/api/v1/parse_query`;\n return fetchWithPost<ParseQueryRequestParameters, ParseQueryResponse>(apiURI, params, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers } = queryOptions;\n let url = `${datasourceUrl}${apiURI}`;\n const urlParams = createSearchParams(params).toString();\n if (urlParams !== '') {\n url += `?${urlParams}`;\n }\n return fetchJson<TResponse>(url, { method: 'GET', headers });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, abortSignal: signal } = queryOptions;\n const url = `${datasourceUrl}${apiURI}`;\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n ...headers,\n },\n signal,\n body: createSearchParams(params),\n };\n return fetchResults<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T): URLSearchParams {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n\n/**\n * Fetch JSON and parse warnings for query inspector\n */\nexport async function fetchResults<T>(...args: Parameters<typeof global.fetch>): Promise<T> {\n const response = await fetch(...args);\n const json: T = await response.json();\n return { ...json, rawResponse: response };\n}\n"],"names":["fetch","fetchJson","healthCheck","queryOptions","url","datasourceUrl","resp","headers","signal","abortSignal","status","instantQuery","params","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","length","Promise","resolve","data","apiURI","encodeURIComponent","fetchWithGet","metricMetadata","series","parseQuery","urlParams","createSearchParams","toString","method","init","body","fetchResults","URLSearchParams","key","value","undefined","append","val","args","response","json","rawResponse"],"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,KAAK,EAAEC,SAAS,QAAwB,mBAAmB;AAkEpE;;CAEC,GACD,OAAO,SAASC,YAAYC,YAA0B;IACpD,OAAO;QACL,MAAMC,MAAM,GAAGD,aAAaE,aAA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AgB,GAAGO,IAAqC;IAC5E,MAAMC,WAAW,MAAM3C,SAAS0C;IAChC,MAAME,OAAU,MAAMD,SAASC,IAAI;IACnC,OAAO;QAAE,GAAGA,IAAI;QAAEC,aAAaF;IAAS;AAC1C"}
|
|
@@ -14,9 +14,9 @@ export declare const DEFAULT_PROM: PrometheusDatasourceSelector;
|
|
|
14
14
|
/**
|
|
15
15
|
* Returns true if the provided datasourceSelectValue is the default PrometheusDatasourceSelector.
|
|
16
16
|
*/
|
|
17
|
-
export declare function isDefaultPromSelector(datasourceSelectValue: DatasourceSelectValue): boolean;
|
|
17
|
+
export declare function isDefaultPromSelector(datasourceSelectValue: DatasourceSelectValue<PrometheusDatasourceSelector>): boolean;
|
|
18
18
|
/**
|
|
19
19
|
* Type guard to make sure a datasourceSelectValue is a Prometheus one.
|
|
20
20
|
*/
|
|
21
|
-
export declare function isPrometheusDatasourceSelector(datasourceSelectValue: DatasourceSelectValue): datasourceSelectValue is PrometheusDatasourceSelector;
|
|
21
|
+
export declare function isPrometheusDatasourceSelector(datasourceSelectValue: DatasourceSelectValue<DatasourceSelector>): datasourceSelectValue is PrometheusDatasourceSelector;
|
|
22
22
|
//# sourceMappingURL=prometheus-selectors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-selectors.d.ts","sourceRoot":"","sources":["../../../src/model/prometheus-selectors.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAwB,MAAM,2BAA2B,CAAC;AAExF,eAAO,MAAM,oBAAoB,EAAG,sBAA+B,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,4BAA6B,SAAQ,kBAAkB;IACtE,IAAI,EAAE,OAAO,oBAAoB,CAAC;CACnC;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,4BAA6D,CAAC;AAEzF;;GAEG;AACH,wBAAgB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"prometheus-selectors.d.ts","sourceRoot":"","sources":["../../../src/model/prometheus-selectors.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAwB,MAAM,2BAA2B,CAAC;AAExF,eAAO,MAAM,oBAAoB,EAAG,sBAA+B,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,4BAA6B,SAAQ,kBAAkB;IACtE,IAAI,EAAE,OAAO,oBAAoB,CAAC;CACnC;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,4BAA6D,CAAC;AAEzF;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,qBAAqB,EAAE,qBAAqB,CAAC,4BAA4B,CAAC,GACzE,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAC5C,qBAAqB,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,GAC/D,qBAAqB,IAAI,4BAA4B,CAEvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/prometheus-selectors.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 { DatasourceSelector } from '@perses-dev/core';\nimport { DatasourceSelectValue, isVariableDatasource } from '@perses-dev/plugin-system';\n\nexport const PROM_DATASOURCE_KIND = 'PrometheusDatasource' as const;\n\n/**\n * DatasourceSelector for Prom Datasources.\n */\nexport interface PrometheusDatasourceSelector extends DatasourceSelector {\n kind: typeof PROM_DATASOURCE_KIND;\n}\n\n/**\n * A default selector that asks for the default Prom Datasource.\n */\nexport const DEFAULT_PROM: PrometheusDatasourceSelector = { kind: PROM_DATASOURCE_KIND };\n\n/**\n * Returns true if the provided datasourceSelectValue is the default PrometheusDatasourceSelector.\n */\nexport function isDefaultPromSelector(datasourceSelectValue: DatasourceSelectValue): boolean {\n return !isVariableDatasource(datasourceSelectValue) && datasourceSelectValue.name === undefined;\n}\n\n/**\n * Type guard to make sure a datasourceSelectValue is a Prometheus one.\n */\nexport function isPrometheusDatasourceSelector(\n datasourceSelectValue: DatasourceSelectValue
|
|
1
|
+
{"version":3,"sources":["../../../src/model/prometheus-selectors.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 { DatasourceSelector } from '@perses-dev/core';\nimport { DatasourceSelectValue, isVariableDatasource } from '@perses-dev/plugin-system';\n\nexport const PROM_DATASOURCE_KIND = 'PrometheusDatasource' as const;\n\n/**\n * DatasourceSelector for Prom Datasources.\n */\nexport interface PrometheusDatasourceSelector extends DatasourceSelector {\n kind: typeof PROM_DATASOURCE_KIND;\n}\n\n/**\n * A default selector that asks for the default Prom Datasource.\n */\nexport const DEFAULT_PROM: PrometheusDatasourceSelector = { kind: PROM_DATASOURCE_KIND };\n\n/**\n * Returns true if the provided datasourceSelectValue is the default PrometheusDatasourceSelector.\n */\nexport function isDefaultPromSelector(\n datasourceSelectValue: DatasourceSelectValue<PrometheusDatasourceSelector>\n): boolean {\n return !isVariableDatasource(datasourceSelectValue) && datasourceSelectValue.name === undefined;\n}\n\n/**\n * Type guard to make sure a datasourceSelectValue is a Prometheus one.\n */\nexport function isPrometheusDatasourceSelector(\n datasourceSelectValue: DatasourceSelectValue<DatasourceSelector>\n): datasourceSelectValue is PrometheusDatasourceSelector {\n return isVariableDatasource(datasourceSelectValue) || datasourceSelectValue.kind === PROM_DATASOURCE_KIND;\n}\n"],"names":["isVariableDatasource","PROM_DATASOURCE_KIND","DEFAULT_PROM","kind","isDefaultPromSelector","datasourceSelectValue","name","undefined","isPrometheusDatasourceSelector"],"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;AAGjC,SAAgCA,oBAAoB,QAAQ,4BAA4B;AAExF,OAAO,MAAMC,uBAAuB,uBAAgC;AASpE;;CAEC,GACD,OAAO,MAAMC,eAA6C;IAAEC,MAAMF;AAAqB,EAAE;AAEzF;;CAEC,GACD,OAAO,SAASG,sBACdC,qBAA0E;IAE1E,OAAO,CAACL,qBAAqBK,0BAA0BA,sBAAsBC,IAAI,KAAKC;AACxF;AAEA;;CAEC,GACD,OAAO,SAASC,+BACdH,qBAAgE;IAEhE,OAAOL,qBAAqBK,0BAA0BA,sBAAsBF,IAAI,KAAKF;AACvF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusLabelNamesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"PrometheusLabelNamesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAMf,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,mCAAmC,EAAE,MAAM,SAAS,CAAC;AAE9D,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAyB5F,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { replaceVariables, parseVariables } from '@perses-dev/plugin-system';
|
|
2
|
-
import { DEFAULT_PROM, getPrometheusTimeRange } from '../model';
|
|
1
|
+
import { replaceVariables, parseVariables, datasourceSelectValueToSelector, isVariableDatasource } from '@perses-dev/plugin-system';
|
|
2
|
+
import { DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';
|
|
3
3
|
import { stringArrayToVariableOptions, PrometheusLabelNamesVariableEditor } from './prometheus-variables';
|
|
4
4
|
export const PrometheusLabelNamesVariable = {
|
|
5
5
|
getVariableOptions: async (spec, ctx)=>{
|
|
6
|
-
const
|
|
6
|
+
const datasourceSelector = datasourceSelectValueToSelector(spec.datasource ?? DEFAULT_PROM, ctx.variables, await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)) ?? DEFAULT_PROM;
|
|
7
|
+
const client = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);
|
|
7
8
|
const match = spec.matchers ? spec.matchers.map((m)=>replaceVariables(m, ctx.variables)) : undefined;
|
|
8
9
|
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
9
10
|
const { data: options } = await client.labelNames({
|
|
@@ -15,8 +16,13 @@ export const PrometheusLabelNamesVariable = {
|
|
|
15
16
|
};
|
|
16
17
|
},
|
|
17
18
|
dependsOn: (spec)=>{
|
|
19
|
+
const matcherVariables = spec.matchers?.map((m)=>parseVariables(m)).flat() || [];
|
|
20
|
+
const datasourceVariables = spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];
|
|
18
21
|
return {
|
|
19
|
-
variables:
|
|
22
|
+
variables: [
|
|
23
|
+
...matcherVariables,
|
|
24
|
+
...datasourceVariables
|
|
25
|
+
]
|
|
20
26
|
};
|
|
21
27
|
},
|
|
22
28
|
OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"sourcesContent":["import {\n VariablePlugin,\n GetVariableOptionsContext,\n replaceVariables,\n parseVariables,\n datasourceSelectValueToSelector,\n isVariableDatasource,\n} from '@perses-dev/plugin-system';\nimport { PrometheusClient, DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';\nimport { stringArrayToVariableOptions, PrometheusLabelNamesVariableEditor } from './prometheus-variables';\nimport { PrometheusLabelNamesVariableOptions } from './types';\n\nexport const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelNamesVariableOptions, ctx: GetVariableOptionsContext) => {\n const datasourceSelector =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n ctx.variables,\n await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)\n ) ?? DEFAULT_PROM;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);\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 const matcherVariables = spec.matchers?.map((m) => parseVariables(m)).flat() || [];\n const datasourceVariables =\n spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];\n return { variables: [...matcherVariables, ...datasourceVariables] };\n },\n OptionsEditorComponent: PrometheusLabelNamesVariableEditor,\n createInitialOptions: () => ({}),\n};\n"],"names":["replaceVariables","parseVariables","datasourceSelectValueToSelector","isVariableDatasource","DEFAULT_PROM","getPrometheusTimeRange","PROM_DATASOURCE_KIND","stringArrayToVariableOptions","PrometheusLabelNamesVariableEditor","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","datasourceSelector","datasource","variables","datasourceStore","listDatasourceSelectItems","client","getDatasourceClient","match","matchers","map","m","undefined","timeRange","data","options","labelNames","dependsOn","matcherVariables","flat","datasourceVariables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,SAGEA,gBAAgB,EAChBC,cAAc,EACdC,+BAA+B,EAC/BC,oBAAoB,QACf,4BAA4B;AACnC,SAA2BC,YAAY,EAAEC,sBAAsB,EAAEC,oBAAoB,QAAQ,WAAW;AACxG,SAASC,4BAA4B,EAAEC,kCAAkC,QAAQ,yBAAyB;AAG1G,OAAO,MAAMC,+BAAoF;IAC/FC,oBAAoB,OAAOC,MAA2CC;QACpE,MAAMC,qBACJX,gCACES,KAAKG,UAAU,IAAIV,cACnBQ,IAAIG,SAAS,EACb,MAAMH,IAAII,eAAe,CAACC,yBAAyB,CAACX,0BACjDF;QACP,MAAMc,SAA2B,MAAMN,IAAII,eAAe,CAACG,mBAAmB,CAACN;QAC/E,MAAMO,QAAQT,KAAKU,QAAQ,GAAGV,KAAKU,QAAQ,CAACC,GAAG,CAAC,CAACC,IAAMvB,iBAAiBuB,GAAGX,IAAIG,SAAS,KAAKS;QAC7F,MAAMC,YAAYpB,uBAAuBO,IAAIa,SAAS;QAEtD,MAAM,EAAEC,MAAMC,OAAO,EAAE,GAAG,MAAMT,OAAOU,UAAU,CAAC;YAAE,WAAWR;YAAO,GAAGK,SAAS;QAAC;QACnF,OAAO;YACLC,MAAMnB,6BAA6BoB;QACrC;IACF;IACAE,WAAW,CAAClB;QACV,MAAMmB,mBAAmBnB,KAAKU,QAAQ,EAAEC,IAAI,CAACC,IAAMtB,eAAesB,IAAIQ,UAAU,EAAE;QAClF,MAAMC,sBACJrB,KAAKG,UAAU,IAAIX,qBAAqBQ,KAAKG,UAAU,IAAIb,eAAeU,KAAKG,UAAU,IAAI,EAAE;QACjG,OAAO;YAAEC,WAAW;mBAAIe;mBAAqBE;aAAoB;QAAC;IACpE;IACAC,wBAAwBzB;IACxB0B,sBAAsB,IAAO,CAAA,CAAC,CAAA;AAChC,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusLabelValuesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"PrometheusLabelValuesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAMf,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,oCAAoC,EAAE,MAAM,SAAS,CAAC;AAE/D,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CAkC9F,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { replaceVariables, parseVariables } from '@perses-dev/plugin-system';
|
|
2
|
-
import { DEFAULT_PROM, getPrometheusTimeRange } from '../model';
|
|
1
|
+
import { replaceVariables, parseVariables, datasourceSelectValueToSelector, isVariableDatasource } from '@perses-dev/plugin-system';
|
|
2
|
+
import { DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';
|
|
3
3
|
import { stringArrayToVariableOptions, PrometheusLabelValuesVariableEditor } from './prometheus-variables';
|
|
4
4
|
export const PrometheusLabelValuesVariable = {
|
|
5
5
|
getVariableOptions: async (spec, ctx)=>{
|
|
6
6
|
const pluginDef = spec;
|
|
7
|
-
const
|
|
7
|
+
const datasourceSelector = datasourceSelectValueToSelector(spec.datasource ?? DEFAULT_PROM, ctx.variables, await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)) ?? DEFAULT_PROM;
|
|
8
|
+
const client = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);
|
|
8
9
|
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceVariables(m, ctx.variables)) : undefined;
|
|
9
10
|
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
10
11
|
const { data: options } = await client.labelValues({
|
|
@@ -17,8 +18,15 @@ export const PrometheusLabelValuesVariable = {
|
|
|
17
18
|
};
|
|
18
19
|
},
|
|
19
20
|
dependsOn: (spec)=>{
|
|
21
|
+
const matcherVariables = spec.matchers?.map((m)=>parseVariables(m)).flat() || [];
|
|
22
|
+
const labelVariables = parseVariables(spec.labelName);
|
|
23
|
+
const datasourceVariables = spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];
|
|
20
24
|
return {
|
|
21
|
-
variables:
|
|
25
|
+
variables: [
|
|
26
|
+
...matcherVariables,
|
|
27
|
+
...labelVariables,
|
|
28
|
+
...datasourceVariables
|
|
29
|
+
]
|
|
22
30
|
};
|
|
23
31
|
},
|
|
24
32
|
OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"sourcesContent":["import {\n VariablePlugin,\n GetVariableOptionsContext,\n replaceVariables,\n parseVariables,\n datasourceSelectValueToSelector,\n isVariableDatasource,\n} from '@perses-dev/plugin-system';\nimport { PrometheusClient, DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';\nimport { stringArrayToVariableOptions, PrometheusLabelValuesVariableEditor } from './prometheus-variables';\nimport { PrometheusLabelValuesVariableOptions } from './types';\n\nexport const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelValuesVariableOptions, ctx: GetVariableOptionsContext) => {\n const pluginDef = spec;\n const datasourceSelector =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n ctx.variables,\n await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)\n ) ?? DEFAULT_PROM;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);\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 const matcherVariables = spec.matchers?.map((m) => parseVariables(m)).flat() || [];\n const labelVariables = parseVariables(spec.labelName);\n const datasourceVariables =\n spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];\n return {\n variables: [...matcherVariables, ...labelVariables, ...datasourceVariables],\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ labelName: '' }),\n};\n"],"names":["replaceVariables","parseVariables","datasourceSelectValueToSelector","isVariableDatasource","DEFAULT_PROM","getPrometheusTimeRange","PROM_DATASOURCE_KIND","stringArrayToVariableOptions","PrometheusLabelValuesVariableEditor","PrometheusLabelValuesVariable","getVariableOptions","spec","ctx","pluginDef","datasourceSelector","datasource","variables","datasourceStore","listDatasourceSelectItems","client","getDatasourceClient","match","matchers","map","m","undefined","timeRange","data","options","labelValues","labelName","dependsOn","matcherVariables","flat","labelVariables","datasourceVariables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,SAGEA,gBAAgB,EAChBC,cAAc,EACdC,+BAA+B,EAC/BC,oBAAoB,QACf,4BAA4B;AACnC,SAA2BC,YAAY,EAAEC,sBAAsB,EAAEC,oBAAoB,QAAQ,WAAW;AACxG,SAASC,4BAA4B,EAAEC,mCAAmC,QAAQ,yBAAyB;AAG3G,OAAO,MAAMC,gCAAsF;IACjGC,oBAAoB,OAAOC,MAA4CC;QACrE,MAAMC,YAAYF;QAClB,MAAMG,qBACJZ,gCACES,KAAKI,UAAU,IAAIX,cACnBQ,IAAII,SAAS,EACb,MAAMJ,IAAIK,eAAe,CAACC,yBAAyB,CAACZ,0BACjDF;QACP,MAAMe,SAA2B,MAAMP,IAAIK,eAAe,CAACG,mBAAmB,CAACN;QAC/E,MAAMO,QAAQR,UAAUS,QAAQ,GAAGT,UAAUS,QAAQ,CAACC,GAAG,CAAC,CAACC,IAAMxB,iBAAiBwB,GAAGZ,IAAII,SAAS,KAAKS;QAEvG,MAAMC,YAAYrB,uBAAuBO,IAAIc,SAAS;QAEtD,MAAM,EAAEC,MAAMC,OAAO,EAAE,GAAG,MAAMT,OAAOU,WAAW,CAAC;YACjDC,WAAW9B,iBAAiBa,UAAUiB,SAAS,EAAElB,IAAII,SAAS;YAC9D,WAAWK;YACX,GAAGK,SAAS;QACd;QACA,OAAO;YACLC,MAAMpB,6BAA6BqB;QACrC;IACF;IACAG,WAAW,CAACpB;QACV,MAAMqB,mBAAmBrB,KAAKW,QAAQ,EAAEC,IAAI,CAACC,IAAMvB,eAAeuB,IAAIS,UAAU,EAAE;QAClF,MAAMC,iBAAiBjC,eAAeU,KAAKmB,SAAS;QACpD,MAAMK,sBACJxB,KAAKI,UAAU,IAAIZ,qBAAqBQ,KAAKI,UAAU,IAAId,eAAeU,KAAKI,UAAU,IAAI,EAAE;QACjG,OAAO;YACLC,WAAW;mBAAIgB;mBAAqBE;mBAAmBC;aAAoB;QAC7E;IACF;IACAC,wBAAwB5B;IACxB6B,sBAAsB,IAAO,CAAA;YAAEP,WAAW;QAAG,CAAA;AAC/C,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusPromQLVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusPromQLVariable.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"PrometheusPromQLVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusPromQLVariable.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAMf,MAAM,2BAA2B,CAAC;AAQnC,OAAO,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE1D,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,+BAA+B,CAkCpF,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { replaceVariables, parseVariables } from '@perses-dev/plugin-system';
|
|
2
|
-
import { DEFAULT_PROM } from '../model';
|
|
1
|
+
import { replaceVariables, parseVariables, datasourceSelectValueToSelector, isVariableDatasource } from '@perses-dev/plugin-system';
|
|
2
|
+
import { DEFAULT_PROM, PROM_DATASOURCE_KIND } from '../model';
|
|
3
3
|
import { capturingMatrix, capturingVector, stringArrayToVariableOptions, PrometheusPromQLVariableEditor } from './prometheus-variables';
|
|
4
4
|
export const PrometheusPromQLVariable = {
|
|
5
5
|
getVariableOptions: async (spec, ctx)=>{
|
|
6
|
-
const
|
|
6
|
+
const datasourceSelector = datasourceSelectValueToSelector(spec.datasource ?? DEFAULT_PROM, ctx.variables, await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)) ?? DEFAULT_PROM;
|
|
7
|
+
const client = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);
|
|
7
8
|
// TODO we may want to manage a range query as well.
|
|
8
9
|
const { data: options } = await client.instantQuery({
|
|
9
10
|
query: replaceVariables(spec.expr, ctx.variables)
|
|
@@ -20,8 +21,15 @@ export const PrometheusPromQLVariable = {
|
|
|
20
21
|
};
|
|
21
22
|
},
|
|
22
23
|
dependsOn: (spec)=>{
|
|
24
|
+
const exprVariables = parseVariables(spec.expr);
|
|
25
|
+
const labelVariables = parseVariables(spec.labelName);
|
|
26
|
+
const datasourceVariables = spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];
|
|
23
27
|
return {
|
|
24
|
-
variables:
|
|
28
|
+
variables: [
|
|
29
|
+
...exprVariables,
|
|
30
|
+
...labelVariables,
|
|
31
|
+
...datasourceVariables
|
|
32
|
+
]
|
|
25
33
|
};
|
|
26
34
|
},
|
|
27
35
|
OptionsEditorComponent: PrometheusPromQLVariableEditor,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/PrometheusPromQLVariable.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusPromQLVariable.tsx"],"sourcesContent":["import {\n VariablePlugin,\n GetVariableOptionsContext,\n replaceVariables,\n parseVariables,\n datasourceSelectValueToSelector,\n isVariableDatasource,\n} from '@perses-dev/plugin-system';\nimport { PrometheusClient, DEFAULT_PROM, PROM_DATASOURCE_KIND } from '../model';\nimport {\n capturingMatrix,\n capturingVector,\n stringArrayToVariableOptions,\n PrometheusPromQLVariableEditor,\n} from './prometheus-variables';\nimport { PrometheusPromQLVariableOptions } from './types';\n\nexport const PrometheusPromQLVariable: VariablePlugin<PrometheusPromQLVariableOptions> = {\n getVariableOptions: async (spec: PrometheusPromQLVariableOptions, ctx: GetVariableOptionsContext) => {\n const datasourceSelector =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n ctx.variables,\n await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)\n ) ?? DEFAULT_PROM;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);\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 const exprVariables = parseVariables(spec.expr);\n const labelVariables = parseVariables(spec.labelName);\n const datasourceVariables =\n spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];\n return { variables: [...exprVariables, ...labelVariables, ...datasourceVariables] };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', labelName: '' }),\n};\n"],"names":["replaceVariables","parseVariables","datasourceSelectValueToSelector","isVariableDatasource","DEFAULT_PROM","PROM_DATASOURCE_KIND","capturingMatrix","capturingVector","stringArrayToVariableOptions","PrometheusPromQLVariableEditor","PrometheusPromQLVariable","getVariableOptions","spec","ctx","datasourceSelector","datasource","variables","datasourceStore","listDatasourceSelectItems","client","getDatasourceClient","data","options","instantQuery","query","expr","labelName","values","resultType","dependsOn","exprVariables","labelVariables","datasourceVariables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,SAGEA,gBAAgB,EAChBC,cAAc,EACdC,+BAA+B,EAC/BC,oBAAoB,QACf,4BAA4B;AACnC,SAA2BC,YAAY,EAAEC,oBAAoB,QAAQ,WAAW;AAChF,SACEC,eAAe,EACfC,eAAe,EACfC,4BAA4B,EAC5BC,8BAA8B,QACzB,yBAAyB;AAGhC,OAAO,MAAMC,2BAA4E;IACvFC,oBAAoB,OAAOC,MAAuCC;QAChE,MAAMC,qBACJZ,gCACEU,KAAKG,UAAU,IAAIX,cACnBS,IAAIG,SAAS,EACb,MAAMH,IAAII,eAAe,CAACC,yBAAyB,CAACb,0BACjDD;QACP,MAAMe,SAA2B,MAAMN,IAAII,eAAe,CAACG,mBAAmB,CAACN;QAC/E,oDAAoD;QACpD,MAAM,EAAEO,MAAMC,OAAO,EAAE,GAAG,MAAMH,OAAOI,YAAY,CAAC;YAClDC,OAAOxB,iBAAiBY,KAAKa,IAAI,EAAEZ,IAAIG,SAAS;QAClD;QACA,MAAMU,YAAY1B,iBAAiBY,KAAKc,SAAS,EAAEb,IAAIG,SAAS;QAChE,IAAIW,SAAmB,EAAE;QACzB,IAAIL,SAASM,eAAe,UAAU;YACpCD,SAASrB,gBAAgBgB,SAASI;QACpC,OAAO,IAAIJ,SAASM,eAAe,UAAU;Y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