@perses-dev/prometheus-plugin 0.11.0 → 0.13.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/index.js +2 -2
- package/dist/cjs/plugins/MatcherEditor.js +1 -0
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +30 -0
- package/dist/cjs/plugins/{PrometheusTimeSeriesQueryEditor.js → prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js} +7 -14
- package/dist/cjs/plugins/{time-series-query.js → prometheus-time-series-query/get-time-series-data.js} +3 -11
- package/dist/cjs/plugins/prometheus-time-series-query/index.js +28 -0
- package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +51 -0
- package/dist/cjs/plugins/prometheus-time-series-query/time-series-query-model.js +16 -0
- package/dist/cjs/plugins/prometheus-variables.js +6 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/plugins/MatcherEditor.d.ts.map +1 -1
- package/dist/plugins/MatcherEditor.js +1 -0
- package/dist/plugins/MatcherEditor.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.d.ts +7 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +26 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts +7 -0
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -0
- package/dist/plugins/{PrometheusTimeSeriesQueryEditor.js → prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js} +9 -9
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts +4 -0
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -0
- package/dist/plugins/{time-series-query.js → prometheus-time-series-query/get-time-series-data.js} +3 -13
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/index.d.ts +2 -0
- package/dist/plugins/prometheus-time-series-query/index.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/index.js +15 -0
- package/dist/plugins/prometheus-time-series-query/index.js.map +1 -0
- package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +16 -0
- package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js +50 -0
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -0
- package/dist/plugins/{time-series-query.d.ts → prometheus-time-series-query/time-series-query-model.d.ts} +5 -7
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -0
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +15 -0
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -0
- package/dist/plugins/prometheus-variables.d.ts.map +1 -1
- package/dist/plugins/prometheus-variables.js +7 -3
- package/dist/plugins/prometheus-variables.js.map +1 -1
- package/package.json +3 -3
- package/dist/cjs/plugins/JSONSpecEditor.js +0 -54
- package/dist/plugins/JSONSpecEditor.d.ts +0 -4
- package/dist/plugins/JSONSpecEditor.d.ts.map +0 -1
- package/dist/plugins/JSONSpecEditor.js +0 -48
- package/dist/plugins/JSONSpecEditor.js.map +0 -1
- package/dist/plugins/PrometheusTimeSeriesQueryEditor.d.ts +0 -6
- package/dist/plugins/PrometheusTimeSeriesQueryEditor.d.ts.map +0 -1
- package/dist/plugins/PrometheusTimeSeriesQueryEditor.js.map +0 -1
- package/dist/plugins/time-series-query.d.ts.map +0 -1
- package/dist/plugins/time-series-query.js.map +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -21,13 +21,13 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
-
PrometheusTimeSeriesQuery: ()=>
|
|
24
|
+
PrometheusTimeSeriesQuery: ()=>_prometheusTimeSeriesQuery.PrometheusTimeSeriesQuery,
|
|
25
25
|
StaticListVariable: ()=>_variable.StaticListVariable,
|
|
26
26
|
PrometheusLabelNamesVariable: ()=>_prometheusVariables.PrometheusLabelNamesVariable,
|
|
27
27
|
PrometheusLabelValuesVariable: ()=>_prometheusVariables.PrometheusLabelValuesVariable,
|
|
28
28
|
PrometheusDatasource: ()=>_prometheusDatasource.PrometheusDatasource
|
|
29
29
|
});
|
|
30
|
-
const
|
|
30
|
+
const _prometheusTimeSeriesQuery = require("./plugins/prometheus-time-series-query");
|
|
31
31
|
const _variable = require("./plugins/variable");
|
|
32
32
|
const _prometheusVariables = require("./plugins/prometheus-variables");
|
|
33
33
|
const _prometheusDatasource = require("./plugins/prometheus-datasource");
|
|
@@ -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
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "PrometheusTimeSeriesQuery", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>PrometheusTimeSeriesQuery
|
|
20
|
+
});
|
|
21
|
+
const _getTimeSeriesData = require("./get-time-series-data");
|
|
22
|
+
const _prometheusTimeSeriesQueryEditor = require("./PrometheusTimeSeriesQueryEditor");
|
|
23
|
+
const PrometheusTimeSeriesQuery = {
|
|
24
|
+
getTimeSeriesData: _getTimeSeriesData.getTimeSeriesData,
|
|
25
|
+
OptionsEditorComponent: _prometheusTimeSeriesQueryEditor.PrometheusTimeSeriesQueryEditor,
|
|
26
|
+
createInitialOptions: ()=>({
|
|
27
|
+
query: '',
|
|
28
|
+
datasource: undefined
|
|
29
|
+
})
|
|
30
|
+
};
|
|
@@ -19,26 +19,18 @@ Object.defineProperty(exports, "PrometheusTimeSeriesQueryEditor", {
|
|
|
19
19
|
get: ()=>PrometheusTimeSeriesQueryEditor
|
|
20
20
|
});
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
const _immer =
|
|
22
|
+
const _immer = require("immer");
|
|
23
23
|
const _material = require("@mui/material");
|
|
24
24
|
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
25
|
-
const _model = require("
|
|
26
|
-
|
|
27
|
-
return obj && obj.__esModule ? obj : {
|
|
28
|
-
default: obj
|
|
29
|
-
};
|
|
30
|
-
}
|
|
25
|
+
const _model = require("../../model");
|
|
26
|
+
const _queryEditorModel = require("./query-editor-model");
|
|
31
27
|
function PrometheusTimeSeriesQueryEditor(props) {
|
|
32
28
|
const { onChange , value } = props;
|
|
33
|
-
const {
|
|
34
|
-
const handleQueryChange = (
|
|
35
|
-
onChange((0, _immer.default)(value, (draft)=>{
|
|
36
|
-
draft.query = e.target.value;
|
|
37
|
-
}));
|
|
38
|
-
};
|
|
29
|
+
const { datasource } = value;
|
|
30
|
+
const { query , handleQueryChange , handleQueryBlur } = (0, _queryEditorModel.useQueryState)(props);
|
|
39
31
|
const handleDatasourceChange = (next)=>{
|
|
40
32
|
if ((0, _model.isPrometheusDatasourceSelector)(next)) {
|
|
41
|
-
onChange((0, _immer.
|
|
33
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
42
34
|
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
43
35
|
const nextDatasource = (0, _model.isDefaultPromSelector)(next) ? undefined : next;
|
|
44
36
|
draft.datasource = nextDatasource;
|
|
@@ -54,6 +46,7 @@ function PrometheusTimeSeriesQueryEditor(props) {
|
|
|
54
46
|
label: "Query",
|
|
55
47
|
value: query,
|
|
56
48
|
onChange: handleQueryChange,
|
|
49
|
+
onBlur: handleQueryBlur,
|
|
57
50
|
margin: "dense"
|
|
58
51
|
}),
|
|
59
52
|
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
|
|
@@ -14,13 +14,12 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
Object.defineProperty(exports, "
|
|
17
|
+
Object.defineProperty(exports, "getTimeSeriesData", {
|
|
18
18
|
enumerable: true,
|
|
19
|
-
get: ()=>
|
|
19
|
+
get: ()=>getTimeSeriesData
|
|
20
20
|
});
|
|
21
21
|
const _dateFns = require("date-fns");
|
|
22
|
-
const _model = require("
|
|
23
|
-
const _prometheusTimeSeriesQueryEditor = require("./PrometheusTimeSeriesQueryEditor");
|
|
22
|
+
const _model = require("../../model");
|
|
24
23
|
const getTimeSeriesData = async (spec, context)=>{
|
|
25
24
|
var ref;
|
|
26
25
|
const minStep = (0, _model.getDurationStringSeconds)(spec.min_step);
|
|
@@ -73,10 +72,3 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
73
72
|
};
|
|
74
73
|
return chartData;
|
|
75
74
|
};
|
|
76
|
-
const PrometheusTimeSeriesQuery = {
|
|
77
|
-
getTimeSeriesData,
|
|
78
|
-
OptionsEditorComponent: _prometheusTimeSeriesQueryEditor.PrometheusTimeSeriesQueryEditor,
|
|
79
|
-
createInitialOptions: ()=>({
|
|
80
|
-
query: ''
|
|
81
|
-
})
|
|
82
|
-
};
|
|
@@ -0,0 +1,28 @@
|
|
|
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("./PrometheusTimeSeriesQuery"), exports);
|
|
18
|
+
function _exportStar(from, to) {
|
|
19
|
+
Object.keys(from).forEach(function(k) {
|
|
20
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return from[k];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return from;
|
|
28
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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, "useQueryState", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>useQueryState
|
|
20
|
+
});
|
|
21
|
+
const _react = require("react");
|
|
22
|
+
const _immer = require("immer");
|
|
23
|
+
function useQueryState(props) {
|
|
24
|
+
const { onChange , value } = props;
|
|
25
|
+
// Local copy of the query's value
|
|
26
|
+
const [query, setQuery] = (0, _react.useState)(value.query);
|
|
27
|
+
// This is basically "getDerivedStateFromProps" to make sure if spec's value changes external to this component,
|
|
28
|
+
// we render with the latest value
|
|
29
|
+
const [lastSyncedQuery, setLastSyncedQuery] = (0, _react.useState)(value.query);
|
|
30
|
+
if (value.query !== lastSyncedQuery) {
|
|
31
|
+
setQuery(value.query);
|
|
32
|
+
setLastSyncedQuery(value.query);
|
|
33
|
+
}
|
|
34
|
+
// Update our local state's copy as the user types
|
|
35
|
+
const handleQueryChange = (e)=>{
|
|
36
|
+
setQuery(e.target.value);
|
|
37
|
+
};
|
|
38
|
+
// Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the
|
|
39
|
+
// PanelPreview
|
|
40
|
+
const handleQueryBlur = ()=>{
|
|
41
|
+
setLastSyncedQuery(query);
|
|
42
|
+
onChange((0, _immer.produce)(value, (draft)=>{
|
|
43
|
+
draft.query = query;
|
|
44
|
+
}));
|
|
45
|
+
};
|
|
46
|
+
return {
|
|
47
|
+
query,
|
|
48
|
+
handleQueryChange,
|
|
49
|
+
handleQueryBlur
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -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
|
+
});
|
|
@@ -85,8 +85,10 @@ const PrometheusLabelNamesVariable = {
|
|
|
85
85
|
var _datasource;
|
|
86
86
|
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
87
87
|
const match = spec.matchers ? spec.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
|
|
88
|
+
const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
|
|
88
89
|
const { data: options } = await client.labelNames({
|
|
89
|
-
'match[]': match
|
|
90
|
+
'match[]': match,
|
|
91
|
+
...timeRange
|
|
90
92
|
});
|
|
91
93
|
return {
|
|
92
94
|
data: stringArrayToVariableOptions(options)
|
|
@@ -102,9 +104,11 @@ const PrometheusLabelValuesVariable = {
|
|
|
102
104
|
var _datasource;
|
|
103
105
|
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
|
|
104
106
|
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
|
|
107
|
+
const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
|
|
105
108
|
const { data: options } = await client.labelValues({
|
|
106
109
|
labelName: pluginDef.label_name,
|
|
107
|
-
'match[]': match
|
|
110
|
+
'match[]': match,
|
|
111
|
+
...timeRange
|
|
108
112
|
});
|
|
109
113
|
return {
|
|
110
114
|
data: stringArrayToVariableOptions(options)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrometheusTimeSeriesQuery } from './plugins/time-series-query';
|
|
1
|
+
import { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';
|
|
2
2
|
import { StaticListVariable } from './plugins/variable';
|
|
3
3
|
import { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';
|
|
4
4
|
import { PrometheusDatasource } from './plugins/prometheus-datasource';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,yBAAyB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,yBAAyB,EAAE,MAAM,wCAAwC,CAAC;AAEnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,4BAA4B,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC7G,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EACL,yBAAyB,EACzB,kBAAkB,EAClB,4BAA4B,EAC5B,6BAA6B,EAC7B,oBAAoB,GACrB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -10,7 +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 { PrometheusTimeSeriesQuery } from './plugins/time-series-query';
|
|
13
|
+
import { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';
|
|
14
14
|
// @TODO: Move this to a more generic location;
|
|
15
15
|
import { StaticListVariable } from './plugins/variable';
|
|
16
16
|
import { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/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\nimport { PrometheusTimeSeriesQuery } from './plugins/time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';\nimport { PrometheusDatasource } from './plugins/prometheus-datasource';\n\n// Export plugins under the same name as the kinds they handle from the plugin.json\nexport {\n PrometheusTimeSeriesQuery,\n StaticListVariable,\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusDatasource,\n};\n"],"names":["PrometheusTimeSeriesQuery","StaticListVariable","PrometheusLabelNamesVariable","PrometheusLabelValuesVariable","PrometheusDatasource"],"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,yBAAyB,QAAQ,
|
|
1
|
+
{"version":3,"sources":["../src/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\nimport { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport { PrometheusLabelNamesVariable, PrometheusLabelValuesVariable } from './plugins/prometheus-variables';\nimport { PrometheusDatasource } from './plugins/prometheus-datasource';\n\n// Export plugins under the same name as the kinds they handle from the plugin.json\nexport {\n PrometheusTimeSeriesQuery,\n StaticListVariable,\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusDatasource,\n};\n"],"names":["PrometheusTimeSeriesQuery","StaticListVariable","PrometheusLabelNamesVariable","PrometheusLabelValuesVariable","PrometheusDatasource"],"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,yBAAyB,QAAQ,wCAAwC,CAAC;AACnF,+CAA+C;AAC/C,SAASC,kBAAkB,QAAQ,oBAAoB,CAAC;AACxD,SAASC,4BAA4B,EAAEC,6BAA6B,QAAQ,gCAAgC,CAAC;AAC7G,SAASC,oBAAoB,QAAQ,iCAAiC,CAAC;AAEvE,mFAAmF;AACnF,SACEJ,yBAAyB,EACzBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,oBAAoB,GACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MatcherEditor.d.ts","sourceRoot":"","sources":["../../src/plugins/MatcherEditor.tsx"],"names":[],"mappings":";AAiBA,wBAAgB,aAAa,CAAC,KAAK,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"MatcherEditor.d.ts","sourceRoot":"","sources":["../../src/plugins/MatcherEditor.tsx"],"names":[],"mappings":";AAiBA,wBAAgB,aAAa,CAAC,KAAK,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,IAAI,CAAA;CAAE,eA2C1G"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/MatcherEditor.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 { useState } from 'react';\nimport { Stack, TextField, Button, Box, IconButton } from '@mui/material';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\n\nexport function MatcherEditor(props: { initialMatchers?: string[]; onChange: (matchers: string[]) => void }) {\n const [matchers, setMatchers] = useState<string[]>(props.initialMatchers ?? []);\n return (\n <Stack spacing={1}>\n {matchers.map((matcher, index) => (\n <Box key={index} display=\"flex\">\n <TextField\n onBlur={() => {\n props.onChange(matchers);\n }}\n label=\"Series Selector\"\n value={matcher}\n onChange={(e) => {\n const newMatchers = [...matchers];\n newMatchers[index] = e.target.value;\n setMatchers(newMatchers);\n }}\n />\n <IconButton\n onClick={() => {\n const newMatchers = [...matchers];\n newMatchers.splice(index, 1);\n setMatchers(newMatchers);\n }}\n >\n <TrashIcon />\n </IconButton>\n </Box>\n ))}\n <Box>\n <Button\n fullWidth={false}\n variant=\"outlined\"\n onClick={() => {\n setMatchers([...matchers, '']);\n }}\n >\n Add Series Selector\n </Button>\n </Box>\n </Stack>\n );\n}\n"],"names":["useState","Stack","TextField","Button","Box","IconButton","TrashIcon","MatcherEditor","props","matchers","setMatchers","initialMatchers","spacing","map","matcher","index","display","onBlur","onChange","label","value","e","newMatchers","target","onClick","splice","
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/MatcherEditor.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 { useState } from 'react';\nimport { Stack, TextField, Button, Box, IconButton } from '@mui/material';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\n\nexport function MatcherEditor(props: { initialMatchers?: string[]; onChange: (matchers: string[]) => void }) {\n const [matchers, setMatchers] = useState<string[]>(props.initialMatchers ?? []);\n return (\n <Stack spacing={1}>\n {matchers.map((matcher, index) => (\n <Box key={index} display=\"flex\">\n <TextField\n fullWidth\n onBlur={() => {\n props.onChange(matchers);\n }}\n label=\"Series Selector\"\n value={matcher}\n onChange={(e) => {\n const newMatchers = [...matchers];\n newMatchers[index] = e.target.value;\n setMatchers(newMatchers);\n }}\n />\n <IconButton\n onClick={() => {\n const newMatchers = [...matchers];\n newMatchers.splice(index, 1);\n setMatchers(newMatchers);\n }}\n >\n <TrashIcon />\n </IconButton>\n </Box>\n ))}\n <Box>\n <Button\n fullWidth={false}\n variant=\"outlined\"\n onClick={() => {\n setMatchers([...matchers, '']);\n }}\n >\n Add Series Selector\n </Button>\n </Box>\n </Stack>\n );\n}\n"],"names":["useState","Stack","TextField","Button","Box","IconButton","TrashIcon","MatcherEditor","props","matchers","setMatchers","initialMatchers","spacing","map","matcher","index","display","fullWidth","onBlur","onChange","label","value","e","newMatchers","target","onClick","splice","variant"],"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,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,KAAK,EAAEC,SAAS,EAAEC,MAAM,EAAEC,GAAG,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAC1E,OAAOC,SAAS,MAAM,0BAA0B,CAAC;AAEjD,OAAO,SAASC,aAAa,CAACC,KAA6E,EAAE;QACxDA,gBAAqB;IAAxE,MAAM,CAACC,QAAQ,EAAEC,WAAW,CAAC,GAAGV,QAAQ,CAAWQ,CAAAA,gBAAqB,GAArBA,KAAK,CAACG,eAAe,cAArBH,gBAAqB,cAArBA,gBAAqB,GAAI,EAAE,CAAC,AAAC;IAChF,qBACE,MAACP,KAAK;QAACW,OAAO,EAAE,CAAC;;YACdH,QAAQ,CAACI,GAAG,CAAC,CAACC,OAAO,EAAEC,KAAK,iBAC3B,MAACX,GAAG;oBAAaY,OAAO,EAAC,MAAM;;sCAC7B,KAACd,SAAS;4BACRe,SAAS;4BACTC,MAAM,EAAE,IAAM;gCACZV,KAAK,CAACW,QAAQ,CAACV,QAAQ,CAAC,CAAC;4BAC3B,CAAC;4BACDW,KAAK,EAAC,iBAAiB;4BACvBC,KAAK,EAAEP,OAAO;4BACdK,QAAQ,EAAE,CAACG,CAAC,GAAK;gCACf,MAAMC,WAAW,GAAG;uCAAId,QAAQ;iCAAC,AAAC;gCAClCc,WAAW,CAACR,KAAK,CAAC,GAAGO,CAAC,CAACE,MAAM,CAACH,KAAK,CAAC;gCACpCX,WAAW,CAACa,WAAW,CAAC,CAAC;4BAC3B,CAAC;0BACD;sCACF,KAAClB,UAAU;4BACToB,OAAO,EAAE,IAAM;gCACb,MAAMF,WAAW,GAAG;uCAAId,QAAQ;iCAAC,AAAC;gCAClCc,WAAW,CAACG,MAAM,CAACX,KAAK,EAAE,CAAC,CAAC,CAAC;gCAC7BL,WAAW,CAACa,WAAW,CAAC,CAAC;4BAC3B,CAAC;sCAED,cAAA,KAACjB,SAAS,KAAG;0BACF;;mBAtBLS,KAAK,CAuBT,AACP,CAAC;0BACF,KAACX,GAAG;0BACF,cAAA,KAACD,MAAM;oBACLc,SAAS,EAAE,KAAK;oBAChBU,OAAO,EAAC,UAAU;oBAClBF,OAAO,EAAE,IAAM;wBACbf,WAAW,CAAC;+BAAID,QAAQ;4BAAE,EAAE;yBAAC,CAAC,CAAC;oBACjC,CAAC;8BACF,qBAED;kBAAS;cACL;;MACA,CACR;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';
|
|
2
|
+
import { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';
|
|
3
|
+
/**
|
|
4
|
+
* The core Prometheus TimeSeriesQuery plugin for Perses.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>;
|
|
7
|
+
//# sourceMappingURL=PrometheusTimeSeriesQuery.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrometheusTimeSeriesQuery.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,qBAAqB,CAAC,6BAA6B,CAO1F,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 { getTimeSeriesData } from './get-time-series-data';
|
|
14
|
+
import { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';
|
|
15
|
+
/**
|
|
16
|
+
* The core Prometheus TimeSeriesQuery plugin for Perses.
|
|
17
|
+
*/ export const PrometheusTimeSeriesQuery = {
|
|
18
|
+
getTimeSeriesData,
|
|
19
|
+
OptionsEditorComponent: PrometheusTimeSeriesQueryEditor,
|
|
20
|
+
createInitialOptions: ()=>({
|
|
21
|
+
query: '',
|
|
22
|
+
datasource: undefined
|
|
23
|
+
})
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=PrometheusTimeSeriesQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.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 { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { getTimeSeriesData } from './get-time-series-data';\nimport { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\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 datasource: undefined,\n }),\n};\n"],"names":["getTimeSeriesData","PrometheusTimeSeriesQueryEditor","PrometheusTimeSeriesQuery","OptionsEditorComponent","createInitialOptions","query","datasource","undefined"],"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,iBAAiB,QAAQ,wBAAwB,CAAC;AAC3D,SAASC,+BAA+B,QAAQ,mCAAmC,CAAC;AAGpF;;CAEC,GACD,OAAO,MAAMC,yBAAyB,GAAyD;IAC7FF,iBAAiB;IACjBG,sBAAsB,EAAEF,+BAA+B;IACvDG,oBAAoB,EAAE,IAAO,CAAA;YAC3BC,KAAK,EAAE,EAAE;YACTC,UAAU,EAAEC,SAAS;SACtB,CAAA,AAAC;CACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { PrometheusTimeSeriesQueryEditorProps } from './query-editor-model';
|
|
3
|
+
/**
|
|
4
|
+
* The options editor component for editing a PrometheusTimeSeriesQuery's spec.
|
|
5
|
+
*/
|
|
6
|
+
export declare function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): JSX.Element;
|
|
7
|
+
//# sourceMappingURL=PrometheusTimeSeriesQueryEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,oCAAoC,EAAiB,MAAM,sBAAsB,CAAC;AAE3F;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eA6C1F"}
|
|
@@ -11,18 +11,17 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import produce from 'immer';
|
|
14
|
+
import { produce } from 'immer';
|
|
15
15
|
import { Box, TextField, FormControl, InputLabel } from '@mui/material';
|
|
16
16
|
import { DatasourceSelect } from '@perses-dev/plugin-system';
|
|
17
|
-
import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '
|
|
18
|
-
|
|
17
|
+
import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../../model';
|
|
18
|
+
import { useQueryState } from './query-editor-model';
|
|
19
|
+
/**
|
|
20
|
+
* The options editor component for editing a PrometheusTimeSeriesQuery's spec.
|
|
21
|
+
*/ export function PrometheusTimeSeriesQueryEditor(props) {
|
|
19
22
|
const { onChange , value } = props;
|
|
20
|
-
const {
|
|
21
|
-
const handleQueryChange = (
|
|
22
|
-
onChange(produce(value, (draft)=>{
|
|
23
|
-
draft.query = e.target.value;
|
|
24
|
-
}));
|
|
25
|
-
};
|
|
23
|
+
const { datasource } = value;
|
|
24
|
+
const { query , handleQueryChange , handleQueryBlur } = useQueryState(props);
|
|
26
25
|
const handleDatasourceChange = (next)=>{
|
|
27
26
|
if (isPrometheusDatasourceSelector(next)) {
|
|
28
27
|
onChange(produce(value, (draft)=>{
|
|
@@ -41,6 +40,7 @@ export function PrometheusTimeSeriesQueryEditor(props) {
|
|
|
41
40
|
label: "Query",
|
|
42
41
|
value: query,
|
|
43
42
|
onChange: handleQueryChange,
|
|
43
|
+
onBlur: handleQueryBlur,
|
|
44
44
|
margin: "dense"
|
|
45
45
|
}),
|
|
46
46
|
/*#__PURE__*/ _jsxs(FormControl, {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/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 { produce } from 'immer';\nimport { Box, TextField, FormControl, InputLabel } from '@mui/material';\nimport { DatasourceSelect, DatasourceSelectProps } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector } from '../../model';\nimport { PrometheusTimeSeriesQueryEditorProps, useQueryState } from './query-editor-model';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n const { datasource } = value;\n\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\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\n fullWidth\n label=\"Query\"\n value={query}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n margin=\"dense\"\n />\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","useQueryState","PrometheusTimeSeriesQueryEditor","props","onChange","value","datasource","query","handleQueryChange","handleQueryBlur","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","fullWidth","label","onBlur","margin","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;AAAA,SAASA,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,GAAG,EAAEC,SAAS,EAAEC,WAAW,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACxE,SAASC,gBAAgB,QAA+B,2BAA2B,CAAC;AACpF,SAASC,YAAY,EAAEC,qBAAqB,EAAEC,8BAA8B,QAAQ,aAAa,CAAC;AAClG,SAA+CC,aAAa,QAAQ,sBAAsB,CAAC;AAE3F;;CAEC,GACD,OAAO,SAASC,+BAA+B,CAACC,KAA2C,EAAE;IAC3F,MAAM,EAAEC,QAAQ,CAAA,E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,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';
|
|
2
|
+
import { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';
|
|
3
|
+
export declare const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'];
|
|
4
|
+
//# sourceMappingURL=get-time-series-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAkB,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAWlF,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CA4DvG,CAAC"}
|
package/dist/plugins/{time-series-query.js → prometheus-time-series-query/get-time-series-data.js}
RENAMED
|
@@ -11,9 +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, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, replaceTemplateVariables, DEFAULT_PROM } from '
|
|
15
|
-
|
|
16
|
-
const getTimeSeriesData = async (spec, context)=>{
|
|
14
|
+
import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, replaceTemplateVariables, DEFAULT_PROM } from '../../model';
|
|
15
|
+
export const getTimeSeriesData = async (spec, context)=>{
|
|
17
16
|
var ref;
|
|
18
17
|
const minStep = getDurationStringSeconds(spec.min_step);
|
|
19
18
|
const timeRange = getPrometheusTimeRange(context.timeRange);
|
|
@@ -65,14 +64,5 @@ const getTimeSeriesData = async (spec, context)=>{
|
|
|
65
64
|
};
|
|
66
65
|
return chartData;
|
|
67
66
|
};
|
|
68
|
-
/**
|
|
69
|
-
* The core Prometheus TimeSeriesQuery plugin for Perses.
|
|
70
|
-
*/ export const PrometheusTimeSeriesQuery = {
|
|
71
|
-
getTimeSeriesData,
|
|
72
|
-
OptionsEditorComponent: PrometheusTimeSeriesQueryEditor,
|
|
73
|
-
createInitialOptions: ()=>({
|
|
74
|
-
query: ''
|
|
75
|
-
})
|
|
76
|
-
};
|
|
77
67
|
|
|
78
|
-
//# sourceMappingURL=time-series-
|
|
68
|
+
//# sourceMappingURL=get-time-series-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.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 { TimeSeriesData, TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n replaceTemplateVariables,\n DEFAULT_PROM,\n} from '../../model';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const 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"],"names":["fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","replaceTemplateVariables","DEFAULT_PROM","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"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3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AAI,CAAC,AAAC;YACd,IAAIL,IAAI,KAAK,EAAE,EAAEA,IAAI,GAAGjB,KAAK,CAAC;YAE9B,OAAO;gBACLiB,IAAI;gBACJD,MAAM,EAAEA,MAAM,CAACH,GAAG,CAACtC,eAAe,CAAC;aACpC,CAAC;QACJ,CAAC,CAAC;KACH,AAAC;IACF,OAAOmC,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/index.ts"],"names":[],"mappings":"AAaA,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 './PrometheusTimeSeriesQuery';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/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 './PrometheusTimeSeriesQuery';\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,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
3
|
+
import { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';
|
|
4
|
+
export declare type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;
|
|
5
|
+
/**
|
|
6
|
+
* A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with
|
|
7
|
+
* `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those
|
|
8
|
+
* changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview
|
|
9
|
+
* every time the user types.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useQueryState(props: PrometheusTimeSeriesQueryEditorProps): {
|
|
12
|
+
query: string;
|
|
13
|
+
handleQueryChange: import("react").ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement>;
|
|
14
|
+
handleQueryBlur: import("react").FocusEventHandler<HTMLTextAreaElement | HTMLInputElement>;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=query-editor-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-editor-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"names":[],"mappings":";AAgBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,oBAAY,oCAAoC,GAAG,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AAErG;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,oCAAoC;;;;EA+BxE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 { useState } from 'react';
|
|
14
|
+
import { produce } from 'immer';
|
|
15
|
+
/**
|
|
16
|
+
* A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with
|
|
17
|
+
* `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those
|
|
18
|
+
* changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview
|
|
19
|
+
* every time the user types.
|
|
20
|
+
*/ export function useQueryState(props) {
|
|
21
|
+
const { onChange , value } = props;
|
|
22
|
+
// Local copy of the query's value
|
|
23
|
+
const [query, setQuery] = useState(value.query);
|
|
24
|
+
// This is basically "getDerivedStateFromProps" to make sure if spec's value changes external to this component,
|
|
25
|
+
// we render with the latest value
|
|
26
|
+
const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);
|
|
27
|
+
if (value.query !== lastSyncedQuery) {
|
|
28
|
+
setQuery(value.query);
|
|
29
|
+
setLastSyncedQuery(value.query);
|
|
30
|
+
}
|
|
31
|
+
// Update our local state's copy as the user types
|
|
32
|
+
const handleQueryChange = (e)=>{
|
|
33
|
+
setQuery(e.target.value);
|
|
34
|
+
};
|
|
35
|
+
// Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the
|
|
36
|
+
// PanelPreview
|
|
37
|
+
const handleQueryBlur = ()=>{
|
|
38
|
+
setLastSyncedQuery(query);
|
|
39
|
+
onChange(produce(value, (draft)=>{
|
|
40
|
+
draft.query = query;
|
|
41
|
+
}));
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
query,
|
|
45
|
+
handleQueryChange,
|
|
46
|
+
handleQueryBlur
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=query-editor-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.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 { useState } from 'react';\nimport { TextFieldProps } from '@mui/material';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\n/**\n * A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with\n * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those\n * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview\n * every time the user types.\n */\nexport function useQueryState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // Local copy of the query's value\n const [query, setQuery] = useState(value.query);\n\n // This is basically \"getDerivedStateFromProps\" to make sure if spec's value changes external to this component,\n // we render with the latest value\n const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);\n if (value.query !== lastSyncedQuery) {\n setQuery(value.query);\n setLastSyncedQuery(value.query);\n }\n\n // Update our local state's copy as the user types\n const handleQueryChange: TextFieldProps['onChange'] = (e) => {\n setQuery(e.target.value);\n };\n\n // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the\n // PanelPreview\n const handleQueryBlur: TextFieldProps['onBlur'] = () => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n"],"names":["useState","produce","useQueryState","props","onChange","value","query","setQuery","lastSyncedQuery","setLastSyncedQuery","handleQueryChange","e","target","handleQueryBlur","draft"],"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,QAAQ,QAAQ,OAAO,CAAC;AAEjC,SAASC,OAAO,QAAQ,OAAO,CAAC;AAMhC;;;;;CAKC,GACD,OAAO,SAASC,aAAa,CAACC,KAA2C,EAAE;IACzE,MAAM,EAAEC,QAAQ,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGF,KAAK,AAAC;IAElC,kCAAkC;IAClC,MAAM,CAACG,KAAK,EAAEC,QAAQ,CAAC,GAAGP,QAAQ,CAACK,KAAK,CAACC,KAAK,CAAC,AAAC;IAEhD,gHAAgH;IAChH,kCAAkC;IAClC,MAAM,CAACE,eAAe,EAAEC,kBAAkB,CAAC,GAAGT,QAAQ,CAACK,KAAK,CAACC,KAAK,CAAC,AAAC;IACpE,IAAID,KAAK,CAACC,KAAK,KAAKE,eAAe,EAAE;QACnCD,QAAQ,CAACF,KAAK,CAACC,KAAK,CAAC,CAAC;QACtBG,kBAAkB,CAACJ,KAAK,CAACC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,kDAAkD;IAClD,MAAMI,iBAAiB,GAA+B,CAACC,CAAC,GAAK;QAC3DJ,QAAQ,CAACI,CAAC,CAACC,MAAM,CAACP,KAAK,CAAC,CAAC;IAC3B,CAAC,AAAC;IAEF,iHAAiH;IACjH,eAAe;IACf,MAAMQ,eAAe,GAA6B,IAAM;QACtDJ,kBAAkB,CAACH,KAAK,CAAC,CAAC;QAC1BF,QAAQ,CACNH,OAAO,CAACI,KAAK,EAAE,CAACS,KAAK,GAAK;YACxBA,KAAK,CAACR,KAAK,GAAGA,KAAK,CAAC;QACtB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,OAAO;QAAEA,KAAK;QAAEI,iBAAiB;QAAEG,eAAe;KAAE,CAAC;AACvD,CAAC"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { DurationString } from '@perses-dev/core';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { PrometheusDatasourceSelector, TemplateString } from '../../model';
|
|
3
|
+
/**
|
|
4
|
+
* The spec/options for the PrometheusTimeSeriesQuery plugin.
|
|
5
|
+
*/
|
|
4
6
|
export interface PrometheusTimeSeriesQuerySpec {
|
|
5
7
|
query: TemplateString;
|
|
6
8
|
min_step?: DurationString;
|
|
7
9
|
resolution?: number;
|
|
8
10
|
datasource?: PrometheusDatasourceSelector;
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
* The core Prometheus TimeSeriesQuery plugin for Perses.
|
|
12
|
-
*/
|
|
13
|
-
export declare const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>;
|
|
14
|
-
//# sourceMappingURL=time-series-query.d.ts.map
|
|
12
|
+
//# sourceMappingURL=time-series-query-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"time-series-query-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3E;;GAEG;AACH,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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 { };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=time-series-query-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.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 { PrometheusDatasourceSelector, TemplateString } from '../../model';\n\n/**\n * The spec/options for the PrometheusTimeSeriesQuery plugin.\n */\nexport interface PrometheusTimeSeriesQuerySpec {\n query: TemplateString;\n min_step?: DurationString;\n resolution?: number;\n datasource?: PrometheusDatasourceSelector;\n}\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,WAWC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAsC,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAAE,cAAc,EAAsC,MAAM,2BAA2B,CAAC;AAS/F,OAAO,EAAE,mCAAmC,EAAE,oCAAoC,EAAE,MAAM,SAAS,CAAC;AAgDpG,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAc5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CAwB9F,CAAC"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { Stack, TextField } from '@mui/material';
|
|
15
|
-
import { replaceTemplateVariables, parseTemplateVariables, DEFAULT_PROM } from '../model';
|
|
15
|
+
import { replaceTemplateVariables, parseTemplateVariables, DEFAULT_PROM, getPrometheusTimeRange } from '../model';
|
|
16
16
|
import { MatcherEditor } from './MatcherEditor';
|
|
17
17
|
function PrometheusLabelValuesVariableEditor(props) {
|
|
18
18
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
@@ -71,8 +71,10 @@ export const PrometheusLabelNamesVariable = {
|
|
|
71
71
|
var _datasource;
|
|
72
72
|
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
|
|
73
73
|
const match = spec.matchers ? spec.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
|
|
74
|
+
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
74
75
|
const { data: options } = await client.labelNames({
|
|
75
|
-
'match[]': match
|
|
76
|
+
'match[]': match,
|
|
77
|
+
...timeRange
|
|
76
78
|
});
|
|
77
79
|
return {
|
|
78
80
|
data: stringArrayToVariableOptions(options)
|
|
@@ -88,9 +90,11 @@ export const PrometheusLabelValuesVariable = {
|
|
|
88
90
|
var _datasource;
|
|
89
91
|
const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
|
|
90
92
|
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
|
|
93
|
+
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
91
94
|
const { data: options } = await client.labelValues({
|
|
92
95
|
labelName: pluginDef.label_name,
|
|
93
|
-
'match[]': match
|
|
96
|
+
'match[]': match,
|
|
97
|
+
...timeRange
|
|
94
98
|
});
|
|
95
99
|
return {
|
|
96
100
|
data: stringArrayToVariableOptions(options)
|
|
@@ -1 +1 @@
|
|
|
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, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Stack, TextField } from '@mui/material';\nimport {
|
|
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, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Stack, TextField } from '@mui/material';\nimport {\n replaceTemplateVariables,\n parseTemplateVariables,\n PrometheusClient,\n DEFAULT_PROM,\n getPrometheusTimeRange,\n} from '../model';\nimport { PrometheusLabelNamesVariableOptions, PrometheusLabelValuesVariableOptions } from './types';\nimport { MatcherEditor } from './MatcherEditor';\n\nfunction PrometheusLabelValuesVariableEditor(props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>) {\n return (\n <Stack spacing={1}>\n <TextField\n sx={{ mb: 1 }}\n label=\"Label Name\"\n value={props.value.label_name}\n onChange={(e) => {\n props.onChange({ ...props.value, label_name: e.target.value });\n }}\n />\n <MatcherEditor\n initialMatchers={props.value.matchers}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\n}\n\nfunction PrometheusLabelNamesVariableEditor(props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>) {\n return (\n <Stack spacing={1}>\n <MatcherEditor\n initialMatchers={props.value.matchers}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\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 timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelNames({ 'match[]': match, ...timeRange });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: () => [],\n OptionsEditorComponent: PrometheusLabelNamesVariableEditor,\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\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues({\n labelName: pluginDef.label_name,\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return spec.matchers?.map((m) => parseTemplateVariables(m)).flat() || [];\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ label_name: '' }),\n};\n"],"names":["Stack","TextField","replaceTemplateVariables","parseTemplateVariables","DEFAULT_PROM","getPrometheusTimeRange","MatcherEditor","PrometheusLabelValuesVariableEditor","props","spacing","sx","mb","label","value","label_name","onChange","e","target","initialMatchers","matchers","PrometheusLabelNamesVariableEditor","stringArrayToVariableOptions","values","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","client","datasourceStore","getDatasourceClient","datasource","match","m","variables","undefined","timeRange","data","options","labelNames","dependsOn","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","labelName","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;AACjC;AACA,SAASA,KAAK,EAAEC,SAAS,QAAQ,eAAe,CAAC;AACjD,SACEC,wBAAwB,EACxBC,sBAAsB,EAEtBC,YAAY,EACZC,sBAAsB,QACjB,UAAU,CAAC;AAElB,SAASC,aAAa,QAAQ,iBAAiB,CAAC;AAEhD,SAASC,mCAAmC,CAACC,KAA+D,EAAE;IAC5G,qBACE,MAACR,KAAK;QAACS,OAAO,EAAE,CAAC;;0BACf,KAACR,SAAS;gBACRS,EAAE,EAAE;oBAAEC,EAAE,EAAE,CAAC;iBAAE;gBACbC,KAAK,EAAC,YAAY;gBAClBC,KAAK,EAAEL,KAAK,CAACK,KAAK,CAACC,UAAU;gBAC7BC,QAAQ,EAAE,CAACC,CAAC,GAAK;oBACfR,KAAK,CAACO,QAAQ,CAAC;wBAAE,GAAGP,KAAK,CAACK,KAAK;wBAAEC,UAAU,EAAEE,CAAC,CAACC,MAAM,CAACJ,KAAK;qBAAE,CAAC,CAAC;gBACjE,CAAC;cACD;0BACF,KAACP,aAAa;gBACZY,eAAe,EAAEV,KAAK,CAACK,KAAK,CAACM,QAAQ;gBACrCJ,QAAQ,EAAE,CAACC,CAAC,GAAK;oBACfR,KAAK,CAACO,QAAQ,CAAC;wBAAE,GAAGP,KAAK,CAACK,KAAK;wBAAEM,QAAQ,EAA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AK;YACZA,GAAa;QAApB,OAAOA,CAAAA,CAAAA,GAAa,GAAbA,IAAI,CAACP,QAAQ,cAAbO,GAAa,WAAK,GAAlBA,KAAAA,CAAkB,GAAlBA,GAAa,CAAEH,GAAG,CAAC,CAACU,CAAC,GAAK9B,sBAAsB,CAAC8B,CAAC,CAAC,CAAC,CAACc,IAAI,EAAE,CAAA,IAAI,EAAE,CAAC;IAC3E,CAAC;IACDN,sBAAsB,EAAElC,mCAAmC;IAC3DmC,oBAAoB,EAAE,IAAO,CAAA;YAAE5B,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CACjD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/prometheus-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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,8 +29,8 @@
|
|
|
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.13.0",
|
|
33
|
+
"@perses-dev/plugin-system": "^0.13.0",
|
|
34
34
|
"@prometheus-io/lezer-promql": "^0.37.0",
|
|
35
35
|
"date-fns": "^2.28.0",
|
|
36
36
|
"immer": "^9.0.15"
|
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,cAAc,CAAIC,KAA4B,EAAE;IAC9D,MAAMC,GAAG,GAAGL,MAAM,CAAmB,IAAI,CAAC,AAAC;IAC3C,MAAM,CAACM,KAAK,EAAEC,QAAQ,CAAC,GAAGN,QAAQ,CAACO,IAAI,CAACC,SAAS,CAACL,KAAK,CAACE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,AAAC;IACzE,MAAM,CAACI,WAAW,EAAEC,cAAc,CAAC,GAAGV,QAAQ,CAAC,KAAK,CAAC,AAAC;IAEtDF,SAAS,CAAC,IAAM;QACdQ,QAAQ,CAACC,IAAI,CAACC,SAAS,CAACL,KAAK,CAACE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/CK,cAAc,CAAC,KAAK,CAAC,CAAC;IACxB,CAAC,EAAE;QAACP,KAAK,CAACE,KAAK;KAAC,CAAC,CAAC;IAElB,qBACE,KAACJ,SAAS;QACRU,KAAK,EAAC,MAAM;QACZC,KAAK,EAAEH,WAAW;QAClBI,UAAU,EAAEJ,WAAW,GAAG,cAAc,GAAG,EAAE;QAC7CK,SAAS;QACTC,QAAQ,EAAEX,GAAG;QACbC,KAAK,EAAEA,KAAK;QACZW,QAAQ,EAAE,CAACC,KAAK,GAAK;YACnBX,QAAQ,CAACW,KAAK,CAACC,MAAM,CAACb,KAAK,CAAC,CAAC;QAC/B,CAAC;QACDc,MAAM,EAAE,IAAM;YACZ,IAAI;gBACF,MAAMC,IAAI,GAAGb,IAAI,CAACc,KAAK,CAAChB,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,IAAI,CAAC,AAAC;gBACvCK,cAAc,CAAC,KAAK,CAAC,CAAC;gBACtBP,KAAK,CAACa,QAAQ,CAACI,IAAI,CAAC,CAAC;YACvB,EAAE,OAAOE,CAAC,EAAE;gBACVZ,cAAc,CAAC,IAAI,CAAC,CAAC;YACvB,CAAC;QACH,CAAC;MACD,CACF;AACJ,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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 fullWidth 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","fullWidth","label","margin","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,AAAC;IAClC,MAAM,EAAEG,KAAK,CAAA,EAAEC,UAAU,CAAA,EAAE,GAAGF,KAAK,AAAC;IAEpC,MAAMG,iBAAiB,GAAG,CAACC,CAAgC,GAAK;QAC9DL,QAAQ,CACNX,OAAO,CAACY,KAAK,EAAE,CAACK,KAAK,GAAK;YACxBA,KAAK,CAACJ,KAAK,GAAGG,CAAC,CAACE,MAAM,CAACN,KAAK,CAAC;QAC/B,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,MAAMO,sBAAsB,GAAsC,CAACC,IAAI,GAAK;QAC1E,IAAIZ,8BAA8B,CAACY,IAAI,CAAC,EAAE;YACxCT,QAAQ,CACNX,OAAO,CAACY,KAAK,EAAE,CAACK,KAAK,GAAK;gBACxB,sFAAsF;gBACtF,MAAMI,cAAc,GAAGd,qBAAqB,CAACa,IAAI,CAAC,GAAGE,SAAS,GAAGF,IAAI,AAAC;gBACtEH,KAAK,CAACH,UAAU,GAAGO,cAAc,CAAC;YACpC,CAAC,CAAC,CACH,CAAC;YACF,OAAO;QACT,CAAC;QAED,MAAM,IAAIE,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC,AAAC;IAEF,qBACE,MAACtB,GAAG;;0BACF,KAACC,SAAS;gBAACsB,SAAS;gBAACC,KAAK,EAAC,OAAO;gBAACb,KAAK,EAAEC,KAAK;gBAAEF,QAAQ,EAAEI,iBAAiB;gBAAEW,MAAM,EAAC,OAAO;cAAG;0BAC/F,MAACvB,WAAW;gBAACuB,MAAM,EAAC,OAAO;gBAACF,SAAS,EAAE,KAAK;;kCAG1C,KAACpB,UAAU;wBAACuB,EAAE,EAAC,uBAAuB;kCAAC,uBAAqB;sBAAa;kCACzE,KAACtB,gBAAgB;wBACfuB,oBAAoB,EAAC,sBAAsB;wBAC3ChB,KAAK,EAAEE,UAAU,aAAVA,UAAU,cAAVA,UAAU,GAAIR,YAAY;wBACjCK,QAAQ,EAAEQ,sBAAsB;wBAChCU,OAAO,EAAC,uBAAuB;wBAC/BJ,KAAK,EAAC,uBAAuB;sBAC7B;;cACU;;MACV,CACN;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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,G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