@perses-dev/prometheus-plugin 0.54.0 → 0.56.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.7a79b403.js → Prometheus.4d0d5812.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/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.1fcb466e.js +1 -0
- package/__mf/js/async/4557.f3eb9456.js +2 -0
- package/__mf/js/async/4576.f42daf99.js +1 -0
- package/__mf/js/async/4676.b7a22f90.js +22 -0
- package/__mf/js/async/58.1c9a8daa.js +2 -0
- package/__mf/js/async/6341.20eccf91.js +7 -0
- package/__mf/js/async/684.4495f632.js +1 -0
- package/__mf/js/async/8164.bb3d3363.js +1 -0
- package/__mf/js/async/8706.89677575.js +1 -0
- package/__mf/js/async/{2675.27451820.js → 9010.bdb2ef97.js} +1 -1
- package/__mf/js/async/__federation_expose_PrometheusDatasource.45ee94e2.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusExplorer.b8e555e1.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.00dfb1dd.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.956ef2d0.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.59f2d170.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.d7143352.js +1 -0
- package/__mf/js/{main.d2018d3d.js → main.afc2ee60.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/PrometheusTimeSeriesQueryEditor.js +7 -43
- package/lib/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +3 -3
- package/lib/cjs/plugins/prometheus-variables.js +20 -73
- 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/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +7 -43
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.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 +22 -81
- 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 +103 -97
- package/mf-stats.json +106 -100
- package/package.json +6 -6
- 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 → 4557.f3eb9456.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{3391.eced295d.js.LICENSE.txt → 4676.b7a22f90.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{6714.fd02e782.js.LICENSE.txt → 58.1c9a8daa.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{2275.95fa6219.js.LICENSE.txt → 6341.20eccf91.js.LICENSE.txt} +0 -0
|
@@ -12,61 +12,36 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { FormControl, Stack, TextField } from '@mui/material';
|
|
15
|
-
import { DatasourceSelect, useDatasourceClient } from '@perses-dev/plugin-system';
|
|
15
|
+
import { DatasourceSelect, isVariableDatasource, useDatasourceClient, useDatasourceSelectValueToSelector } from '@perses-dev/plugin-system';
|
|
16
16
|
import { produce } from 'immer';
|
|
17
17
|
import { useCallback, useState } from 'react';
|
|
18
18
|
import { PromQLEditor } from '../components';
|
|
19
19
|
import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PROM_DATASOURCE_KIND } from '../model';
|
|
20
20
|
import { MatcherEditor } from './MatcherEditor';
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
The usage of direct onchange here causes an immediate spec update which eventually updates the panel
|
|
24
|
-
This was probably intentional to allow for quick switching between values.
|
|
25
|
-
Shouldn't we update the panel only through the Run Query Button?
|
|
26
|
-
I think we should only track the changes and let the button to Run the query
|
|
27
|
-
*/ export function PrometheusLabelValuesVariableEditor(props) {
|
|
28
|
-
const { onChange, value, value: { datasource }, queryHandlerSettings } = props;
|
|
21
|
+
export function PrometheusLabelValuesVariableEditor(props) {
|
|
22
|
+
const { onChange, value, value: { datasource } } = props;
|
|
29
23
|
const selectedDatasource = datasource ?? DEFAULT_PROM;
|
|
30
24
|
const [labelValue, setLabelValue] = useState(props.value.labelName);
|
|
31
25
|
const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);
|
|
32
26
|
const handleDatasourceChange = useCallback((next)=>{
|
|
33
|
-
if (isPrometheusDatasourceSelector(next)) {
|
|
27
|
+
if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {
|
|
34
28
|
onChange(produce(value, (draft)=>{
|
|
35
29
|
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
36
|
-
draft.datasource = isDefaultPromSelector(next) ? undefined : next;
|
|
30
|
+
draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;
|
|
37
31
|
}));
|
|
38
|
-
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
|
|
39
|
-
...value,
|
|
40
|
-
datasource: next
|
|
41
|
-
});
|
|
42
32
|
return;
|
|
43
33
|
}
|
|
44
34
|
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
45
35
|
}, [
|
|
46
36
|
onChange,
|
|
47
|
-
queryHandlerSettings,
|
|
48
37
|
value
|
|
49
38
|
]);
|
|
50
39
|
const handleLabelChange = useCallback((e)=>{
|
|
51
40
|
setLabelValue(e.target.value);
|
|
52
|
-
|
|
53
|
-
...value,
|
|
54
|
-
labelName: e.target.value
|
|
55
|
-
});
|
|
56
|
-
}, [
|
|
57
|
-
value,
|
|
58
|
-
queryHandlerSettings
|
|
59
|
-
]);
|
|
41
|
+
}, []);
|
|
60
42
|
const handleMatchEditorsChange = useCallback((e)=>{
|
|
61
43
|
setMatchersValues(e);
|
|
62
|
-
|
|
63
|
-
...value,
|
|
64
|
-
matchers: e
|
|
65
|
-
});
|
|
66
|
-
}, [
|
|
67
|
-
value,
|
|
68
|
-
queryHandlerSettings
|
|
69
|
-
]);
|
|
44
|
+
}, []);
|
|
70
45
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
71
46
|
spacing: 2,
|
|
72
47
|
children: [
|
|
@@ -99,39 +74,25 @@ I think we should only track the changes and let the button to Run the query
|
|
|
99
74
|
});
|
|
100
75
|
}
|
|
101
76
|
export function PrometheusLabelNamesVariableEditor(props) {
|
|
102
|
-
const { onChange, value, value: { datasource }
|
|
77
|
+
const { onChange, value, value: { datasource } } = props;
|
|
103
78
|
const selectedDatasource = datasource ?? DEFAULT_PROM;
|
|
104
79
|
const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);
|
|
105
80
|
const handleDatasourceChange = useCallback((next)=>{
|
|
106
|
-
if (isPrometheusDatasourceSelector(next)) {
|
|
81
|
+
if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {
|
|
107
82
|
onChange(produce(value, (draft)=>{
|
|
108
83
|
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
109
|
-
draft.datasource = isDefaultPromSelector(next) ? undefined : next;
|
|
84
|
+
draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;
|
|
110
85
|
}));
|
|
111
|
-
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
|
|
112
|
-
...value,
|
|
113
|
-
datasource: next
|
|
114
|
-
});
|
|
115
86
|
return;
|
|
116
87
|
}
|
|
117
88
|
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
118
89
|
}, [
|
|
119
90
|
onChange,
|
|
120
|
-
queryHandlerSettings,
|
|
121
91
|
value
|
|
122
92
|
]);
|
|
123
93
|
const handleMatchEditorChange = useCallback((e)=>{
|
|
124
94
|
setMatchersValues(e);
|
|
125
|
-
|
|
126
|
-
queryHandlerSettings.setWatchOtherSpecs({
|
|
127
|
-
...value,
|
|
128
|
-
matchers: e
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}, [
|
|
132
|
-
value,
|
|
133
|
-
queryHandlerSettings
|
|
134
|
-
]);
|
|
95
|
+
}, []);
|
|
135
96
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
136
97
|
spacing: 2,
|
|
137
98
|
children: [
|
|
@@ -155,28 +116,24 @@ export function PrometheusLabelNamesVariableEditor(props) {
|
|
|
155
116
|
});
|
|
156
117
|
}
|
|
157
118
|
export function PrometheusPromQLVariableEditor(props) {
|
|
158
|
-
const { onChange, value, value: { datasource }
|
|
159
|
-
const
|
|
119
|
+
const { onChange, value, value: { datasource } } = props;
|
|
120
|
+
const datasourceSelectValue = datasource ?? DEFAULT_PROM;
|
|
121
|
+
const selectedDatasource = useDatasourceSelectValueToSelector(datasourceSelectValue, PROM_DATASOURCE_KIND);
|
|
160
122
|
const { data: client } = useDatasourceClient(selectedDatasource);
|
|
161
123
|
const promURL = client?.options.datasourceUrl;
|
|
162
|
-
const [labelValue,
|
|
124
|
+
const [labelValue, setLabelValue] = useState(props.value.labelName);
|
|
163
125
|
const handleDatasourceChange = useCallback((next)=>{
|
|
164
|
-
if (isPrometheusDatasourceSelector(next)) {
|
|
126
|
+
if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {
|
|
165
127
|
onChange(produce(value, (draft)=>{
|
|
166
128
|
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
167
|
-
draft.datasource = isDefaultPromSelector(next) ? undefined : next;
|
|
129
|
+
draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;
|
|
168
130
|
}));
|
|
169
|
-
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
|
|
170
|
-
...value,
|
|
171
|
-
datasource: next
|
|
172
|
-
});
|
|
173
131
|
return;
|
|
174
132
|
}
|
|
175
133
|
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
176
134
|
}, [
|
|
177
135
|
value,
|
|
178
|
-
onChange
|
|
179
|
-
queryHandlerSettings
|
|
136
|
+
onChange
|
|
180
137
|
]);
|
|
181
138
|
const handleOnBlurPromQlChange = useCallback((e)=>{
|
|
182
139
|
onChange({
|
|
@@ -187,25 +144,9 @@ export function PrometheusPromQLVariableEditor(props) {
|
|
|
187
144
|
onChange,
|
|
188
145
|
value
|
|
189
146
|
]);
|
|
190
|
-
const trackPromQlChanges = useCallback((e)=>{
|
|
191
|
-
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
|
|
192
|
-
...value,
|
|
193
|
-
expr: e.target.textContent ?? ''
|
|
194
|
-
});
|
|
195
|
-
}, [
|
|
196
|
-
queryHandlerSettings,
|
|
197
|
-
value
|
|
198
|
-
]);
|
|
199
147
|
const handleLabelNameChange = useCallback((e)=>{
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
...value,
|
|
203
|
-
labelName: e.target.value
|
|
204
|
-
});
|
|
205
|
-
}, [
|
|
206
|
-
queryHandlerSettings,
|
|
207
|
-
value
|
|
208
|
-
]);
|
|
148
|
+
setLabelValue(e.target.value);
|
|
149
|
+
}, []);
|
|
209
150
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
210
151
|
spacing: 2,
|
|
211
152
|
children: [
|
|
@@ -213,7 +154,7 @@ export function PrometheusPromQLVariableEditor(props) {
|
|
|
213
154
|
margin: "dense",
|
|
214
155
|
children: /*#__PURE__*/ _jsx(DatasourceSelect, {
|
|
215
156
|
datasourcePluginKind: PROM_DATASOURCE_KIND,
|
|
216
|
-
value:
|
|
157
|
+
value: datasourceSelectValue,
|
|
217
158
|
onChange: handleDatasourceChange,
|
|
218
159
|
labelId: "prom-datasource-label",
|
|
219
160
|
label: "Prometheus Datasource",
|
|
@@ -228,7 +169,7 @@ export function PrometheusPromQLVariableEditor(props) {
|
|
|
228
169
|
},
|
|
229
170
|
value: value.expr,
|
|
230
171
|
datasource: selectedDatasource,
|
|
231
|
-
onBlur:
|
|
172
|
+
onBlur: handleOnBlurPromQlChange,
|
|
232
173
|
readOnly: props.isReadonly,
|
|
233
174
|
width: "100%"
|
|
234
175
|
}),
|
|
@@ -1 +1 @@
|
|
|
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 { FormControl, Stack, TextField } from '@mui/material';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport { ReactElement, useCallback, useState } from 'react';\nimport { PromQLEditor } from '../components';\nimport {\n DEFAULT_PROM,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n VectorData,\n} from '../model';\nimport { MatcherEditor } from './MatcherEditor';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\n\n/* TODO: \nOpen Question for later improvement\nThe usage of direct onchange here causes an immediate spec update which eventually updates the panel\nThis was probably intentional to allow for quick switching between values.\nShouldn't we update the panel only through the Run Query Button? \nI think we should only track the changes and let the button to Run the query\n*/\n\nexport function PrometheusLabelValuesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n queryHandlerSettings,\n } = props;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n const [labelValue, setLabelValue] = useState(props.value.labelName);\n const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (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 if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, datasource: next });\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [onChange, queryHandlerSettings, value]\n );\n\n const handleLabelChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLabelValue(e.target.value);\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, labelName: e.target.value });\n },\n [value, queryHandlerSettings]\n );\n\n const handleMatchEditorsChange = useCallback(\n (e: string[]) => {\n setMatchersValues(e);\n if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({ ...value, matchers: e });\n },\n [value, queryHandlerSettings]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\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={labelValue}\n onChange={handleLabelChange}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n />\n <MatcherEditor matchers={matchersValues} onChange={handleMatchEditorsChange} isReadonly={props.isReadonly} />\n </Stack>\n );\n}\n\nexport function PrometheusLabelNamesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n queryHandlerSettings,\n } = props;\n\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (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 if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, datasource: next });\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [onChange, queryHandlerSettings, value]\n );\n\n const handleMatchEditorChange = useCallback(\n (e: string[]) => {\n setMatchersValues(e);\n if (queryHandlerSettings?.setWatchOtherSpecs) {\n queryHandlerSettings.setWatchOtherSpecs({ ...value, matchers: e });\n }\n },\n [value, queryHandlerSettings]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\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 matchers={matchersValues} isReadonly={props.isReadonly} onChange={handleMatchEditorChange} />\n </Stack>\n );\n}\n\nexport function PrometheusPromQLVariableEditor(\n props: OptionsEditorProps<PrometheusPromQLVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n queryHandlerSettings,\n } = props;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n const [labelValue, setLableValue] = useState(props.value.labelName);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (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 if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings?.setWatchOtherSpecs({ ...value, datasource: next });\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [value, onChange, queryHandlerSettings]\n );\n\n const handleOnBlurPromQlChange = useCallback(\n (e: React.FocusEvent<HTMLDivElement, Element>) => {\n onChange({ ...value, expr: e.target.textContent ?? '' });\n },\n [onChange, value]\n );\n\n const trackPromQlChanges = useCallback(\n (e: React.FocusEvent<HTMLDivElement, Element>) => {\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings?.setWatchOtherSpecs({ ...value, expr: e.target.textContent ?? '' });\n },\n [queryHandlerSettings, value]\n );\n\n const handleLabelNameChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLableValue(e.target.value);\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings?.setWatchOtherSpecs({ ...value, labelName: e.target.value });\n },\n [queryHandlerSettings, value]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\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 datasource={selectedDatasource}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleOnBlurPromQlChange : trackPromQlChanges}\n readOnly={props.isReadonly}\n width=\"100%\"\n />\n <TextField\n label=\"Label Name\"\n required\n value={labelValue}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n onChange={handleLabelNameChange}\n />\n </Stack>\n );\n}\n\nexport function 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\nexport function 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 */\nexport const stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n"],"names":["FormControl","Stack","TextField","DatasourceSelect","useDatasourceClient","produce","useCallback","useState","PromQLEditor","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","queryHandlerSettings","selectedDatasource","labelValue","setLabelValue","labelName","matchersValues","setMatchersValues","matchers","handleDatasourceChange","next","draft","undefined","setWatchOtherSpecs","Error","handleLabelChange","e","target","handleMatchEditorsChange","spacing","margin","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","InputProps","PrometheusLabelNamesVariableEditor","handleMatchEditorChange","disabled","PrometheusPromQLVariableEditor","data","client","promURL","options","datasourceUrl","setLableValue","handleOnBlurPromQlChange","expr","textContent","trackPromQlChanges","handleLabelNameChange","completeConfig","remote","url","onBlur","runWithOnBlur","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map"],"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,SAASA,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC9D,SACEC,gBAAgB,EAGhBC,mBAAmB,QAEd,4BAA4B;AACnC,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAAuBC,WAAW,EAAEC,QAAQ,QAAQ,QAAQ;AAC5D,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SACEC,YAAY,EACZC,qBAAqB,EACrBC,8BAA8B,EAE9BC,oBAAoB,QAGf,WAAW;AAClB,SAASC,aAAa,QAAQ,kBAAkB;AAOhD;;;;;;AAMA,GAEA,OAAO,SAASC,oCACdC,KAA+D;IAE/D,MAAM,EACJC,QAAQ,EACRC,KAAK,EACLA,OAAO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,MAAM;AACnC;AAEA;;CAEC,GACD,OAAO,MAAMG,+BAA+B,CAACH;IAC3C,IAAI,CAACA,QAAQ,OAAO,EAAE;IACtB,OAAOA,OAAOI,GAAG,CAAC,CAAChE,QAAW,CAAA;YAC5BA;YACA0B,OAAO1B;QACT,CAAA;AACF,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 { FormControl, Stack, TextField } from '@mui/material';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceClient,\n useDatasourceSelectValueToSelector,\n VariableOption,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport { ReactElement, useCallback, useState } from 'react';\nimport { PromQLEditor } from '../components';\nimport {\n DEFAULT_PROM,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n PrometheusDatasourceSelector,\n VectorData,\n} from '../model';\nimport { MatcherEditor } from './MatcherEditor';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\n\nexport function PrometheusLabelValuesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n } = props;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n const [labelValue, setLabelValue] = useState(props.value.labelName);\n const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (next) => {\n if (isVariableDatasource(next) || 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 = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [onChange, value]\n );\n\n const handleLabelChange = useCallback((e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLabelValue(e.target.value);\n }, []);\n\n const handleMatchEditorsChange = useCallback((e: string[]) => {\n setMatchersValues(e);\n }, []);\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\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={labelValue}\n onChange={handleLabelChange}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n />\n <MatcherEditor matchers={matchersValues} onChange={handleMatchEditorsChange} isReadonly={props.isReadonly} />\n </Stack>\n );\n}\n\nexport function PrometheusLabelNamesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n } = props;\n\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (next) => {\n if (isVariableDatasource(next) || 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 = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [onChange, value]\n );\n\n const handleMatchEditorChange = useCallback((e: string[]) => {\n setMatchersValues(e);\n }, []);\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\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 matchers={matchersValues} isReadonly={props.isReadonly} onChange={handleMatchEditorChange} />\n </Stack>\n );\n}\n\nexport function PrometheusPromQLVariableEditor(\n props: OptionsEditorProps<PrometheusPromQLVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n } = props;\n const datasourceSelectValue = datasource ?? DEFAULT_PROM;\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n PROM_DATASOURCE_KIND\n ) as PrometheusDatasourceSelector;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n const [labelValue, setLabelValue] = useState(props.value.labelName);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (next) => {\n if (isVariableDatasource(next) || 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 = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [value, onChange]\n );\n\n const handleOnBlurPromQlChange = useCallback(\n (e: React.FocusEvent<HTMLDivElement, Element>) => {\n onChange({ ...value, expr: e.target.textContent ?? '' });\n },\n [onChange, value]\n );\n\n const handleLabelNameChange = useCallback((e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLabelValue(e.target.value);\n }, []);\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={datasourceSelectValue}\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 datasource={selectedDatasource}\n onBlur={handleOnBlurPromQlChange}\n readOnly={props.isReadonly}\n width=\"100%\"\n />\n <TextField\n label=\"Label Name\"\n required\n value={labelValue}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n onChange={handleLabelNameChange}\n />\n </Stack>\n );\n}\n\nexport function 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\nexport function 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 */\nexport const stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n"],"names":["FormControl","Stack","TextField","DatasourceSelect","isVariableDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","produce","useCallback","useState","PromQLEditor","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","labelValue","setLabelValue","labelName","matchersValues","setMatchersValues","matchers","handleDatasourceChange","next","draft","undefined","Error","handleLabelChange","e","target","handleMatchEditorsChange","spacing","margin","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","InputProps","PrometheusLabelNamesVariableEditor","handleMatchEditorChange","disabled","PrometheusPromQLVariableEditor","datasourceSelectValue","data","client","promURL","options","datasourceUrl","handleOnBlurPromQlChange","expr","textContent","handleLabelNameChange","completeConfig","remote","url","onBlur","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map"],"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,SAASA,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC9D,SACEC,gBAAgB,EAEhBC,oBAAoB,EAEpBC,mBAAmB,EACnBC,kCAAkC,QAE7B,4BAA4B;AACnC,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAAuBC,WAAW,EAAEC,QAAQ,QAAQ,QAAQ;AAC5D,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SACEC,YAAY,EACZC,qBAAqB,EACrBC,8BAA8B,EAE9BC,oBAAoB,QAIf,WAAW;AAClB,SAASC,aAAa,QAAQ,kBAAkB;AAOhD,OAAO,SAASC,oCACdC,KAA+D;IAE/D,MAAM,EACJC,QAAQ,EACRC,KAAK,EACLA,OAAO,EAAEC,UAAU,EAAE,EACtB,GAAGH;IACJ,MAAMI,qBAAqBD,cAAcT;IACzC,MAAM,CAACW,YAAYC,cAAc,GAAGd,SAASQ,MAAME,KAAK,CAACK,SAAS;IAClE,MAAM,CAACC,gBAAgBC,kBAAkB,GAAGjB,SAASQ,MAAME,KAAK,CAACQ,QAAQ,IAAI,EAAE;IAC/E,MAAMC,yBAA4DpB,YAChE,CAACqB;QACC,IAAIzB,qBAAqByB,SAAShB,+BAA+BgB,OAAO;YACtEX,SACEX,QAAQY,OAAO,CAACW;gBACd,sFAAsF;gBACtFA,MAAMV,UAAU,GAAG,CAAChB,qBAAqByB,SAASjB,sBAAsBiB,QAAQE,YAAYF;YAC9F;YAEF;QACF;QAEA,MAAM,IAAIG,MAAM;IACl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EAAE"}
|
package/lib/plugins/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DurationString, HTTPProxy } from '@perses-dev/core';
|
|
2
|
+
import { DatasourceSelectValue } from '@perses-dev/plugin-system';
|
|
2
3
|
import { PrometheusDatasourceSelector } from '../model';
|
|
3
4
|
export declare const DEFAULT_SCRAPE_INTERVAL: DurationString;
|
|
4
5
|
export interface PrometheusDatasourceSpec {
|
|
@@ -7,7 +8,7 @@ export interface PrometheusDatasourceSpec {
|
|
|
7
8
|
scrapeInterval?: DurationString;
|
|
8
9
|
}
|
|
9
10
|
export interface PrometheusVariableOptionsBase {
|
|
10
|
-
datasource?: PrometheusDatasourceSelector
|
|
11
|
+
datasource?: DatasourceSelectValue<PrometheusDatasourceSelector>;
|
|
11
12
|
}
|
|
12
13
|
export type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {
|
|
13
14
|
matchers?: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,uBAAuB,EAAE,cAAqB,CAAC;AAE5D,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,uBAAuB,EAAE,cAAqB,CAAC;AAE5D,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,qBAAqB,CAAC,4BAA4B,CAAC,CAAC;CAClE;AAED,MAAM,MAAM,mCAAmC,GAAG,6BAA6B,GAAG;IAChF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG,6BAA6B,GAAG;IACjF,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,6BAA6B,GAAG;IAE5E,IAAI,EAAE,MAAM,CAAC;IAGb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
package/lib/plugins/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString, HTTPProxy } from '@perses-dev/core';\nimport { PrometheusDatasourceSelector } from '../model';\n\nexport const DEFAULT_SCRAPE_INTERVAL: DurationString = '1m';\n\nexport interface PrometheusDatasourceSpec {\n directUrl?: string;\n proxy?: HTTPProxy;\n scrapeInterval?: DurationString; // default to 1m\n}\n\nexport interface PrometheusVariableOptionsBase {\n datasource?: PrometheusDatasourceSelector
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString, HTTPProxy } from '@perses-dev/core';\nimport { DatasourceSelectValue } from '@perses-dev/plugin-system';\nimport { PrometheusDatasourceSelector } from '../model';\n\nexport const DEFAULT_SCRAPE_INTERVAL: DurationString = '1m';\n\nexport interface PrometheusDatasourceSpec {\n directUrl?: string;\n proxy?: HTTPProxy;\n scrapeInterval?: DurationString; // default to 1m\n}\n\nexport interface PrometheusVariableOptionsBase {\n datasource?: DatasourceSelectValue<PrometheusDatasourceSelector>;\n}\n\nexport type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {\n matchers?: string[];\n};\n\nexport type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n labelName: string;\n matchers?: string[];\n};\n\nexport type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {\n // expr is the PromQL expression.\n expr: string;\n // labelName is the name of the label that will be used after the PromQL query is performed to select the label value.\n // Note: This field is not part of the Prometheus API.\n labelName: string;\n};\n"],"names":["DEFAULT_SCRAPE_INTERVAL"],"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;AAMjC,OAAO,MAAMA,0BAA0C,KAAK"}
|