@perses-dev/prometheus-plugin 0.39.0 → 0.40.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 (78) hide show
  1. package/dist/cjs/components/PromQL.js +9 -7
  2. package/dist/cjs/components/index.js +10 -8
  3. package/dist/cjs/index.js +33 -19
  4. package/dist/cjs/model/index.js +15 -13
  5. package/dist/cjs/model/parse-sample-values.js +6 -2
  6. package/dist/cjs/model/prometheus-client.js +24 -5
  7. package/dist/cjs/model/prometheus-selectors.js +13 -5
  8. package/dist/cjs/model/templating.js +7 -5
  9. package/dist/cjs/model/time.js +14 -8
  10. package/dist/cjs/plugins/MatcherEditor.js +13 -11
  11. package/dist/cjs/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +127 -63
  12. package/dist/cjs/plugins/PrometheusDatasourceEditor/index.js +11 -9
  13. package/dist/cjs/plugins/PrometheusDatasourceEditor/types.js +7 -0
  14. package/dist/cjs/plugins/prometheus-datasource.js +53 -7
  15. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +10 -8
  16. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +44 -20
  17. package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +39 -21
  18. package/dist/cjs/plugins/prometheus-time-series-query/index.js +10 -8
  19. package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +42 -9
  20. package/dist/cjs/plugins/prometheus-variables.js +60 -54
  21. package/dist/cjs/plugins/variable.js +9 -7
  22. package/dist/cjs/utils/index.js +10 -8
  23. package/dist/cjs/utils/utils.js +12 -6
  24. package/dist/components/PromQL.js.map +1 -1
  25. package/dist/components/index.js.map +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/model/index.js.map +1 -1
  28. package/dist/model/parse-sample-values.js.map +1 -1
  29. package/dist/model/prometheus-client.d.ts.map +1 -1
  30. package/dist/model/prometheus-client.js +9 -0
  31. package/dist/model/prometheus-client.js.map +1 -1
  32. package/dist/model/prometheus-selectors.js +1 -1
  33. package/dist/model/prometheus-selectors.js.map +1 -1
  34. package/dist/model/templating.js.map +1 -1
  35. package/dist/model/time.js +1 -1
  36. package/dist/model/time.js.map +1 -1
  37. package/dist/plugins/MatcherEditor.js.map +1 -1
  38. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts.map +1 -1
  39. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +95 -33
  40. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js.map +1 -1
  41. package/dist/plugins/PrometheusDatasourceEditor/index.js.map +1 -1
  42. package/dist/plugins/PrometheusDatasourceEditor/types.d.ts +6 -4
  43. package/dist/plugins/PrometheusDatasourceEditor/types.d.ts.map +1 -1
  44. package/dist/plugins/PrometheusDatasourceEditor/types.js +1 -1
  45. package/dist/plugins/PrometheusDatasourceEditor/types.js.map +1 -1
  46. package/dist/plugins/prometheus-datasource.d.ts +3 -2
  47. package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
  48. package/dist/plugins/prometheus-datasource.js +48 -4
  49. package/dist/plugins/prometheus-datasource.js.map +1 -1
  50. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
  51. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
  52. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  53. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +32 -10
  54. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  55. package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
  56. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +32 -16
  57. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
  58. package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
  59. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +10 -1
  60. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -1
  61. package/dist/plugins/prometheus-time-series-query/query-editor-model.js +36 -8
  62. package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
  63. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts +2 -2
  64. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
  65. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
  66. package/dist/plugins/prometheus-variables.js +27 -27
  67. package/dist/plugins/prometheus-variables.js.map +1 -1
  68. package/dist/plugins/types.d.ts +2 -2
  69. package/dist/plugins/types.d.ts.map +1 -1
  70. package/dist/plugins/types.js.map +1 -1
  71. package/dist/plugins/variable.js +2 -2
  72. package/dist/plugins/variable.js.map +1 -1
  73. package/dist/test/setup-tests.js.map +1 -1
  74. package/dist/utils/index.js.map +1 -1
  75. package/dist/utils/utils.d.ts +1 -1
  76. package/dist/utils/utils.js +3 -3
  77. package/dist/utils/utils.js.map +1 -1
  78. package/package.json +6 -6
@@ -16,23 +16,30 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  Object.defineProperty(exports, "PrometheusTimeSeriesQueryEditor", {
18
18
  enumerable: true,
19
- get: ()=>PrometheusTimeSeriesQueryEditor
19
+ get: function() {
20
+ return PrometheusTimeSeriesQueryEditor;
21
+ }
20
22
  });
21
- const _jsxRuntime = require("react/jsx-runtime");
23
+ const _jsxruntime = require("react/jsx-runtime");
22
24
  const _immer = require("immer");
23
25
  const _material = require("@mui/material");
24
- const _pluginSystem = require("@perses-dev/plugin-system");
26
+ const _pluginsystem = require("@perses-dev/plugin-system");
25
27
  const _model = require("../../model");
26
28
  const _components = require("../../components");
27
- const _queryEditorModel = require("./query-editor-model");
29
+ const _PrometheusDatasourceEditor = require("../PrometheusDatasourceEditor");
30
+ const _queryeditormodel = require("./query-editor-model");
28
31
  function PrometheusTimeSeriesQueryEditor(props) {
29
32
  const { onChange , value } = props;
30
33
  const { datasource } = value;
31
34
  const selectedDatasource = datasource !== null && datasource !== void 0 ? datasource : _model.DEFAULT_PROM;
32
- const { data: client } = (0, _pluginSystem.useDatasourceClient)(selectedDatasource);
35
+ const { data: client } = (0, _pluginsystem.useDatasourceClient)(selectedDatasource);
33
36
  const promURL = client === null || client === void 0 ? void 0 : client.options.datasourceUrl;
34
- const { query , handleQueryChange , handleQueryBlur } = (0, _queryEditorModel.useQueryState)(props);
35
- const { format , handleFormatChange , handleFormatBlur } = (0, _queryEditorModel.useFormatState)(props);
37
+ const { data: datasourceResource } = (0, _pluginsystem.useDatasource)(selectedDatasource);
38
+ const { query , handleQueryChange , handleQueryBlur } = (0, _queryeditormodel.useQueryState)(props);
39
+ const { format , handleFormatChange , handleFormatBlur } = (0, _queryeditormodel.useFormatState)(props);
40
+ const { minStep , handleMinStepChange , handleMinStepBlur } = (0, _queryeditormodel.useMinStepState)(props);
41
+ var _ref;
42
+ const minStepPlaceholder = (_ref = minStep !== null && minStep !== void 0 ? minStep : datasourceResource && (datasourceResource === null || datasourceResource === void 0 ? void 0 : datasourceResource.plugin.spec).scrapeInterval) !== null && _ref !== void 0 ? _ref : _PrometheusDatasourceEditor.DEFAULT_SCRAPE_INTERVAL;
36
43
  const handleDatasourceChange = (next)=>{
37
44
  if ((0, _model.isPrometheusDatasourceSelector)(next)) {
38
45
  onChange((0, _immer.produce)(value, (draft)=>{
@@ -44,18 +51,18 @@ function PrometheusTimeSeriesQueryEditor(props) {
44
51
  }
45
52
  throw new Error('Got unexpected non-Prometheus datasource selector');
46
53
  };
47
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
54
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
48
55
  spacing: 2,
49
56
  children: [
50
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
57
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.FormControl, {
51
58
  margin: "dense",
52
59
  fullWidth: false,
53
60
  children: [
54
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
61
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.InputLabel, {
55
62
  id: "prom-datasource-label",
56
63
  children: "Prometheus Datasource"
57
64
  }),
58
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceSelect, {
65
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DatasourceSelect, {
59
66
  datasourcePluginKind: _model.PROM_DATASOURCE_KIND,
60
67
  value: selectedDatasource,
61
68
  onChange: handleDatasourceChange,
@@ -64,7 +71,7 @@ function PrometheusTimeSeriesQueryEditor(props) {
64
71
  })
65
72
  ]
66
73
  }),
67
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.PromQLEditor, {
74
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.PromQLEditor, {
68
75
  completeConfig: {
69
76
  remote: {
70
77
  url: promURL
@@ -74,14 +81,31 @@ function PrometheusTimeSeriesQueryEditor(props) {
74
81
  onChange: handleQueryChange,
75
82
  onBlur: handleQueryBlur
76
83
  }),
77
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
78
- fullWidth: true,
79
- label: "Legend Name",
80
- placeholder: "Tip: Use {{label_name}}. Example: {{instance}} will be replaced with values such as 'webserver-123' and 'webserver-456'.",
81
- helperText: "Set the name for each series in the legend and the tooltip.",
82
- value: format !== null && format !== void 0 ? format : '',
83
- onChange: (e)=>handleFormatChange(e.target.value),
84
- onBlur: handleFormatBlur
84
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
85
+ direction: "row",
86
+ spacing: 2,
87
+ children: [
88
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
89
+ fullWidth: true,
90
+ label: "Legend Name",
91
+ placeholder: "Tip: Use {{label_name}}. Example: {{instance}} will be replaced with values such as 'webserver-123' and 'webserver-456'.",
92
+ helperText: "Name for each series in the legend and the tooltip.",
93
+ value: format !== null && format !== void 0 ? format : '',
94
+ onChange: (e)=>handleFormatChange(e.target.value),
95
+ onBlur: handleFormatBlur
96
+ }),
97
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
98
+ label: "Min Step",
99
+ placeholder: minStepPlaceholder,
100
+ helperText: "Step parameter of the query. Used by $__interval and $__rate_interval too.",
101
+ value: minStep,
102
+ onChange: (e)=>handleMinStepChange(e.target.value),
103
+ onBlur: handleMinStepBlur,
104
+ sx: {
105
+ width: '250px'
106
+ }
107
+ })
108
+ ]
85
109
  })
86
110
  ]
87
111
  });
@@ -16,23 +16,32 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  Object.defineProperty(exports, "getTimeSeriesData", {
18
18
  enumerable: true,
19
- get: ()=>getTimeSeriesData
19
+ get: function() {
20
+ return getTimeSeriesData;
21
+ }
20
22
  });
21
- const _pluginSystem = require("@perses-dev/plugin-system");
22
- const _dateFns = require("date-fns");
23
+ const _core = require("@perses-dev/core");
24
+ const _pluginsystem = require("@perses-dev/plugin-system");
25
+ const _datefns = require("date-fns");
23
26
  const _model = require("../../model");
24
27
  const _utils = require("../../utils");
28
+ const _PrometheusDatasourceEditor = require("../PrometheusDatasourceEditor");
25
29
  const getTimeSeriesData = async (spec, context)=>{
26
- var ref;
30
+ var _response_data;
27
31
  if (spec.query === undefined || spec.query === null || spec.query === '') {
28
32
  // Do not make a request to the backend, instead return an empty TimeSeriesData
29
33
  return {
30
34
  series: []
31
35
  };
32
36
  }
33
- const minStep = (0, _model.getDurationStringSeconds)(spec.min_step);
37
+ var _spec_datasource;
38
+ const datasource = await context.datasourceStore.getDatasource((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : _model.DEFAULT_PROM);
39
+ var _datasource_plugin_spec_scrapeInterval;
40
+ const datasourceScrapeInterval = Math.trunc((0, _datefns.milliseconds)((0, _core.parseDurationString)((_datasource_plugin_spec_scrapeInterval = datasource.plugin.spec.scrapeInterval) !== null && _datasource_plugin_spec_scrapeInterval !== void 0 ? _datasource_plugin_spec_scrapeInterval : _PrometheusDatasourceEditor.DEFAULT_SCRAPE_INTERVAL)) / 1000);
41
+ var _getDurationStringSeconds;
42
+ const minStep = (_getDurationStringSeconds = (0, _model.getDurationStringSeconds)(spec.minStep)) !== null && _getDurationStringSeconds !== void 0 ? _getDurationStringSeconds : datasourceScrapeInterval;
34
43
  const timeRange = (0, _model.getPrometheusTimeRange)(context.timeRange);
35
- const step = (0, _model.getRangeStep)(timeRange, minStep, undefined, context.suggestedStepMs);
44
+ const step = (0, _model.getRangeStep)(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution
36
45
  // Align the time range so that it's a multiple of the step
37
46
  let { start , end } = timeRange;
38
47
  const utcOffsetSec = new Date().getTimezoneOffset() * 60;
@@ -40,17 +49,26 @@ const getTimeSeriesData = async (spec, context)=>{
40
49
  const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
41
50
  start = alignedStart;
42
51
  end = alignedEnd;
52
+ var _context_suggestedStepMs;
43
53
  // Replace template variable placeholders in PromQL query
44
- let query = spec.query.replace('$__rate_interval', `15s`);
45
- query = (0, _pluginSystem.replaceTemplateVariables)(query, context.variableState);
46
- let seriesNameFormat = spec.series_name_format;
54
+ const intervalMs = (_context_suggestedStepMs = context.suggestedStepMs) !== null && _context_suggestedStepMs !== void 0 ? _context_suggestedStepMs : step * 1000; // Step is in seconds
55
+ let query = (0, _pluginsystem.replaceTemplateVariable)(spec.query, '__interval_ms', intervalMs.toString());
56
+ query = (0, _pluginsystem.replaceTemplateVariable)(spec.query, '__interval', (0, _core.formatDuration)((0, _core.msToPrometheusDuration)(intervalMs)));
57
+ const scrapeIntervalMs = minStep * 1000;
58
+ // The $__rate_interval variable is meant to be used in the rate function.
59
+ // It is defined as max($__interval + Scrape interval, 4 * Scrape interval), where Scrape interval is the Min step setting (a setting per PromQL query),
60
+ // if any is set, and otherwise the Scrape interval as set in the Prometheus datasource
61
+ const rateIntervalMs = Math.max(intervalMs + scrapeIntervalMs, 4 * scrapeIntervalMs);
62
+ query = (0, _pluginsystem.replaceTemplateVariable)(query, '__rate_interval', (0, _core.formatDuration)((0, _core.msToPrometheusDuration)(rateIntervalMs)));
63
+ query = (0, _pluginsystem.replaceTemplateVariables)(query, context.variableState);
64
+ let seriesNameFormat = spec.seriesNameFormat;
47
65
  // if series name format is defined, replace template variable placeholders in series name format
48
66
  if (seriesNameFormat) {
49
- seriesNameFormat = (0, _pluginSystem.replaceTemplateVariables)(seriesNameFormat, context.variableState);
67
+ seriesNameFormat = (0, _pluginsystem.replaceTemplateVariables)(seriesNameFormat, context.variableState);
50
68
  }
51
- var _datasource;
69
+ var _spec_datasource1;
52
70
  // Get the datasource, using the default Prom Datasource if one isn't specified in the query
53
- const client = await context.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
71
+ const client = await context.datasourceStore.getDatasourceClient((_spec_datasource1 = spec.datasource) !== null && _spec_datasource1 !== void 0 ? _spec_datasource1 : _model.DEFAULT_PROM);
54
72
  // Make the request to Prom
55
73
  const response = await client.rangeQuery({
56
74
  query,
@@ -58,16 +76,16 @@ const getTimeSeriesData = async (spec, context)=>{
58
76
  end,
59
77
  step
60
78
  });
61
- var ref1;
79
+ var _response_data_result;
62
80
  // TODO: What about error responses from Prom that have a response body?
63
- const result = (ref1 = (ref = response.data) === null || ref === void 0 ? void 0 : ref.result) !== null && ref1 !== void 0 ? ref1 : [];
81
+ const result = (_response_data_result = (_response_data = response.data) === null || _response_data === void 0 ? void 0 : _response_data.result) !== null && _response_data_result !== void 0 ? _response_data_result : [];
64
82
  // Custom display for response header warnings, configurable error responses display coming next
65
83
  const notices = [];
66
84
  if (response.status === 'success') {
67
- var _warnings;
68
- const warnings = (_warnings = response.warnings) !== null && _warnings !== void 0 ? _warnings : [];
69
- var ref2;
70
- const warningMessage = (ref2 = warnings[0]) !== null && ref2 !== void 0 ? ref2 : '';
85
+ var _response_warnings;
86
+ const warnings = (_response_warnings = response.warnings) !== null && _response_warnings !== void 0 ? _response_warnings : [];
87
+ var _warnings_;
88
+ const warningMessage = (_warnings_ = warnings[0]) !== null && _warnings_ !== void 0 ? _warnings_ : '';
71
89
  if (warningMessage !== '') {
72
90
  notices.push({
73
91
  type: 'warning',
@@ -79,13 +97,13 @@ const getTimeSeriesData = async (spec, context)=>{
79
97
  const chartData = {
80
98
  // Return the time range and step we actually used for the query
81
99
  timeRange: {
82
- start: (0, _dateFns.fromUnixTime)(start),
83
- end: (0, _dateFns.fromUnixTime)(end)
100
+ start: (0, _datefns.fromUnixTime)(start),
101
+ end: (0, _datefns.fromUnixTime)(end)
84
102
  },
85
103
  stepMs: step * 1000,
86
104
  series: result.map((value)=>{
87
105
  const { metric , values } = value;
88
- // Account for series_name_format from query editor when determining name to show in legend, tooltip, etc.
106
+ // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.
89
107
  const { name , formattedName } = (0, _utils.getFormattedPrometheusSeriesName)(query, metric, seriesNameFormat);
90
108
  return {
91
109
  name,
@@ -14,15 +14,17 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- _exportStar(require("./PrometheusTimeSeriesQuery"), exports);
18
- function _exportStar(from, to) {
17
+ _export_star(require("./PrometheusTimeSeriesQuery"), exports);
18
+ function _export_star(from, to) {
19
19
  Object.keys(from).forEach(function(k) {
20
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
- enumerable: true,
22
- get: function() {
23
- return from[k];
24
- }
25
- });
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
21
+ Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ }
26
28
  });
27
29
  return from;
28
30
  }
@@ -21,8 +21,15 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- useQueryState: ()=>useQueryState,
25
- useFormatState: ()=>useFormatState
24
+ useQueryState: function() {
25
+ return useQueryState;
26
+ },
27
+ useFormatState: function() {
28
+ return useFormatState;
29
+ },
30
+ useMinStepState: function() {
31
+ return useMinStepState;
32
+ }
26
33
  });
27
34
  const _react = require("react");
28
35
  const _immer = require("immer");
@@ -58,21 +65,21 @@ function useQueryState(props) {
58
65
  function useFormatState(props) {
59
66
  const { onChange , value } = props;
60
67
  // TODO: reusable hook or helper util instead of duplicating from useQueryState
61
- const [format, setFormat] = (0, _react.useState)(value.series_name_format);
62
- const [lastSyncedFormat, setLastSyncedFormat] = (0, _react.useState)(value.series_name_format);
63
- if (value.series_name_format !== lastSyncedFormat) {
64
- setFormat(value.series_name_format);
65
- setLastSyncedFormat(value.series_name_format);
68
+ const [format, setFormat] = (0, _react.useState)(value.seriesNameFormat);
69
+ const [lastSyncedFormat, setLastSyncedFormat] = (0, _react.useState)(value.seriesNameFormat);
70
+ if (value.seriesNameFormat !== lastSyncedFormat) {
71
+ setFormat(value.seriesNameFormat);
72
+ setLastSyncedFormat(value.seriesNameFormat);
66
73
  }
67
74
  // Update our local state as the user types
68
75
  const handleFormatChange = (e)=>{
69
76
  setFormat(e);
70
77
  };
71
- // Propagate changes to the panel preview component when series_name_format TextField is blurred
78
+ // Propagate changes to the panel preview component when seriesNameFormat TextField is blurred
72
79
  const handleFormatBlur = ()=>{
73
80
  setLastSyncedFormat(format);
74
81
  onChange((0, _immer.produce)(value, (draft)=>{
75
- draft.series_name_format = format;
82
+ draft.seriesNameFormat = format;
76
83
  }));
77
84
  };
78
85
  return {
@@ -81,3 +88,29 @@ function useFormatState(props) {
81
88
  handleFormatBlur
82
89
  };
83
90
  }
91
+ function useMinStepState(props) {
92
+ const { onChange , value } = props;
93
+ // TODO: reusable hook or helper util instead of duplicating from useQueryState
94
+ const [minStep, setMinStep] = (0, _react.useState)(value.minStep);
95
+ const [lastSyncedMinStep, setLastSyncedMinStep] = (0, _react.useState)(value.minStep);
96
+ if (value.minStep !== lastSyncedMinStep) {
97
+ setMinStep(value.minStep);
98
+ setLastSyncedMinStep(value.minStep);
99
+ }
100
+ // Update our local state as the user types
101
+ const handleMinStepChange = (e)=>{
102
+ setMinStep(e);
103
+ };
104
+ // Propagate changes to the panel preview component when minStep TextField is blurred
105
+ const handleMinStepBlur = ()=>{
106
+ setLastSyncedMinStep(minStep);
107
+ onChange((0, _immer.produce)(value, (draft)=>{
108
+ draft.minStep = minStep;
109
+ }));
110
+ };
111
+ return {
112
+ minStep,
113
+ handleMinStepChange,
114
+ handleMinStepBlur
115
+ };
116
+ }
@@ -21,17 +21,23 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- PrometheusLabelNamesVariable: ()=>PrometheusLabelNamesVariable,
25
- PrometheusLabelValuesVariable: ()=>PrometheusLabelValuesVariable,
26
- PrometheusPromQLVariable: ()=>PrometheusPromQLVariable
24
+ PrometheusLabelNamesVariable: function() {
25
+ return PrometheusLabelNamesVariable;
26
+ },
27
+ PrometheusLabelValuesVariable: function() {
28
+ return PrometheusLabelValuesVariable;
29
+ },
30
+ PrometheusPromQLVariable: function() {
31
+ return PrometheusPromQLVariable;
32
+ }
27
33
  });
28
- const _jsxRuntime = require("react/jsx-runtime");
29
- const _pluginSystem = require("@perses-dev/plugin-system");
34
+ const _jsxruntime = require("react/jsx-runtime");
35
+ const _pluginsystem = require("@perses-dev/plugin-system");
30
36
  const _material = require("@mui/material");
31
37
  const _immer = require("immer");
32
38
  const _model = require("../model");
33
39
  const _components = require("../components");
34
- const _matcherEditor = require("./MatcherEditor");
40
+ const _MatcherEditor = require("./MatcherEditor");
35
41
  function PrometheusLabelValuesVariableEditor(props) {
36
42
  const { onChange , value } = props;
37
43
  const { datasource } = value;
@@ -46,18 +52,18 @@ function PrometheusLabelValuesVariableEditor(props) {
46
52
  }
47
53
  throw new Error('Got unexpected non-Prometheus datasource selector');
48
54
  };
49
- var _matchers;
50
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
55
+ var _props_value_matchers;
56
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
51
57
  spacing: 2,
52
58
  children: [
53
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
59
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.FormControl, {
54
60
  margin: "dense",
55
61
  children: [
56
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
62
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.InputLabel, {
57
63
  id: "prom-datasource-label",
58
64
  children: "Prometheus Datasource"
59
65
  }),
60
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceSelect, {
66
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DatasourceSelect, {
61
67
  datasourcePluginKind: "PrometheusDatasource",
62
68
  value: selectedDatasource,
63
69
  onChange: handleDatasourceChange,
@@ -67,22 +73,22 @@ function PrometheusLabelValuesVariableEditor(props) {
67
73
  })
68
74
  ]
69
75
  }),
70
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
76
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
71
77
  label: "Label Name",
72
78
  required: true,
73
- value: props.value.label_name,
79
+ value: props.value.labelName,
74
80
  onChange: (e)=>{
75
81
  props.onChange({
76
82
  ...props.value,
77
- label_name: e.target.value
83
+ labelName: e.target.value
78
84
  });
79
85
  },
80
86
  InputProps: {
81
87
  readOnly: props.isReadonly
82
88
  }
83
89
  }),
84
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_matcherEditor.MatcherEditor, {
85
- matchers: (_matchers = props.value.matchers) !== null && _matchers !== void 0 ? _matchers : [],
90
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_MatcherEditor.MatcherEditor, {
91
+ matchers: (_props_value_matchers = props.value.matchers) !== null && _props_value_matchers !== void 0 ? _props_value_matchers : [],
86
92
  onChange: (e)=>{
87
93
  props.onChange({
88
94
  ...props.value,
@@ -108,18 +114,18 @@ function PrometheusLabelNamesVariableEditor(props) {
108
114
  }
109
115
  throw new Error('Got unexpected non-Prometheus datasource selector');
110
116
  };
111
- var _matchers;
112
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
117
+ var _props_value_matchers;
118
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
113
119
  spacing: 2,
114
120
  children: [
115
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
121
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.FormControl, {
116
122
  margin: "dense",
117
123
  children: [
118
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
124
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.InputLabel, {
119
125
  id: "prom-datasource-label",
120
126
  children: "Prometheus Datasource"
121
127
  }),
122
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceSelect, {
128
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DatasourceSelect, {
123
129
  datasourcePluginKind: "PrometheusDatasource",
124
130
  value: selectedDatasource,
125
131
  onChange: handleDatasourceChange,
@@ -129,8 +135,8 @@ function PrometheusLabelNamesVariableEditor(props) {
129
135
  })
130
136
  ]
131
137
  }),
132
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_matcherEditor.MatcherEditor, {
133
- matchers: (_matchers = props.value.matchers) !== null && _matchers !== void 0 ? _matchers : [],
138
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_MatcherEditor.MatcherEditor, {
139
+ matchers: (_props_value_matchers = props.value.matchers) !== null && _props_value_matchers !== void 0 ? _props_value_matchers : [],
134
140
  isReadonly: props.isReadonly,
135
141
  onChange: (e)=>{
136
142
  props.onChange({
@@ -146,7 +152,7 @@ function PrometheusPromQLVariableEditor(props) {
146
152
  const { onChange , value } = props;
147
153
  const { datasource } = value;
148
154
  const selectedDatasource = datasource !== null && datasource !== void 0 ? datasource : _model.DEFAULT_PROM;
149
- const { data: client } = (0, _pluginSystem.useDatasourceClient)(selectedDatasource);
155
+ const { data: client } = (0, _pluginsystem.useDatasourceClient)(selectedDatasource);
150
156
  const promURL = client === null || client === void 0 ? void 0 : client.options.datasourceUrl;
151
157
  const handleDatasourceChange = (next)=>{
152
158
  if ((0, _model.isPrometheusDatasourceSelector)(next)) {
@@ -158,17 +164,17 @@ function PrometheusPromQLVariableEditor(props) {
158
164
  }
159
165
  throw new Error('Got unexpected non-Prometheus datasource selector');
160
166
  };
161
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
167
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
162
168
  spacing: 2,
163
169
  children: [
164
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
170
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.FormControl, {
165
171
  margin: "dense",
166
172
  children: [
167
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
173
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.InputLabel, {
168
174
  id: "prom-datasource-label",
169
175
  children: "Prometheus Datasource"
170
176
  }),
171
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceSelect, {
177
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DatasourceSelect, {
172
178
  datasourcePluginKind: _model.PROM_DATASOURCE_KIND,
173
179
  value: selectedDatasource,
174
180
  onChange: handleDatasourceChange,
@@ -178,7 +184,7 @@ function PrometheusPromQLVariableEditor(props) {
178
184
  })
179
185
  ]
180
186
  }),
181
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.PromQLEditor, {
187
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.PromQLEditor, {
182
188
  completeConfig: {
183
189
  remote: {
184
190
  url: promURL
@@ -194,36 +200,36 @@ function PrometheusPromQLVariableEditor(props) {
194
200
  readOnly: props.isReadonly,
195
201
  width: "100%"
196
202
  }),
197
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
203
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
198
204
  label: "Label Name",
199
- value: props.value.label_name,
205
+ value: props.value.labelName,
200
206
  InputProps: {
201
207
  readOnly: props.isReadonly
202
208
  },
203
209
  onChange: (e)=>{
204
210
  props.onChange({
205
211
  ...props.value,
206
- label_name: e.target.value
212
+ labelName: e.target.value
207
213
  });
208
214
  }
209
215
  })
210
216
  ]
211
217
  });
212
218
  }
213
- function capturingMatrix(matrix, label_name) {
219
+ function capturingMatrix(matrix, labelName) {
214
220
  const captured = new Set();
215
221
  for (const sample of matrix.result){
216
- const value = sample.metric[label_name];
222
+ const value = sample.metric[labelName];
217
223
  if (value !== undefined) {
218
224
  captured.add(value);
219
225
  }
220
226
  }
221
227
  return Array.from(captured.values());
222
228
  }
223
- function capturingVector(vector, label_name) {
229
+ function capturingVector(vector, labelName) {
224
230
  const captured = new Set();
225
231
  for (const sample of vector.result){
226
- const value = sample.metric[label_name];
232
+ const value = sample.metric[labelName];
227
233
  if (value !== undefined) {
228
234
  captured.add(value);
229
235
  }
@@ -241,9 +247,9 @@ function capturingVector(vector, label_name) {
241
247
  };
242
248
  const PrometheusLabelNamesVariable = {
243
249
  getVariableOptions: async (spec, ctx)=>{
244
- var _datasource;
245
- const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
246
- const match = spec.matchers ? spec.matchers.map((m)=>(0, _pluginSystem.replaceTemplateVariables)(m, ctx.variables)) : undefined;
250
+ var _spec_datasource;
251
+ const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : _model.DEFAULT_PROM);
252
+ const match = spec.matchers ? spec.matchers.map((m)=>(0, _pluginsystem.replaceTemplateVariables)(m, ctx.variables)) : undefined;
247
253
  const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
248
254
  const { data: options } = await client.labelNames({
249
255
  'match[]': match,
@@ -254,9 +260,9 @@ const PrometheusLabelNamesVariable = {
254
260
  };
255
261
  },
256
262
  dependsOn: (spec)=>{
257
- var ref;
263
+ var _spec_matchers;
258
264
  return {
259
- variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _pluginSystem.parseTemplateVariables)(m)).flat()) || []
265
+ variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>(0, _pluginsystem.parseTemplateVariables)(m)).flat()) || []
260
266
  };
261
267
  },
262
268
  OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
@@ -265,12 +271,12 @@ const PrometheusLabelNamesVariable = {
265
271
  const PrometheusLabelValuesVariable = {
266
272
  getVariableOptions: async (spec, ctx)=>{
267
273
  const pluginDef = spec;
268
- var _datasource;
269
- const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
270
- const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _pluginSystem.replaceTemplateVariables)(m, ctx.variables)) : undefined;
274
+ var _spec_datasource;
275
+ const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : _model.DEFAULT_PROM);
276
+ const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _pluginsystem.replaceTemplateVariables)(m, ctx.variables)) : undefined;
271
277
  const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
272
278
  const { data: options } = await client.labelValues({
273
- labelName: (0, _pluginSystem.replaceTemplateVariables)(pluginDef.label_name, ctx.variables),
279
+ labelName: (0, _pluginsystem.replaceTemplateVariables)(pluginDef.labelName, ctx.variables),
274
280
  'match[]': match,
275
281
  ...timeRange
276
282
  });
@@ -279,25 +285,25 @@ const PrometheusLabelValuesVariable = {
279
285
  };
280
286
  },
281
287
  dependsOn: (spec)=>{
282
- var ref;
288
+ var _spec_matchers;
283
289
  return {
284
- variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _pluginSystem.parseTemplateVariables)(m)).flat().concat((0, _pluginSystem.parseTemplateVariables)(spec.label_name))) || []
290
+ variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>(0, _pluginsystem.parseTemplateVariables)(m)).flat().concat((0, _pluginsystem.parseTemplateVariables)(spec.labelName))) || []
285
291
  };
286
292
  },
287
293
  OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
288
294
  createInitialOptions: ()=>({
289
- label_name: ''
295
+ labelName: ''
290
296
  })
291
297
  };
292
298
  const PrometheusPromQLVariable = {
293
299
  getVariableOptions: async (spec, ctx)=>{
294
- var _datasource;
295
- const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
300
+ var _spec_datasource;
301
+ const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : _model.DEFAULT_PROM);
296
302
  // TODO we may want to manage a range query as well.
297
303
  const { data: options } = await client.instantQuery({
298
- query: (0, _pluginSystem.replaceTemplateVariables)(spec.expr, ctx.variables)
304
+ query: (0, _pluginsystem.replaceTemplateVariables)(spec.expr, ctx.variables)
299
305
  });
300
- const labelName = (0, _pluginSystem.replaceTemplateVariables)(spec.label_name, ctx.variables);
306
+ const labelName = (0, _pluginsystem.replaceTemplateVariables)(spec.labelName, ctx.variables);
301
307
  let values = [];
302
308
  if ((options === null || options === void 0 ? void 0 : options.resultType) === 'matrix') {
303
309
  values = capturingMatrix(options, labelName);
@@ -310,12 +316,12 @@ const PrometheusPromQLVariable = {
310
316
  },
311
317
  dependsOn: (spec)=>{
312
318
  return {
313
- variables: (0, _pluginSystem.parseTemplateVariables)(spec.expr).concat((0, _pluginSystem.parseTemplateVariables)(spec.label_name))
319
+ variables: (0, _pluginsystem.parseTemplateVariables)(spec.expr).concat((0, _pluginsystem.parseTemplateVariables)(spec.labelName))
314
320
  };
315
321
  },
316
322
  OptionsEditorComponent: PrometheusPromQLVariableEditor,
317
323
  createInitialOptions: ()=>({
318
324
  expr: '',
319
- label_name: ''
325
+ labelName: ''
320
326
  })
321
327
  };