@perses-dev/prometheus-plugin 0.48.0 → 0.49.0-rc.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/components/PromQLEditor.js +209 -0
- package/dist/cjs/components/TreeNode.js +147 -0
- package/dist/cjs/components/index.js +1 -1
- package/dist/cjs/components/parse.js +42 -0
- package/dist/cjs/components/promql/ast.js +143 -0
- package/dist/cjs/components/promql/format.js +432 -0
- package/dist/cjs/components/promql/utils.js +109 -0
- package/dist/cjs/model/prometheus-client.js +10 -2
- package/dist/cjs/plugins/PrometheusDatasourceEditor.js +4 -0
- package/dist/cjs/plugins/prometheus-datasource.js +4 -0
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +6 -5
- package/dist/cjs/plugins/prometheus-variables.js +4 -2
- package/dist/components/PromQLEditor.d.ts +9 -0
- package/dist/components/PromQLEditor.d.ts.map +1 -0
- package/dist/components/PromQLEditor.js +196 -0
- package/dist/components/PromQLEditor.js.map +1 -0
- package/dist/components/TreeNode.d.ts +10 -0
- package/dist/components/TreeNode.d.ts.map +1 -0
- package/dist/components/TreeNode.js +139 -0
- package/dist/components/TreeNode.js.map +1 -0
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.js.map +1 -1
- package/dist/components/parse.d.ts +4 -0
- package/dist/components/parse.d.ts.map +1 -0
- package/dist/components/parse.js +34 -0
- package/dist/components/parse.js.map +1 -0
- package/dist/components/promql/ast.d.ts +161 -0
- package/dist/components/promql/ast.d.ts.map +1 -0
- package/dist/components/promql/ast.js +106 -0
- package/dist/components/promql/ast.js.map +1 -0
- package/dist/components/promql/format.d.ts +5 -0
- package/dist/components/promql/format.d.ts.map +1 -0
- package/dist/components/promql/format.js +411 -0
- package/dist/components/promql/format.js.map +1 -0
- package/dist/components/promql/utils.d.ts +5 -0
- package/dist/components/promql/utils.d.ts.map +1 -0
- package/dist/components/promql/utils.js +90 -0
- package/dist/components/promql/utils.js.map +1 -0
- package/dist/model/api-types.d.ts +5 -0
- package/dist/model/api-types.d.ts.map +1 -1
- package/dist/model/api-types.js.map +1 -1
- package/dist/model/prometheus-client.d.ts +6 -1
- package/dist/model/prometheus-client.d.ts.map +1 -1
- package/dist/model/prometheus-client.js +9 -2
- package/dist/model/prometheus-client.js.map +1 -1
- package/dist/plugins/PrometheusDatasourceEditor.d.ts.map +1 -1
- package/dist/plugins/PrometheusDatasourceEditor.js +4 -0
- package/dist/plugins/PrometheusDatasourceEditor.js.map +1 -1
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
- package/dist/plugins/prometheus-datasource.js +5 -1
- package/dist/plugins/prometheus-datasource.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +6 -5
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/dist/plugins/prometheus-variables.d.ts.map +1 -1
- package/dist/plugins/prometheus-variables.js +4 -2
- package/dist/plugins/prometheus-variables.js.map +1 -1
- package/package.json +4 -4
- package/dist/cjs/components/PromQL.js +0 -58
- package/dist/components/PromQL.d.ts +0 -7
- package/dist/components/PromQL.d.ts.map +0 -1
- package/dist/components/PromQL.js +0 -45
- package/dist/components/PromQL.js.map +0 -1
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
// Copyright 2024 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
|
+
// Forked from https://github.com/prometheus/prometheus/blob/65f610353919b1c7b42d3776c3a95b68046a6bba/web/ui/mantine-ui/src/promql/format.tsx
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", {
|
|
16
|
+
value: true
|
|
17
|
+
});
|
|
18
|
+
function _export(target, all) {
|
|
19
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: all[name]
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
_export(exports, {
|
|
25
|
+
formatNode: function() {
|
|
26
|
+
return formatNode;
|
|
27
|
+
},
|
|
28
|
+
labelNameList: function() {
|
|
29
|
+
return labelNameList;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const _jsxruntime = require("react/jsx-runtime");
|
|
33
|
+
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
34
|
+
const _material = require("@mui/material");
|
|
35
|
+
const _core = require("@perses-dev/core");
|
|
36
|
+
const _ast = require("./ast");
|
|
37
|
+
const _utils = require("./utils");
|
|
38
|
+
function _interop_require_default(obj) {
|
|
39
|
+
return obj && obj.__esModule ? obj : {
|
|
40
|
+
default: obj
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// Styled components that reproduce the theming of CodeMirror:
|
|
44
|
+
const PromQLCode = (0, _material.styled)('span')(()=>({
|
|
45
|
+
fontFamily: '"DejaVu Sans Mono", monospace'
|
|
46
|
+
}));
|
|
47
|
+
const PromQLKeyword = (0, _material.styled)('span')(({ theme })=>({
|
|
48
|
+
color: theme.palette.mode === 'dark' ? '#e5c07b' : '#708'
|
|
49
|
+
}));
|
|
50
|
+
const PromQLFunction = (0, _material.styled)('span')(({ theme })=>({
|
|
51
|
+
color: theme.palette.mode === 'dark' ? '#61afef' : '#2a2e42'
|
|
52
|
+
}));
|
|
53
|
+
const PromQLMetricName = (0, _material.styled)('span')(({ theme })=>({
|
|
54
|
+
color: theme.palette.mode === 'dark' ? '#e06c75' : '#2a2e42'
|
|
55
|
+
}));
|
|
56
|
+
const PromQLLabelName = (0, _material.styled)('span')(({ theme })=>({
|
|
57
|
+
color: theme.palette.mode === 'dark' ? '#61afef' : '#219'
|
|
58
|
+
}));
|
|
59
|
+
const PromQLString = (0, _material.styled)('span')(({ theme })=>({
|
|
60
|
+
color: theme.palette.mode === 'dark' ? '#98c379' : '#a31515'
|
|
61
|
+
}));
|
|
62
|
+
const PromQLEllipsis = (0, _material.styled)('span')(()=>({
|
|
63
|
+
color: '#aaaaaa'
|
|
64
|
+
}));
|
|
65
|
+
const PromQLDuration = (0, _material.styled)('span')(({ theme })=>({
|
|
66
|
+
color: theme.palette.mode === 'dark' ? '#e5c07b' : '#09885a'
|
|
67
|
+
}));
|
|
68
|
+
const PromQLNumber = (0, _material.styled)('span')(({ theme })=>({
|
|
69
|
+
color: theme.palette.mode === 'dark' ? '#e5c07b' : '#164'
|
|
70
|
+
}));
|
|
71
|
+
const PromQLOperator = (0, _material.styled)('span')(({ theme })=>({
|
|
72
|
+
color: theme.palette.mode === 'dark' ? '#56b6c2' : '#708'
|
|
73
|
+
}));
|
|
74
|
+
const labelNameList = (labels)=>{
|
|
75
|
+
return labels.map((l, i)=>{
|
|
76
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)("span", {
|
|
77
|
+
children: [
|
|
78
|
+
i !== 0 && ', ',
|
|
79
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLLabelName, {
|
|
80
|
+
children: l
|
|
81
|
+
})
|
|
82
|
+
]
|
|
83
|
+
}, i);
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
const formatAtAndOffset = (timestamp, startOrEnd, offset)=>/*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
87
|
+
children: [
|
|
88
|
+
timestamp !== null ? /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
89
|
+
children: [
|
|
90
|
+
' ',
|
|
91
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLOperator, {
|
|
92
|
+
children: "@"
|
|
93
|
+
}),
|
|
94
|
+
" ",
|
|
95
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLNumber, {
|
|
96
|
+
children: (timestamp / 1000).toFixed(3)
|
|
97
|
+
})
|
|
98
|
+
]
|
|
99
|
+
}) : startOrEnd !== null ? /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
100
|
+
children: [
|
|
101
|
+
' ',
|
|
102
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLOperator, {
|
|
103
|
+
children: "@"
|
|
104
|
+
}),
|
|
105
|
+
" ",
|
|
106
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLKeyword, {
|
|
107
|
+
children: startOrEnd
|
|
108
|
+
}),
|
|
109
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
110
|
+
children: "("
|
|
111
|
+
}),
|
|
112
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
113
|
+
children: ")"
|
|
114
|
+
})
|
|
115
|
+
]
|
|
116
|
+
}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {}),
|
|
117
|
+
offset === 0 ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {}) : offset > 0 ? /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
118
|
+
children: [
|
|
119
|
+
' ',
|
|
120
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLKeyword, {
|
|
121
|
+
children: "offset"
|
|
122
|
+
}),
|
|
123
|
+
' ',
|
|
124
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLDuration, {
|
|
125
|
+
children: (0, _core.formatDuration)((0, _core.msToPrometheusDuration)(offset))
|
|
126
|
+
})
|
|
127
|
+
]
|
|
128
|
+
}) : /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
129
|
+
children: [
|
|
130
|
+
' ',
|
|
131
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLKeyword, {
|
|
132
|
+
children: "offset"
|
|
133
|
+
}),
|
|
134
|
+
' ',
|
|
135
|
+
/*#__PURE__*/ (0, _jsxruntime.jsxs)(PromQLDuration, {
|
|
136
|
+
children: [
|
|
137
|
+
"-",
|
|
138
|
+
(0, _core.formatDuration)((0, _core.msToPrometheusDuration)(-offset))
|
|
139
|
+
]
|
|
140
|
+
})
|
|
141
|
+
]
|
|
142
|
+
})
|
|
143
|
+
]
|
|
144
|
+
});
|
|
145
|
+
const formatSelector = (node)=>{
|
|
146
|
+
const matchLabels = node.matchers.filter((m)=>!(m.name === '__name__' && m.type === _ast.matchType.equal && m.value === node.name)).map((m, i)=>/*#__PURE__*/ (0, _jsxruntime.jsxs)("span", {
|
|
147
|
+
children: [
|
|
148
|
+
i !== 0 && ',',
|
|
149
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLLabelName, {
|
|
150
|
+
children: m.name
|
|
151
|
+
}),
|
|
152
|
+
m.type,
|
|
153
|
+
/*#__PURE__*/ (0, _jsxruntime.jsxs)(PromQLString, {
|
|
154
|
+
children: [
|
|
155
|
+
'"',
|
|
156
|
+
(0, _utils.escapeString)(m.value),
|
|
157
|
+
'"'
|
|
158
|
+
]
|
|
159
|
+
})
|
|
160
|
+
]
|
|
161
|
+
}, i));
|
|
162
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
163
|
+
children: [
|
|
164
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLMetricName, {
|
|
165
|
+
children: node.name
|
|
166
|
+
}),
|
|
167
|
+
matchLabels.length > 0 && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
168
|
+
children: [
|
|
169
|
+
'{',
|
|
170
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
171
|
+
children: matchLabels
|
|
172
|
+
}),
|
|
173
|
+
'}'
|
|
174
|
+
]
|
|
175
|
+
}),
|
|
176
|
+
node.type === _ast.nodeType.matrixSelector && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
177
|
+
children: [
|
|
178
|
+
"[",
|
|
179
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLDuration, {
|
|
180
|
+
children: (0, _core.formatDuration)((0, _core.msToPrometheusDuration)(node.range))
|
|
181
|
+
}),
|
|
182
|
+
"]"
|
|
183
|
+
]
|
|
184
|
+
}),
|
|
185
|
+
formatAtAndOffset(node.timestamp, node.startOrEnd, node.offset)
|
|
186
|
+
]
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
const ellipsis = /*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLEllipsis, {
|
|
190
|
+
children: "…"
|
|
191
|
+
});
|
|
192
|
+
const formatNodeInternal = (node, showChildren, maxDepth)=>{
|
|
193
|
+
if (maxDepth === 0) {
|
|
194
|
+
return ellipsis;
|
|
195
|
+
}
|
|
196
|
+
const childMaxDepth = maxDepth === undefined ? undefined : maxDepth - 1;
|
|
197
|
+
switch(node.type){
|
|
198
|
+
case _ast.nodeType.aggregation:
|
|
199
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
200
|
+
children: [
|
|
201
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLOperator, {
|
|
202
|
+
children: node.op
|
|
203
|
+
}),
|
|
204
|
+
node.without ? /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
205
|
+
children: [
|
|
206
|
+
' ',
|
|
207
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLKeyword, {
|
|
208
|
+
children: "without"
|
|
209
|
+
}),
|
|
210
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
211
|
+
children: "("
|
|
212
|
+
}),
|
|
213
|
+
labelNameList(node.grouping),
|
|
214
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
215
|
+
children: ")"
|
|
216
|
+
}),
|
|
217
|
+
' '
|
|
218
|
+
]
|
|
219
|
+
}) : node.grouping.length > 0 && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
220
|
+
children: [
|
|
221
|
+
' ',
|
|
222
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLKeyword, {
|
|
223
|
+
children: "by"
|
|
224
|
+
}),
|
|
225
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
226
|
+
children: "("
|
|
227
|
+
}),
|
|
228
|
+
labelNameList(node.grouping),
|
|
229
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
230
|
+
children: ")"
|
|
231
|
+
}),
|
|
232
|
+
' '
|
|
233
|
+
]
|
|
234
|
+
}),
|
|
235
|
+
showChildren && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
236
|
+
children: [
|
|
237
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
238
|
+
children: "("
|
|
239
|
+
}),
|
|
240
|
+
node.param !== null && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
241
|
+
children: [
|
|
242
|
+
formatNode(node.param, showChildren, childMaxDepth),
|
|
243
|
+
", "
|
|
244
|
+
]
|
|
245
|
+
}),
|
|
246
|
+
formatNode(node.expr, showChildren, childMaxDepth),
|
|
247
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
248
|
+
children: ")"
|
|
249
|
+
})
|
|
250
|
+
]
|
|
251
|
+
})
|
|
252
|
+
]
|
|
253
|
+
});
|
|
254
|
+
case _ast.nodeType.subquery:
|
|
255
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
256
|
+
children: [
|
|
257
|
+
showChildren && formatNode(node.expr, showChildren, childMaxDepth),
|
|
258
|
+
"[",
|
|
259
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLDuration, {
|
|
260
|
+
children: (0, _core.formatDuration)((0, _core.msToPrometheusDuration)(node.range))
|
|
261
|
+
}),
|
|
262
|
+
":",
|
|
263
|
+
node.step !== 0 && /*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLDuration, {
|
|
264
|
+
children: (0, _core.formatDuration)((0, _core.msToPrometheusDuration)(node.step))
|
|
265
|
+
}),
|
|
266
|
+
"]",
|
|
267
|
+
formatAtAndOffset(node.timestamp, node.startOrEnd, node.offset)
|
|
268
|
+
]
|
|
269
|
+
});
|
|
270
|
+
case _ast.nodeType.parenExpr:
|
|
271
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
272
|
+
children: [
|
|
273
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
274
|
+
children: "("
|
|
275
|
+
}),
|
|
276
|
+
showChildren && formatNode(node.expr, showChildren, childMaxDepth),
|
|
277
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
278
|
+
children: ")"
|
|
279
|
+
})
|
|
280
|
+
]
|
|
281
|
+
});
|
|
282
|
+
case _ast.nodeType.call:
|
|
283
|
+
{
|
|
284
|
+
const children = childMaxDepth === undefined || childMaxDepth > 0 ? node.args.map((arg, i)=>/*#__PURE__*/ (0, _jsxruntime.jsxs)("span", {
|
|
285
|
+
children: [
|
|
286
|
+
i !== 0 && ', ',
|
|
287
|
+
formatNode(arg, showChildren)
|
|
288
|
+
]
|
|
289
|
+
}, i)) : node.args.length > 0 ? ellipsis : '';
|
|
290
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
291
|
+
children: [
|
|
292
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLFunction, {
|
|
293
|
+
children: node.func.name
|
|
294
|
+
}),
|
|
295
|
+
showChildren && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
296
|
+
children: [
|
|
297
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
298
|
+
children: "("
|
|
299
|
+
}),
|
|
300
|
+
children,
|
|
301
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
302
|
+
children: ")"
|
|
303
|
+
})
|
|
304
|
+
]
|
|
305
|
+
})
|
|
306
|
+
]
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
case _ast.nodeType.matrixSelector:
|
|
310
|
+
return formatSelector(node);
|
|
311
|
+
case _ast.nodeType.vectorSelector:
|
|
312
|
+
return formatSelector(node);
|
|
313
|
+
case _ast.nodeType.numberLiteral:
|
|
314
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLNumber, {
|
|
315
|
+
children: node.val
|
|
316
|
+
});
|
|
317
|
+
case _ast.nodeType.stringLiteral:
|
|
318
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(PromQLString, {
|
|
319
|
+
children: [
|
|
320
|
+
'"',
|
|
321
|
+
(0, _utils.escapeString)(node.val),
|
|
322
|
+
'"'
|
|
323
|
+
]
|
|
324
|
+
});
|
|
325
|
+
case _ast.nodeType.unaryExpr:
|
|
326
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
327
|
+
children: [
|
|
328
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLOperator, {
|
|
329
|
+
children: node.op
|
|
330
|
+
}),
|
|
331
|
+
showChildren && formatNode(node.expr, showChildren, childMaxDepth)
|
|
332
|
+
]
|
|
333
|
+
});
|
|
334
|
+
case _ast.nodeType.binaryExpr:
|
|
335
|
+
{
|
|
336
|
+
let matching = /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {});
|
|
337
|
+
let grouping = /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {});
|
|
338
|
+
const vm = node.matching;
|
|
339
|
+
if (vm !== null && (vm.labels.length > 0 || vm.on)) {
|
|
340
|
+
if (vm.on) {
|
|
341
|
+
matching = /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
342
|
+
children: [
|
|
343
|
+
' ',
|
|
344
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLKeyword, {
|
|
345
|
+
children: "on"
|
|
346
|
+
}),
|
|
347
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
348
|
+
children: "("
|
|
349
|
+
}),
|
|
350
|
+
labelNameList(vm.labels),
|
|
351
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
352
|
+
children: ")"
|
|
353
|
+
})
|
|
354
|
+
]
|
|
355
|
+
});
|
|
356
|
+
} else {
|
|
357
|
+
matching = /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
358
|
+
children: [
|
|
359
|
+
' ',
|
|
360
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLKeyword, {
|
|
361
|
+
children: "ignoring"
|
|
362
|
+
}),
|
|
363
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
364
|
+
children: "("
|
|
365
|
+
}),
|
|
366
|
+
labelNameList(vm.labels),
|
|
367
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
368
|
+
children: ")"
|
|
369
|
+
})
|
|
370
|
+
]
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
if (vm.card === _ast.vectorMatchCardinality.manyToOne || vm.card === _ast.vectorMatchCardinality.oneToMany) {
|
|
374
|
+
grouping = /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
375
|
+
children: [
|
|
376
|
+
/*#__PURE__*/ (0, _jsxruntime.jsxs)(PromQLKeyword, {
|
|
377
|
+
children: [
|
|
378
|
+
' ',
|
|
379
|
+
"group_",
|
|
380
|
+
vm.card === _ast.vectorMatchCardinality.manyToOne ? 'left' : 'right'
|
|
381
|
+
]
|
|
382
|
+
}),
|
|
383
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
384
|
+
children: "("
|
|
385
|
+
}),
|
|
386
|
+
labelNameList(vm.include),
|
|
387
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
388
|
+
children: ")"
|
|
389
|
+
})
|
|
390
|
+
]
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
395
|
+
children: [
|
|
396
|
+
showChildren && formatNode((0, _utils.maybeParenthesizeBinopChild)(node.op, node.lhs), showChildren, childMaxDepth),
|
|
397
|
+
' ',
|
|
398
|
+
[
|
|
399
|
+
'atan2',
|
|
400
|
+
'and',
|
|
401
|
+
'or',
|
|
402
|
+
'unless'
|
|
403
|
+
].includes(node.op) ? /*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLOperator, {
|
|
404
|
+
children: node.op
|
|
405
|
+
}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLOperator, {
|
|
406
|
+
children: node.op
|
|
407
|
+
}),
|
|
408
|
+
node.bool && /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
409
|
+
children: [
|
|
410
|
+
' ',
|
|
411
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLKeyword, {
|
|
412
|
+
children: "bool"
|
|
413
|
+
})
|
|
414
|
+
]
|
|
415
|
+
}),
|
|
416
|
+
matching,
|
|
417
|
+
grouping,
|
|
418
|
+
' ',
|
|
419
|
+
showChildren && formatNode((0, _utils.maybeParenthesizeBinopChild)(node.op, node.rhs), showChildren, childMaxDepth)
|
|
420
|
+
]
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
case _ast.nodeType.placeholder:
|
|
424
|
+
// TODO: Include possible children of placeholders somehow?
|
|
425
|
+
return ellipsis;
|
|
426
|
+
default:
|
|
427
|
+
throw new Error('unsupported node type');
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
const formatNode = (node, showChildren, maxDepth)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(PromQLCode, {
|
|
431
|
+
children: formatNodeInternal(node, showChildren, maxDepth)
|
|
432
|
+
});
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Copyright 2024 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
|
+
// Forked from https://github.com/prometheus/prometheus/blob/65f610353919b1c7b42d3776c3a95b68046a6bba/web/ui/mantine-ui/src/promql/utils.ts
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", {
|
|
16
|
+
value: true
|
|
17
|
+
});
|
|
18
|
+
function _export(target, all) {
|
|
19
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: all[name]
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
_export(exports, {
|
|
25
|
+
escapeString: function() {
|
|
26
|
+
return escapeString;
|
|
27
|
+
},
|
|
28
|
+
getNodeChildren: function() {
|
|
29
|
+
return getNodeChildren;
|
|
30
|
+
},
|
|
31
|
+
maybeParenthesizeBinopChild: function() {
|
|
32
|
+
return maybeParenthesizeBinopChild;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
const _ast = require("./ast");
|
|
36
|
+
const binOpPrecedence = {
|
|
37
|
+
[_ast.binaryOperatorType.add]: 3,
|
|
38
|
+
[_ast.binaryOperatorType.sub]: 3,
|
|
39
|
+
[_ast.binaryOperatorType.mul]: 2,
|
|
40
|
+
[_ast.binaryOperatorType.div]: 2,
|
|
41
|
+
[_ast.binaryOperatorType.mod]: 2,
|
|
42
|
+
[_ast.binaryOperatorType.pow]: 1,
|
|
43
|
+
[_ast.binaryOperatorType.eql]: 4,
|
|
44
|
+
[_ast.binaryOperatorType.neq]: 4,
|
|
45
|
+
[_ast.binaryOperatorType.gtr]: 4,
|
|
46
|
+
[_ast.binaryOperatorType.lss]: 4,
|
|
47
|
+
[_ast.binaryOperatorType.gte]: 4,
|
|
48
|
+
[_ast.binaryOperatorType.lte]: 4,
|
|
49
|
+
[_ast.binaryOperatorType.and]: 5,
|
|
50
|
+
[_ast.binaryOperatorType.or]: 6,
|
|
51
|
+
[_ast.binaryOperatorType.unless]: 5,
|
|
52
|
+
[_ast.binaryOperatorType.atan2]: 2
|
|
53
|
+
};
|
|
54
|
+
const maybeParenthesizeBinopChild = (op, child)=>{
|
|
55
|
+
if (child.type !== _ast.nodeType.binaryExpr) {
|
|
56
|
+
return child;
|
|
57
|
+
}
|
|
58
|
+
if (binOpPrecedence[op] > binOpPrecedence[child.op]) {
|
|
59
|
+
return child;
|
|
60
|
+
}
|
|
61
|
+
// TODO: Parens aren't necessary for left-associativity within same precedence,
|
|
62
|
+
// or right-associativity between two power operators.
|
|
63
|
+
return {
|
|
64
|
+
type: _ast.nodeType.parenExpr,
|
|
65
|
+
expr: child
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const getNodeChildren = (node)=>{
|
|
69
|
+
switch(node.type){
|
|
70
|
+
case _ast.nodeType.aggregation:
|
|
71
|
+
return node.param === null ? [
|
|
72
|
+
node.expr
|
|
73
|
+
] : [
|
|
74
|
+
node.param,
|
|
75
|
+
node.expr
|
|
76
|
+
];
|
|
77
|
+
case _ast.nodeType.subquery:
|
|
78
|
+
return [
|
|
79
|
+
node.expr
|
|
80
|
+
];
|
|
81
|
+
case _ast.nodeType.parenExpr:
|
|
82
|
+
return [
|
|
83
|
+
node.expr
|
|
84
|
+
];
|
|
85
|
+
case _ast.nodeType.call:
|
|
86
|
+
return node.args;
|
|
87
|
+
case _ast.nodeType.matrixSelector:
|
|
88
|
+
case _ast.nodeType.vectorSelector:
|
|
89
|
+
case _ast.nodeType.numberLiteral:
|
|
90
|
+
case _ast.nodeType.stringLiteral:
|
|
91
|
+
return [];
|
|
92
|
+
case _ast.nodeType.placeholder:
|
|
93
|
+
return node.children;
|
|
94
|
+
case _ast.nodeType.unaryExpr:
|
|
95
|
+
return [
|
|
96
|
+
node.expr
|
|
97
|
+
];
|
|
98
|
+
case _ast.nodeType.binaryExpr:
|
|
99
|
+
return [
|
|
100
|
+
node.lhs,
|
|
101
|
+
node.rhs
|
|
102
|
+
];
|
|
103
|
+
default:
|
|
104
|
+
throw new Error('unsupported node type');
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
const escapeString = (str)=>{
|
|
108
|
+
return str.replace(/([\\"])/g, '\\$1');
|
|
109
|
+
};
|
|
@@ -39,6 +39,9 @@ _export(exports, {
|
|
|
39
39
|
metricMetadata: function() {
|
|
40
40
|
return metricMetadata;
|
|
41
41
|
},
|
|
42
|
+
parseQuery: function() {
|
|
43
|
+
return parseQuery;
|
|
44
|
+
},
|
|
42
45
|
rangeQuery: function() {
|
|
43
46
|
return rangeQuery;
|
|
44
47
|
},
|
|
@@ -91,15 +94,20 @@ function series(params, queryOptions) {
|
|
|
91
94
|
const apiURI = `/api/v1/series`;
|
|
92
95
|
return fetchWithPost(apiURI, params, queryOptions);
|
|
93
96
|
}
|
|
97
|
+
function parseQuery(params, queryOptions) {
|
|
98
|
+
const apiURI = `/api/v1/parse_query`;
|
|
99
|
+
return fetchWithPost(apiURI, params, queryOptions);
|
|
100
|
+
}
|
|
94
101
|
function fetchWithGet(apiURI, params, queryOptions) {
|
|
95
|
-
const { datasourceUrl } = queryOptions;
|
|
102
|
+
const { datasourceUrl, headers } = queryOptions;
|
|
96
103
|
let url = `${datasourceUrl}${apiURI}`;
|
|
97
104
|
const urlParams = createSearchParams(params).toString();
|
|
98
105
|
if (urlParams !== '') {
|
|
99
106
|
url += `?${urlParams}`;
|
|
100
107
|
}
|
|
101
108
|
return (0, _core.fetchJson)(url, {
|
|
102
|
-
method: 'GET'
|
|
109
|
+
method: 'GET',
|
|
110
|
+
headers
|
|
103
111
|
});
|
|
104
112
|
}
|
|
105
113
|
function fetchWithPost(apiURI, params, queryOptions) {
|
|
@@ -65,6 +65,10 @@ const _PrometheusDatasourceEditor = require("./PrometheusDatasourceEditor");
|
|
|
65
65
|
series: (params, headers)=>(0, _model.series)(params, {
|
|
66
66
|
datasourceUrl,
|
|
67
67
|
headers: headers !== null && headers !== void 0 ? headers : specHeaders
|
|
68
|
+
}),
|
|
69
|
+
parseQuery: (params, headers)=>(0, _model.parseQuery)(params, {
|
|
70
|
+
datasourceUrl,
|
|
71
|
+
headers: headers !== null && headers !== void 0 ? headers : specHeaders
|
|
68
72
|
})
|
|
69
73
|
};
|
|
70
74
|
};
|
|
@@ -36,7 +36,7 @@ function PrometheusTimeSeriesQueryEditor(props) {
|
|
|
36
36
|
const { data: client } = (0, _pluginsystem.useDatasourceClient)(selectedDatasource);
|
|
37
37
|
const promURL = client === null || client === void 0 ? void 0 : client.options.datasourceUrl;
|
|
38
38
|
const { data: datasourceResource } = (0, _pluginsystem.useDatasource)(selectedDatasource);
|
|
39
|
-
const {
|
|
39
|
+
const { handleQueryChange, handleQueryBlur } = (0, _queryeditormodel.useQueryState)(props);
|
|
40
40
|
const { format, handleFormatChange, handleFormatBlur } = (0, _queryeditormodel.useFormatState)(props);
|
|
41
41
|
const { minStep, handleMinStepChange, handleMinStepBlur } = (0, _queryeditormodel.useMinStepState)(props);
|
|
42
42
|
var _ref;
|
|
@@ -78,7 +78,8 @@ function PrometheusTimeSeriesQueryEditor(props) {
|
|
|
78
78
|
url: promURL
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
|
-
value: query,
|
|
81
|
+
value: value.query,
|
|
82
|
+
datasource: selectedDatasource,
|
|
82
83
|
onChange: handleQueryChange,
|
|
83
84
|
onBlur: handleQueryBlur
|
|
84
85
|
}),
|
|
@@ -88,9 +89,9 @@ function PrometheusTimeSeriesQueryEditor(props) {
|
|
|
88
89
|
children: [
|
|
89
90
|
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
|
|
90
91
|
fullWidth: true,
|
|
91
|
-
label: "Legend
|
|
92
|
-
placeholder: "
|
|
93
|
-
helperText: "
|
|
92
|
+
label: "Legend",
|
|
93
|
+
placeholder: "Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...",
|
|
94
|
+
helperText: "Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.",
|
|
94
95
|
value: format !== null && format !== void 0 ? format : '',
|
|
95
96
|
onChange: (e)=>handleFormatChange(e.target.value),
|
|
96
97
|
onBlur: handleFormatBlur
|
|
@@ -191,10 +191,12 @@ function PrometheusPromQLVariableEditor(props) {
|
|
|
191
191
|
}
|
|
192
192
|
},
|
|
193
193
|
value: value.expr,
|
|
194
|
-
|
|
194
|
+
datasource: selectedDatasource,
|
|
195
|
+
onBlur: (event)=>{
|
|
196
|
+
var _event_target_textContent;
|
|
195
197
|
props.onChange({
|
|
196
198
|
...props.value,
|
|
197
|
-
expr:
|
|
199
|
+
expr: (_event_target_textContent = event.target.textContent) !== null && _event_target_textContent !== void 0 ? _event_target_textContent : ''
|
|
198
200
|
});
|
|
199
201
|
},
|
|
200
202
|
readOnly: props.isReadonly,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ReactCodeMirrorProps } from '@uiw/react-codemirror';
|
|
2
|
+
import { CompleteConfiguration } from '@prometheus-io/codemirror-promql';
|
|
3
|
+
import { PrometheusDatasourceSelector } from '../model';
|
|
4
|
+
export type PromQLEditorProps = {
|
|
5
|
+
completeConfig: CompleteConfiguration;
|
|
6
|
+
datasource: PrometheusDatasourceSelector;
|
|
7
|
+
} & Omit<ReactCodeMirrorProps, 'theme' | 'extensions'>;
|
|
8
|
+
export declare function PromQLEditor({ completeConfig, datasource, ...rest }: PromQLEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
//# sourceMappingURL=PromQLEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PromQLEditor.d.ts","sourceRoot":"","sources":["../../src/components/PromQLEditor.tsx"],"names":[],"mappings":"AAaA,OAAmB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAmB,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAQ1F,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAsCxD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,qBAAqB,CAAC;IACtC,UAAU,EAAE,4BAA4B,CAAC;CAC1C,GAAG,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,YAAY,CAAC,CAAC;AAEvD,wBAAgB,YAAY,CAAC,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,EAAE,iBAAiB,2CAsHtF"}
|