@perses-dev/prometheus-plugin 0.55.0 → 0.57.0-beta.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.
Files changed (204) hide show
  1. package/__mf/js/Prometheus.2bb892ab.js +6 -0
  2. package/__mf/js/async/1233.0ab88b51.js +1 -0
  3. package/__mf/js/async/1324.ce01eced.js +1 -0
  4. package/__mf/js/async/1432.0c3e4ed0.js +1 -0
  5. package/__mf/js/async/1490.7e5068f1.js +22 -0
  6. package/__mf/js/async/1605.dc180cb8.js +110 -0
  7. package/__mf/js/async/1616.7587ce79.js +1 -0
  8. package/__mf/js/async/1728.af16c4ec.js +1 -0
  9. package/__mf/js/async/1969.372d36b8.js +1 -0
  10. package/__mf/js/async/2043.d0fbb886.js +2 -0
  11. package/__mf/js/async/2186.e58838a5.js +38 -0
  12. package/__mf/js/async/2506.1e336b3b.js +1 -0
  13. package/__mf/js/async/2984.7182c2f5.js +1 -0
  14. package/__mf/js/async/2999.1d8347df.js +1 -0
  15. package/__mf/js/async/3184.6b4ad42e.js +1 -0
  16. package/__mf/js/async/3664.ba8b26b6.js +2 -0
  17. package/__mf/js/async/392.7cda691a.js +2 -0
  18. package/__mf/js/async/3963.5fef6ffb.js +1 -0
  19. package/__mf/js/async/3996.69a9c1dc.js +1 -0
  20. package/__mf/js/async/{1964.1d168a86.js → 4121.828d661d.js} +2 -2
  21. package/__mf/js/async/4626.173e602a.js +1 -0
  22. package/__mf/js/async/4987.c12b89cb.js +1 -0
  23. package/__mf/js/async/{8930.700a5439.js → 5002.e4f54e8e.js} +1 -1
  24. package/__mf/js/async/5071.e1c33fa7.js +1 -0
  25. package/__mf/js/async/529.2303b01b.js +1 -0
  26. package/__mf/js/async/5440.c13c3533.js +2 -0
  27. package/__mf/js/async/5501.6166367c.js +2 -0
  28. package/__mf/js/async/{5214.0fca84ed.js → 5587.4d72fc35.js} +1 -1
  29. package/__mf/js/async/5763.4ba478ff.js +1 -0
  30. package/__mf/js/async/5922.d1619ac1.js +1 -0
  31. package/__mf/js/async/6149.19799c37.js +7 -0
  32. package/__mf/js/async/6274.478a68f8.js +2 -0
  33. package/__mf/js/async/6283.181cb622.js +2 -0
  34. package/__mf/js/async/6969.b959b6f8.js +1 -0
  35. package/__mf/js/async/{4062.06f48b93.js → 7177.205c9aaf.js} +1 -1
  36. package/__mf/js/async/7192.d835931b.js +1 -0
  37. package/__mf/js/async/7894.9c5245d7.js +1 -0
  38. package/__mf/js/async/7968.6ac0ce96.js +1 -0
  39. package/__mf/js/async/7978.9532d5b8.js +1 -0
  40. package/__mf/js/async/8356.789e1dfb.js +1 -0
  41. package/__mf/js/async/8470.9b14a625.js +2 -0
  42. package/__mf/js/async/873.448eab23.js +1 -0
  43. package/__mf/js/async/8888.59eb50a2.js +1 -0
  44. package/__mf/js/async/9020.c19782f1.js +1 -0
  45. package/__mf/js/async/9184.43a8d927.js +1 -0
  46. package/__mf/js/async/9235.36c3cd8c.js +1 -0
  47. package/__mf/js/async/9351.715f25c3.js +1 -0
  48. package/__mf/js/async/941.53b13124.js +2 -0
  49. package/__mf/js/async/9518.38e38a33.js +1 -0
  50. package/__mf/js/async/9588.9081c7de.js +1 -0
  51. package/__mf/js/async/9605.a92ec9c1.js +1 -0
  52. package/__mf/js/async/9836.00da6086.js +1 -0
  53. package/__mf/js/async/__federation_expose_PrometheusDatasource.6f63e147.js +1 -0
  54. package/__mf/js/async/__federation_expose_PrometheusExplorer.584a073d.js +1 -0
  55. package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.40984a4d.js +1 -0
  56. package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.bd3eb00c.js +1 -0
  57. package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.5cca8417.js +1 -0
  58. package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.f59141f4.js +1 -0
  59. package/__mf/js/main.9617b605.js +6 -0
  60. package/lib/bootstrap.js +1 -1
  61. package/lib/bootstrap.js.map +1 -1
  62. package/lib/cjs/components/PromQLEditor.js +4 -7
  63. package/lib/cjs/components/promql/ast.js +10 -10
  64. package/lib/cjs/components/promql/format.js +3 -3
  65. package/lib/cjs/components/promql/utils.js +5 -5
  66. package/lib/cjs/components/query.js +3 -3
  67. package/lib/cjs/explore/PrometheusExplorer.js +10 -6
  68. package/lib/cjs/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js +4 -4
  69. package/lib/cjs/explore/PrometheusMetricsFinder/display/list/MetricList.js +3 -3
  70. package/lib/cjs/explore/PrometheusMetricsFinder/filter/FilterInputs.js +4 -4
  71. package/lib/cjs/explore/PrometheusMetricsFinder/overview/MetricOverview.js +3 -3
  72. package/lib/cjs/explore/PrometheusMetricsFinder/overview/tabs/JobTab.js +4 -4
  73. package/lib/cjs/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.js +4 -4
  74. package/lib/cjs/explore/PrometheusMetricsFinder/utils.js +5 -5
  75. package/lib/cjs/index-federation.js +12 -12
  76. package/lib/cjs/model/parse-sample-values.js +3 -3
  77. package/lib/cjs/model/prometheus-client.js +29 -19
  78. package/lib/cjs/model/prometheus-selectors.js +5 -5
  79. package/lib/cjs/model/time.js +4 -4
  80. package/lib/cjs/plugins/PrometheusDatasourceEditor.js +175 -2
  81. package/lib/cjs/plugins/prometheus-datasource.js +17 -9
  82. package/lib/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +35 -36
  83. package/lib/cjs/plugins/prometheus-time-series-query/query-editor-model.js +4 -4
  84. package/lib/cjs/plugins/prometheus-variables.js +48 -83
  85. package/lib/cjs/utils/utils.js +4 -4
  86. package/lib/components/PromQLEditor.d.ts +5 -1
  87. package/lib/components/PromQLEditor.d.ts.map +1 -1
  88. package/lib/components/PromQLEditor.js +5 -8
  89. package/lib/components/PromQLEditor.js.map +1 -1
  90. package/lib/components/TreeNode.js +1 -1
  91. package/lib/components/TreeNode.js.map +1 -1
  92. package/lib/components/promql/format.js +1 -1
  93. package/lib/components/promql/format.js.map +1 -1
  94. package/lib/explore/PrometheusExplorer.d.ts.map +1 -1
  95. package/lib/explore/PrometheusExplorer.js +10 -6
  96. package/lib/explore/PrometheusExplorer.js.map +1 -1
  97. package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js +1 -1
  98. package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js.map +1 -1
  99. package/lib/explore/PrometheusMetricsFinder/display/MetricChip.js +1 -1
  100. package/lib/explore/PrometheusMetricsFinder/display/MetricChip.js.map +1 -1
  101. package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.js +1 -1
  102. package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.js.map +1 -1
  103. package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.js +1 -1
  104. package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.js.map +1 -1
  105. package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.js +1 -1
  106. package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.js.map +1 -1
  107. package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.js +1 -1
  108. package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.js.map +1 -1
  109. package/lib/model/prometheus-client.d.ts +1 -0
  110. package/lib/model/prometheus-client.d.ts.map +1 -1
  111. package/lib/model/prometheus-client.js +19 -9
  112. package/lib/model/prometheus-client.js.map +1 -1
  113. package/lib/plugins/MatcherEditor.js +1 -1
  114. package/lib/plugins/MatcherEditor.js.map +1 -1
  115. package/lib/plugins/PrometheusDatasourceEditor.d.ts.map +1 -1
  116. package/lib/plugins/PrometheusDatasourceEditor.js +135 -3
  117. package/lib/plugins/PrometheusDatasourceEditor.js.map +1 -1
  118. package/lib/plugins/prometheus-datasource.js +17 -9
  119. package/lib/plugins/prometheus-datasource.js.map +1 -1
  120. package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  121. package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +39 -40
  122. package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  123. package/lib/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
  124. package/lib/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
  125. package/lib/plugins/prometheus-variables.d.ts.map +1 -1
  126. package/lib/plugins/prometheus-variables.js +44 -85
  127. package/lib/plugins/prometheus-variables.js.map +1 -1
  128. package/lib/plugins/types.d.ts +1 -0
  129. package/lib/plugins/types.d.ts.map +1 -1
  130. package/lib/plugins/types.js.map +1 -1
  131. package/mf-manifest.json +268 -253
  132. package/mf-stats.json +271 -254
  133. package/package.json +7 -7
  134. package/__mf/js/Prometheus.f0d65264.js +0 -5
  135. package/__mf/js/async/1339.194207db.js +0 -1
  136. package/__mf/js/async/1441.c735f7dd.js +0 -1
  137. package/__mf/js/async/1576.8eac7ce9.js +0 -1
  138. package/__mf/js/async/212.5fcca998.js +0 -1
  139. package/__mf/js/async/2178.0f075947.js +0 -2
  140. package/__mf/js/async/2292.57d8fd0d.js +0 -2
  141. package/__mf/js/async/2472.2134f9f7.js +0 -22
  142. package/__mf/js/async/3224.b63f87bf.js +0 -1
  143. package/__mf/js/async/3507.f1653337.js +0 -101
  144. package/__mf/js/async/3749.3ecd9372.js +0 -1
  145. package/__mf/js/async/3863.7192dfdf.js +0 -2
  146. package/__mf/js/async/3960.3eedafbd.js +0 -2
  147. package/__mf/js/async/3980.0b0d272c.js +0 -2
  148. package/__mf/js/async/4075.dab1b7b8.js +0 -1
  149. package/__mf/js/async/4238.c48b1950.js +0 -1
  150. package/__mf/js/async/4421.6ebf935f.js +0 -1
  151. package/__mf/js/async/4535.f24704ea.js +0 -1
  152. package/__mf/js/async/4576.f42daf99.js +0 -1
  153. package/__mf/js/async/4665.cad36935.js +0 -1
  154. package/__mf/js/async/5257.ce463cb7.js +0 -1
  155. package/__mf/js/async/5409.955ffd51.js +0 -1
  156. package/__mf/js/async/5614.cce8ba96.js +0 -1
  157. package/__mf/js/async/5724.794828e3.js +0 -1
  158. package/__mf/js/async/5774.a3fae698.js +0 -1
  159. package/__mf/js/async/5790.a9b31ca8.js +0 -1
  160. package/__mf/js/async/5981.eb502d27.js +0 -2
  161. package/__mf/js/async/6292.2afe0c6d.js +0 -1
  162. package/__mf/js/async/6341.70ddfbe9.js +0 -7
  163. package/__mf/js/async/6377.c40920f2.js +0 -2
  164. package/__mf/js/async/6620.5a15a075.js +0 -2
  165. package/__mf/js/async/6770.7099bb3b.js +0 -1
  166. package/__mf/js/async/684.4495f632.js +0 -1
  167. package/__mf/js/async/694.8462a746.js +0 -1
  168. package/__mf/js/async/7272.6fa2f127.js +0 -1
  169. package/__mf/js/async/7376.2e948f2b.js +0 -1
  170. package/__mf/js/async/738.a1ffff79.js +0 -1
  171. package/__mf/js/async/7740.a8777825.js +0 -1
  172. package/__mf/js/async/8045.7f554a45.js +0 -10
  173. package/__mf/js/async/8164.bb3d3363.js +0 -1
  174. package/__mf/js/async/8216.e689c178.js +0 -1
  175. package/__mf/js/async/8488.cbbe542b.js +0 -1
  176. package/__mf/js/async/8587.40df6f5c.js +0 -1
  177. package/__mf/js/async/8706.08030938.js +0 -1
  178. package/__mf/js/async/9010.bdb2ef97.js +0 -1
  179. package/__mf/js/async/9173.915b80af.js +0 -2
  180. package/__mf/js/async/9550.642ce5ad.js +0 -38
  181. package/__mf/js/async/9817.70eae424.js +0 -1
  182. package/__mf/js/async/__federation_expose_PrometheusDatasource.dcb93aae.js +0 -1
  183. package/__mf/js/async/__federation_expose_PrometheusExplorer.9ab5666d.js +0 -1
  184. package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.0f7697ac.js +0 -1
  185. package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.cd804473.js +0 -1
  186. package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.4c376d6b.js +0 -1
  187. package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.d4984d73.js +0 -1
  188. package/__mf/js/main.d76b840e.js +0 -5
  189. /package/__mf/css/async/{1339.d3010b86.css → 1233.d3010b86.css} +0 -0
  190. /package/__mf/css/async/{1576.d3010b86.css → 1324.d3010b86.css} +0 -0
  191. /package/__mf/css/async/{4576.d3010b86.css → 9518.d3010b86.css} +0 -0
  192. /package/__mf/js/async/{2472.2134f9f7.js.LICENSE.txt → 1490.7e5068f1.js.LICENSE.txt} +0 -0
  193. /package/__mf/js/async/{8045.7f554a45.js.LICENSE.txt → 1605.dc180cb8.js.LICENSE.txt} +0 -0
  194. /package/__mf/js/async/{2292.57d8fd0d.js.LICENSE.txt → 2043.d0fbb886.js.LICENSE.txt} +0 -0
  195. /package/__mf/js/async/{6620.5a15a075.js.LICENSE.txt → 3664.ba8b26b6.js.LICENSE.txt} +0 -0
  196. /package/__mf/js/async/{5981.eb502d27.js.LICENSE.txt → 392.7cda691a.js.LICENSE.txt} +0 -0
  197. /package/__mf/js/async/{1964.1d168a86.js.LICENSE.txt → 4121.828d661d.js.LICENSE.txt} +0 -0
  198. /package/__mf/js/async/{6377.c40920f2.js.LICENSE.txt → 5440.c13c3533.js.LICENSE.txt} +0 -0
  199. /package/__mf/js/async/{2178.0f075947.js.LICENSE.txt → 5501.6166367c.js.LICENSE.txt} +0 -0
  200. /package/__mf/js/async/{6341.70ddfbe9.js.LICENSE.txt → 6149.19799c37.js.LICENSE.txt} +0 -0
  201. /package/__mf/js/async/{3960.3eedafbd.js.LICENSE.txt → 6274.478a68f8.js.LICENSE.txt} +0 -0
  202. /package/__mf/js/async/{3980.0b0d272c.js.LICENSE.txt → 6283.181cb622.js.LICENSE.txt} +0 -0
  203. /package/__mf/js/async/{9173.915b80af.js.LICENSE.txt → 8470.9b14a625.js.LICENSE.txt} +0 -0
  204. /package/__mf/js/async/{3863.7192dfdf.js.LICENSE.txt → 941.53b13124.js.LICENSE.txt} +0 -0
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  // Copyright 2023 The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,20 +11,20 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { produce } from 'immer';
15
- import { DatasourceSelect, useDatasource, useDatasourceClient, useDatasourceSelectValueToSelector } from '@perses-dev/plugin-system';
15
+ import { DatasourceSelect, replaceVariables, useAllVariableValues, useDatasource, useDatasourceClient, useDatasourceSelectValueToSelector, useSuggestedStepMs, useTimeRange } from '@perses-dev/plugin-system';
16
16
  import { useId } from '@perses-dev/components';
17
17
  import { FormControl, Stack, TextField } from '@mui/material';
18
- import { useCallback } from 'react';
19
- import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PROM_DATASOURCE_KIND } from '../../model';
18
+ import { useContext, useMemo } from 'react';
19
+ import { PanelEditorContext } from '@perses-dev/dashboards';
20
+ import { DEFAULT_PROM, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, isDefaultPromSelector, isPrometheusDatasourceSelector, PROM_DATASOURCE_KIND } from '../../model';
20
21
  import { DEFAULT_SCRAPE_INTERVAL } from '../types';
21
22
  import { PromQLEditor } from '../../components';
22
23
  import { useQueryState, useFormatState, useMinStepState } from './query-editor-model';
23
24
  /**
24
25
  * The options editor component for editing a PrometheusTimeSeriesQuery's spec.
25
26
  */ export function PrometheusTimeSeriesQueryEditor(props) {
26
- const { onChange, value, value: { query, datasource }, queryHandlerSettings, isReadonly } = props;
27
+ const { onChange, value, value: { query, datasource }, isReadonly } = props;
27
28
  const datasourceSelectValue = datasource ?? DEFAULT_PROM;
28
29
  const datasourceSelectLabelID = useId('prom-datasource-label'); // for panels with multiple queries, this component is rendered multiple times on the same page
29
30
  const selectedDatasource = useDatasourceSelectValueToSelector(datasourceSelectValue, PROM_DATASOURCE_KIND);
@@ -44,44 +45,41 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
44
45
  const nextDatasource = isDefaultPromSelector(next) ? undefined : next;
45
46
  draft.datasource = nextDatasource;
46
47
  }));
47
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
48
- ...value,
49
- datasource: next
50
- });
51
48
  return;
52
49
  }
53
50
  throw new Error('Got unexpected non-Prometheus datasource selector');
54
51
  };
55
- const handlePromQlEditorChanges = useCallback((e)=>{
56
- handleQueryChange(e);
57
- if (queryHandlerSettings?.watchQueryChanges) {
58
- queryHandlerSettings?.watchQueryChanges(e);
52
+ const variableState = useAllVariableValues();
53
+ const { absoluteTimeRange } = useTimeRange();
54
+ const panelEditorContext = useContext(PanelEditorContext);
55
+ const suggestedStepMs = useSuggestedStepMs(panelEditorContext?.preview.previewPanelWidth);
56
+ const minStepMs = useMemo(()=>{
57
+ /* Try catch is necessary, because when the minStep value is being typed, it will be valid when the duration unit is added. Example: 2m = 2 + m */ try {
58
+ const durationsSeconds = getDurationStringSeconds(replaceVariables(minStepPlaceholder, variableState));
59
+ return durationsSeconds !== undefined ? durationsSeconds * 1000 : undefined;
60
+ } catch {
61
+ return undefined;
59
62
  }
60
63
  }, [
61
- queryHandlerSettings,
62
- handleQueryChange
64
+ variableState,
65
+ minStepPlaceholder
63
66
  ]);
64
- const handleLegendSpecChange = useCallback((e)=>{
65
- handleFormatChange(e.target.value);
66
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
67
- ...value,
68
- seriesNameFormat: e.target.value
69
- });
67
+ const intervalMs = useMemo(()=>{
68
+ const minStepSeconds = (minStepMs ?? 0) / 1000;
69
+ return getRangeStep(getPrometheusTimeRange(absoluteTimeRange), minStepSeconds, undefined, suggestedStepMs) * 1000;
70
70
  }, [
71
- queryHandlerSettings,
72
- handleFormatChange,
73
- value
71
+ absoluteTimeRange,
72
+ minStepMs,
73
+ suggestedStepMs
74
74
  ]);
75
- const handleMinStepSpecChange = useCallback((e)=>{
76
- handleMinStepChange(e.target.value ? e.target.value : undefined);
77
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
78
- ...value,
79
- minStep: e.target.value
80
- });
75
+ const treeViewMetadata = useMemo(()=>{
76
+ return minStepMs && intervalMs ? {
77
+ minStepMs,
78
+ intervalMs
79
+ } : undefined;
81
80
  }, [
82
- queryHandlerSettings,
83
- handleMinStepChange,
84
- value
81
+ minStepMs,
82
+ intervalMs
85
83
  ]);
86
84
  return /*#__PURE__*/ _jsxs(Stack, {
87
85
  spacing: 2,
@@ -107,9 +105,10 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
107
105
  },
108
106
  value: query,
109
107
  datasource: selectedDatasource,
110
- onChange: handlePromQlEditorChanges,
111
- onBlur: queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined,
112
- isReadOnly: isReadonly
108
+ onChange: handleQueryChange,
109
+ onBlur: handleQueryBlur,
110
+ isReadOnly: isReadonly,
111
+ treeViewMetadata: treeViewMetadata
113
112
  }),
114
113
  /*#__PURE__*/ _jsxs(Stack, {
115
114
  direction: "row",
@@ -121,8 +120,8 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
121
120
  placeholder: "Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...",
122
121
  helperText: "Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.",
123
122
  value: format ?? '',
124
- onChange: handleLegendSpecChange,
125
- onBlur: queryHandlerSettings?.runWithOnBlur ? handleFormatBlur : undefined,
123
+ onChange: (e)=>handleFormatChange(e.target.value),
124
+ onBlur: handleFormatBlur,
126
125
  slotProps: {
127
126
  inputLabel: {
128
127
  shrink: isReadonly ? true : undefined
@@ -137,8 +136,8 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
137
136
  placeholder: minStepPlaceholder,
138
137
  helperText: "Lower bound for the step. If not provided, the scrape interval of the datasource is used.",
139
138
  value: minStep ?? '',
140
- onChange: handleMinStepSpecChange,
141
- onBlur: queryHandlerSettings?.runWithOnBlur ? handleMinStepBlur : undefined,
139
+ onChange: (e)=>handleMinStepChange(e.target.value ? e.target.value : undefined),
140
+ onBlur: handleMinStepBlur,
142
141
  sx: {
143
142
  width: '250px'
144
143
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { produce } from 'immer';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n useDatasource,\n useDatasourceClient,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { useId } from '@perses-dev/components';\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport { ReactElement, useCallback } from 'react';\nimport {\n DEFAULT_PROM,\n DurationString,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n PrometheusDatasourceSelector,\n} from '../../model';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PromQLEditor } from '../../components';\nimport {\n PrometheusTimeSeriesQueryEditorProps,\n useQueryState,\n useFormatState,\n useMinStepState,\n} from './query-editor-model';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): ReactElement {\n const {\n onChange,\n value,\n value: { query, datasource },\n queryHandlerSettings,\n isReadonly,\n } = props;\n\n const datasourceSelectValue = datasource ?? DEFAULT_PROM;\n\n const datasourceSelectLabelID = useId('prom-datasource-label'); // for panels with multiple queries, this component is rendered multiple times on the same page\n\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 { data: datasourceResource } = useDatasource(selectedDatasource);\n\n const { handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\n const { minStep, handleMinStepChange, handleMinStepBlur } = useMinStepState(props);\n const minStepPlaceholder =\n minStep ??\n (datasourceResource && (datasourceResource?.plugin.spec as PrometheusDatasourceSpec).scrapeInterval) ??\n DEFAULT_SCRAPE_INTERVAL;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n /* Good to know: The usage of onchange here causes an immediate spec update which eventually updates the panel\n This was probably intentional to allow for quick switching between datasources.\n Could have been triggered only with Run Query button as well.\n */\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n 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\n const handlePromQlEditorChanges = useCallback(\n (e: string) => {\n handleQueryChange(e);\n if (queryHandlerSettings?.watchQueryChanges) {\n queryHandlerSettings?.watchQueryChanges(e);\n }\n },\n [queryHandlerSettings, handleQueryChange]\n );\n\n const handleLegendSpecChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n handleFormatChange(e.target.value);\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, seriesNameFormat: e.target.value });\n },\n [queryHandlerSettings, handleFormatChange, value]\n );\n\n const handleMinStepSpecChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n handleMinStepChange(e.target.value ? (e.target.value as DurationString) : undefined);\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, minStep: e.target.value });\n },\n [queryHandlerSettings, handleMinStepChange, value]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\" fullWidth={false}>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={datasourceSelectValue}\n onChange={handleDatasourceChange}\n labelId={datasourceSelectLabelID}\n label=\"Prometheus Datasource\"\n notched\n readOnly={isReadonly}\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={query} // here we are passing `value.query` and not `query` from useQueryState in order to get updates only on onBlur events\n datasource={selectedDatasource}\n onChange={handlePromQlEditorChanges}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined}\n isReadOnly={isReadonly}\n />\n <Stack direction=\"row\" spacing={2}>\n <TextField\n fullWidth\n label=\"Legend\"\n placeholder=\"Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...\"\n helperText=\"Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.\"\n value={format ?? ''}\n onChange={handleLegendSpecChange}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleFormatBlur : undefined}\n slotProps={{\n inputLabel: { shrink: isReadonly ? true : undefined },\n input: { readOnly: isReadonly },\n }}\n />\n <TextField\n label=\"Min Step\"\n placeholder={minStepPlaceholder}\n helperText=\"Lower bound for the step. If not provided, the scrape interval of the datasource is used.\"\n value={minStep ?? ''}\n onChange={handleMinStepSpecChange}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleMinStepBlur : undefined}\n sx={{ width: '250px' }}\n slotProps={{\n inputLabel: { shrink: isReadonly ? true : undefined },\n input: { readOnly: isReadonly },\n }}\n />\n </Stack>\n </Stack>\n );\n}\n"],"names":["produce","DatasourceSelect","useDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","useId","FormControl","Stack","TextField","useCallback","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","DEFAULT_SCRAPE_INTERVAL","PromQLEditor","useQueryState","useFormatState","useMinStepState","PrometheusTimeSeriesQueryEditor","props","onChange","value","query","datasource","queryHandlerSettings","isReadonly","datasourceSelectValue","datasourceSelectLabelID","selectedDatasource","data","client","promURL","options","datasourceUrl","datasourceResource","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","minStep","handleMinStepChange","handleMinStepBlur","minStepPlaceholder","plugin","spec","scrapeInterval","handleDatasourceChange","next","draft","nextDatasource","undefined","setWatchOtherSpecs","Error","handlePromQlEditorChanges","e","watchQueryChanges","handleLegendSpecChange","target","seriesNameFormat","handleMinStepSpecChange","spacing","margin","fullWidth","datasourcePluginKind","labelId","label","notched","readOnly","completeConfig","remote","url","onBlur","runWithOnBlur","isReadOnly","direction","placeholder","helperText","slotProps","inputLabel","shrink","input","sx","width"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,OAAO,QAAQ,QAAQ;AAChC,SACEC,gBAAgB,EAEhBC,aAAa,EACbC,mBAAmB,EACnBC,kCAAkC,QAC7B,4BAA4B;AACnC,SAASC,KAAK,QAAQ,yBAAyB;AAC/C,SAASC,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC9D,SAAuBC,WAAW,QAAQ,QAAQ;AAClD,SACEC,Y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d,MAACnB;gBAAMqE,WAAU;gBAAMd,SAAS;;kCAC9B,KAACtD;wBACCwD,SAAS;wBACTG,OAAM;wBACNU,aAAY;wBACZC,YAAW;wBACXxD,OAAOgB,UAAU;wBACjBjB,UAAUqC;wBACVe,QAAQhD,sBAAsBiD,gBAAgBlC,mBAAmBY;wBACjE2B,WAAW;4BACTC,YAAY;gCAAEC,QAAQvD,aAAa,OAAO0B;4BAAU;4BACpD8B,OAAO;gCAAEb,UAAU3C;4BAAW;wBAChC;;kCAEF,KAAClB;wBACC2D,OAAM;wBACNU,aAAajC;wBACbkC,YAAW;wBACXxD,OAAOmB,WAAW;wBAClBpB,UAAUwC;wBACVY,QAAQhD,sBAAsBiD,gBAAgB/B,oBAAoBS;wBAClE+B,IAAI;4BAAEC,OAAO;wBAAQ;wBACrBL,WAAW;4BACTC,YAAY;gCAAEC,QAAQvD,aAAa,OAAO0B;4BAAU;4BACpD8B,OAAO;gCAAEb,UAAU3C;4BAAW;wBAChC;;;;;;AAKV"}
1
+ {"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { produce } from 'immer';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n replaceVariables,\n useAllVariableValues,\n useDatasource,\n useDatasourceClient,\n useDatasourceSelectValueToSelector,\n useSuggestedStepMs,\n useTimeRange,\n} from '@perses-dev/plugin-system';\nimport { useId } from '@perses-dev/components';\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport { ReactElement, useContext, useMemo } from 'react';\nimport { PanelEditorContext } from '@perses-dev/dashboards';\nimport {\n DEFAULT_PROM,\n DurationString,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n PrometheusDatasourceSelector,\n} from '../../model';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PromQLEditor } from '../../components';\nimport {\n PrometheusTimeSeriesQueryEditorProps,\n useQueryState,\n useFormatState,\n useMinStepState,\n} from './query-editor-model';\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): ReactElement {\n const {\n onChange,\n value,\n value: { query, datasource },\n isReadonly,\n } = props;\n\n const datasourceSelectValue = datasource ?? DEFAULT_PROM;\n\n const datasourceSelectLabelID = useId('prom-datasource-label'); // for panels with multiple queries, this component is rendered multiple times on the same page\n\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 { data: datasourceResource } = useDatasource(selectedDatasource);\n\n const { handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\n const { minStep, handleMinStepChange, handleMinStepBlur } = useMinStepState(props);\n const minStepPlaceholder =\n minStep ??\n (datasourceResource && (datasourceResource?.plugin.spec as PrometheusDatasourceSpec).scrapeInterval) ??\n DEFAULT_SCRAPE_INTERVAL;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n /* Good to know: The usage of onchange here causes an immediate spec update which eventually updates the panel\n This was probably intentional to allow for quick switching between datasources.\n Could have been triggered only with Run Query button as well.\n */\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n const variableState = useAllVariableValues();\n const { absoluteTimeRange } = useTimeRange();\n const panelEditorContext = useContext(PanelEditorContext);\n const suggestedStepMs = useSuggestedStepMs(panelEditorContext?.preview.previewPanelWidth);\n\n const minStepMs = useMemo(() => {\n /* Try catch is necessary, because when the minStep value is being typed, it will be valid when the duration unit is added. Example: 2m = 2 + m */\n try {\n const durationsSeconds = getDurationStringSeconds(\n replaceVariables(minStepPlaceholder, variableState) as DurationString\n );\n return durationsSeconds !== undefined ? durationsSeconds * 1000 : undefined;\n } catch {\n return undefined;\n }\n }, [variableState, minStepPlaceholder]);\n\n const intervalMs = useMemo(() => {\n const minStepSeconds = (minStepMs ?? 0) / 1000;\n return getRangeStep(getPrometheusTimeRange(absoluteTimeRange), minStepSeconds, undefined, suggestedStepMs) * 1000;\n }, [absoluteTimeRange, minStepMs, suggestedStepMs]);\n\n const treeViewMetadata = useMemo(() => {\n return minStepMs && intervalMs\n ? {\n minStepMs,\n intervalMs,\n }\n : undefined;\n }, [minStepMs, intervalMs]);\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\" fullWidth={false}>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={datasourceSelectValue}\n onChange={handleDatasourceChange}\n labelId={datasourceSelectLabelID}\n label=\"Prometheus Datasource\"\n notched\n readOnly={isReadonly}\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={query} // here we are passing `value.query` and not `query` from useQueryState in order to get updates only on onBlur events\n datasource={selectedDatasource}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n isReadOnly={isReadonly}\n treeViewMetadata={treeViewMetadata}\n />\n <Stack direction=\"row\" spacing={2}>\n <TextField\n fullWidth\n label=\"Legend\"\n placeholder=\"Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...\"\n helperText=\"Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.\"\n value={format ?? ''}\n onChange={(e) => handleFormatChange(e.target.value)}\n onBlur={handleFormatBlur}\n slotProps={{\n inputLabel: { shrink: isReadonly ? true : undefined },\n input: { readOnly: isReadonly },\n }}\n />\n <TextField\n label=\"Min Step\"\n placeholder={minStepPlaceholder}\n helperText=\"Lower bound for the step. If not provided, the scrape interval of the datasource is used.\"\n value={minStep ?? ''}\n onChange={(e) => handleMinStepChange(e.target.value ? (e.target.value as DurationString) : undefined)}\n onBlur={handleMinStepBlur}\n sx={{ width: '250px' }}\n slotProps={{\n inputLabel: { shrink: isReadonly ? true : undefined },\n input: { readOnly: isReadonly },\n }}\n />\n </Stack>\n </Stack>\n );\n}\n"],"names":["produce","DatasourceSelect","replaceVariables","useAllVariableValues","useDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","useSuggestedStepMs","useTimeRange","useId","FormControl","Stack","TextField","useContext","useMemo","PanelEditorContext","DEFAULT_PROM","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","DEFAULT_SCRAPE_INTERVAL","PromQLEditor","useQueryState","useFormatState","useMinStepState","PrometheusTimeSeriesQueryEditor","props","onChange","value","query","datasource","isReadonly","datasourceSelectValue","datasourceSelectLabelID","selectedDatasource","data","client","promURL","options","datasourceUrl","datasourceResource","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","minStep","handleMinStepChange","handleMinStepBlur","minStepPlaceholder","plugin","spec","scrapeInterval","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","variableState","absoluteTimeRange","panelEditorContext","suggestedStepMs","preview","previewPanelWidth","minStepMs","durationsSeconds","intervalMs","minStepSeconds","treeViewMetadata","spacing","margin","fullWidth","datasourcePluginKind","labelId","label","notched","readOnly","completeConfig","remote","url","onBlur","isReadOnly","direction","placeholder","helperText","e","target","slotProps","inputLabel","shrink","input","sx","width"],"mappings":";AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,OAAO,QAAQ,QAAQ;AAChC,SACEC,gBAAgB,EAEhBC,gBAAgB,EAChBC,oBAAoB,EACpBC,aAAa,EACbC,mBAAmB,EACnBC,kCAAkC,EAClCC,kBAAkB,EAClBC,YAAY,QACP,4BAA4B;AACnC,SAASC,KAAK,QAAQ,yBAAyB;AAC/C,SAASC,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC9D,SAAuBC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAC1D,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,SACEC,YAAY,EAEZC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,qBAAqB,EACrBC,8BAA8B,EAC9BC,oBAAoB,QAGf,cAAc;AACrB,SAASC,uBAAuB,QAAkC,WAAW;AAC7E,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAEEC,aAAa,EACbC,cAAc,EACdC,eAAe,QACV,uBAAuB;AAC9B;;CAEC,GACD,OAAO,SAASC,gCAAgCC,KAA2C;IACzF,MAAM,EACJC,QAAQ,EACRC,KAAK,EACLA,OAAO,EAAEC,KAAK,EAAEC,UAAU,EAAE,EAC5BC,UAAU,EACX,GAAGL;IAEJ,MAAMM,wBAAwBF,cAAcjB;IAE5C,MAAMoB,0BAA0B3B,MAAM,0BAA0B,+FAA+F;IAE/J,MAAM4B,qBAAqB/B,mCACzB6B,uBACAb;IAGF,MAAM,EAAEgB,MAAMC,MAAM,EAAE,GAAGlC,oBAAsCgC;IAC/D,MAAMG,UAAUD,QAAQE,QAAQC;IACh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1 @@
1
- {"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,qBAAqB,EAAqD,MAAM,2BAA2B,CAAC;AAiBrH,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAG1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CAmIvG,CAAC"}
1
+ {"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,qBAAqB,EAAqD,MAAM,2BAA2B,CAAC;AAiBrH,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAG1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CAqIvG,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n DatasourceSpec,\n DurationString,\n Notice,\n parseDurationString,\n TimeSeries,\n TimeSeriesData,\n} from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, datasourceSelectValueToSelector, replaceVariables } from '@perses-dev/plugin-system';\nimport { fromUnixTime, milliseconds } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n MatrixData,\n VectorData,\n ScalarData,\n InstantQueryResultType,\n PROM_DATASOURCE_KIND,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\nimport { replacePromBuiltinVariables } from './replace-prom-builtin-variables';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context,\n abortSignal\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const listDatasourceSelectItems = await context.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND);\n\n const selectedDatasource =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n context.variableState,\n listDatasourceSelectItems\n ) ?? DEFAULT_PROM;\n\n const datasource = (await context.datasourceStore.getDatasource(\n selectedDatasource\n )) as DatasourceSpec<PrometheusDatasourceSpec>;\n const datasourceScrapeInterval = Math.trunc(\n milliseconds(parseDurationString(datasource.plugin.spec.scrapeInterval ?? DEFAULT_SCRAPE_INTERVAL)) / 1000\n );\n\n // Min step is the lower bound of the interval between data points\n // If no value is provided for it, it should default to the scrape interval of the datasource\n const minStep =\n getDurationStringSeconds(\n // resolve any variable that may have been provided\n // TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here\n replaceVariables(spec.minStep as string, context.variableState) as DurationString\n ) ?? datasourceScrapeInterval;\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n /* Ensure end is always greater than start:\n If the step is greater than equal to the diff of end and start,\n both start, and end will eventually be rounded to the same value,\n Consequently, the time range will be zero, which does not return any valid value\n */\n if (end === start) {\n end = start + step;\n console.warn(`Step (${step}) was larger than the time range! end of time range was set accordingly.`);\n }\n\n // Replace variable placeholders in PromQL query\n const intervalMs = step * 1000;\n const minStepMs = minStep * 1000;\n let query = replacePromBuiltinVariables(spec.query, minStepMs, intervalMs);\n query = replaceVariables(query, context.variableState);\n\n let seriesNameFormat = spec.seriesNameFormat;\n // if series name format is defined, replace variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceVariables(seriesNameFormat, context.variableState);\n }\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(selectedDatasource);\n\n // Make the request to Prom\n\n let response;\n switch (context.mode) {\n case 'instant':\n response = await client.instantQuery(\n {\n query,\n time: end,\n },\n undefined,\n abortSignal\n );\n break;\n case 'range':\n default:\n response = await client.rangeQuery(\n {\n query,\n start,\n end,\n step,\n },\n undefined,\n abortSignal\n );\n break;\n }\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data;\n\n // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n series: buildTimeSeries(query, result, seriesNameFormat),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n\nfunction buildVectorData(query: string, data: VectorData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, value, histogram } = res;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n if (histogram) {\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple([histogram[0], histogram[1].sum])],\n histograms: [histogram],\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple(value)],\n };\n });\n}\n\nfunction buildMatrixData(query: string, data: MatrixData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, values, histograms } = res;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n if (histograms) {\n return {\n name,\n formattedName,\n labels: metric,\n values: histograms.map((histogram) => parseValueTuple([histogram[0], histogram[1].sum])),\n histograms: histograms.map((histogram) => histogram),\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: values.map(parseValueTuple),\n };\n });\n}\n\nfunction buildScalarData(query: string, data: ScalarData, seriesNameFormat: string | undefined): TimeSeries[] {\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, {}, seriesNameFormat);\n return [\n {\n name,\n values: [parseValueTuple(data.result)],\n formattedName,\n },\n ];\n}\n\nfunction buildTimeSeries(query: string, data?: InstantQueryResultType, seriesNameFormat?: string): TimeSeries[] {\n if (!data) {\n return [];\n }\n\n const resultType = data.resultType;\n switch (resultType) {\n case 'vector':\n return buildVectorData(query, data, seriesNameFormat);\n case 'matrix':\n return buildMatrixData(query, data, seriesNameFormat);\n case 'scalar':\n return buildScalarData(query, data, seriesNameFormat);\n default:\n console.warn('Unknown result type', resultType, data);\n return [];\n }\n}\n"],"names":["parseDurationString","datasourceSelectValueToSelector","replaceVariables","fromUnixTime","milliseconds","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","PROM_DATASOURCE_KIND","getFormattedPrometheusSeriesName","DEFAULT_SCRAPE_INTERVAL","replacePromBuiltinVariables","getTimeSeriesData","spec","context","abortSignal","query","undefined","series","listDatasourceSelectItems","datasourceStore","selectedDatasource","datasource","variableState","getDatasource","datasourceScrapeInterval","Math","trunc","plugin","scrapeInterval","minStep","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","floor","alignedStart","console","warn","intervalMs","minStepMs","seriesNameFormat","client","getDatasourceClient","response","mode","instantQuery","time","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","buildTimeSeries","metadata","executedQueryString","buildVectorData","map","res","metric","value","histogram","name","formattedName","labels","values","sum","histograms","buildMatrixData","buildScalarData","resultType"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAIEA,mBAAmB,QAGd,mBAAmB;AAC1B,SAAgCC,+BAA+B,EAAEC,gBAAgB,QAAQ,4BAA4B;AACrH,SAASC,YAAY,EAAEC,YAAY,QAAQ,WAAW;AACtD,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,EAKZC,oBAAoB,QACf,cAAc;AACrB,SAASC,gCAAgC,QAAQ,cAAc;AAC/D,SAASC,uBAAuB,QAAkC,WAAW;AAE7E,SAASC,2BAA2B,QAAQ,mCAAmC;AAE/E,OAAO,MAAMC,oBAA+F,OAC1GC,MACAC,SACAC;IAEA,IAAIF,KAAKG,KAAK,KAAKC,aAAaJ,KAAKG,KAAK,KAAK,QAAQH,KAAKG,KAAK,KAAK,IAAI;QACxE,+EAA+E;QAC/E,OAAO;YAAEE,QAAQ,EAAE;QAAC;IACtB;IAEA,MAAMC,4BAA4B,MAAML,QAAQM,eAAe,CAACD,yBAAyB,CAACX;I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AAa,EAAEuC,IAA6B,EAAET,gBAAyB;IAC9F,IAAI,CAACS,MAAM;QACT,OAAO,EAAE;IACX;IAEA,MAAM2B,aAAa3B,KAAK2B,UAAU;IAClC,OAAQA;QACN,KAAK;YACH,OAAOd,gBAAgBpD,OAAOuC,MAAMT;QACtC,KAAK;YACH,OAAOkC,gBAAgBhE,OAAOuC,MAAMT;QACtC,KAAK;YACH,OAAOmC,gBAAgBjE,OAAOuC,MAAMT;QACtC;YACEJ,QAAQC,IAAI,CAAC,uBAAuBuC,YAAY3B;YAChD,OAAO,EAAE;IACb;AACF"}
1
+ {"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n DatasourceSpec,\n DurationString,\n Notice,\n parseDurationString,\n TimeSeries,\n TimeSeriesData,\n} from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, datasourceSelectValueToSelector, replaceVariables } from '@perses-dev/plugin-system';\nimport { fromUnixTime, milliseconds } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n MatrixData,\n VectorData,\n ScalarData,\n InstantQueryResultType,\n PROM_DATASOURCE_KIND,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\nimport { replacePromBuiltinVariables } from './replace-prom-builtin-variables';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context,\n abortSignal\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const listDatasourceSelectItems = await context.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND);\n\n const selectedDatasource =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n context.variableState,\n listDatasourceSelectItems\n ) ?? DEFAULT_PROM;\n\n const datasource = (await context.datasourceStore.getDatasource(\n selectedDatasource\n )) as DatasourceSpec<PrometheusDatasourceSpec>;\n const datasourceScrapeInterval = Math.trunc(\n milliseconds(parseDurationString(datasource.plugin.spec.scrapeInterval ?? DEFAULT_SCRAPE_INTERVAL)) / 1000\n );\n\n // Min step is the lower bound of the interval between data points\n // If no value is provided for it, it should default to the scrape interval of the datasource\n const minStep =\n getDurationStringSeconds(\n // resolve any variable that may have been provided\n // TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here\n replaceVariables(spec.minStep as string, context.variableState) as DurationString\n ) ?? datasourceScrapeInterval;\n\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n /* Ensure end is always greater than start:\n If the step is greater than equal to the diff of end and start,\n both start, and end will eventually be rounded to the same value,\n Consequently, the time range will be zero, which does not return any valid value\n */\n if (end === start) {\n end = start + step;\n console.warn(`Step (${step}) was larger than the time range! end of time range was set accordingly.`);\n }\n\n // Replace variable placeholders in PromQL query\n const intervalMs = step * 1000;\n const minStepMs = minStep * 1000;\n\n let query = replacePromBuiltinVariables(spec.query, minStepMs, intervalMs);\n query = replaceVariables(query, context.variableState);\n\n let seriesNameFormat = spec.seriesNameFormat;\n // if series name format is defined, replace variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceVariables(seriesNameFormat, context.variableState);\n }\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(selectedDatasource);\n\n // Make the request to Prom\n\n let response;\n switch (context.mode) {\n case 'instant':\n response = await client.instantQuery(\n {\n query,\n time: end,\n },\n undefined,\n abortSignal\n );\n break;\n case 'range':\n default:\n response = await client.rangeQuery(\n {\n query,\n start,\n end,\n step,\n },\n undefined,\n abortSignal\n );\n break;\n }\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data;\n\n // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n series: buildTimeSeries(query, result, seriesNameFormat),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n\nfunction buildVectorData(query: string, data: VectorData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, value, histogram } = res;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n if (histogram) {\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple([histogram[0], histogram[1].sum])],\n histograms: [histogram],\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple(value)],\n };\n });\n}\n\nfunction buildMatrixData(query: string, data: MatrixData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, values, histograms } = res;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n if (histograms) {\n return {\n name,\n formattedName,\n labels: metric,\n values: histograms.map((histogram) => parseValueTuple([histogram[0], histogram[1].sum])),\n histograms: histograms.map((histogram) => histogram),\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: values.map(parseValueTuple),\n };\n });\n}\n\nfunction buildScalarData(query: string, data: ScalarData, seriesNameFormat: string | undefined): TimeSeries[] {\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, {}, seriesNameFormat);\n return [\n {\n name,\n values: [parseValueTuple(data.result)],\n formattedName,\n },\n ];\n}\n\nfunction buildTimeSeries(query: string, data?: InstantQueryResultType, seriesNameFormat?: string): TimeSeries[] {\n if (!data) {\n return [];\n }\n\n const resultType = data.resultType;\n switch (resultType) {\n case 'vector':\n return buildVectorData(query, data, seriesNameFormat);\n case 'matrix':\n return buildMatrixData(query, data, seriesNameFormat);\n case 'scalar':\n return buildScalarData(query, data, seriesNameFormat);\n default:\n console.warn('Unknown result type', resultType, data);\n return [];\n }\n}\n"],"names":["parseDurationString","datasourceSelectValueToSelector","replaceVariables","fromUnixTime","milliseconds","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","PROM_DATASOURCE_KIND","getFormattedPrometheusSeriesName","DEFAULT_SCRAPE_INTERVAL","replacePromBuiltinVariables","getTimeSeriesData","spec","context","abortSignal","query","undefined","series","listDatasourceSelectItems","datasourceStore","selectedDatasource","datasource","variableState","getDatasource","datasourceScrapeInterval","Math","trunc","plugin","scrapeInterval","minStep","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","floor","alignedStart","console","warn","intervalMs","minStepMs","seriesNameFormat","client","getDatasourceClient","response","mode","instantQuery","time","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","buildTimeSeries","metadata","executedQueryString","buildVectorData","map","res","metric","value","histogram","name","formattedName","labels","values","sum","histograms","buildMatrixData","buildScalarData","resultType"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAIEA,mBAAmB,QAGd,mBAAmB;AAC1B,SAAgCC,+BAA+B,EAAEC,gBAAgB,QAAQ,4BAA4B;AACrH,SAASC,YAAY,EAAEC,YAAY,QAAQ,WAAW;AACtD,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,EAKZC,oBAAoB,QACf,cAAc;AACrB,SAASC,gCAAgC,QAAQ,cAAc;AAC/D,SAASC,uBAAuB,QAAkC,WAAW;AAE7E,SAASC,2BAA2B,QAAQ,mCAAmC;AAE/E,OAAO,MAAMC,oBAA+F,OAC1GC,MACAC,SACAC;IAEA,IAAIF,KAAKG,KAAK,KAAKC,aAAaJ,KAAKG,KAAK,KAAK,QAAQH,KAAKG,KAAK,KAAK,IAAI;QACxE,+EAA+E;QAC/E,OAAO;YAAEE,QAAQ,EAAE;QAAC;IACtB;IAEA,MAAMC,4BAA4B,MAAML,QAAQM,eAAe,CAACD,yBAAyB,CAACX;IAE1F,MAAMa,qBACJtB,gCACEc,KAAKS,UAAU,IAAIf,cACnBO,QAAQS,aAAa,EACrBJ,8BACGZ;IAEP,MAAMe,aAAc,MAAMR,QAAQM,eAAe,CAACI,aAAa,CAC7DH;IAEF,MAAMI,2BAA2BC,KAAKC,KAAK,CACzCzB,aAAaJ,oBAAoBwB,WAAWM,MAAM,CAACf,IAAI,CAACgB,cAAc,IAAInB,4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C,gBAAgBjE,OAAOuC,MAAMT;QACtC;YACEJ,QAAQC,IAAI,CAAC,uBAAuBuC,YAAY3B;YAChD,OAAO,EAAE;IACb;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAGlB,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAyB,MAAM,OAAO,CAAC;AAE5D,OAAO,EAIL,UAAU,EAIV,UAAU,EACX,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AAUjB,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,kBAAkB,CAAC,oCAAoC,CAAC,GAC9D,YAAY,CAsEd;AAED,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,kBAAkB,CAAC,mCAAmC,CAAC,GAC7D,YAAY,CAsDd;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,kBAAkB,CAAC,+BAA+B,CAAC,GACzD,YAAY,CA0Fd;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAS/E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAS/E;AAED;;GAEG;AACH,eAAO,MAAM,4BAA4B,GAAI,SAAS,MAAM,EAAE,KAAG,cAAc,EAM9E,CAAC"}
1
+ {"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAGlB,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAwC,MAAM,OAAO,CAAC;AAE3E,OAAO,EAIL,UAAU,EAIV,UAAU,EACX,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AAEjB,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,kBAAkB,CAAC,oCAAoC,CAAC,GAC9D,YAAY,CA6Ed;AAED,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,kBAAkB,CAAC,mCAAmC,CAAC,GAC7D,YAAY,CAuDd;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,kBAAkB,CAAC,+BAA+B,CAAC,GACzD,YAAY,CAsFd;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAS/E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAS/E;AAED;;GAEG;AACH,eAAO,MAAM,4BAA4B,GAAI,SAAS,MAAM,EAAE,KAAG,cAAc,EAM9E,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  // Copyright 2024 The Perses Authors
2
3
  // Licensed under the Apache License, Version 2.0 (the "License");
3
4
  // you may not use this file except in compliance with the License.
@@ -10,62 +11,44 @@
10
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12
  // See the License for the specific language governing permissions and
12
13
  // limitations under the License.
13
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { FormControl, Stack, TextField } from '@mui/material';
15
15
  import { DatasourceSelect, isVariableDatasource, useDatasourceClient, useDatasourceSelectValueToSelector } from '@perses-dev/plugin-system';
16
16
  import { produce } from 'immer';
17
- import { useCallback, useState } from 'react';
17
+ import { useCallback } 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
- /* TODO:
22
- Open Question for later improvement
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
- const [labelValue, setLabelValue] = useState(props.value.labelName);
31
- const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);
32
24
  const handleDatasourceChange = useCallback((next)=>{
33
25
  if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {
34
26
  onChange(produce(value, (draft)=>{
35
27
  // If they're using the default, just omit the datasource prop (i.e. set to undefined)
36
28
  draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;
37
29
  }));
38
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
39
- ...value,
40
- datasource: next
41
- });
42
30
  return;
43
31
  }
44
32
  throw new Error('Got unexpected non-Prometheus datasource selector');
45
33
  }, [
46
34
  onChange,
47
- queryHandlerSettings,
48
35
  value
49
36
  ]);
50
37
  const handleLabelChange = useCallback((e)=>{
51
- setLabelValue(e.target.value);
52
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
53
- ...value,
54
- labelName: e.target.value
55
- });
38
+ onChange(produce(value, (draft)=>{
39
+ draft.labelName = e.target.value;
40
+ }));
56
41
  }, [
57
- value,
58
- queryHandlerSettings
42
+ onChange,
43
+ value
59
44
  ]);
60
- const handleMatchEditorsChange = useCallback((e)=>{
61
- setMatchersValues(e);
62
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
63
- ...value,
64
- matchers: e
65
- });
45
+ const handleMatchEditorsChange = useCallback((matchers)=>{
46
+ onChange(produce(value, (draft)=>{
47
+ draft.matchers = matchers;
48
+ }));
66
49
  }, [
67
- value,
68
- queryHandlerSettings
50
+ onChange,
51
+ value
69
52
  ]);
70
53
  return /*#__PURE__*/ _jsxs(Stack, {
71
54
  spacing: 2,
@@ -84,14 +67,16 @@ I think we should only track the changes and let the button to Run the query
84
67
  /*#__PURE__*/ _jsx(TextField, {
85
68
  label: "Label Name",
86
69
  required: true,
87
- value: labelValue,
70
+ value: props.value.labelName,
88
71
  onChange: handleLabelChange,
89
- InputProps: {
90
- readOnly: props.isReadonly
72
+ slotProps: {
73
+ input: {
74
+ readOnly: props.isReadonly
75
+ }
91
76
  }
92
77
  }),
93
78
  /*#__PURE__*/ _jsx(MatcherEditor, {
94
- matchers: matchersValues,
79
+ matchers: props.value.matchers ?? [],
95
80
  onChange: handleMatchEditorsChange,
96
81
  isReadonly: props.isReadonly
97
82
  })
@@ -99,38 +84,28 @@ I think we should only track the changes and let the button to Run the query
99
84
  });
100
85
  }
101
86
  export function PrometheusLabelNamesVariableEditor(props) {
102
- const { onChange, value, value: { datasource }, queryHandlerSettings } = props;
87
+ const { onChange, value, value: { datasource } } = props;
103
88
  const selectedDatasource = datasource ?? DEFAULT_PROM;
104
- const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);
105
89
  const handleDatasourceChange = useCallback((next)=>{
106
90
  if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {
107
91
  onChange(produce(value, (draft)=>{
108
92
  // If they're using the default, just omit the datasource prop (i.e. set to undefined)
109
93
  draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;
110
94
  }));
111
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
112
- ...value,
113
- datasource: next
114
- });
115
95
  return;
116
96
  }
117
97
  throw new Error('Got unexpected non-Prometheus datasource selector');
118
98
  }, [
119
99
  onChange,
120
- queryHandlerSettings,
121
100
  value
122
101
  ]);
123
- const handleMatchEditorChange = useCallback((e)=>{
124
- setMatchersValues(e);
125
- if (queryHandlerSettings?.setWatchOtherSpecs) {
126
- queryHandlerSettings.setWatchOtherSpecs({
127
- ...value,
128
- matchers: e
129
- });
130
- }
102
+ const handleMatchEditorChange = useCallback((matchers)=>{
103
+ onChange(produce(value, (draft)=>{
104
+ draft.matchers = matchers;
105
+ }));
131
106
  }, [
132
- value,
133
- queryHandlerSettings
107
+ onChange,
108
+ value
134
109
  ]);
135
110
  return /*#__PURE__*/ _jsxs(Stack, {
136
111
  spacing: 2,
@@ -147,7 +122,7 @@ export function PrometheusLabelNamesVariableEditor(props) {
147
122
  })
148
123
  }),
149
124
  /*#__PURE__*/ _jsx(MatcherEditor, {
150
- matchers: matchersValues,
125
+ matchers: props.value.matchers ?? [],
151
126
  isReadonly: props.isReadonly,
152
127
  onChange: handleMatchEditorChange
153
128
  })
@@ -155,56 +130,38 @@ export function PrometheusLabelNamesVariableEditor(props) {
155
130
  });
156
131
  }
157
132
  export function PrometheusPromQLVariableEditor(props) {
158
- const { onChange, value, value: { datasource }, queryHandlerSettings } = props;
133
+ const { onChange, value, value: { datasource } } = props;
159
134
  const datasourceSelectValue = datasource ?? DEFAULT_PROM;
160
135
  const selectedDatasource = useDatasourceSelectValueToSelector(datasourceSelectValue, PROM_DATASOURCE_KIND);
161
136
  const { data: client } = useDatasourceClient(selectedDatasource);
162
137
  const promURL = client?.options.datasourceUrl;
163
- const [labelValue, setLableValue] = useState(props.value.labelName);
164
138
  const handleDatasourceChange = useCallback((next)=>{
165
139
  if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {
166
140
  onChange(produce(value, (draft)=>{
167
141
  // If they're using the default, just omit the datasource prop (i.e. set to undefined)
168
142
  draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;
169
143
  }));
170
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
171
- ...value,
172
- datasource: next
173
- });
174
144
  return;
175
145
  }
176
146
  throw new Error('Got unexpected non-Prometheus datasource selector');
177
147
  }, [
178
148
  value,
179
- onChange,
180
- queryHandlerSettings
149
+ onChange
181
150
  ]);
182
151
  const handleOnBlurPromQlChange = useCallback((e)=>{
183
- onChange({
184
- ...value,
185
- expr: e.target.textContent ?? ''
186
- });
152
+ onChange(produce(value, (draft)=>{
153
+ draft.expr = e.target.textContent ?? '';
154
+ }));
187
155
  }, [
188
156
  onChange,
189
157
  value
190
158
  ]);
191
- const trackPromQlChanges = useCallback((e)=>{
192
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
193
- ...value,
194
- expr: e.target.textContent ?? ''
195
- });
196
- }, [
197
- queryHandlerSettings,
198
- value
199
- ]);
200
159
  const handleLabelNameChange = useCallback((e)=>{
201
- setLableValue(e.target.value);
202
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
203
- ...value,
204
- labelName: e.target.value
205
- });
160
+ onChange(produce(value, (draft)=>{
161
+ draft.labelName = e.target.value;
162
+ }));
206
163
  }, [
207
- queryHandlerSettings,
164
+ onChange,
208
165
  value
209
166
  ]);
210
167
  return /*#__PURE__*/ _jsxs(Stack, {
@@ -229,16 +186,18 @@ export function PrometheusPromQLVariableEditor(props) {
229
186
  },
230
187
  value: value.expr,
231
188
  datasource: selectedDatasource,
232
- onBlur: queryHandlerSettings?.runWithOnBlur ? handleOnBlurPromQlChange : trackPromQlChanges,
189
+ onBlur: handleOnBlurPromQlChange,
233
190
  readOnly: props.isReadonly,
234
191
  width: "100%"
235
192
  }),
236
193
  /*#__PURE__*/ _jsx(TextField, {
237
194
  label: "Label Name",
238
195
  required: true,
239
- value: labelValue,
240
- InputProps: {
241
- readOnly: props.isReadonly
196
+ value: props.value.labelName,
197
+ slotProps: {
198
+ input: {
199
+ readOnly: props.isReadonly
200
+ }
242
201
  },
243
202
  onChange: handleLabelNameChange
244
203
  })
@@ -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 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\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 (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 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 (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 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 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, setLableValue] = 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 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={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={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","isVariableDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","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","datasourceSelectValue","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,2E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2C,OAAM;gBACNC,QAAQ;gBACR3B,OAAOI;gBACPwB,YAAY;oBACVL,UAAUzB,MAAM0B,UAAU;gBAC5B;gBACAzB,UAAU6C;;;;AAIlB;AAEA,OAAO,SAASO,gBAAgBC,MAAkB,EAAE9C,SAAiB;IACnE,MAAM+C,WAAW,IAAIC;IACrB,KAAK,MAAMC,UAAUH,OAAOI,MAAM,CAAE;QAClC,MAAMxD,QAAQuD,OAAOE,MAAM,CAACnD,UAAU;QACtC,IAAIN,UAAUa,WAAW;YACvBwC,SAASK,GAAG,CAAC1D;QACf;IACF;IACA,OAAO2D,MAAMC,IAAI,CAACP,SAASQ,MAAM;AACnC;AAEA,OAAO,SAASC,gBAAgBC,MAAkB,EAAEzD,SAAiB;IACnE,MAAM+C,WAAW,IAAIC;IACrB,KAAK,MAAMC,UAAUQ,OAAOP,MAAM,CAAE;QAClC,MAAMxD,QAAQuD,OAAOE,MAAM,CAACnD,UAAU;QACtC,IAAIN,UAAUa,WAAW;YACvBwC,SAASK,GAAG,CAAC1D;QACf;IACF;IACA,OAAO2D,MAAMC,IAAI,CAACP,SAASQ,MAAM;AACnC;AAEA;;CAEC,GACD,OAAO,MAAMG,+BAA+B,CAACH;IAC3C,IAAI,CAACA,QAAQ,OAAO,EAAE;IACtB,OAAOA,OAAOI,GAAG,CAAC,CAACjE,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, ChangeEvent, FocusEvent } 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\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(\n (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n onChange(\n produce(value, (draft) => {\n draft.labelName = e.target.value;\n })\n );\n },\n [onChange, value]\n );\n\n const handleMatchEditorsChange = useCallback(\n (matchers: string[]) => {\n onChange(\n produce(value, (draft) => {\n draft.matchers = matchers;\n })\n );\n },\n [onChange, value]\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={props.value.labelName}\n onChange={handleLabelChange}\n slotProps={{\n input: {\n readOnly: props.isReadonly,\n },\n }}\n />\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n onChange={handleMatchEditorsChange}\n isReadonly={props.isReadonly}\n />\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 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(\n (matchers: string[]) => {\n onChange(\n produce(value, (draft) => {\n draft.matchers = matchers;\n })\n );\n },\n [onChange, value]\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\n matchers={props.value.matchers ?? []}\n isReadonly={props.isReadonly}\n onChange={handleMatchEditorChange}\n />\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 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: FocusEvent<HTMLDivElement>) => {\n onChange(\n produce(value, (draft) => {\n draft.expr = e.target.textContent ?? '';\n })\n );\n },\n [onChange, value]\n );\n\n const handleLabelNameChange = useCallback(\n (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n onChange(\n produce(value, (draft) => {\n draft.labelName = e.target.value;\n })\n );\n },\n [onChange, 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={props.value.labelName}\n slotProps={{\n input: {\n readOnly: props.isReadonly,\n },\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","PromQLEditor","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","handleDatasourceChange","next","draft","undefined","Error","handleLabelChange","e","labelName","target","handleMatchEditorsChange","matchers","spacing","margin","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","slotProps","input","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,QA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,OAAO;wBACLN,UAAUnB,MAAMoB,UAAU;oBAC5B;gBACF;gBACAnB,UAAUsC;;;;AAIlB;AAEA,OAAO,SAASM,gBAAgBC,MAAkB,EAAElC,SAAiB;IACnE,MAAMmC,WAAW,IAAIC;IACrB,KAAK,MAAMC,UAAUH,OAAOI,MAAM,CAAE;QAClC,MAAMhD,QAAQ+C,OAAOE,MAAM,CAACvC,UAAU;QACtC,IAAIV,UAAUM,WAAW;YACvBuC,SAASK,GAAG,CAAClD;QACf;IACF;IACA,OAAOmD,MAAMC,IAAI,CAACP,SAASQ,MAAM;AACnC;AAEA,OAAO,SAASC,gBAAgBC,MAAkB,EAAE7C,SAAiB;IACnE,MAAMmC,WAAW,IAAIC;IACrB,KAAK,MAAMC,UAAUQ,OAAOP,MAAM,CAAE;QAClC,MAAMhD,QAAQ+C,OAAOE,MAAM,CAACvC,UAAU;QACtC,IAAIV,UAAUM,WAAW;YACvBuC,SAASK,GAAG,CAAClD;QACf;IACF;IACA,OAAOmD,MAAMC,IAAI,CAACP,SAASQ,MAAM;AACnC;AAEA;;CAEC,GACD,OAAO,MAAMG,+BAA+B,CAACH;IAC3C,IAAI,CAACA,QAAQ,OAAO,EAAE;IACtB,OAAOA,OAAOI,GAAG,CAAC,CAACzD,QAAW,CAAA;YAC5BA;YACAoB,OAAOpB;QACT,CAAA;AACF,EAAE"}
@@ -6,6 +6,7 @@ export interface PrometheusDatasourceSpec {
6
6
  directUrl?: string;
7
7
  proxy?: HTTPProxy;
8
8
  scrapeInterval?: DurationString;
9
+ queryParams?: Record<string, string>;
9
10
  }
10
11
  export interface PrometheusVariableOptionsBase {
11
12
  datasource?: DatasourceSelectValue<PrometheusDatasourceSelector>;