@perses-dev/prometheus-plugin 0.0.0-snapshot-panel-extra-content-3-17f9c42 → 0.0.0-snapshot-scatterplot-fix-imports-95e1b59

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 (111) hide show
  1. package/dist/cjs/components/PromQL.js +10 -8
  2. package/dist/cjs/components/index.js +10 -8
  3. package/dist/cjs/index.js +33 -19
  4. package/dist/cjs/model/index.js +14 -13
  5. package/dist/cjs/model/parse-sample-values.js +6 -2
  6. package/dist/cjs/model/prometheus-client.js +43 -8
  7. package/dist/cjs/model/prometheus-selectors.js +12 -4
  8. package/dist/cjs/model/time.js +15 -9
  9. package/dist/cjs/plugins/MatcherEditor.js +14 -12
  10. package/dist/cjs/plugins/PrometheusDatasourceEditor.js +610 -0
  11. package/dist/cjs/plugins/prometheus-datasource.js +59 -8
  12. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +10 -8
  13. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +49 -24
  14. package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +44 -24
  15. package/dist/cjs/plugins/prometheus-time-series-query/index.js +10 -8
  16. package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +44 -11
  17. package/dist/cjs/plugins/prometheus-variables.js +69 -63
  18. package/dist/cjs/plugins/types.js +7 -0
  19. package/dist/cjs/plugins/variable.js +9 -7
  20. package/dist/cjs/utils/index.js +10 -8
  21. package/dist/cjs/utils/utils.js +13 -7
  22. package/dist/components/PromQL.d.ts +2 -3
  23. package/dist/components/PromQL.d.ts.map +1 -1
  24. package/dist/components/PromQL.js +1 -1
  25. package/dist/components/PromQL.js.map +1 -1
  26. package/dist/components/index.js.map +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/model/api-types.d.ts +11 -11
  29. package/dist/model/api-types.d.ts.map +1 -1
  30. package/dist/model/api-types.js.map +1 -1
  31. package/dist/model/index.d.ts +0 -1
  32. package/dist/model/index.d.ts.map +1 -1
  33. package/dist/model/index.js +0 -1
  34. package/dist/model/index.js.map +1 -1
  35. package/dist/model/parse-sample-values.d.ts +1 -1
  36. package/dist/model/parse-sample-values.d.ts.map +1 -1
  37. package/dist/model/parse-sample-values.js.map +1 -1
  38. package/dist/model/prometheus-client.d.ts +4 -0
  39. package/dist/model/prometheus-client.d.ts.map +1 -1
  40. package/dist/model/prometheus-client.js +27 -3
  41. package/dist/model/prometheus-client.js.map +1 -1
  42. package/dist/model/prometheus-selectors.js.map +1 -1
  43. package/dist/model/time.js +2 -2
  44. package/dist/model/time.js.map +1 -1
  45. package/dist/plugins/MatcherEditor.d.ts +2 -3
  46. package/dist/plugins/MatcherEditor.d.ts.map +1 -1
  47. package/dist/plugins/MatcherEditor.js +1 -1
  48. package/dist/plugins/MatcherEditor.js.map +1 -1
  49. package/dist/plugins/{PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts → PrometheusDatasourceEditor.d.ts} +1 -2
  50. package/dist/plugins/PrometheusDatasourceEditor.d.ts.map +1 -0
  51. package/dist/plugins/PrometheusDatasourceEditor.js +556 -0
  52. package/dist/plugins/PrometheusDatasourceEditor.js.map +1 -0
  53. package/dist/plugins/prometheus-datasource.d.ts +2 -7
  54. package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
  55. package/dist/plugins/prometheus-datasource.js +55 -6
  56. package/dist/plugins/prometheus-datasource.js.map +1 -1
  57. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
  58. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
  59. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts +1 -2
  60. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  61. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +41 -18
  62. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  63. package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
  64. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +37 -19
  65. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
  66. package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
  67. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +11 -2
  68. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -1
  69. package/dist/plugins/prometheus-time-series-query/query-editor-model.js +38 -10
  70. package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
  71. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts +4 -4
  72. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
  73. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +3 -1
  74. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
  75. package/dist/plugins/prometheus-variables.d.ts.map +1 -1
  76. package/dist/plugins/prometheus-variables.js +37 -37
  77. package/dist/plugins/prometheus-variables.js.map +1 -1
  78. package/dist/plugins/types.d.ts +12 -5
  79. package/dist/plugins/types.d.ts.map +1 -1
  80. package/dist/plugins/types.js +1 -1
  81. package/dist/plugins/types.js.map +1 -1
  82. package/dist/plugins/variable.d.ts +2 -2
  83. package/dist/plugins/variable.d.ts.map +1 -1
  84. package/dist/plugins/variable.js +2 -2
  85. package/dist/plugins/variable.js.map +1 -1
  86. package/dist/test/setup-tests.js.map +1 -1
  87. package/dist/utils/index.js.map +1 -1
  88. package/dist/utils/utils.d.ts +2 -2
  89. package/dist/utils/utils.d.ts.map +1 -1
  90. package/dist/utils/utils.js +4 -4
  91. package/dist/utils/utils.js.map +1 -1
  92. package/package.json +6 -6
  93. package/dist/cjs/model/templating.js +0 -26
  94. package/dist/cjs/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +0 -392
  95. package/dist/cjs/plugins/PrometheusDatasourceEditor/index.js +0 -29
  96. package/dist/cjs/plugins/PrometheusDatasourceEditor/types.js +0 -16
  97. package/dist/model/templating.d.ts +0 -6
  98. package/dist/model/templating.d.ts.map +0 -1
  99. package/dist/model/templating.js +0 -20
  100. package/dist/model/templating.js.map +0 -1
  101. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts.map +0 -1
  102. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +0 -342
  103. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js.map +0 -1
  104. package/dist/plugins/PrometheusDatasourceEditor/index.d.ts +0 -3
  105. package/dist/plugins/PrometheusDatasourceEditor/index.d.ts.map +0 -1
  106. package/dist/plugins/PrometheusDatasourceEditor/index.js +0 -16
  107. package/dist/plugins/PrometheusDatasourceEditor/index.js.map +0 -1
  108. package/dist/plugins/PrometheusDatasourceEditor/types.d.ts +0 -20
  109. package/dist/plugins/PrometheusDatasourceEditor/types.d.ts.map +0 -1
  110. package/dist/plugins/PrometheusDatasourceEditor/types.js +0 -15
  111. package/dist/plugins/PrometheusDatasourceEditor/types.js.map +0 -1
@@ -16,25 +16,32 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  Object.defineProperty(exports, "PrometheusDatasource", {
18
18
  enumerable: true,
19
- get: ()=>PrometheusDatasource
19
+ get: function() {
20
+ return PrometheusDatasource;
21
+ }
20
22
  });
21
23
  const _model = require("../model");
22
- const _prometheusDatasourceEditor = require("./PrometheusDatasourceEditor");
24
+ const _PrometheusDatasourceEditor = require("./PrometheusDatasourceEditor");
23
25
  /**
24
26
  * Creates a PrometheusClient for a specific datasource spec.
25
27
  */ const createClient = (spec, options)=>{
26
- const { direct_url , headers: specHeaders } = spec;
27
- const { proxyUrl } = options;
28
+ const { directUrl, proxy } = spec;
29
+ const { proxyUrl } = options;
28
30
  // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified
29
- const datasourceUrl = direct_url !== null && direct_url !== void 0 ? direct_url : proxyUrl;
31
+ const datasourceUrl = directUrl !== null && directUrl !== void 0 ? directUrl : proxyUrl;
30
32
  if (datasourceUrl === undefined) {
31
- throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');
33
+ throw new Error('No URL specified for Prometheus client. You can use directUrl in the spec to configure it.');
32
34
  }
35
+ const specHeaders = proxy === null || proxy === void 0 ? void 0 : proxy.spec.headers;
33
36
  // Could think about this becoming a class, although it definitely doesn't have to be
34
37
  return {
35
38
  options: {
36
39
  datasourceUrl
37
40
  },
41
+ healthCheck: (0, _model.healthCheck)({
42
+ datasourceUrl,
43
+ headers: specHeaders
44
+ }),
38
45
  instantQuery: (params, headers)=>(0, _model.instantQuery)(params, {
39
46
  datasourceUrl,
40
47
  headers: headers !== null && headers !== void 0 ? headers : specHeaders
@@ -53,10 +60,54 @@ const _prometheusDatasourceEditor = require("./PrometheusDatasourceEditor");
53
60
  })
54
61
  };
55
62
  };
63
+ const getBuiltinVariableDefinitions = ()=>{
64
+ return [
65
+ {
66
+ kind: 'BuiltinVariable',
67
+ spec: {
68
+ name: '__interval',
69
+ value: ()=>'$__interval',
70
+ source: 'Prometheus',
71
+ display: {
72
+ name: '__interval',
73
+ description: 'Interval that can be used to group by time in queries. When there are more data points than can be shown on a graph then queries can be made more efficient by grouping by a larger interval.',
74
+ hidden: true
75
+ }
76
+ }
77
+ },
78
+ {
79
+ kind: 'BuiltinVariable',
80
+ spec: {
81
+ name: '__interval_ms',
82
+ value: ()=>'$__interval_ms',
83
+ source: 'Prometheus',
84
+ display: {
85
+ name: '__interval_ms',
86
+ description: 'Interval in millisecond that can be used to group by time in queries. When there are more data points than can be shown on a graph then queries can be made more efficient by grouping by a larger interval.',
87
+ hidden: true
88
+ }
89
+ }
90
+ },
91
+ {
92
+ kind: 'BuiltinVariable',
93
+ spec: {
94
+ name: '__rate_interval',
95
+ value: ()=>'$__rate_interval',
96
+ source: 'Prometheus',
97
+ display: {
98
+ name: '__rate_interval',
99
+ description: "Interval at least four times the value of the scrape interval. It avoids problems specific to Prometheus when using 'rate' and 'increase' functions.",
100
+ hidden: true
101
+ }
102
+ }
103
+ }
104
+ ];
105
+ };
56
106
  const PrometheusDatasource = {
57
107
  createClient,
58
- OptionsEditorComponent: _prometheusDatasourceEditor.PrometheusDatasourceEditor,
108
+ getBuiltinVariableDefinitions,
109
+ OptionsEditorComponent: _PrometheusDatasourceEditor.PrometheusDatasourceEditor,
59
110
  createInitialOptions: ()=>({
60
- direct_url: ''
111
+ directUrl: ''
61
112
  })
62
113
  };
@@ -16,22 +16,24 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  Object.defineProperty(exports, "PrometheusTimeSeriesQuery", {
18
18
  enumerable: true,
19
- get: ()=>PrometheusTimeSeriesQuery
19
+ get: function() {
20
+ return PrometheusTimeSeriesQuery;
21
+ }
20
22
  });
21
- const _pluginSystem = require("@perses-dev/plugin-system");
22
- const _getTimeSeriesData = require("./get-time-series-data");
23
- const _prometheusTimeSeriesQueryEditor = require("./PrometheusTimeSeriesQueryEditor");
23
+ const _pluginsystem = require("@perses-dev/plugin-system");
24
+ const _gettimeseriesdata = require("./get-time-series-data");
25
+ const _PrometheusTimeSeriesQueryEditor = require("./PrometheusTimeSeriesQueryEditor");
24
26
  const PrometheusTimeSeriesQuery = {
25
- getTimeSeriesData: _getTimeSeriesData.getTimeSeriesData,
26
- OptionsEditorComponent: _prometheusTimeSeriesQueryEditor.PrometheusTimeSeriesQueryEditor,
27
+ getTimeSeriesData: _gettimeseriesdata.getTimeSeriesData,
28
+ OptionsEditorComponent: _PrometheusTimeSeriesQueryEditor.PrometheusTimeSeriesQueryEditor,
27
29
  createInitialOptions: ()=>({
28
30
  query: '',
29
31
  datasource: undefined
30
32
  }),
31
33
  dependsOn: (spec)=>{
32
34
  // Variables can be used in the query and/or in the legend format string
33
- const queryVariables = (0, _pluginSystem.parseTemplateVariables)(spec.query);
34
- const legendVariables = (0, _pluginSystem.parseTemplateVariables)(spec.series_name_format || '');
35
+ const queryVariables = (0, _pluginsystem.parseTemplateVariables)(spec.query);
36
+ const legendVariables = (0, _pluginsystem.parseTemplateVariables)(spec.seriesNameFormat || '');
35
37
  const allVariables = [
36
38
  ...new Set([
37
39
  ...queryVariables,
@@ -16,23 +16,31 @@ 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");
25
+ const _pluginsystem = require("@perses-dev/plugin-system");
23
26
  const _material = require("@mui/material");
24
- const _pluginSystem = require("@perses-dev/plugin-system");
25
27
  const _model = require("../../model");
28
+ const _types = require("../types");
26
29
  const _components = require("../../components");
27
- const _queryEditorModel = require("./query-editor-model");
30
+ const _queryeditormodel = require("./query-editor-model");
28
31
  function PrometheusTimeSeriesQueryEditor(props) {
29
- const { onChange , value } = props;
30
- const { datasource } = value;
32
+ const { onChange, value } = props;
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 datasourceSelectLabelID = `prom-datasource-label-${selectedDatasource.name || 'default'}`;
36
+ const { data: client } = (0, _pluginsystem.useDatasourceClient)(selectedDatasource);
33
37
  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);
38
+ const { data: datasourceResource } = (0, _pluginsystem.useDatasource)(selectedDatasource);
39
+ const { query, handleQueryChange, handleQueryBlur } = (0, _queryeditormodel.useQueryState)(props);
40
+ const { format, handleFormatChange, handleFormatBlur } = (0, _queryeditormodel.useFormatState)(props);
41
+ const { minStep, handleMinStepChange, handleMinStepBlur } = (0, _queryeditormodel.useMinStepState)(props);
42
+ var _ref;
43
+ 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 : _types.DEFAULT_SCRAPE_INTERVAL;
36
44
  const handleDatasourceChange = (next)=>{
37
45
  if ((0, _model.isPrometheusDatasourceSelector)(next)) {
38
46
  onChange((0, _immer.produce)(value, (draft)=>{
@@ -44,27 +52,27 @@ function PrometheusTimeSeriesQueryEditor(props) {
44
52
  }
45
53
  throw new Error('Got unexpected non-Prometheus datasource selector');
46
54
  };
47
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
55
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
48
56
  spacing: 2,
49
57
  children: [
50
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
58
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.FormControl, {
51
59
  margin: "dense",
52
60
  fullWidth: false,
53
61
  children: [
54
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
55
- id: "prom-datasource-label",
62
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.InputLabel, {
63
+ id: datasourceSelectLabelID,
56
64
  children: "Prometheus Datasource"
57
65
  }),
58
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceSelect, {
66
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DatasourceSelect, {
59
67
  datasourcePluginKind: _model.PROM_DATASOURCE_KIND,
60
68
  value: selectedDatasource,
61
69
  onChange: handleDatasourceChange,
62
- labelId: "prom-datasource-label",
70
+ labelId: datasourceSelectLabelID,
63
71
  label: "Prometheus Datasource"
64
72
  })
65
73
  ]
66
74
  }),
67
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.PromQLEditor, {
75
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.PromQLEditor, {
68
76
  completeConfig: {
69
77
  remote: {
70
78
  url: promURL
@@ -74,14 +82,31 @@ function PrometheusTimeSeriesQueryEditor(props) {
74
82
  onChange: handleQueryChange,
75
83
  onBlur: handleQueryBlur
76
84
  }),
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
85
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
86
+ direction: "row",
87
+ spacing: 2,
88
+ children: [
89
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
90
+ fullWidth: true,
91
+ label: "Legend Name",
92
+ placeholder: "Tip: Use {{label_name}}. Example: {{instance}} will be replaced with values such as 'webserver-123' and 'webserver-456'.",
93
+ helperText: "Name for each series in the legend and the tooltip.",
94
+ value: format !== null && format !== void 0 ? format : '',
95
+ onChange: (e)=>handleFormatChange(e.target.value),
96
+ onBlur: handleFormatBlur
97
+ }),
98
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
99
+ label: "Min Step",
100
+ placeholder: minStepPlaceholder,
101
+ helperText: "Step parameter of the query. Used by $__interval and $__rate_interval too.",
102
+ value: minStep,
103
+ onChange: (e)=>handleMinStepChange(e.target.value),
104
+ onBlur: handleMinStepBlur,
105
+ sx: {
106
+ width: '250px'
107
+ }
108
+ })
109
+ ]
85
110
  })
86
111
  ]
87
112
  });
@@ -16,41 +16,61 @@ 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 _types = require("../types");
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 : _types.DEFAULT_SCRAPE_INTERVAL)) / 1000);
41
+ var _getDurationStringSeconds;
42
+ const minStep = (_getDurationStringSeconds = (0, _model.getDurationStringSeconds)(// resolve any variable that may have been provided
43
+ // TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here
44
+ (0, _pluginsystem.replaceTemplateVariables)(spec.minStep, context.variableState))) !== null && _getDurationStringSeconds !== void 0 ? _getDurationStringSeconds : datasourceScrapeInterval;
34
45
  const timeRange = (0, _model.getPrometheusTimeRange)(context.timeRange);
35
- const step = (0, _model.getRangeStep)(timeRange, minStep, undefined, context.suggestedStepMs);
46
+ const step = (0, _model.getRangeStep)(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution
36
47
  // Align the time range so that it's a multiple of the step
37
- let { start , end } = timeRange;
48
+ let { start, end } = timeRange;
38
49
  const utcOffsetSec = new Date().getTimezoneOffset() * 60;
39
50
  const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;
40
51
  const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
41
52
  start = alignedStart;
42
53
  end = alignedEnd;
54
+ var _context_suggestedStepMs;
43
55
  // 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;
56
+ const intervalMs = (_context_suggestedStepMs = context.suggestedStepMs) !== null && _context_suggestedStepMs !== void 0 ? _context_suggestedStepMs : step * 1000; // Step is in seconds
57
+ let query = (0, _pluginsystem.replaceTemplateVariable)(spec.query, '__interval_ms', intervalMs.toString());
58
+ query = (0, _pluginsystem.replaceTemplateVariable)(spec.query, '__interval', (0, _core.formatDuration)((0, _core.msToPrometheusDuration)(intervalMs)));
59
+ const scrapeIntervalMs = minStep * 1000;
60
+ // The $__rate_interval variable is meant to be used in the rate function.
61
+ // It is defined as max($__interval + Scrape interval, 4 * Scrape interval), where Scrape interval is the Min step setting (a setting per PromQL query),
62
+ // if any is set, and otherwise the Scrape interval as set in the Prometheus datasource
63
+ const rateIntervalMs = Math.max(intervalMs + scrapeIntervalMs, 4 * scrapeIntervalMs);
64
+ query = (0, _pluginsystem.replaceTemplateVariable)(query, '__rate_interval', (0, _core.formatDuration)((0, _core.msToPrometheusDuration)(rateIntervalMs)));
65
+ query = (0, _pluginsystem.replaceTemplateVariables)(query, context.variableState);
66
+ let seriesNameFormat = spec.seriesNameFormat;
47
67
  // if series name format is defined, replace template variable placeholders in series name format
48
68
  if (seriesNameFormat) {
49
- seriesNameFormat = (0, _pluginSystem.replaceTemplateVariables)(seriesNameFormat, context.variableState);
69
+ seriesNameFormat = (0, _pluginsystem.replaceTemplateVariables)(seriesNameFormat, context.variableState);
50
70
  }
51
- var _datasource;
71
+ var _spec_datasource1;
52
72
  // 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);
73
+ const client = await context.datasourceStore.getDatasourceClient((_spec_datasource1 = spec.datasource) !== null && _spec_datasource1 !== void 0 ? _spec_datasource1 : _model.DEFAULT_PROM);
54
74
  // Make the request to Prom
55
75
  const response = await client.rangeQuery({
56
76
  query,
@@ -58,16 +78,16 @@ const getTimeSeriesData = async (spec, context)=>{
58
78
  end,
59
79
  step
60
80
  });
61
- var ref1;
81
+ var _response_data_result;
62
82
  // 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 : [];
83
+ 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
84
  // Custom display for response header warnings, configurable error responses display coming next
65
85
  const notices = [];
66
86
  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 : '';
87
+ var _response_warnings;
88
+ const warnings = (_response_warnings = response.warnings) !== null && _response_warnings !== void 0 ? _response_warnings : [];
89
+ var _warnings_;
90
+ const warningMessage = (_warnings_ = warnings[0]) !== null && _warnings_ !== void 0 ? _warnings_ : '';
71
91
  if (warningMessage !== '') {
72
92
  notices.push({
73
93
  type: 'warning',
@@ -79,14 +99,14 @@ const getTimeSeriesData = async (spec, context)=>{
79
99
  const chartData = {
80
100
  // Return the time range and step we actually used for the query
81
101
  timeRange: {
82
- start: (0, _dateFns.fromUnixTime)(start),
83
- end: (0, _dateFns.fromUnixTime)(end)
102
+ start: (0, _datefns.fromUnixTime)(start),
103
+ end: (0, _datefns.fromUnixTime)(end)
84
104
  },
85
105
  stepMs: step * 1000,
86
106
  series: result.map((value)=>{
87
- const { metric , values } = value;
88
- // Account for series_name_format from query editor when determining name to show in legend, tooltip, etc.
89
- const { name , formattedName } = (0, _utils.getFormattedPrometheusSeriesName)(query, metric, seriesNameFormat);
107
+ const { metric, values } = value;
108
+ // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.
109
+ const { name, formattedName } = (0, _utils.getFormattedPrometheusSeriesName)(query, metric, seriesNameFormat);
90
110
  return {
91
111
  name,
92
112
  values: values.map(_model.parseValueTuple),
@@ -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,13 +21,20 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- useQueryState: ()=>useQueryState,
25
- useFormatState: ()=>useFormatState
24
+ useFormatState: function() {
25
+ return useFormatState;
26
+ },
27
+ useMinStepState: function() {
28
+ return useMinStepState;
29
+ },
30
+ useQueryState: function() {
31
+ return useQueryState;
32
+ }
26
33
  });
27
34
  const _react = require("react");
28
35
  const _immer = require("immer");
29
36
  function useQueryState(props) {
30
- const { onChange , value } = props;
37
+ const { onChange, value } = props;
31
38
  // Local copy of the query's value
32
39
  const [query, setQuery] = (0, _react.useState)(value.query);
33
40
  // This is basically "getDerivedStateFromProps" to make sure if spec's value changes external to this component,
@@ -56,23 +63,23 @@ function useQueryState(props) {
56
63
  };
57
64
  }
58
65
  function useFormatState(props) {
59
- const { onChange , value } = props;
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
+ }