@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.
- package/dist/cjs/components/PromQL.js +10 -8
- package/dist/cjs/components/index.js +10 -8
- package/dist/cjs/index.js +33 -19
- package/dist/cjs/model/index.js +14 -13
- package/dist/cjs/model/parse-sample-values.js +6 -2
- package/dist/cjs/model/prometheus-client.js +43 -8
- package/dist/cjs/model/prometheus-selectors.js +12 -4
- package/dist/cjs/model/time.js +15 -9
- package/dist/cjs/plugins/MatcherEditor.js +14 -12
- package/dist/cjs/plugins/PrometheusDatasourceEditor.js +610 -0
- package/dist/cjs/plugins/prometheus-datasource.js +59 -8
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +10 -8
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +49 -24
- package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +44 -24
- package/dist/cjs/plugins/prometheus-time-series-query/index.js +10 -8
- package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +44 -11
- package/dist/cjs/plugins/prometheus-variables.js +69 -63
- package/dist/cjs/plugins/types.js +7 -0
- package/dist/cjs/plugins/variable.js +9 -7
- package/dist/cjs/utils/index.js +10 -8
- package/dist/cjs/utils/utils.js +13 -7
- package/dist/components/PromQL.d.ts +2 -3
- package/dist/components/PromQL.d.ts.map +1 -1
- package/dist/components/PromQL.js +1 -1
- package/dist/components/PromQL.js.map +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/api-types.d.ts +11 -11
- package/dist/model/api-types.d.ts.map +1 -1
- package/dist/model/api-types.js.map +1 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +0 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/parse-sample-values.d.ts +1 -1
- package/dist/model/parse-sample-values.d.ts.map +1 -1
- package/dist/model/parse-sample-values.js.map +1 -1
- package/dist/model/prometheus-client.d.ts +4 -0
- package/dist/model/prometheus-client.d.ts.map +1 -1
- package/dist/model/prometheus-client.js +27 -3
- package/dist/model/prometheus-client.js.map +1 -1
- package/dist/model/prometheus-selectors.js.map +1 -1
- package/dist/model/time.js +2 -2
- package/dist/model/time.js.map +1 -1
- package/dist/plugins/MatcherEditor.d.ts +2 -3
- package/dist/plugins/MatcherEditor.d.ts.map +1 -1
- package/dist/plugins/MatcherEditor.js +1 -1
- package/dist/plugins/MatcherEditor.js.map +1 -1
- package/dist/plugins/{PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts → PrometheusDatasourceEditor.d.ts} +1 -2
- package/dist/plugins/PrometheusDatasourceEditor.d.ts.map +1 -0
- package/dist/plugins/PrometheusDatasourceEditor.js +556 -0
- package/dist/plugins/PrometheusDatasourceEditor.js.map +1 -0
- package/dist/plugins/prometheus-datasource.d.ts +2 -7
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
- package/dist/plugins/prometheus-datasource.js +55 -6
- package/dist/plugins/prometheus-datasource.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts +1 -2
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +41 -18
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +37 -19
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +11 -2
- package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js +38 -10
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts +4 -4
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +3 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
- package/dist/plugins/prometheus-variables.d.ts.map +1 -1
- package/dist/plugins/prometheus-variables.js +37 -37
- package/dist/plugins/prometheus-variables.js.map +1 -1
- package/dist/plugins/types.d.ts +12 -5
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/plugins/types.js +1 -1
- package/dist/plugins/types.js.map +1 -1
- package/dist/plugins/variable.d.ts +2 -2
- package/dist/plugins/variable.d.ts.map +1 -1
- package/dist/plugins/variable.js +2 -2
- package/dist/plugins/variable.js.map +1 -1
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/utils.d.ts +2 -2
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +4 -4
- package/dist/utils/utils.js.map +1 -1
- package/package.json +6 -6
- package/dist/cjs/model/templating.js +0 -26
- package/dist/cjs/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +0 -392
- package/dist/cjs/plugins/PrometheusDatasourceEditor/index.js +0 -29
- package/dist/cjs/plugins/PrometheusDatasourceEditor/types.js +0 -16
- package/dist/model/templating.d.ts +0 -6
- package/dist/model/templating.d.ts.map +0 -1
- package/dist/model/templating.js +0 -20
- package/dist/model/templating.js.map +0 -1
- package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts.map +0 -1
- package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +0 -342
- package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js.map +0 -1
- package/dist/plugins/PrometheusDatasourceEditor/index.d.ts +0 -3
- package/dist/plugins/PrometheusDatasourceEditor/index.d.ts.map +0 -1
- package/dist/plugins/PrometheusDatasourceEditor/index.js +0 -16
- package/dist/plugins/PrometheusDatasourceEditor/index.js.map +0 -1
- package/dist/plugins/PrometheusDatasourceEditor/types.d.ts +0 -20
- package/dist/plugins/PrometheusDatasourceEditor/types.d.ts.map +0 -1
- package/dist/plugins/PrometheusDatasourceEditor/types.js +0 -15
- 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: ()
|
|
19
|
+
get: function() {
|
|
20
|
+
return PrometheusDatasource;
|
|
21
|
+
}
|
|
20
22
|
});
|
|
21
23
|
const _model = require("../model");
|
|
22
|
-
const
|
|
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 {
|
|
27
|
-
const { proxyUrl
|
|
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 =
|
|
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
|
|
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
|
-
|
|
108
|
+
getBuiltinVariableDefinitions,
|
|
109
|
+
OptionsEditorComponent: _PrometheusDatasourceEditor.PrometheusDatasourceEditor,
|
|
59
110
|
createInitialOptions: ()=>({
|
|
60
|
-
|
|
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: ()
|
|
19
|
+
get: function() {
|
|
20
|
+
return PrometheusTimeSeriesQuery;
|
|
21
|
+
}
|
|
20
22
|
});
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
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:
|
|
26
|
-
OptionsEditorComponent:
|
|
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,
|
|
34
|
-
const legendVariables = (0,
|
|
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: ()
|
|
19
|
+
get: function() {
|
|
20
|
+
return PrometheusTimeSeriesQueryEditor;
|
|
21
|
+
}
|
|
20
22
|
});
|
|
21
|
-
const
|
|
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
|
|
30
|
+
const _queryeditormodel = require("./query-editor-model");
|
|
28
31
|
function PrometheusTimeSeriesQueryEditor(props) {
|
|
29
|
-
const { onChange
|
|
30
|
-
const { datasource
|
|
32
|
+
const { onChange, value } = props;
|
|
33
|
+
const { datasource } = value;
|
|
31
34
|
const selectedDatasource = datasource !== null && datasource !== void 0 ? datasource : _model.DEFAULT_PROM;
|
|
32
|
-
const {
|
|
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 {
|
|
35
|
-
const {
|
|
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,
|
|
55
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
48
56
|
spacing: 2,
|
|
49
57
|
children: [
|
|
50
|
-
/*#__PURE__*/ (0,
|
|
58
|
+
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.FormControl, {
|
|
51
59
|
margin: "dense",
|
|
52
60
|
fullWidth: false,
|
|
53
61
|
children: [
|
|
54
|
-
/*#__PURE__*/ (0,
|
|
55
|
-
id:
|
|
62
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.InputLabel, {
|
|
63
|
+
id: datasourceSelectLabelID,
|
|
56
64
|
children: "Prometheus Datasource"
|
|
57
65
|
}),
|
|
58
|
-
/*#__PURE__*/ (0,
|
|
66
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DatasourceSelect, {
|
|
59
67
|
datasourcePluginKind: _model.PROM_DATASOURCE_KIND,
|
|
60
68
|
value: selectedDatasource,
|
|
61
69
|
onChange: handleDatasourceChange,
|
|
62
|
-
labelId:
|
|
70
|
+
labelId: datasourceSelectLabelID,
|
|
63
71
|
label: "Prometheus Datasource"
|
|
64
72
|
})
|
|
65
73
|
]
|
|
66
74
|
}),
|
|
67
|
-
/*#__PURE__*/ (0,
|
|
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,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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: ()
|
|
19
|
+
get: function() {
|
|
20
|
+
return getTimeSeriesData;
|
|
21
|
+
}
|
|
20
22
|
});
|
|
21
|
-
const
|
|
22
|
-
const
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
45
|
-
query = (0,
|
|
46
|
-
|
|
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,
|
|
69
|
+
seriesNameFormat = (0, _pluginsystem.replaceTemplateVariables)(seriesNameFormat, context.variableState);
|
|
50
70
|
}
|
|
51
|
-
var
|
|
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((
|
|
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
|
|
81
|
+
var _response_data_result;
|
|
62
82
|
// TODO: What about error responses from Prom that have a response body?
|
|
63
|
-
const result = (
|
|
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
|
|
68
|
-
const warnings = (
|
|
69
|
-
var
|
|
70
|
-
const warningMessage = (
|
|
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,
|
|
83
|
-
end: (0,
|
|
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
|
|
88
|
-
// Account for
|
|
89
|
-
const { name
|
|
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
|
-
|
|
18
|
-
function
|
|
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))
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
|
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
|
|
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.
|
|
62
|
-
const [lastSyncedFormat, setLastSyncedFormat] = (0, _react.useState)(value.
|
|
63
|
-
if (value.
|
|
64
|
-
setFormat(value.
|
|
65
|
-
setLastSyncedFormat(value.
|
|
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
|
|
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.
|
|
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
|
+
}
|