@perses-dev/prometheus-plugin 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/model/index.js +34 -0
- package/dist/cjs/model/prometheus-client.js +4 -4
- package/dist/cjs/model/prometheus-selectors.js +37 -0
- package/dist/cjs/plugins/JSONSpecEditor.js +54 -0
- package/dist/cjs/plugins/PrometheusTimeSeriesQueryEditor.js +77 -0
- package/dist/cjs/plugins/prometheus-datasource.js +28 -0
- package/dist/cjs/plugins/prometheus-variables.js +22 -23
- package/dist/cjs/plugins/time-series-query.js +15 -20
- package/dist/cjs/plugins/variable.js +6 -1
- package/dist/model/index.d.ts +8 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +21 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/prometheus-client.d.ts +7 -8
- package/dist/model/prometheus-client.d.ts.map +1 -1
- package/dist/model/prometheus-client.js +4 -4
- package/dist/model/prometheus-client.js.map +1 -1
- package/dist/model/prometheus-selectors.d.ts +22 -0
- package/dist/model/prometheus-selectors.d.ts.map +1 -0
- package/dist/model/prometheus-selectors.js +30 -0
- package/dist/model/prometheus-selectors.js.map +1 -0
- package/dist/plugins/JSONSpecEditor.d.ts +4 -0
- package/dist/plugins/JSONSpecEditor.d.ts.map +1 -0
- package/dist/plugins/JSONSpecEditor.js +48 -0
- package/dist/plugins/JSONSpecEditor.js.map +1 -0
- package/dist/plugins/PrometheusTimeSeriesQueryEditor.d.ts +6 -0
- package/dist/plugins/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -0
- package/dist/plugins/PrometheusTimeSeriesQueryEditor.js +66 -0
- package/dist/plugins/PrometheusTimeSeriesQueryEditor.js.map +1 -0
- package/dist/plugins/prometheus-datasource.d.ts +5 -2
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
- package/dist/plugins/prometheus-datasource.js +28 -0
- package/dist/plugins/prometheus-datasource.js.map +1 -1
- package/dist/plugins/prometheus-variables.d.ts +4 -2
- package/dist/plugins/prometheus-variables.d.ts.map +1 -1
- package/dist/plugins/prometheus-variables.js +20 -21
- package/dist/plugins/prometheus-variables.js.map +1 -1
- package/dist/plugins/time-series-query.d.ts +2 -4
- package/dist/plugins/time-series-query.d.ts.map +1 -1
- package/dist/plugins/time-series-query.js +10 -15
- package/dist/plugins/time-series-query.js.map +1 -1
- package/dist/plugins/variable.d.ts.map +1 -1
- package/dist/plugins/variable.js +6 -1
- package/dist/plugins/variable.js.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
_exportStar(require("./api-types"), exports);
|
|
18
|
+
_exportStar(require("./parse-sample-values"), exports);
|
|
19
|
+
_exportStar(require("./prometheus-client"), exports);
|
|
20
|
+
_exportStar(require("./prometheus-selectors"), exports);
|
|
21
|
+
_exportStar(require("./templating"), exports);
|
|
22
|
+
_exportStar(require("./time"), exports);
|
|
23
|
+
_exportStar(require("./utils"), exports);
|
|
24
|
+
function _exportStar(from, to) {
|
|
25
|
+
Object.keys(from).forEach(function(k) {
|
|
26
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function() {
|
|
29
|
+
return from[k];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
return from;
|
|
34
|
+
}
|
|
@@ -42,8 +42,8 @@ function labelValues(params, queryOptions) {
|
|
|
42
42
|
return fetchWithGet(apiURI, searchParams, queryOptions);
|
|
43
43
|
}
|
|
44
44
|
function fetchWithGet(apiURI, params, queryOptions) {
|
|
45
|
-
const {
|
|
46
|
-
let url = `${
|
|
45
|
+
const { datasourceUrl } = queryOptions;
|
|
46
|
+
let url = `${datasourceUrl}${apiURI}`;
|
|
47
47
|
const urlParams = createSearchParams(params).toString();
|
|
48
48
|
if (urlParams !== '') {
|
|
49
49
|
url += `?${urlParams}`;
|
|
@@ -53,8 +53,8 @@ function fetchWithGet(apiURI, params, queryOptions) {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
function fetchWithPost(apiURI, params, queryOptions) {
|
|
56
|
-
const {
|
|
57
|
-
const url = `${
|
|
56
|
+
const { datasourceUrl } = queryOptions;
|
|
57
|
+
const url = `${datasourceUrl}${apiURI}`;
|
|
58
58
|
const init = {
|
|
59
59
|
method: 'POST',
|
|
60
60
|
headers: {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
DEFAULT_PROM: ()=>DEFAULT_PROM,
|
|
25
|
+
isDefaultPromSelector: ()=>isDefaultPromSelector,
|
|
26
|
+
isPrometheusDatasourceSelector: ()=>isPrometheusDatasourceSelector
|
|
27
|
+
});
|
|
28
|
+
const PROM_DATASOURCE_KIND = 'PrometheusDatasource';
|
|
29
|
+
const DEFAULT_PROM = {
|
|
30
|
+
kind: PROM_DATASOURCE_KIND
|
|
31
|
+
};
|
|
32
|
+
function isDefaultPromSelector(selector) {
|
|
33
|
+
return selector.name === undefined;
|
|
34
|
+
}
|
|
35
|
+
function isPrometheusDatasourceSelector(selector) {
|
|
36
|
+
return selector.kind === PROM_DATASOURCE_KIND;
|
|
37
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "JSONSpecEditor", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>JSONSpecEditor
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _react = require("react");
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
function JSONSpecEditor(props) {
|
|
25
|
+
const ref = (0, _react.useRef)(null);
|
|
26
|
+
const [value, setValue] = (0, _react.useState)(JSON.stringify(props.value, null, 2));
|
|
27
|
+
const [invalidJSON, setInvalidJSON] = (0, _react.useState)(false);
|
|
28
|
+
(0, _react.useEffect)(()=>{
|
|
29
|
+
setValue(JSON.stringify(props.value, null, 2));
|
|
30
|
+
setInvalidJSON(false);
|
|
31
|
+
}, [
|
|
32
|
+
props.value
|
|
33
|
+
]);
|
|
34
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
35
|
+
label: "JSON",
|
|
36
|
+
error: invalidJSON,
|
|
37
|
+
helperText: invalidJSON ? 'Invalid JSON' : '',
|
|
38
|
+
multiline: true,
|
|
39
|
+
inputRef: ref,
|
|
40
|
+
value: value,
|
|
41
|
+
onChange: (event)=>{
|
|
42
|
+
setValue(event.target.value);
|
|
43
|
+
},
|
|
44
|
+
onBlur: ()=>{
|
|
45
|
+
try {
|
|
46
|
+
const json = JSON.parse(value !== null && value !== void 0 ? value : '{}');
|
|
47
|
+
setInvalidJSON(false);
|
|
48
|
+
props.onChange(json);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
setInvalidJSON(true);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "PrometheusTimeSeriesQueryEditor", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>PrometheusTimeSeriesQueryEditor
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _immer = /*#__PURE__*/ _interopRequireDefault(require("immer"));
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
25
|
+
const _model = require("../model");
|
|
26
|
+
function _interopRequireDefault(obj) {
|
|
27
|
+
return obj && obj.__esModule ? obj : {
|
|
28
|
+
default: obj
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function PrometheusTimeSeriesQueryEditor(props) {
|
|
32
|
+
const { onChange , value } = props;
|
|
33
|
+
const { query , datasource } = value;
|
|
34
|
+
const handleQueryChange = (e)=>{
|
|
35
|
+
onChange((0, _immer.default)(value, (draft)=>{
|
|
36
|
+
draft.query = e.target.value;
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
39
|
+
const handleDatasourceChange = (next)=>{
|
|
40
|
+
if ((0, _model.isPrometheusDatasourceSelector)(next)) {
|
|
41
|
+
onChange((0, _immer.default)(value, (draft)=>{
|
|
42
|
+
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
43
|
+
const nextDatasource = (0, _model.isDefaultPromSelector)(next) ? undefined : next;
|
|
44
|
+
draft.datasource = nextDatasource;
|
|
45
|
+
}));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
49
|
+
};
|
|
50
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
51
|
+
children: [
|
|
52
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
53
|
+
label: "Query",
|
|
54
|
+
value: query,
|
|
55
|
+
onChange: handleQueryChange,
|
|
56
|
+
margin: "dense"
|
|
57
|
+
}),
|
|
58
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
|
|
59
|
+
margin: "dense",
|
|
60
|
+
fullWidth: false,
|
|
61
|
+
children: [
|
|
62
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
|
|
63
|
+
id: "prom-datasource-label",
|
|
64
|
+
children: "Prometheus Datasource"
|
|
65
|
+
}),
|
|
66
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceSelect, {
|
|
67
|
+
datasourcePluginKind: "PrometheusDatasource",
|
|
68
|
+
value: datasource !== null && datasource !== void 0 ? datasource : _model.DEFAULT_PROM,
|
|
69
|
+
onChange: handleDatasourceChange,
|
|
70
|
+
labelId: "prom-datasource-label",
|
|
71
|
+
label: "Prometheus Datasource"
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
})
|
|
75
|
+
]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -18,7 +18,35 @@ Object.defineProperty(exports, "PrometheusDatasource", {
|
|
|
18
18
|
enumerable: true,
|
|
19
19
|
get: ()=>PrometheusDatasource
|
|
20
20
|
});
|
|
21
|
+
const _model = require("../model");
|
|
22
|
+
/**
|
|
23
|
+
* Creates a PrometheusClient for a specific datasource spec.
|
|
24
|
+
*/ const createClient = (spec, options)=>{
|
|
25
|
+
const { direct_url } = spec;
|
|
26
|
+
const { proxyUrl } = options;
|
|
27
|
+
// Use the direct URL if specified, but fallback to the proxyUrl by default if not specified
|
|
28
|
+
const datasourceUrl = direct_url !== null && direct_url !== void 0 ? direct_url : proxyUrl;
|
|
29
|
+
if (datasourceUrl === undefined) {
|
|
30
|
+
throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');
|
|
31
|
+
}
|
|
32
|
+
// Could think about this becoming a class, although it definitely doesn't have to be
|
|
33
|
+
return {
|
|
34
|
+
instantQuery: (params)=>(0, _model.instantQuery)(params, {
|
|
35
|
+
datasourceUrl
|
|
36
|
+
}),
|
|
37
|
+
rangeQuery: (params)=>(0, _model.rangeQuery)(params, {
|
|
38
|
+
datasourceUrl
|
|
39
|
+
}),
|
|
40
|
+
labelNames: (params)=>(0, _model.labelNames)(params, {
|
|
41
|
+
datasourceUrl
|
|
42
|
+
}),
|
|
43
|
+
labelValues: (params)=>(0, _model.labelValues)(params, {
|
|
44
|
+
datasourceUrl
|
|
45
|
+
})
|
|
46
|
+
};
|
|
47
|
+
};
|
|
21
48
|
const PrometheusDatasource = {
|
|
49
|
+
createClient,
|
|
22
50
|
OptionsEditorComponent: ()=>null,
|
|
23
51
|
createInitialOptions: ()=>({
|
|
24
52
|
direct_url: ''
|
|
@@ -24,8 +24,8 @@ _export(exports, {
|
|
|
24
24
|
PrometheusLabelNamesVariable: ()=>PrometheusLabelNamesVariable,
|
|
25
25
|
PrometheusLabelValuesVariable: ()=>PrometheusLabelValuesVariable
|
|
26
26
|
});
|
|
27
|
-
const
|
|
28
|
-
const
|
|
27
|
+
const _model = require("../model");
|
|
28
|
+
const _jsonspecEditor = require("./JSONSpecEditor");
|
|
29
29
|
/**
|
|
30
30
|
* Takes a list of strings and returns a list of VariableOptions
|
|
31
31
|
*/ const stringArrayToVariableOptions = (values)=>{
|
|
@@ -35,43 +35,42 @@ const _prometheusClient = require("../model/prometheus-client");
|
|
|
35
35
|
label: value
|
|
36
36
|
}));
|
|
37
37
|
};
|
|
38
|
-
async function getQueryOptions(ctx, spec) {
|
|
39
|
-
var _datasource;
|
|
40
|
-
// Just use the default Prom datatsource if not specified in variable's spec
|
|
41
|
-
const datasourceSelector = (_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : {
|
|
42
|
-
kind: 'PrometheusDatasource'
|
|
43
|
-
};
|
|
44
|
-
const datasource = await ctx.datasourceStore.getDatasource(datasourceSelector);
|
|
45
|
-
const queryOptions = {
|
|
46
|
-
datasource: datasource.plugin.spec
|
|
47
|
-
};
|
|
48
|
-
return queryOptions;
|
|
49
|
-
}
|
|
50
38
|
const PrometheusLabelNamesVariable = {
|
|
51
39
|
getVariableOptions: async (spec, ctx)=>{
|
|
52
|
-
|
|
53
|
-
const
|
|
40
|
+
var _datasource;
|
|
41
|
+
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
42
|
+
const match = spec.matchers ? spec.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
|
|
43
|
+
const { data: options } = await client.labelNames({
|
|
44
|
+
'match[]': match
|
|
45
|
+
});
|
|
54
46
|
return {
|
|
55
47
|
data: stringArrayToVariableOptions(options)
|
|
56
48
|
};
|
|
57
49
|
},
|
|
58
|
-
dependsOn: ()=>[]
|
|
50
|
+
dependsOn: ()=>[],
|
|
51
|
+
OptionsEditorComponent: _jsonspecEditor.JSONSpecEditor,
|
|
52
|
+
createInitialOptions: ()=>({})
|
|
59
53
|
};
|
|
60
54
|
const PrometheusLabelValuesVariable = {
|
|
61
55
|
getVariableOptions: async (spec, ctx)=>{
|
|
62
56
|
const pluginDef = spec;
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
const
|
|
57
|
+
var _datasource;
|
|
58
|
+
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
59
|
+
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
|
|
60
|
+
const { data: options } = await client.labelValues({
|
|
66
61
|
labelName: pluginDef.label_name,
|
|
67
62
|
'match[]': match
|
|
68
|
-
}
|
|
63
|
+
});
|
|
69
64
|
return {
|
|
70
65
|
data: stringArrayToVariableOptions(options)
|
|
71
66
|
};
|
|
72
67
|
},
|
|
73
68
|
dependsOn: (spec)=>{
|
|
74
69
|
var ref;
|
|
75
|
-
return ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0,
|
|
76
|
-
}
|
|
70
|
+
return ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _model.parseTemplateVariables)(m)).flat()) || [];
|
|
71
|
+
},
|
|
72
|
+
OptionsEditorComponent: _jsonspecEditor.JSONSpecEditor,
|
|
73
|
+
createInitialOptions: ()=>({
|
|
74
|
+
label_name: ''
|
|
75
|
+
})
|
|
77
76
|
};
|
|
@@ -19,15 +19,13 @@ Object.defineProperty(exports, "PrometheusTimeSeriesQuery", {
|
|
|
19
19
|
get: ()=>PrometheusTimeSeriesQuery
|
|
20
20
|
});
|
|
21
21
|
const _dateFns = require("date-fns");
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const _time = require("../model/time");
|
|
25
|
-
const _utils = require("../model/utils");
|
|
22
|
+
const _model = require("../model");
|
|
23
|
+
const _prometheusTimeSeriesQueryEditor = require("./PrometheusTimeSeriesQueryEditor");
|
|
26
24
|
const getTimeSeriesData = async (spec, context)=>{
|
|
27
25
|
var ref;
|
|
28
|
-
const minStep = (0,
|
|
29
|
-
const timeRange = (0,
|
|
30
|
-
const step = (0,
|
|
26
|
+
const minStep = (0, _model.getDurationStringSeconds)(spec.min_step);
|
|
27
|
+
const timeRange = (0, _model.getPrometheusTimeRange)(context.timeRange);
|
|
28
|
+
const step = (0, _model.getRangeStep)(timeRange, minStep, undefined, context.suggestedStepMs);
|
|
31
29
|
// Align the time range so that it's a multiple of the step
|
|
32
30
|
let { start , end } = timeRange;
|
|
33
31
|
const utcOffsetSec = new Date().getTimezoneOffset() * 60;
|
|
@@ -37,24 +35,17 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
37
35
|
end = alignedEnd;
|
|
38
36
|
// Replace template variable placeholders in PromQL query
|
|
39
37
|
let query = spec.query.replace('$__rate_interval', `15s`);
|
|
40
|
-
query = (0,
|
|
38
|
+
query = (0, _model.replaceTemplateVariables)(query, context.variableState);
|
|
41
39
|
var _datasource;
|
|
42
40
|
// Get the datasource, using the default Prom Datasource if one isn't specified in the query
|
|
43
|
-
const
|
|
44
|
-
kind: 'PrometheusDatasource'
|
|
45
|
-
};
|
|
46
|
-
const datasource = await context.datasourceStore.getDatasource(datasourceSelector);
|
|
47
|
-
const queryOptions = {
|
|
48
|
-
datasource: datasource.plugin.spec
|
|
49
|
-
};
|
|
41
|
+
const client = await context.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
50
42
|
// Make the request to Prom
|
|
51
|
-
const
|
|
43
|
+
const response = await client.rangeQuery({
|
|
52
44
|
query,
|
|
53
45
|
start,
|
|
54
46
|
end,
|
|
55
47
|
step
|
|
56
|
-
};
|
|
57
|
-
const response = await (0, _prometheusClient.rangeQuery)(request, queryOptions);
|
|
48
|
+
});
|
|
58
49
|
var ref1;
|
|
59
50
|
// TODO: What about error responses from Prom that have a response body?
|
|
60
51
|
const result = (ref1 = (ref = response.data) === null || ref === void 0 ? void 0 : ref.result) !== null && ref1 !== void 0 ? ref1 : [];
|
|
@@ -76,12 +67,16 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
76
67
|
if (name === '') name = query;
|
|
77
68
|
return {
|
|
78
69
|
name,
|
|
79
|
-
values: values.map(
|
|
70
|
+
values: values.map(_model.parseValueTuple)
|
|
80
71
|
};
|
|
81
72
|
})
|
|
82
73
|
};
|
|
83
74
|
return chartData;
|
|
84
75
|
};
|
|
85
76
|
const PrometheusTimeSeriesQuery = {
|
|
86
|
-
getTimeSeriesData
|
|
77
|
+
getTimeSeriesData,
|
|
78
|
+
OptionsEditorComponent: _prometheusTimeSeriesQueryEditor.PrometheusTimeSeriesQueryEditor,
|
|
79
|
+
createInitialOptions: ()=>({
|
|
80
|
+
query: ''
|
|
81
|
+
})
|
|
87
82
|
};
|
|
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "StaticListVariable", {
|
|
|
18
18
|
enumerable: true,
|
|
19
19
|
get: ()=>StaticListVariable
|
|
20
20
|
});
|
|
21
|
+
const _jsonspecEditor = require("./JSONSpecEditor");
|
|
21
22
|
const StaticListVariable = {
|
|
22
23
|
getVariableOptions: async (spec)=>{
|
|
23
24
|
var ref;
|
|
@@ -34,5 +35,9 @@ const StaticListVariable = {
|
|
|
34
35
|
data: values
|
|
35
36
|
};
|
|
36
37
|
},
|
|
37
|
-
dependsOn: ()=>[]
|
|
38
|
+
dependsOn: ()=>[],
|
|
39
|
+
OptionsEditorComponent: _jsonspecEditor.JSONSpecEditor,
|
|
40
|
+
createInitialOptions: ()=>({
|
|
41
|
+
values: []
|
|
42
|
+
})
|
|
38
43
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './api-types';
|
|
2
|
+
export * from './parse-sample-values';
|
|
3
|
+
export * from './prometheus-client';
|
|
4
|
+
export * from './prometheus-selectors';
|
|
5
|
+
export * from './templating';
|
|
6
|
+
export * from './time';
|
|
7
|
+
export * from './utils';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export * from './api-types';
|
|
14
|
+
export * from './parse-sample-values';
|
|
15
|
+
export * from './prometheus-client';
|
|
16
|
+
export * from './prometheus-selectors';
|
|
17
|
+
export * from './templating';
|
|
18
|
+
export * from './time';
|
|
19
|
+
export * from './utils';
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './api-types';\nexport * from './parse-sample-values';\nexport * from './prometheus-client';\nexport * from './prometheus-selectors';\nexport * from './templating';\nexport * from './time';\nexport * from './utils';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { DatasourceSelector } from '@perses-dev/core';
|
|
2
1
|
import { InstantQueryRequestParameters, InstantQueryResponse, LabelNamesRequestParameters, LabelNamesResponse, LabelValuesRequestParameters, LabelValuesResponse, RangeQueryRequestParameters, RangeQueryResponse } from './api-types';
|
|
3
|
-
export interface
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export interface PrometheusClient {
|
|
3
|
+
instantQuery(params: InstantQueryRequestParameters): Promise<InstantQueryResponse>;
|
|
4
|
+
rangeQuery(params: RangeQueryRequestParameters): Promise<RangeQueryResponse>;
|
|
5
|
+
labelNames(params: LabelNamesRequestParameters): Promise<LabelNamesResponse>;
|
|
6
|
+
labelValues(params: LabelValuesRequestParameters): Promise<LabelValuesResponse>;
|
|
8
7
|
}
|
|
9
|
-
export interface
|
|
10
|
-
|
|
8
|
+
export interface QueryOptions {
|
|
9
|
+
datasourceUrl: string;
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* Calls the `/api/v1/query` endpoint to get metrics data.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,gBAAgB;IAC/B,YAAY,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnF,UAAU,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC7E,UAAU,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC7E,WAAW,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACjF;AAED,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,6BAA6B,EAAE,YAAY,EAAE,YAAY,iCAE7F;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,EAAE,YAAY,+BAEzF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,EAAE,YAAY,+BAEzF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,4BAA4B,EAAE,YAAY,EAAE,YAAY,gCAI3F"}
|
|
@@ -34,8 +34,8 @@ import { fetchJson } from '@perses-dev/core';
|
|
|
34
34
|
return fetchWithGet(apiURI, searchParams, queryOptions);
|
|
35
35
|
}
|
|
36
36
|
function fetchWithGet(apiURI, params, queryOptions) {
|
|
37
|
-
const {
|
|
38
|
-
let url = `${
|
|
37
|
+
const { datasourceUrl } = queryOptions;
|
|
38
|
+
let url = `${datasourceUrl}${apiURI}`;
|
|
39
39
|
const urlParams = createSearchParams(params).toString();
|
|
40
40
|
if (urlParams !== '') {
|
|
41
41
|
url += `?${urlParams}`;
|
|
@@ -45,8 +45,8 @@ function fetchWithGet(apiURI, params, queryOptions) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
function fetchWithPost(apiURI, params, queryOptions) {
|
|
48
|
-
const {
|
|
49
|
-
const url = `${
|
|
48
|
+
const { datasourceUrl } = queryOptions;
|
|
49
|
+
const url = `${datasourceUrl}${apiURI}`;
|
|
50
50
|
const init = {
|
|
51
51
|
method: 'POST',
|
|
52
52
|
headers: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/prometheus-client.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/model/prometheus-client.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { fetchJson } from '@perses-dev/core';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n} from './api-types';\n\nexport interface PrometheusClient {\n instantQuery(params: InstantQueryRequestParameters): Promise<InstantQueryResponse>;\n rangeQuery(params: RangeQueryRequestParameters): Promise<RangeQueryResponse>;\n labelNames(params: LabelNamesRequestParameters): Promise<LabelNamesResponse>;\n labelValues(params: LabelValuesRequestParameters): Promise<LabelValuesResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(params: InstantQueryRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(params: RangeQueryRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(params: LabelNamesRequestParameters, queryOptions: QueryOptions) {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(params: LabelValuesRequestParameters, queryOptions: QueryOptions) {\n const { labelName, ...searchParams } = params;\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(apiURI: string, params: T, queryOptions: QueryOptions) {\n const { datasourceUrl } = queryOptions;\n\n let url = `${datasourceUrl}${apiURI}`;\n const urlParams = createSearchParams(params).toString();\n if (urlParams !== '') {\n url += `?${urlParams}`;\n }\n return fetchJson<TResponse>(url, { method: 'GET' });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(apiURI: string, params: T, queryOptions: QueryOptions) {\n const { datasourceUrl } = queryOptions;\n\n const url = `${datasourceUrl}${apiURI}`;\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n },\n body: createSearchParams(params),\n };\n return fetchJson<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T) {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n"],"names":["fetchJson","instantQuery","params","queryOptions","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","apiURI","encodeURIComponent","fetchWithGet","datasourceUrl","url","urlParams","createSearchParams","toString","method","init","headers","body","URLSearchParams","key","value","undefined","append","val"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,SAAS,QAAQ,kBAAkB,CAAC;AAuB7C;;CAEC,GACD,OAAO,SAASC,YAAY,CAACC,MAAqC,EAAEC,YAA0B,EAAE;IAC9F,OAAOC,aAAa,CAAsD,eAAe,EAAEF,MAAM,EAAEC,YAAY,CAAC,CAAC;AACnH,CAAC;AAED;;CAEC,GACD,OAAO,SAASE,UAAU,CAACH,MAAmC,EAAEC,YAA0B,EAAE;IAC1F,OAAOC,aAAa,CAAkD,qBAAqB,EAAEF,MAAM,EAAEC,YAAY,CAAC,CAAC;AACrH,CAAC;AAED;;CAEC,GACD,OAAO,SAASG,UAAU,CAACJ,MAAmC,EAAEC,YAA0B,EAAE;IAC1F,OAAOC,aAAa,CAAkD,gBAAgB,EAAEF,MAAM,EAAEC,YAAY,CAAC,CAAC;AAChH,CAAC;AAED;;CAEC,GACD,OAAO,SAASI,WAAW,CAACL,MAAoC,EAA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S,EAAE;IACjE,MAAMO,YAAY,GAAG,IAAIa,eAAe,EAAE,AAAC;IAC3C,IAAK,MAAMC,GAAG,IAAIrB,MAAM,CAAE;QACxB,MAAMsB,KAAK,GAAetB,MAAM,CAACqB,GAAG,CAAC,AAAC;QACtC,IAAIC,KAAK,KAAKC,SAAS,EAAE,SAAS;QAElC,IAAI,OAAOD,KAAK,KAAK,QAAQ,EAAE;YAC7Bf,YAAY,CAACiB,MAAM,CAACH,GAAG,EAAEC,KAAK,CAAC,CAAC;YAChC,SAAS;QACX,CAAC;QAED,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;YAC7Bf,YAAY,CAACiB,MAAM,CAACH,GAAG,EAAEC,KAAK,CAACP,QAAQ,EAAE,CAAC,CAAC;YAC3C,SAAS;QACX,CAAC;QAED,KAAK,MAAMU,GAAG,IAAIH,KAAK,CAAE;YACvBf,YAAY,CAACiB,MAAM,CAACH,GAAG,EAAEI,GAAG,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IACD,OAAOlB,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DatasourceSelector } from '@perses-dev/core';
|
|
2
|
+
declare const PROM_DATASOURCE_KIND: "PrometheusDatasource";
|
|
3
|
+
/**
|
|
4
|
+
* DatasourceSelector for Prom Datasources.
|
|
5
|
+
*/
|
|
6
|
+
export interface PrometheusDatasourceSelector extends DatasourceSelector {
|
|
7
|
+
kind: typeof PROM_DATASOURCE_KIND;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A default selector that asks for the default Prom Datasource.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_PROM: PrometheusDatasourceSelector;
|
|
13
|
+
/**
|
|
14
|
+
* Returns true if the provided PrometheusDatasourceSelector is the default one.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isDefaultPromSelector(selector: PrometheusDatasourceSelector): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Type guard to make sure a DatasourceSelector is a Prometheus one.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isPrometheusDatasourceSelector(selector: DatasourceSelector): selector is PrometheusDatasourceSelector;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=prometheus-selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prometheus-selectors.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-selectors.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,QAAA,MAAM,oBAAoB,wBAAkC,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,4BAA6B,SAAQ,kBAAkB;IACtE,IAAI,EAAE,OAAO,oBAAoB,CAAC;CACnC;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,4BAA6D,CAAC;AAEzF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,4BAA4B,WAE3E;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,kBAAkB,GAAG,QAAQ,IAAI,4BAA4B,CAErH"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
const PROM_DATASOURCE_KIND = 'PrometheusDatasource';
|
|
14
|
+
/**
|
|
15
|
+
* A default selector that asks for the default Prom Datasource.
|
|
16
|
+
*/ export const DEFAULT_PROM = {
|
|
17
|
+
kind: PROM_DATASOURCE_KIND
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Returns true if the provided PrometheusDatasourceSelector is the default one.
|
|
21
|
+
*/ export function isDefaultPromSelector(selector) {
|
|
22
|
+
return selector.name === undefined;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Type guard to make sure a DatasourceSelector is a Prometheus one.
|
|
26
|
+
*/ export function isPrometheusDatasourceSelector(selector) {
|
|
27
|
+
return selector.kind === PROM_DATASOURCE_KIND;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=prometheus-selectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/model/prometheus-selectors.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourceSelector } from '@perses-dev/core';\n\nconst PROM_DATASOURCE_KIND = 'PrometheusDatasource' as const;\n\n/**\n * DatasourceSelector for Prom Datasources.\n */\nexport interface PrometheusDatasourceSelector extends DatasourceSelector {\n kind: typeof PROM_DATASOURCE_KIND;\n}\n\n/**\n * A default selector that asks for the default Prom Datasource.\n */\nexport const DEFAULT_PROM: PrometheusDatasourceSelector = { kind: PROM_DATASOURCE_KIND };\n\n/**\n * Returns true if the provided PrometheusDatasourceSelector is the default one.\n */\nexport function isDefaultPromSelector(selector: PrometheusDatasourceSelector) {\n return selector.name === undefined;\n}\n\n/**\n * Type guard to make sure a DatasourceSelector is a Prometheus one.\n */\nexport function isPrometheusDatasourceSelector(selector: DatasourceSelector): selector is PrometheusDatasourceSelector {\n return selector.kind === PROM_DATASOURCE_KIND;\n}\n"],"names":["PROM_DATASOURCE_KIND","DEFAULT_PROM","kind","isDefaultPromSelector","selector","name","undefined","isPrometheusDatasourceSelector"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,MAAMA,oBAAoB,GAAG,sBAAsB,AAAS,AAAC;AAS7D;;CAEC,GACD,OAAO,MAAMC,YAAY,GAAiC;IAAEC,IAAI,EAAEF,oBAAoB;CAAE,CAAC;AAEzF;;CAEC,GACD,OAAO,SAASG,qBAAqB,CAACC,QAAsC,EAAE;IAC5E,OAAOA,QAAQ,CAACC,IAAI,KAAKC,SAAS,CAAC;AACrC,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,8BAA8B,CAACH,QAA4B,EAA4C;IACrH,OAAOA,QAAQ,CAACF,IAAI,KAAKF,oBAAoB,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSONSpecEditor.d.ts","sourceRoot":"","sources":["../../src/plugins/JSONSpecEditor.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC,eAgC7D"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { useEffect, useRef, useState } from 'react';
|
|
15
|
+
import { TextField } from '@mui/material';
|
|
16
|
+
export function JSONSpecEditor(props) {
|
|
17
|
+
const ref = useRef(null);
|
|
18
|
+
const [value, setValue] = useState(JSON.stringify(props.value, null, 2));
|
|
19
|
+
const [invalidJSON, setInvalidJSON] = useState(false);
|
|
20
|
+
useEffect(()=>{
|
|
21
|
+
setValue(JSON.stringify(props.value, null, 2));
|
|
22
|
+
setInvalidJSON(false);
|
|
23
|
+
}, [
|
|
24
|
+
props.value
|
|
25
|
+
]);
|
|
26
|
+
return /*#__PURE__*/ _jsx(TextField, {
|
|
27
|
+
label: "JSON",
|
|
28
|
+
error: invalidJSON,
|
|
29
|
+
helperText: invalidJSON ? 'Invalid JSON' : '',
|
|
30
|
+
multiline: true,
|
|
31
|
+
inputRef: ref,
|
|
32
|
+
value: value,
|
|
33
|
+
onChange: (event)=>{
|
|
34
|
+
setValue(event.target.value);
|
|
35
|
+
},
|
|
36
|
+
onBlur: ()=>{
|
|
37
|
+
try {
|
|
38
|
+
const json = JSON.parse(value !== null && value !== void 0 ? value : '{}');
|
|
39
|
+
setInvalidJSON(false);
|
|
40
|
+
props.onChange(json);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
setInvalidJSON(true);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=JSONSpecEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/JSONSpecEditor.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useEffect, useRef, useState } from 'react';\nimport { TextField } from '@mui/material';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\n\nexport function JSONSpecEditor<T>(props: OptionsEditorProps<T>) {\n const ref = useRef<HTMLInputElement>(null);\n const [value, setValue] = useState(JSON.stringify(props.value, null, 2));\n const [invalidJSON, setInvalidJSON] = useState(false);\n\n useEffect(() => {\n setValue(JSON.stringify(props.value, null, 2));\n setInvalidJSON(false);\n }, [props.value]);\n\n return (\n <TextField\n label=\"JSON\"\n error={invalidJSON}\n helperText={invalidJSON ? 'Invalid JSON' : ''}\n multiline\n inputRef={ref}\n value={value}\n onChange={(event) => {\n setValue(event.target.value);\n }}\n onBlur={() => {\n try {\n const json = JSON.parse(value ?? '{}');\n setInvalidJSON(false);\n props.onChange(json);\n } catch (e) {\n setInvalidJSON(true);\n }\n }}\n />\n );\n}\n"],"names":["useEffect","useRef","useState","TextField","JSONSpecEditor","props","ref","value","setValue","JSON","stringify","invalidJSON","setInvalidJSON","label","error","helperText","multiline","inputRef","onChange","event","target","onBlur","json","parse","e"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACpD,SAASC,SAAS,QAAQ,eAAe,CAAC;AAG1C,OAAO,SAASC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|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
3
|
+
import { PrometheusTimeSeriesQuerySpec } from './time-series-query';
|
|
4
|
+
export declare type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;
|
|
5
|
+
export declare function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): JSX.Element;
|
|
6
|
+
//# sourceMappingURL=PrometheusTimeSeriesQueryEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../src/plugins/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,kBAAkB,EAA2C,MAAM,2BAA2B,CAAC;AAExG,OAAO,EAAE,6BAA6B,EAAE,MAAM,qBAAqB,CAAC;AAEpE,oBAAY,oCAAoC,GAAG,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AAErG,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eA4C1F"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import produce from 'immer';
|
|
15
|
+
import { Box, TextField, FormControl, InputLabel } from '@mui/material';
|
|
16
|
+
import { DatasourceSelect } from '@perses-dev/plugin-system';
|
|
17
|
+
import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../model';
|
|
18
|
+
export function PrometheusTimeSeriesQueryEditor(props) {
|
|
19
|
+
const { onChange , value } = props;
|
|
20
|
+
const { query , datasource } = value;
|
|
21
|
+
const handleQueryChange = (e)=>{
|
|
22
|
+
onChange(produce(value, (draft)=>{
|
|
23
|
+
draft.query = e.target.value;
|
|
24
|
+
}));
|
|
25
|
+
};
|
|
26
|
+
const handleDatasourceChange = (next)=>{
|
|
27
|
+
if (isPrometheusDatasourceSelector(next)) {
|
|
28
|
+
onChange(produce(value, (draft)=>{
|
|
29
|
+
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
30
|
+
const nextDatasource = isDefaultPromSelector(next) ? undefined : next;
|
|
31
|
+
draft.datasource = nextDatasource;
|
|
32
|
+
}));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
36
|
+
};
|
|
37
|
+
return /*#__PURE__*/ _jsxs(Box, {
|
|
38
|
+
children: [
|
|
39
|
+
/*#__PURE__*/ _jsx(TextField, {
|
|
40
|
+
label: "Query",
|
|
41
|
+
value: query,
|
|
42
|
+
onChange: handleQueryChange,
|
|
43
|
+
margin: "dense"
|
|
44
|
+
}),
|
|
45
|
+
/*#__PURE__*/ _jsxs(FormControl, {
|
|
46
|
+
margin: "dense",
|
|
47
|
+
fullWidth: false,
|
|
48
|
+
children: [
|
|
49
|
+
/*#__PURE__*/ _jsx(InputLabel, {
|
|
50
|
+
id: "prom-datasource-label",
|
|
51
|
+
children: "Prometheus Datasource"
|
|
52
|
+
}),
|
|
53
|
+
/*#__PURE__*/ _jsx(DatasourceSelect, {
|
|
54
|
+
datasourcePluginKind: "PrometheusDatasource",
|
|
55
|
+
value: datasource !== null && datasource !== void 0 ? datasource : DEFAULT_PROM,
|
|
56
|
+
onChange: handleDatasourceChange,
|
|
57
|
+
labelId: "prom-datasource-label",
|
|
58
|
+
label: "Prometheus Datasource"
|
|
59
|
+
})
|
|
60
|
+
]
|
|
61
|
+
})
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//# sourceMappingURL=PrometheusTimeSeriesQueryEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ChangeEvent } from 'react';\nimport produce from 'immer';\nimport { Box, TextField, FormControl, InputLabel } from '@mui/material';\nimport { OptionsEditorProps, DatasourceSelect, DatasourceSelectProps } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../model';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n const { query, datasource } = value;\n\n const handleQueryChange = (e: ChangeEvent<HTMLInputElement>) => {\n onChange(\n produce(value, (draft) => {\n draft.query = e.target.value;\n })\n );\n };\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Box>\n <TextField label=\"Query\" value={query} onChange={handleQueryChange} margin=\"dense\" />\n <FormControl margin=\"dense\" fullWidth={false}>\n {/* TODO: How do we ensure unique ID values if there are multiple of these? Can we use React 18 useId and\n maintain 17 compatibility somehow with a polyfill/shim? */}\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={datasource ?? DEFAULT_PROM}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n </Box>\n );\n}\n"],"names":["produce","Box","TextField","FormControl","InputLabel","DatasourceSelect","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PrometheusTimeSeriesQueryEditor","props","onChange","value","query","datasource","handleQueryChange","e","draft","target","handleDatasourceChange","next","nextDatasource","undefined","Error","label","margin","fullWidth","id","datasourcePluginKind","labelId"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AACA,OAAOA,OAAO,MAAM,OAAO,CAAC;AAC5B,SAASC,GAAG,EAAEC,SAAS,EAAEC,WAAW,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACxE,SAA6BC,gBAAgB,QAA+B,2BAA2B,CAAC;AACxG,SAASC,YAAY,EAAEC,qBAAqB,EAAEC,8BAA8B,QAAQ,UAAU,CAAC;AAK/F,OAAO,SAASC,+BAA+B,CAACC,KAA2C,EAAE;IAC3F,MAAM,EAAEC,QAAQ,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGF,KAAK,AAA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/BL,KAAK,EAAC,uBAAuB;sBAC7B;;cACU;;MACV,CACN;AACJ,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { DatasourcePlugin } from '@perses-dev/plugin-system';
|
|
2
|
-
import {
|
|
3
|
-
export
|
|
2
|
+
import { PrometheusClient } from '../model';
|
|
3
|
+
export interface PrometheusDatasourceSpec {
|
|
4
|
+
direct_url?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>;
|
|
4
7
|
//# sourceMappingURL=prometheus-datasource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"prometheus-datasource.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAqD,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE/F,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAwBD,eAAO,MAAM,oBAAoB,EAAE,gBAAgB,CAAC,wBAAwB,EAAE,gBAAgB,CAI7F,CAAC"}
|
|
@@ -10,7 +10,35 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
+
import { instantQuery, rangeQuery, labelNames, labelValues } from '../model';
|
|
14
|
+
/**
|
|
15
|
+
* Creates a PrometheusClient for a specific datasource spec.
|
|
16
|
+
*/ const createClient = (spec, options)=>{
|
|
17
|
+
const { direct_url } = spec;
|
|
18
|
+
const { proxyUrl } = options;
|
|
19
|
+
// Use the direct URL if specified, but fallback to the proxyUrl by default if not specified
|
|
20
|
+
const datasourceUrl = direct_url !== null && direct_url !== void 0 ? direct_url : proxyUrl;
|
|
21
|
+
if (datasourceUrl === undefined) {
|
|
22
|
+
throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');
|
|
23
|
+
}
|
|
24
|
+
// Could think about this becoming a class, although it definitely doesn't have to be
|
|
25
|
+
return {
|
|
26
|
+
instantQuery: (params)=>instantQuery(params, {
|
|
27
|
+
datasourceUrl
|
|
28
|
+
}),
|
|
29
|
+
rangeQuery: (params)=>rangeQuery(params, {
|
|
30
|
+
datasourceUrl
|
|
31
|
+
}),
|
|
32
|
+
labelNames: (params)=>labelNames(params, {
|
|
33
|
+
datasourceUrl
|
|
34
|
+
}),
|
|
35
|
+
labelValues: (params)=>labelValues(params, {
|
|
36
|
+
datasourceUrl
|
|
37
|
+
})
|
|
38
|
+
};
|
|
39
|
+
};
|
|
13
40
|
export const PrometheusDatasource = {
|
|
41
|
+
createClient,
|
|
14
42
|
OptionsEditorComponent: ()=>null,
|
|
15
43
|
createInitialOptions: ()=>({
|
|
16
44
|
direct_url: ''
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/prometheus-datasource.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/prometheus-datasource.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport { instantQuery, rangeQuery, labelNames, labelValues, PrometheusClient } from '../model';\n\nexport interface PrometheusDatasourceSpec {\n direct_url?: string;\n}\n\n/**\n * Creates a PrometheusClient for a specific datasource spec.\n */\nconst createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>['createClient'] = (spec, options) => {\n const { direct_url } = spec;\n const { proxyUrl } = options;\n\n // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified\n const datasourceUrl = direct_url ?? proxyUrl;\n if (datasourceUrl === undefined) {\n throw new Error('No URL specified for Prometheus client. You can use direct_url in the spec to configure it.');\n }\n\n // Could think about this becoming a class, although it definitely doesn't have to be\n return {\n instantQuery: (params) => instantQuery(params, { datasourceUrl }),\n rangeQuery: (params) => rangeQuery(params, { datasourceUrl }),\n labelNames: (params) => labelNames(params, { datasourceUrl }),\n labelValues: (params) => labelValues(params, { datasourceUrl }),\n };\n};\n\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient> = {\n createClient,\n OptionsEditorComponent: () => null,\n createInitialOptions: () => ({ direct_url: '' }),\n};\n"],"names":["instantQuery","rangeQuery","labelNames","labelValues","createClient","spec","options","direct_url","proxyUrl","datasourceUrl","undefined","Error","params","PrometheusDatasource","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE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rometheusDatasourceSelector } from '../model';
|
|
3
3
|
interface PrometheusVariableOptionsBase {
|
|
4
4
|
datasource?: PrometheusDatasourceSelector;
|
|
5
5
|
}
|
|
6
|
-
declare type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase
|
|
6
|
+
declare type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {
|
|
7
|
+
matchers?: [string];
|
|
8
|
+
};
|
|
7
9
|
declare type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {
|
|
8
10
|
label_name: string;
|
|
9
11
|
matchers?: [string];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.
|
|
1
|
+
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAkB,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAKL,4BAA4B,EAC7B,MAAM,UAAU,CAAC;AAGlB,UAAU,6BAA6B;IACrC,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAED,aAAK,mCAAmC,GAAG,6BAA6B,GAAG;IACzE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;CACrB,CAAC;AAEF,aAAK,oCAAoC,GAAG,6BAA6B,GAAG;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;CACrB,CAAC;AAaF,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAY5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CAiB9F,CAAC"}
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { replaceTemplateVariables, parseTemplateVariables } from '../model
|
|
14
|
-
import {
|
|
13
|
+
import { replaceTemplateVariables, parseTemplateVariables, DEFAULT_PROM } from '../model';
|
|
14
|
+
import { JSONSpecEditor } from './JSONSpecEditor';
|
|
15
15
|
/**
|
|
16
16
|
* Takes a list of strings and returns a list of VariableOptions
|
|
17
17
|
*/ const stringArrayToVariableOptions = (values)=>{
|
|
@@ -21,37 +21,32 @@ import { labelValues, labelNames } from '../model/prometheus-client';
|
|
|
21
21
|
label: value
|
|
22
22
|
}));
|
|
23
23
|
};
|
|
24
|
-
async function getQueryOptions(ctx, spec) {
|
|
25
|
-
var _datasource;
|
|
26
|
-
// Just use the default Prom datatsource if not specified in variable's spec
|
|
27
|
-
const datasourceSelector = (_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : {
|
|
28
|
-
kind: 'PrometheusDatasource'
|
|
29
|
-
};
|
|
30
|
-
const datasource = await ctx.datasourceStore.getDatasource(datasourceSelector);
|
|
31
|
-
const queryOptions = {
|
|
32
|
-
datasource: datasource.plugin.spec
|
|
33
|
-
};
|
|
34
|
-
return queryOptions;
|
|
35
|
-
}
|
|
36
24
|
export const PrometheusLabelNamesVariable = {
|
|
37
25
|
getVariableOptions: async (spec, ctx)=>{
|
|
38
|
-
|
|
39
|
-
const
|
|
26
|
+
var _datasource;
|
|
27
|
+
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
|
|
28
|
+
const match = spec.matchers ? spec.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
|
|
29
|
+
const { data: options } = await client.labelNames({
|
|
30
|
+
'match[]': match
|
|
31
|
+
});
|
|
40
32
|
return {
|
|
41
33
|
data: stringArrayToVariableOptions(options)
|
|
42
34
|
};
|
|
43
35
|
},
|
|
44
|
-
dependsOn: ()=>[]
|
|
36
|
+
dependsOn: ()=>[],
|
|
37
|
+
OptionsEditorComponent: JSONSpecEditor,
|
|
38
|
+
createInitialOptions: ()=>({})
|
|
45
39
|
};
|
|
46
40
|
export const PrometheusLabelValuesVariable = {
|
|
47
41
|
getVariableOptions: async (spec, ctx)=>{
|
|
48
42
|
const pluginDef = spec;
|
|
49
|
-
|
|
43
|
+
var _datasource;
|
|
44
|
+
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
|
|
50
45
|
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
|
|
51
|
-
const { data: options } = await labelValues({
|
|
46
|
+
const { data: options } = await client.labelValues({
|
|
52
47
|
labelName: pluginDef.label_name,
|
|
53
48
|
'match[]': match
|
|
54
|
-
}
|
|
49
|
+
});
|
|
55
50
|
return {
|
|
56
51
|
data: stringArrayToVariableOptions(options)
|
|
57
52
|
};
|
|
@@ -59,7 +54,11 @@ export const PrometheusLabelValuesVariable = {
|
|
|
59
54
|
dependsOn: (spec)=>{
|
|
60
55
|
var ref;
|
|
61
56
|
return ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>parseTemplateVariables(m)).flat()) || [];
|
|
62
|
-
}
|
|
57
|
+
},
|
|
58
|
+
OptionsEditorComponent: JSONSpecEditor,
|
|
59
|
+
createInitialOptions: ()=>({
|
|
60
|
+
label_name: ''
|
|
61
|
+
})
|
|
63
62
|
};
|
|
64
63
|
|
|
65
64
|
//# sourceMappingURL=prometheus-variables.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/prometheus-variables.
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/prometheus-variables.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport { VariablePlugin, VariableOption } from '@perses-dev/plugin-system';\nimport {\n replaceTemplateVariables,\n parseTemplateVariables,\n PrometheusClient,\n DEFAULT_PROM,\n PrometheusDatasourceSelector,\n} from '../model';\nimport { JSONSpecEditor } from './JSONSpecEditor';\n\ninterface PrometheusVariableOptionsBase {\n datasource?: PrometheusDatasourceSelector;\n}\n\ntype PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {\n matchers?: [string];\n};\n\ntype PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n label_name: string;\n matchers?: [string];\n};\n\n/**\n * Takes a list of strings and returns a list of VariableOptions\n */\nconst stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n\nexport const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = spec.matchers ? spec.matchers.map((m) => replaceTemplateVariables(m, ctx.variables)) : undefined;\n const { data: options } = await client.labelNames({ 'match[]': match });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: () => [],\n OptionsEditorComponent: JSONSpecEditor,\n createInitialOptions: () => ({}),\n};\n\nexport const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const pluginDef = spec;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = pluginDef.matchers\n ? pluginDef.matchers.map((m) => replaceTemplateVariables(m, ctx.variables))\n : undefined;\n const { data: options } = await client.labelValues({ labelName: pluginDef.label_name, 'match[]': match });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return spec.matchers?.map((m) => parseTemplateVariables(m)).flat() || [];\n },\n OptionsEditorComponent: JSONSpecEditor,\n createInitialOptions: () => ({ label_name: '' }),\n};\n"],"names":["replaceTemplateVariables","parseTemplateVariables","DEFAULT_PROM","JSONSpecEditor","stringArrayToVariableOptions","values","map","value","label","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","client","datasourceStore","getDatasourceClient","datasource","match","matchers","m","variables","undefined","data","options","labelNames","dependsOn","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","labelName","label_name","flat"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SACEA,wBAAwB,EACxBC,sBAAsB,EAEtBC,YAAY,QAEP,UAAU,CAAC;AAClB,SAASC,cAAc,QAAQ,kBAAkB,CAAC;AAelD;;CAEC,GACD,MAAMC,4BAA4B,GAAG,CAACC,MAAiB,GAAuB;IAC5E,IAAI,CAACA,MAAM,EAAE,OAAO,EAAE,CAAC;IACvB,OAAOA,MAAM,CAACC,GAAG,CAAC,CAACC,KAAK,GAAM,CAAA;YAC5BA,KAAK;YACLC,KAAK,EAAED,KAAK;SACb,CAAA,AAAC,CAAC,CAAC;AACN,CAAC,AAAC;AAEF,OAAO,MAAME,4BAA4B,GAAwD;IAC/FC,kBAAkB,EAAE,OAAOC,IAAI,EAAEC,GAAG,GAAK;YACwCD,WAAe;QAA9F,MAAME,MAAM,GAAqB,MAAMD,GAAG,CAACE,eAAe,CAACC,mBAAmB,CAACJ,CAAAA,WAAe,GAAfA,IAAI,CAACK,UAAU,cAAfL,WAAe,cAAfA,WAAe,GAAIT,YAAY,CAAC,AAAC;QAChH,MAAMe,KAAK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,OAAO,CAAC;SAC5C,CAAC;IACJ,CAAC;IACDE,SAAS,EAAE,CAACd,IAAI,GAAK;YACZA,GAAa;QAApB,OAAOA,CAAAA,CAAAA,GAAa,GAAbA,IAAI,CAACO,QAAQ,cAAbP,GAAa,WAAK,GAAlBA,KAAAA,CAAkB,GAAlBA,GAAa,CAAEL,GAAG,CAAC,CAACa,CAAC,GAAKlB,sBAAsB,CAACkB,CAAC,CAAC,CAAC,CAACc,IAAI,EAAE,CAAA,IAAI,EAAE,CAAC;IAC3E,CAAC;IACDP,sBAAsB,EAAEvB,cAAc;IACtCwB,oBAAoB,EAAE,IAAO,CAAA;YAAEK,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CACjD,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { DurationString } from '@perses-dev/core';
|
|
2
2
|
import { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';
|
|
3
|
-
import { PrometheusDatasourceSelector } from '../model
|
|
4
|
-
|
|
5
|
-
interface PrometheusTimeSeriesQuerySpec {
|
|
3
|
+
import { PrometheusDatasourceSelector, TemplateString } from '../model';
|
|
4
|
+
export interface PrometheusTimeSeriesQuerySpec {
|
|
6
5
|
query: TemplateString;
|
|
7
6
|
min_step?: DurationString;
|
|
8
7
|
resolution?: number;
|
|
@@ -12,5 +11,4 @@ interface PrometheusTimeSeriesQuerySpec {
|
|
|
12
11
|
* The core Prometheus TimeSeriesQuery plugin for Perses.
|
|
13
12
|
*/
|
|
14
13
|
export declare const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>;
|
|
15
|
-
export {};
|
|
16
14
|
//# sourceMappingURL=time-series-query.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-series-query.d.ts","sourceRoot":"","sources":["../../src/plugins/time-series-query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"time-series-query.d.ts","sourceRoot":"","sources":["../../src/plugins/time-series-query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElF,OAAO,EAEL,4BAA4B,EAE5B,cAAc,EAMf,MAAM,UAAU,CAAC;AAGlB,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAgED;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,qBAAqB,CAAC,6BAA6B,CAM1F,CAAC"}
|
|
@@ -11,10 +11,8 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { fromUnixTime } from 'date-fns';
|
|
14
|
-
import { parseValueTuple } from '../model
|
|
15
|
-
import {
|
|
16
|
-
import { getDurationStringSeconds, getPrometheusTimeRange, getRangeStep } from '../model/time';
|
|
17
|
-
import { replaceTemplateVariables } from '../model/utils';
|
|
14
|
+
import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, replaceTemplateVariables, DEFAULT_PROM } from '../model';
|
|
15
|
+
import { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';
|
|
18
16
|
const getTimeSeriesData = async (spec, context)=>{
|
|
19
17
|
var ref;
|
|
20
18
|
const minStep = getDurationStringSeconds(spec.min_step);
|
|
@@ -32,21 +30,14 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
32
30
|
query = replaceTemplateVariables(query, context.variableState);
|
|
33
31
|
var _datasource;
|
|
34
32
|
// Get the datasource, using the default Prom Datasource if one isn't specified in the query
|
|
35
|
-
const
|
|
36
|
-
kind: 'PrometheusDatasource'
|
|
37
|
-
};
|
|
38
|
-
const datasource = await context.datasourceStore.getDatasource(datasourceSelector);
|
|
39
|
-
const queryOptions = {
|
|
40
|
-
datasource: datasource.plugin.spec
|
|
41
|
-
};
|
|
33
|
+
const client = await context.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
|
|
42
34
|
// Make the request to Prom
|
|
43
|
-
const
|
|
35
|
+
const response = await client.rangeQuery({
|
|
44
36
|
query,
|
|
45
37
|
start,
|
|
46
38
|
end,
|
|
47
39
|
step
|
|
48
|
-
};
|
|
49
|
-
const response = await rangeQuery(request, queryOptions);
|
|
40
|
+
});
|
|
50
41
|
var ref1;
|
|
51
42
|
// TODO: What about error responses from Prom that have a response body?
|
|
52
43
|
const result = (ref1 = (ref = response.data) === null || ref === void 0 ? void 0 : ref.result) !== null && ref1 !== void 0 ? ref1 : [];
|
|
@@ -77,7 +68,11 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
77
68
|
/**
|
|
78
69
|
* The core Prometheus TimeSeriesQuery plugin for Perses.
|
|
79
70
|
*/ export const PrometheusTimeSeriesQuery = {
|
|
80
|
-
getTimeSeriesData
|
|
71
|
+
getTimeSeriesData,
|
|
72
|
+
OptionsEditorComponent: PrometheusTimeSeriesQueryEditor,
|
|
73
|
+
createInitialOptions: ()=>({
|
|
74
|
+
query: ''
|
|
75
|
+
})
|
|
81
76
|
};
|
|
82
77
|
|
|
83
78
|
//# sourceMappingURL=time-series-query.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/time-series-query.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport { TimeSeriesData, TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/time-series-query.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport { TimeSeriesData, TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusDatasourceSelector,\n PrometheusClient,\n TemplateString,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n replaceTemplateVariables,\n DEFAULT_PROM,\n} from '../model';\nimport { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';\n\nexport interface PrometheusTimeSeriesQuerySpec {\n query: TemplateString;\n min_step?: DurationString;\n resolution?: number;\n datasource?: PrometheusDatasourceSelector;\n}\n\nconst getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n const minStep = getDurationStringSeconds(spec.min_step);\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs);\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n // Replace template variable placeholders in PromQL query\n let query = spec.query.replace('$__rate_interval', `15s`);\n query = replaceTemplateVariables(query, context.variableState);\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n\n // Make the request to Prom\n const response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data?.result ?? [];\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n // TODO: Maybe do a proper Iterable implementation that defers some of this\n // processing until its needed\n series: result.map((value) => {\n const { metric, values } = value;\n\n // Name the series after the metric labels or if no metric, just use the\n // overall query\n let name = Object.entries(metric)\n .map(([labelName, labelValue]) => `${labelName}=\"${labelValue}\"`)\n .join(', ');\n if (name === '') name = query;\n\n return {\n name,\n values: values.map(parseValueTuple),\n };\n }),\n };\n return chartData;\n};\n\n/**\n * The core Prometheus TimeSeriesQuery plugin for Perses.\n */\nexport const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec> = {\n getTimeSeriesData,\n OptionsEditorComponent: PrometheusTimeSeriesQueryEditor,\n createInitialOptions: () => ({\n query: '',\n }),\n};\n"],"names":["fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","replaceTemplateVariables","DEFAULT_PROM","PrometheusTimeSeriesQueryEditor","getTimeSeriesData","spec","context","response","minStep","min_step","timeRange","step","undefined","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","Math","floor","alignedStart","query","replace","variableState","client","datasourceStore","getDatasourceClient","datasource","rangeQuery","result","data","chartData","stepMs","series","map","value","metric","values","name","Object","entries","labelName","labelValue","join","PrometheusTimeSeriesQuery","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,YAAY,QAAQ,UAAU,CAAC;AACxC,SACEC,eAAe,EAIfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,wBAAwB,EACxBC,YAAY,QACP,UAAU,CAAC;AAClB,SAASC,+BAA+B,QAAQ,mCAAmC,CAAC;AASpF,MAAMC,iBAAiB,GAA8E,OACnGC,IAAI,EACJC,OAAO,GACJ;QA8BYC,GAAa;IA7B5B,MAAMC,OAAO,GAAGV,wBAAwB,CAACO,IAAI,CAACI,QAAQ,CAAC,AAAC;IACxD,MAAMC,SAAS,GAAGX,sBAAsB,CAACO,OAAO,CAACI,SAAS,CAAC,AAAC;IAC5D,MAAMC,IAAI,GAAGX,YAAY,CAACU,SAAS,EAAEF,OAAO,EAAEI,SAAS,EAAEN,OAAO,CAACO,eAAe,CAAC,AAAC;IAElF,2DAA2D;IAC3D,IAAI,EAAEC,KAAK,CAAA,EAAEC,GAAG,CAAA,EAAE,GAAGL,SAAS,AAAC;IAC/B,MAAMM,YAAY,GAAG,IAAIC,IAAI,EAAE,CAACC,iBAAiB,EAAE,GAAG,EAAE,AAAC;IAEzD,MAAMC,UAAU,GAAGC,IAAI,CAACC,KAAK,CAAC,AAACN,CAAAA,GAAG,GAAGC,YAAY,CAAA,GAAIL,IAAI,CAAC,GAAGA,IAAI,GAAGK,YAAY,AAAC;IACjF,MAAMM,YAAY,GAAGF,IAAI,CAACC,KAAK,CAAC,AAACP,CAAAA,KAAK,GAAGE,YAAY,CAAA,GAAIL,IAAI,CAAC,GAAGA,IAAI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C,MAAM,CAAA,EAAE,GAAGF,KAAK,AAAC;YAEjC,wEAAwE;YACxE,gBAAgB;YAChB,IAAIG,IAAI,GAAGC,MAAM,CAACC,OAAO,CAACJ,MAAM,CAAC,CAC9BF,GAAG,CAAC,CAAC,CAACO,SAAS,EAAEC,UAAU,CAAC,GAAK,CAAC,EAAED,SAAS,CAAC,EAAE,EAAEC,UAAU,CAAC,CAAC,CAAC,CAAC,CAChEC,IAAI,CAAC,IAAI,CAAC,AAAC;YACd,IAAIL,IAAI,KAAK,EAAE,EAAEA,IAAI,GAAGjB,KAAK,CAAC;YAE9B,OAAO;gBACLiB,IAAI;gBACJD,MAAM,EAAEA,MAAM,CAACH,GAAG,CAACvC,eAAe,CAAC;aACpC,CAAC;QACJ,CAAC,CAAC;KACH,AAAC;IACF,OAAOoC,SAAS,CAAC;AACnB,CAAC,AAAC;AAEF;;CAEC,GACD,OAAO,MAAMa,yBAAyB,GAAyD;IAC7F1C,iBAAiB;IACjB2C,sBAAsB,EAAE5C,+BAA+B;IACvD6C,oBAAoB,EAAE,IAAO,CAAA;YAC3BzB,KAAK,EAAE,EAAE;SACV,CAAA,AAAC;CACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../src/plugins/variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../src/plugins/variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAG3E,aAAK,gBAAgB,GAAG,MAAM,GAAG,cAAc,CAAC;AAEhD,aAAK,yBAAyB,GAAG;IAC/B,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,yBAAyB,CAexE,CAAC"}
|
package/dist/plugins/variable.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
+
import { JSONSpecEditor } from './JSONSpecEditor';
|
|
13
14
|
export const StaticListVariable = {
|
|
14
15
|
getVariableOptions: async (spec)=>{
|
|
15
16
|
var ref;
|
|
@@ -26,7 +27,11 @@ export const StaticListVariable = {
|
|
|
26
27
|
data: values
|
|
27
28
|
};
|
|
28
29
|
},
|
|
29
|
-
dependsOn: ()=>[]
|
|
30
|
+
dependsOn: ()=>[],
|
|
31
|
+
OptionsEditorComponent: JSONSpecEditor,
|
|
32
|
+
createInitialOptions: ()=>({
|
|
33
|
+
values: []
|
|
34
|
+
})
|
|
30
35
|
};
|
|
31
36
|
|
|
32
37
|
//# sourceMappingURL=variable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/variable.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { VariablePlugin, VariableOption } from '@perses-dev/plugin-system';\n\ntype StaticListOption = string | VariableOption;\n\ntype StaticListVariableOptions = {\n values: StaticListOption[];\n};\n\nexport const StaticListVariable: VariablePlugin<StaticListVariableOptions> = {\n getVariableOptions: async (spec) => {\n const values = spec.values?.map((v) => {\n if (typeof v === 'string') {\n return { label: v, value: v };\n }\n return v;\n });\n return {\n data: values,\n };\n },\n dependsOn: () => [],\n};\n"],"names":["StaticListVariable","getVariableOptions","spec","values","map","v","label","value","data","dependsOn"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/variable.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { VariablePlugin, VariableOption } from '@perses-dev/plugin-system';\nimport { JSONSpecEditor } from './JSONSpecEditor';\n\ntype StaticListOption = string | VariableOption;\n\ntype StaticListVariableOptions = {\n values: StaticListOption[];\n};\n\nexport const StaticListVariable: VariablePlugin<StaticListVariableOptions> = {\n getVariableOptions: async (spec) => {\n const values = spec.values?.map((v) => {\n if (typeof v === 'string') {\n return { label: v, value: v };\n }\n return v;\n });\n return {\n data: values,\n };\n },\n dependsOn: () => [],\n OptionsEditorComponent: JSONSpecEditor,\n createInitialOptions: () => ({ values: [] }),\n};\n"],"names":["JSONSpecEditor","StaticListVariable","getVariableOptions","spec","values","map","v","label","value","data","dependsOn","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,cAAc,QAAQ,kBAAkB,CAAC;AAQlD,OAAO,MAAMC,kBAAkB,GAA8C;IAC3EC,kBAAkB,EAAE,OAAOC,IAAI,GAAK;YACnBA,GAAW;QAA1B,MAAMC,MAAM,GAAGD,CAAAA,GAAW,GAAXA,IAAI,CAACC,MAAM,cAAXD,GAAW,WAAK,GAAhBA,KAAAA,CAAgB,GAAhBA,GAAW,CAAEE,GAAG,CAAC,CAACC,CAAC,GAAK;YACrC,IAAI,OAAOA,CAAC,KAAK,QAAQ,EAAE;gBACzB,OAAO;oBAAEC,KAAK,EAAED,CAAC;oBAAEE,KAAK,EAAEF,CAAC;iBAAE,CAAC;YAChC,CAAC;YACD,OAAOA,CAAC,CAAC;QACX,CAAC,CAAC,AAAC;QACH,OAAO;YACLG,IAAI,EAAEL,MAAM;SACb,CAAC;IACJ,CAAC;IACDM,SAAS,EAAE,IAAM,EAAE;IACnBC,sBAAsB,EAAEX,cAAc;IACtCY,oBAAoB,EAAE,IAAO,CAAA;YAAER,MAAM,EAAE,EAAE;SAAE,CAAA,AAAC;CAC7C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/prometheus-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Prometheus plugin for Perses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -29,10 +29,11 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@lezer/highlight": "^1.0.0",
|
|
31
31
|
"@lezer/lr": "^1.2.0",
|
|
32
|
-
"@perses-dev/core": "^0.
|
|
33
|
-
"@perses-dev/plugin-system": "^0.
|
|
32
|
+
"@perses-dev/core": "^0.10.0",
|
|
33
|
+
"@perses-dev/plugin-system": "^0.10.0",
|
|
34
34
|
"@prometheus-io/lezer-promql": "^0.37.0",
|
|
35
|
-
"date-fns": "^2.28.0"
|
|
35
|
+
"date-fns": "^2.28.0",
|
|
36
|
+
"immer": "^9.0.15"
|
|
36
37
|
},
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"react": "^17.0.2 || ^18.0.0"
|