@perses-dev/prometheus-plugin 0.9.0 → 0.11.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/MatcherEditor.js +80 -0
- package/dist/cjs/plugins/PrometheusTimeSeriesQueryEditor.js +78 -0
- package/dist/cjs/plugins/prometheus-datasource.js +28 -0
- package/dist/cjs/plugins/prometheus-variables.js +67 -23
- package/dist/cjs/plugins/time-series-query.js +15 -20
- package/dist/cjs/plugins/types.js +16 -0
- package/dist/cjs/plugins/variable.js +40 -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/MatcherEditor.d.ts +6 -0
- package/dist/plugins/MatcherEditor.d.ts.map +1 -0
- package/dist/plugins/MatcherEditor.js +69 -0
- package/dist/plugins/MatcherEditor.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 +67 -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 +1 -10
- package/dist/plugins/prometheus-variables.d.ts.map +1 -1
- package/dist/plugins/prometheus-variables.js +65 -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/types.d.ts +12 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +15 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/plugins/variable.d.ts.map +1 -1
- package/dist/plugins/variable.js +40 -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,80 @@
|
|
|
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, "MatcherEditor", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>MatcherEditor
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _react = require("react");
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
const _trashCan = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/TrashCan"));
|
|
25
|
+
function _interopRequireDefault(obj) {
|
|
26
|
+
return obj && obj.__esModule ? obj : {
|
|
27
|
+
default: obj
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function MatcherEditor(props) {
|
|
31
|
+
var _initialMatchers;
|
|
32
|
+
const [matchers, setMatchers] = (0, _react.useState)((_initialMatchers = props.initialMatchers) !== null && _initialMatchers !== void 0 ? _initialMatchers : []);
|
|
33
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
34
|
+
spacing: 1,
|
|
35
|
+
children: [
|
|
36
|
+
matchers.map((matcher, index)=>/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
37
|
+
display: "flex",
|
|
38
|
+
children: [
|
|
39
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
40
|
+
onBlur: ()=>{
|
|
41
|
+
props.onChange(matchers);
|
|
42
|
+
},
|
|
43
|
+
label: "Series Selector",
|
|
44
|
+
value: matcher,
|
|
45
|
+
onChange: (e)=>{
|
|
46
|
+
const newMatchers = [
|
|
47
|
+
...matchers
|
|
48
|
+
];
|
|
49
|
+
newMatchers[index] = e.target.value;
|
|
50
|
+
setMatchers(newMatchers);
|
|
51
|
+
}
|
|
52
|
+
}),
|
|
53
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
54
|
+
onClick: ()=>{
|
|
55
|
+
const newMatchers = [
|
|
56
|
+
...matchers
|
|
57
|
+
];
|
|
58
|
+
newMatchers.splice(index, 1);
|
|
59
|
+
setMatchers(newMatchers);
|
|
60
|
+
},
|
|
61
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_trashCan.default, {})
|
|
62
|
+
})
|
|
63
|
+
]
|
|
64
|
+
}, index)),
|
|
65
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
66
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
|
|
67
|
+
fullWidth: false,
|
|
68
|
+
variant: "outlined",
|
|
69
|
+
onClick: ()=>{
|
|
70
|
+
setMatchers([
|
|
71
|
+
...matchers,
|
|
72
|
+
''
|
|
73
|
+
]);
|
|
74
|
+
},
|
|
75
|
+
children: "Add Series Selector"
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
fullWidth: true,
|
|
54
|
+
label: "Query",
|
|
55
|
+
value: query,
|
|
56
|
+
onChange: handleQueryChange,
|
|
57
|
+
margin: "dense"
|
|
58
|
+
}),
|
|
59
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
|
|
60
|
+
margin: "dense",
|
|
61
|
+
fullWidth: false,
|
|
62
|
+
children: [
|
|
63
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
|
|
64
|
+
id: "prom-datasource-label",
|
|
65
|
+
children: "Prometheus Datasource"
|
|
66
|
+
}),
|
|
67
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceSelect, {
|
|
68
|
+
datasourcePluginKind: "PrometheusDatasource",
|
|
69
|
+
value: datasource !== null && datasource !== void 0 ? datasource : _model.DEFAULT_PROM,
|
|
70
|
+
onChange: handleDatasourceChange,
|
|
71
|
+
labelId: "prom-datasource-label",
|
|
72
|
+
label: "Prometheus Datasource"
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
})
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -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,53 @@ _export(exports, {
|
|
|
24
24
|
PrometheusLabelNamesVariable: ()=>PrometheusLabelNamesVariable,
|
|
25
25
|
PrometheusLabelValuesVariable: ()=>PrometheusLabelValuesVariable
|
|
26
26
|
});
|
|
27
|
-
const
|
|
28
|
-
const
|
|
27
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
28
|
+
const _material = require("@mui/material");
|
|
29
|
+
const _model = require("../model");
|
|
30
|
+
const _matcherEditor = require("./MatcherEditor");
|
|
31
|
+
function PrometheusLabelValuesVariableEditor(props) {
|
|
32
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
33
|
+
spacing: 1,
|
|
34
|
+
children: [
|
|
35
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
36
|
+
sx: {
|
|
37
|
+
mb: 1
|
|
38
|
+
},
|
|
39
|
+
label: "Label Name",
|
|
40
|
+
value: props.value.label_name,
|
|
41
|
+
onChange: (e)=>{
|
|
42
|
+
props.onChange({
|
|
43
|
+
...props.value,
|
|
44
|
+
label_name: e.target.value
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}),
|
|
48
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_matcherEditor.MatcherEditor, {
|
|
49
|
+
initialMatchers: props.value.matchers,
|
|
50
|
+
onChange: (e)=>{
|
|
51
|
+
props.onChange({
|
|
52
|
+
...props.value,
|
|
53
|
+
matchers: e
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
]
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function PrometheusLabelNamesVariableEditor(props) {
|
|
61
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Stack, {
|
|
62
|
+
spacing: 1,
|
|
63
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_matcherEditor.MatcherEditor, {
|
|
64
|
+
initialMatchers: props.value.matchers,
|
|
65
|
+
onChange: (e)=>{
|
|
66
|
+
props.onChange({
|
|
67
|
+
...props.value,
|
|
68
|
+
matchers: e
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
}
|
|
29
74
|
/**
|
|
30
75
|
* Takes a list of strings and returns a list of VariableOptions
|
|
31
76
|
*/ const stringArrayToVariableOptions = (values)=>{
|
|
@@ -35,43 +80,42 @@ const _prometheusClient = require("../model/prometheus-client");
|
|
|
35
80
|
label: value
|
|
36
81
|
}));
|
|
37
82
|
};
|
|
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
83
|
const PrometheusLabelNamesVariable = {
|
|
51
84
|
getVariableOptions: async (spec, ctx)=>{
|
|
52
|
-
|
|
53
|
-
const
|
|
85
|
+
var _datasource;
|
|
86
|
+
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
87
|
+
const match = spec.matchers ? spec.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
|
|
88
|
+
const { data: options } = await client.labelNames({
|
|
89
|
+
'match[]': match
|
|
90
|
+
});
|
|
54
91
|
return {
|
|
55
92
|
data: stringArrayToVariableOptions(options)
|
|
56
93
|
};
|
|
57
94
|
},
|
|
58
|
-
dependsOn: ()=>[]
|
|
95
|
+
dependsOn: ()=>[],
|
|
96
|
+
OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
|
|
97
|
+
createInitialOptions: ()=>({})
|
|
59
98
|
};
|
|
60
99
|
const PrometheusLabelValuesVariable = {
|
|
61
100
|
getVariableOptions: async (spec, ctx)=>{
|
|
62
101
|
const pluginDef = spec;
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
const
|
|
102
|
+
var _datasource;
|
|
103
|
+
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
104
|
+
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
|
|
105
|
+
const { data: options } = await client.labelValues({
|
|
66
106
|
labelName: pluginDef.label_name,
|
|
67
107
|
'match[]': match
|
|
68
|
-
}
|
|
108
|
+
});
|
|
69
109
|
return {
|
|
70
110
|
data: stringArrayToVariableOptions(options)
|
|
71
111
|
};
|
|
72
112
|
},
|
|
73
113
|
dependsOn: (spec)=>{
|
|
74
114
|
var ref;
|
|
75
|
-
return ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0,
|
|
76
|
-
}
|
|
115
|
+
return ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _model.parseTemplateVariables)(m)).flat()) || [];
|
|
116
|
+
},
|
|
117
|
+
OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
|
|
118
|
+
createInitialOptions: ()=>({
|
|
119
|
+
label_name: ''
|
|
120
|
+
})
|
|
77
121
|
};
|
|
@@ -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
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
});
|
|
@@ -18,6 +18,41 @@ Object.defineProperty(exports, "StaticListVariable", {
|
|
|
18
18
|
enumerable: true,
|
|
19
19
|
get: ()=>StaticListVariable
|
|
20
20
|
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
function StaticListVariableOptionEditor(props) {
|
|
24
|
+
const value = props.value.values.map((v)=>{
|
|
25
|
+
if (typeof v === 'string') {
|
|
26
|
+
return v;
|
|
27
|
+
} else {
|
|
28
|
+
return v.value;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const onChange = (__, value)=>{
|
|
32
|
+
props.onChange({
|
|
33
|
+
values: value.map((v)=>{
|
|
34
|
+
return {
|
|
35
|
+
value: v,
|
|
36
|
+
label: v
|
|
37
|
+
};
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
42
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
|
|
43
|
+
multiple: true,
|
|
44
|
+
value: value,
|
|
45
|
+
onChange: onChange,
|
|
46
|
+
options: [],
|
|
47
|
+
freeSolo: true,
|
|
48
|
+
renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
49
|
+
...params,
|
|
50
|
+
label: "Values",
|
|
51
|
+
placeholder: "Values"
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
});
|
|
55
|
+
}
|
|
21
56
|
const StaticListVariable = {
|
|
22
57
|
getVariableOptions: async (spec)=>{
|
|
23
58
|
var ref;
|
|
@@ -34,5 +69,9 @@ const StaticListVariable = {
|
|
|
34
69
|
data: values
|
|
35
70
|
};
|
|
36
71
|
},
|
|
37
|
-
dependsOn: ()=>[]
|
|
72
|
+
dependsOn: ()=>[],
|
|
73
|
+
OptionsEditorComponent: StaticListVariableOptionEditor,
|
|
74
|
+
createInitialOptions: ()=>({
|
|
75
|
+
values: []
|
|
76
|
+
})
|
|
38
77
|
};
|
|
@@ -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"}
|