@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.
Files changed (65) hide show
  1. package/dist/cjs/components/PromQLEditor.js +209 -0
  2. package/dist/cjs/components/TreeNode.js +147 -0
  3. package/dist/cjs/components/index.js +1 -1
  4. package/dist/cjs/components/parse.js +42 -0
  5. package/dist/cjs/components/promql/ast.js +143 -0
  6. package/dist/cjs/components/promql/format.js +432 -0
  7. package/dist/cjs/components/promql/utils.js +109 -0
  8. package/dist/cjs/model/prometheus-client.js +10 -2
  9. package/dist/cjs/plugins/PrometheusDatasourceEditor.js +4 -0
  10. package/dist/cjs/plugins/prometheus-datasource.js +4 -0
  11. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +6 -5
  12. package/dist/cjs/plugins/prometheus-variables.js +4 -2
  13. package/dist/components/PromQLEditor.d.ts +9 -0
  14. package/dist/components/PromQLEditor.d.ts.map +1 -0
  15. package/dist/components/PromQLEditor.js +196 -0
  16. package/dist/components/PromQLEditor.js.map +1 -0
  17. package/dist/components/TreeNode.d.ts +10 -0
  18. package/dist/components/TreeNode.d.ts.map +1 -0
  19. package/dist/components/TreeNode.js +139 -0
  20. package/dist/components/TreeNode.js.map +1 -0
  21. package/dist/components/index.d.ts +1 -1
  22. package/dist/components/index.d.ts.map +1 -1
  23. package/dist/components/index.js +1 -1
  24. package/dist/components/index.js.map +1 -1
  25. package/dist/components/parse.d.ts +4 -0
  26. package/dist/components/parse.d.ts.map +1 -0
  27. package/dist/components/parse.js +34 -0
  28. package/dist/components/parse.js.map +1 -0
  29. package/dist/components/promql/ast.d.ts +161 -0
  30. package/dist/components/promql/ast.d.ts.map +1 -0
  31. package/dist/components/promql/ast.js +106 -0
  32. package/dist/components/promql/ast.js.map +1 -0
  33. package/dist/components/promql/format.d.ts +5 -0
  34. package/dist/components/promql/format.d.ts.map +1 -0
  35. package/dist/components/promql/format.js +411 -0
  36. package/dist/components/promql/format.js.map +1 -0
  37. package/dist/components/promql/utils.d.ts +5 -0
  38. package/dist/components/promql/utils.d.ts.map +1 -0
  39. package/dist/components/promql/utils.js +90 -0
  40. package/dist/components/promql/utils.js.map +1 -0
  41. package/dist/model/api-types.d.ts +5 -0
  42. package/dist/model/api-types.d.ts.map +1 -1
  43. package/dist/model/api-types.js.map +1 -1
  44. package/dist/model/prometheus-client.d.ts +6 -1
  45. package/dist/model/prometheus-client.d.ts.map +1 -1
  46. package/dist/model/prometheus-client.js +9 -2
  47. package/dist/model/prometheus-client.js.map +1 -1
  48. package/dist/plugins/PrometheusDatasourceEditor.d.ts.map +1 -1
  49. package/dist/plugins/PrometheusDatasourceEditor.js +4 -0
  50. package/dist/plugins/PrometheusDatasourceEditor.js.map +1 -1
  51. package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
  52. package/dist/plugins/prometheus-datasource.js +5 -1
  53. package/dist/plugins/prometheus-datasource.js.map +1 -1
  54. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  55. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +6 -5
  56. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  57. package/dist/plugins/prometheus-variables.d.ts.map +1 -1
  58. package/dist/plugins/prometheus-variables.js +4 -2
  59. package/dist/plugins/prometheus-variables.js.map +1 -1
  60. package/package.json +4 -4
  61. package/dist/cjs/components/PromQL.js +0 -58
  62. package/dist/components/PromQL.d.ts +0 -7
  63. package/dist/components/PromQL.d.ts.map +0 -1
  64. package/dist/components/PromQL.js +0 -45
  65. package/dist/components/PromQL.js.map +0 -1
@@ -0,0 +1,106 @@
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/ast.ts
14
+ export var nodeType;
15
+ (function(nodeType) {
16
+ nodeType["aggregation"] = "aggregation";
17
+ nodeType["binaryExpr"] = "binaryExpr";
18
+ nodeType["call"] = "call";
19
+ nodeType["matrixSelector"] = "matrixSelector";
20
+ nodeType["subquery"] = "subquery";
21
+ nodeType["numberLiteral"] = "numberLiteral";
22
+ nodeType["parenExpr"] = "parenExpr";
23
+ nodeType["stringLiteral"] = "stringLiteral";
24
+ nodeType["unaryExpr"] = "unaryExpr";
25
+ nodeType["vectorSelector"] = "vectorSelector";
26
+ nodeType["placeholder"] = "placeholder";
27
+ })(nodeType || (nodeType = {}));
28
+ export var aggregationType;
29
+ (function(aggregationType) {
30
+ aggregationType["sum"] = "sum";
31
+ aggregationType["min"] = "min";
32
+ aggregationType["max"] = "max";
33
+ aggregationType["avg"] = "avg";
34
+ aggregationType["stddev"] = "stddev";
35
+ aggregationType["stdvar"] = "stdvar";
36
+ aggregationType["count"] = "count";
37
+ aggregationType["group"] = "group";
38
+ aggregationType["countValues"] = "count_values";
39
+ aggregationType["bottomk"] = "bottomk";
40
+ aggregationType["topk"] = "topk";
41
+ aggregationType["quantile"] = "quantile";
42
+ aggregationType["limitK"] = "limitk";
43
+ aggregationType["limitRatio"] = "limit_ratio";
44
+ })(aggregationType || (aggregationType = {}));
45
+ export var binaryOperatorType;
46
+ (function(binaryOperatorType) {
47
+ binaryOperatorType["add"] = "+";
48
+ binaryOperatorType["sub"] = "-";
49
+ binaryOperatorType["mul"] = "*";
50
+ binaryOperatorType["div"] = "/";
51
+ binaryOperatorType["mod"] = "%";
52
+ binaryOperatorType["pow"] = "^";
53
+ binaryOperatorType["eql"] = "==";
54
+ binaryOperatorType["neq"] = "!=";
55
+ binaryOperatorType["gtr"] = ">";
56
+ binaryOperatorType["lss"] = "<";
57
+ binaryOperatorType["gte"] = ">=";
58
+ binaryOperatorType["lte"] = "<=";
59
+ binaryOperatorType["and"] = "and";
60
+ binaryOperatorType["or"] = "or";
61
+ binaryOperatorType["unless"] = "unless";
62
+ binaryOperatorType["atan2"] = "atan2";
63
+ })(binaryOperatorType || (binaryOperatorType = {}));
64
+ export const compOperatorTypes = [
65
+ "==",
66
+ "!=",
67
+ ">",
68
+ "<",
69
+ ">=",
70
+ "<="
71
+ ];
72
+ export const setOperatorTypes = [
73
+ "and",
74
+ "or",
75
+ "unless"
76
+ ];
77
+ export var unaryOperatorType;
78
+ (function(unaryOperatorType) {
79
+ unaryOperatorType["plus"] = "+";
80
+ unaryOperatorType["minus"] = "-";
81
+ })(unaryOperatorType || (unaryOperatorType = {}));
82
+ export var vectorMatchCardinality;
83
+ (function(vectorMatchCardinality) {
84
+ vectorMatchCardinality["oneToOne"] = "one-to-one";
85
+ vectorMatchCardinality["manyToOne"] = "many-to-one";
86
+ vectorMatchCardinality["oneToMany"] = "one-to-many";
87
+ vectorMatchCardinality["manyToMany"] = "many-to-many";
88
+ })(vectorMatchCardinality || (vectorMatchCardinality = {}));
89
+ export var valueType;
90
+ (function(valueType) {
91
+ // TODO: 'none' should never make it out of Prometheus. Do we need this here?
92
+ valueType["none"] = "none";
93
+ valueType["vector"] = "vector";
94
+ valueType["scalar"] = "scalar";
95
+ valueType["matrix"] = "matrix";
96
+ valueType["string"] = "string";
97
+ })(valueType || (valueType = {}));
98
+ export var matchType;
99
+ (function(matchType) {
100
+ matchType["equal"] = "=";
101
+ matchType["notEqual"] = "!=";
102
+ matchType["matchRegexp"] = "=~";
103
+ matchType["matchNotRegexp"] = "!~";
104
+ })(matchType || (matchType = {}));
105
+
106
+ //# sourceMappingURL=ast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/promql/ast.ts"],"sourcesContent":["// Copyright 2024 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\n// Forked from https://github.com/prometheus/prometheus/blob/65f610353919b1c7b42d3776c3a95b68046a6bba/web/ui/mantine-ui/src/promql/ast.ts\n\nexport enum nodeType {\n aggregation = 'aggregation',\n binaryExpr = 'binaryExpr',\n call = 'call',\n matrixSelector = 'matrixSelector',\n subquery = 'subquery',\n numberLiteral = 'numberLiteral',\n parenExpr = 'parenExpr',\n stringLiteral = 'stringLiteral',\n unaryExpr = 'unaryExpr',\n vectorSelector = 'vectorSelector',\n placeholder = 'placeholder',\n}\n\nexport enum aggregationType {\n sum = 'sum',\n min = 'min',\n max = 'max',\n avg = 'avg',\n stddev = 'stddev',\n stdvar = 'stdvar',\n count = 'count',\n group = 'group',\n countValues = 'count_values',\n bottomk = 'bottomk',\n topk = 'topk',\n quantile = 'quantile',\n limitK = 'limitk',\n limitRatio = 'limit_ratio',\n}\n\nexport enum binaryOperatorType {\n add = '+',\n sub = '-',\n mul = '*',\n div = '/',\n mod = '%',\n pow = '^',\n eql = '==',\n neq = '!=',\n gtr = '>',\n lss = '<',\n gte = '>=',\n lte = '<=',\n and = 'and',\n or = 'or',\n unless = 'unless',\n atan2 = 'atan2',\n}\n\nexport const compOperatorTypes: binaryOperatorType[] = [\n binaryOperatorType.eql,\n binaryOperatorType.neq,\n binaryOperatorType.gtr,\n binaryOperatorType.lss,\n binaryOperatorType.gte,\n binaryOperatorType.lte,\n];\n\nexport const setOperatorTypes: binaryOperatorType[] = [\n binaryOperatorType.and,\n binaryOperatorType.or,\n binaryOperatorType.unless,\n];\n\nexport enum unaryOperatorType {\n plus = '+',\n minus = '-',\n}\n\nexport enum vectorMatchCardinality {\n oneToOne = 'one-to-one',\n manyToOne = 'many-to-one',\n oneToMany = 'one-to-many',\n manyToMany = 'many-to-many',\n}\n\nexport enum valueType {\n // TODO: 'none' should never make it out of Prometheus. Do we need this here?\n none = 'none',\n vector = 'vector',\n scalar = 'scalar',\n matrix = 'matrix',\n string = 'string',\n}\n\nexport enum matchType {\n equal = '=',\n notEqual = '!=',\n matchRegexp = '=~',\n matchNotRegexp = '!~',\n}\n\nexport interface Func {\n name: string;\n argTypes: valueType[];\n variadic: number;\n returnType: valueType;\n}\n\nexport interface LabelMatcher {\n type: matchType;\n name: string;\n value: string;\n}\n\nexport interface VectorMatching {\n card: vectorMatchCardinality;\n labels: string[];\n on: boolean;\n include: string[];\n}\n\nexport type StartOrEnd = 'start' | 'end' | null;\n\n// AST Node Types.\n\nexport interface Aggregation {\n type: nodeType.aggregation;\n expr: ASTNode;\n op: aggregationType;\n param: ASTNode | null;\n grouping: string[];\n without: boolean;\n}\n\nexport interface BinaryExpr {\n type: nodeType.binaryExpr;\n op: binaryOperatorType;\n lhs: ASTNode;\n rhs: ASTNode;\n matching: VectorMatching | null;\n bool: boolean;\n}\n\nexport interface Call {\n type: nodeType.call;\n func: Func;\n args: ASTNode[];\n}\n\nexport interface MatrixSelector {\n type: nodeType.matrixSelector;\n name: string;\n matchers: LabelMatcher[];\n range: number;\n offset: number;\n timestamp: number | null;\n startOrEnd: StartOrEnd;\n}\n\nexport interface Subquery {\n type: nodeType.subquery;\n expr: ASTNode;\n range: number;\n offset: number;\n step: number;\n timestamp: number | null;\n startOrEnd: StartOrEnd;\n}\n\nexport interface NumberLiteral {\n type: nodeType.numberLiteral;\n val: string; // Can't be 'number' because JS doesn't support NaN/Inf/-Inf etc.\n}\n\nexport interface ParenExpr {\n type: nodeType.parenExpr;\n expr: ASTNode;\n}\n\nexport interface StringLiteral {\n type: nodeType.stringLiteral;\n val: string;\n}\n\nexport interface UnaryExpr {\n type: nodeType.unaryExpr;\n op: unaryOperatorType;\n expr: ASTNode;\n}\n\nexport interface VectorSelector {\n type: nodeType.vectorSelector;\n name: string;\n matchers: LabelMatcher[];\n offset: number;\n timestamp: number | null;\n startOrEnd: StartOrEnd;\n}\n\nexport interface Placeholder {\n type: nodeType.placeholder;\n children: ASTNode[];\n}\n\n// NB: AST stands for Abstract Syntax Tree\ntype ASTNode =\n | Aggregation\n | BinaryExpr\n | Call\n | MatrixSelector\n | Subquery\n | NumberLiteral\n | ParenExpr\n | StringLiteral\n | UnaryExpr\n | VectorSelector\n | Placeholder;\n\nexport default ASTNode;\n"],"names":["nodeType","aggregationType","binaryOperatorType","compOperatorTypes","setOperatorTypes","unaryOperatorType","vectorMatchCardinality","valueType","matchType"],"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,yIAAyI;;UAE7HA;;;;;;;;;;;;GAAAA,aAAAA;;UAcAC;;;;;;;;;;;;;;;GAAAA,oBAAAA;;UAiBAC;;;;;;;;;;;;;;;;;GAAAA,uBAAAA;AAmBZ,OAAO,MAAMC,oBAA0C;;;;;;;CAOtD,CAAC;AAEF,OAAO,MAAMC,mBAAyC;;;;CAIrD,CAAC;;UAEUC;;;GAAAA,sBAAAA;;UAKAC;;;;;GAAAA,2BAAAA;;UAOAC;IACV,6EAA6E;;;;;;GADnEA,cAAAA;;UASAC;;;;;GAAAA,cAAAA"}
@@ -0,0 +1,5 @@
1
+ import React, { ReactElement, ReactNode } from 'react';
2
+ import ASTNode from './ast';
3
+ export declare const labelNameList: (labels: string[]) => React.ReactNode[];
4
+ export declare const formatNode: (node: ASTNode, showChildren: boolean, maxDepth?: number) => React.ReactElement;
5
+ //# sourceMappingURL=format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/components/promql/format.tsx"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvD,OAAO,OAON,MAAM,OAAO,CAAC;AA6Cf,eAAO,MAAM,aAAa,WAAY,MAAM,EAAE,KAAG,eAAe,EAS/D,CAAC;AAiPF,eAAO,MAAM,UAAU,SAAU,OAAO,gBAAgB,OAAO,aAAa,MAAM,KAAG,kBAEpF,CAAC"}
@@ -0,0 +1,411 @@
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
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
15
+ import React from 'react';
16
+ import { styled } from '@mui/material';
17
+ import { formatDuration, msToPrometheusDuration } from '@perses-dev/core';
18
+ import { matchType, vectorMatchCardinality, nodeType } from './ast';
19
+ import { maybeParenthesizeBinopChild, escapeString } from './utils';
20
+ // Styled components that reproduce the theming of CodeMirror:
21
+ const PromQLCode = styled('span')(()=>({
22
+ fontFamily: '"DejaVu Sans Mono", monospace'
23
+ }));
24
+ const PromQLKeyword = styled('span')(({ theme })=>({
25
+ color: theme.palette.mode === 'dark' ? '#e5c07b' : '#708'
26
+ }));
27
+ const PromQLFunction = styled('span')(({ theme })=>({
28
+ color: theme.palette.mode === 'dark' ? '#61afef' : '#2a2e42'
29
+ }));
30
+ const PromQLMetricName = styled('span')(({ theme })=>({
31
+ color: theme.palette.mode === 'dark' ? '#e06c75' : '#2a2e42'
32
+ }));
33
+ const PromQLLabelName = styled('span')(({ theme })=>({
34
+ color: theme.palette.mode === 'dark' ? '#61afef' : '#219'
35
+ }));
36
+ const PromQLString = styled('span')(({ theme })=>({
37
+ color: theme.palette.mode === 'dark' ? '#98c379' : '#a31515'
38
+ }));
39
+ const PromQLEllipsis = styled('span')(()=>({
40
+ color: '#aaaaaa'
41
+ }));
42
+ const PromQLDuration = styled('span')(({ theme })=>({
43
+ color: theme.palette.mode === 'dark' ? '#e5c07b' : '#09885a'
44
+ }));
45
+ const PromQLNumber = styled('span')(({ theme })=>({
46
+ color: theme.palette.mode === 'dark' ? '#e5c07b' : '#164'
47
+ }));
48
+ const PromQLOperator = styled('span')(({ theme })=>({
49
+ color: theme.palette.mode === 'dark' ? '#56b6c2' : '#708'
50
+ }));
51
+ export const labelNameList = (labels)=>{
52
+ return labels.map((l, i)=>{
53
+ return /*#__PURE__*/ _jsxs("span", {
54
+ children: [
55
+ i !== 0 && ', ',
56
+ /*#__PURE__*/ _jsx(PromQLLabelName, {
57
+ children: l
58
+ })
59
+ ]
60
+ }, i);
61
+ });
62
+ };
63
+ const formatAtAndOffset = (timestamp, startOrEnd, offset)=>/*#__PURE__*/ _jsxs(_Fragment, {
64
+ children: [
65
+ timestamp !== null ? /*#__PURE__*/ _jsxs(_Fragment, {
66
+ children: [
67
+ ' ',
68
+ /*#__PURE__*/ _jsx(PromQLOperator, {
69
+ children: "@"
70
+ }),
71
+ " ",
72
+ /*#__PURE__*/ _jsx(PromQLNumber, {
73
+ children: (timestamp / 1000).toFixed(3)
74
+ })
75
+ ]
76
+ }) : startOrEnd !== null ? /*#__PURE__*/ _jsxs(_Fragment, {
77
+ children: [
78
+ ' ',
79
+ /*#__PURE__*/ _jsx(PromQLOperator, {
80
+ children: "@"
81
+ }),
82
+ " ",
83
+ /*#__PURE__*/ _jsx(PromQLKeyword, {
84
+ children: startOrEnd
85
+ }),
86
+ /*#__PURE__*/ _jsx("span", {
87
+ children: "("
88
+ }),
89
+ /*#__PURE__*/ _jsx("span", {
90
+ children: ")"
91
+ })
92
+ ]
93
+ }) : /*#__PURE__*/ _jsx(_Fragment, {}),
94
+ offset === 0 ? /*#__PURE__*/ _jsx(_Fragment, {}) : offset > 0 ? /*#__PURE__*/ _jsxs(_Fragment, {
95
+ children: [
96
+ ' ',
97
+ /*#__PURE__*/ _jsx(PromQLKeyword, {
98
+ children: "offset"
99
+ }),
100
+ ' ',
101
+ /*#__PURE__*/ _jsx(PromQLDuration, {
102
+ children: formatDuration(msToPrometheusDuration(offset))
103
+ })
104
+ ]
105
+ }) : /*#__PURE__*/ _jsxs(_Fragment, {
106
+ children: [
107
+ ' ',
108
+ /*#__PURE__*/ _jsx(PromQLKeyword, {
109
+ children: "offset"
110
+ }),
111
+ ' ',
112
+ /*#__PURE__*/ _jsxs(PromQLDuration, {
113
+ children: [
114
+ "-",
115
+ formatDuration(msToPrometheusDuration(-offset))
116
+ ]
117
+ })
118
+ ]
119
+ })
120
+ ]
121
+ });
122
+ const formatSelector = (node)=>{
123
+ const matchLabels = node.matchers.filter((m)=>!(m.name === '__name__' && m.type === matchType.equal && m.value === node.name)).map((m, i)=>/*#__PURE__*/ _jsxs("span", {
124
+ children: [
125
+ i !== 0 && ',',
126
+ /*#__PURE__*/ _jsx(PromQLLabelName, {
127
+ children: m.name
128
+ }),
129
+ m.type,
130
+ /*#__PURE__*/ _jsxs(PromQLString, {
131
+ children: [
132
+ '"',
133
+ escapeString(m.value),
134
+ '"'
135
+ ]
136
+ })
137
+ ]
138
+ }, i));
139
+ return /*#__PURE__*/ _jsxs(_Fragment, {
140
+ children: [
141
+ /*#__PURE__*/ _jsx(PromQLMetricName, {
142
+ children: node.name
143
+ }),
144
+ matchLabels.length > 0 && /*#__PURE__*/ _jsxs(_Fragment, {
145
+ children: [
146
+ '{',
147
+ /*#__PURE__*/ _jsx("span", {
148
+ children: matchLabels
149
+ }),
150
+ '}'
151
+ ]
152
+ }),
153
+ node.type === nodeType.matrixSelector && /*#__PURE__*/ _jsxs(_Fragment, {
154
+ children: [
155
+ "[",
156
+ /*#__PURE__*/ _jsx(PromQLDuration, {
157
+ children: formatDuration(msToPrometheusDuration(node.range))
158
+ }),
159
+ "]"
160
+ ]
161
+ }),
162
+ formatAtAndOffset(node.timestamp, node.startOrEnd, node.offset)
163
+ ]
164
+ });
165
+ };
166
+ const ellipsis = /*#__PURE__*/ _jsx(PromQLEllipsis, {
167
+ children: "…"
168
+ });
169
+ const formatNodeInternal = (node, showChildren, maxDepth)=>{
170
+ if (maxDepth === 0) {
171
+ return ellipsis;
172
+ }
173
+ const childMaxDepth = maxDepth === undefined ? undefined : maxDepth - 1;
174
+ switch(node.type){
175
+ case nodeType.aggregation:
176
+ return /*#__PURE__*/ _jsxs(_Fragment, {
177
+ children: [
178
+ /*#__PURE__*/ _jsx(PromQLOperator, {
179
+ children: node.op
180
+ }),
181
+ node.without ? /*#__PURE__*/ _jsxs(_Fragment, {
182
+ children: [
183
+ ' ',
184
+ /*#__PURE__*/ _jsx(PromQLKeyword, {
185
+ children: "without"
186
+ }),
187
+ /*#__PURE__*/ _jsx("span", {
188
+ children: "("
189
+ }),
190
+ labelNameList(node.grouping),
191
+ /*#__PURE__*/ _jsx("span", {
192
+ children: ")"
193
+ }),
194
+ ' '
195
+ ]
196
+ }) : node.grouping.length > 0 && /*#__PURE__*/ _jsxs(_Fragment, {
197
+ children: [
198
+ ' ',
199
+ /*#__PURE__*/ _jsx(PromQLKeyword, {
200
+ children: "by"
201
+ }),
202
+ /*#__PURE__*/ _jsx("span", {
203
+ children: "("
204
+ }),
205
+ labelNameList(node.grouping),
206
+ /*#__PURE__*/ _jsx("span", {
207
+ children: ")"
208
+ }),
209
+ ' '
210
+ ]
211
+ }),
212
+ showChildren && /*#__PURE__*/ _jsxs(_Fragment, {
213
+ children: [
214
+ /*#__PURE__*/ _jsx("span", {
215
+ children: "("
216
+ }),
217
+ node.param !== null && /*#__PURE__*/ _jsxs(_Fragment, {
218
+ children: [
219
+ formatNode(node.param, showChildren, childMaxDepth),
220
+ ", "
221
+ ]
222
+ }),
223
+ formatNode(node.expr, showChildren, childMaxDepth),
224
+ /*#__PURE__*/ _jsx("span", {
225
+ children: ")"
226
+ })
227
+ ]
228
+ })
229
+ ]
230
+ });
231
+ case nodeType.subquery:
232
+ return /*#__PURE__*/ _jsxs(_Fragment, {
233
+ children: [
234
+ showChildren && formatNode(node.expr, showChildren, childMaxDepth),
235
+ "[",
236
+ /*#__PURE__*/ _jsx(PromQLDuration, {
237
+ children: formatDuration(msToPrometheusDuration(node.range))
238
+ }),
239
+ ":",
240
+ node.step !== 0 && /*#__PURE__*/ _jsx(PromQLDuration, {
241
+ children: formatDuration(msToPrometheusDuration(node.step))
242
+ }),
243
+ "]",
244
+ formatAtAndOffset(node.timestamp, node.startOrEnd, node.offset)
245
+ ]
246
+ });
247
+ case nodeType.parenExpr:
248
+ return /*#__PURE__*/ _jsxs(_Fragment, {
249
+ children: [
250
+ /*#__PURE__*/ _jsx("span", {
251
+ children: "("
252
+ }),
253
+ showChildren && formatNode(node.expr, showChildren, childMaxDepth),
254
+ /*#__PURE__*/ _jsx("span", {
255
+ children: ")"
256
+ })
257
+ ]
258
+ });
259
+ case nodeType.call:
260
+ {
261
+ const children = childMaxDepth === undefined || childMaxDepth > 0 ? node.args.map((arg, i)=>/*#__PURE__*/ _jsxs("span", {
262
+ children: [
263
+ i !== 0 && ', ',
264
+ formatNode(arg, showChildren)
265
+ ]
266
+ }, i)) : node.args.length > 0 ? ellipsis : '';
267
+ return /*#__PURE__*/ _jsxs(_Fragment, {
268
+ children: [
269
+ /*#__PURE__*/ _jsx(PromQLFunction, {
270
+ children: node.func.name
271
+ }),
272
+ showChildren && /*#__PURE__*/ _jsxs(_Fragment, {
273
+ children: [
274
+ /*#__PURE__*/ _jsx("span", {
275
+ children: "("
276
+ }),
277
+ children,
278
+ /*#__PURE__*/ _jsx("span", {
279
+ children: ")"
280
+ })
281
+ ]
282
+ })
283
+ ]
284
+ });
285
+ }
286
+ case nodeType.matrixSelector:
287
+ return formatSelector(node);
288
+ case nodeType.vectorSelector:
289
+ return formatSelector(node);
290
+ case nodeType.numberLiteral:
291
+ return /*#__PURE__*/ _jsx(PromQLNumber, {
292
+ children: node.val
293
+ });
294
+ case nodeType.stringLiteral:
295
+ return /*#__PURE__*/ _jsxs(PromQLString, {
296
+ children: [
297
+ '"',
298
+ escapeString(node.val),
299
+ '"'
300
+ ]
301
+ });
302
+ case nodeType.unaryExpr:
303
+ return /*#__PURE__*/ _jsxs(_Fragment, {
304
+ children: [
305
+ /*#__PURE__*/ _jsx(PromQLOperator, {
306
+ children: node.op
307
+ }),
308
+ showChildren && formatNode(node.expr, showChildren, childMaxDepth)
309
+ ]
310
+ });
311
+ case nodeType.binaryExpr:
312
+ {
313
+ let matching = /*#__PURE__*/ _jsx(_Fragment, {});
314
+ let grouping = /*#__PURE__*/ _jsx(_Fragment, {});
315
+ const vm = node.matching;
316
+ if (vm !== null && (vm.labels.length > 0 || vm.on)) {
317
+ if (vm.on) {
318
+ matching = /*#__PURE__*/ _jsxs(_Fragment, {
319
+ children: [
320
+ ' ',
321
+ /*#__PURE__*/ _jsx(PromQLKeyword, {
322
+ children: "on"
323
+ }),
324
+ /*#__PURE__*/ _jsx("span", {
325
+ children: "("
326
+ }),
327
+ labelNameList(vm.labels),
328
+ /*#__PURE__*/ _jsx("span", {
329
+ children: ")"
330
+ })
331
+ ]
332
+ });
333
+ } else {
334
+ matching = /*#__PURE__*/ _jsxs(_Fragment, {
335
+ children: [
336
+ ' ',
337
+ /*#__PURE__*/ _jsx(PromQLKeyword, {
338
+ children: "ignoring"
339
+ }),
340
+ /*#__PURE__*/ _jsx("span", {
341
+ children: "("
342
+ }),
343
+ labelNameList(vm.labels),
344
+ /*#__PURE__*/ _jsx("span", {
345
+ children: ")"
346
+ })
347
+ ]
348
+ });
349
+ }
350
+ if (vm.card === vectorMatchCardinality.manyToOne || vm.card === vectorMatchCardinality.oneToMany) {
351
+ grouping = /*#__PURE__*/ _jsxs(_Fragment, {
352
+ children: [
353
+ /*#__PURE__*/ _jsxs(PromQLKeyword, {
354
+ children: [
355
+ ' ',
356
+ "group_",
357
+ vm.card === vectorMatchCardinality.manyToOne ? 'left' : 'right'
358
+ ]
359
+ }),
360
+ /*#__PURE__*/ _jsx("span", {
361
+ children: "("
362
+ }),
363
+ labelNameList(vm.include),
364
+ /*#__PURE__*/ _jsx("span", {
365
+ children: ")"
366
+ })
367
+ ]
368
+ });
369
+ }
370
+ }
371
+ return /*#__PURE__*/ _jsxs(_Fragment, {
372
+ children: [
373
+ showChildren && formatNode(maybeParenthesizeBinopChild(node.op, node.lhs), showChildren, childMaxDepth),
374
+ ' ',
375
+ [
376
+ 'atan2',
377
+ 'and',
378
+ 'or',
379
+ 'unless'
380
+ ].includes(node.op) ? /*#__PURE__*/ _jsx(PromQLOperator, {
381
+ children: node.op
382
+ }) : /*#__PURE__*/ _jsx(PromQLOperator, {
383
+ children: node.op
384
+ }),
385
+ node.bool && /*#__PURE__*/ _jsxs(_Fragment, {
386
+ children: [
387
+ ' ',
388
+ /*#__PURE__*/ _jsx(PromQLKeyword, {
389
+ children: "bool"
390
+ })
391
+ ]
392
+ }),
393
+ matching,
394
+ grouping,
395
+ ' ',
396
+ showChildren && formatNode(maybeParenthesizeBinopChild(node.op, node.rhs), showChildren, childMaxDepth)
397
+ ]
398
+ });
399
+ }
400
+ case nodeType.placeholder:
401
+ // TODO: Include possible children of placeholders somehow?
402
+ return ellipsis;
403
+ default:
404
+ throw new Error('unsupported node type');
405
+ }
406
+ };
407
+ export const formatNode = (node, showChildren, maxDepth)=>/*#__PURE__*/ _jsx(PromQLCode, {
408
+ children: formatNodeInternal(node, showChildren, maxDepth)
409
+ });
410
+
411
+ //# sourceMappingURL=format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/promql/format.tsx"],"sourcesContent":["// Copyright 2024 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\n// Forked from https://github.com/prometheus/prometheus/blob/65f610353919b1c7b42d3776c3a95b68046a6bba/web/ui/mantine-ui/src/promql/format.tsx\n\nimport React, { ReactElement, ReactNode } from 'react';\nimport { styled } from '@mui/material';\nimport { formatDuration, msToPrometheusDuration } from '@perses-dev/core';\nimport ASTNode, {\n VectorSelector,\n matchType,\n vectorMatchCardinality,\n nodeType,\n StartOrEnd,\n MatrixSelector,\n} from './ast';\nimport { maybeParenthesizeBinopChild, escapeString } from './utils';\n\n// Styled components that reproduce the theming of CodeMirror:\n\nconst PromQLCode = styled('span')(() => ({\n fontFamily: '\"DejaVu Sans Mono\", monospace',\n}));\n\nconst PromQLKeyword = styled('span')(({ theme }) => ({\n color: theme.palette.mode === 'dark' ? '#e5c07b' : '#708',\n}));\n\nconst PromQLFunction = styled('span')(({ theme }) => ({\n color: theme.palette.mode === 'dark' ? '#61afef' : '#2a2e42',\n}));\n\nconst PromQLMetricName = styled('span')(({ theme }) => ({\n color: theme.palette.mode === 'dark' ? '#e06c75' : '#2a2e42',\n}));\n\nconst PromQLLabelName = styled('span')(({ theme }) => ({\n color: theme.palette.mode === 'dark' ? '#61afef' : '#219',\n}));\n\nconst PromQLString = styled('span')(({ theme }) => ({\n color: theme.palette.mode === 'dark' ? '#98c379' : '#a31515',\n}));\n\nconst PromQLEllipsis = styled('span')(() => ({\n color: '#aaaaaa', // Same color for both modes as in the original CSS\n}));\n\nconst PromQLDuration = styled('span')(({ theme }) => ({\n color: theme.palette.mode === 'dark' ? '#e5c07b' : '#09885a',\n}));\n\nconst PromQLNumber = styled('span')(({ theme }) => ({\n color: theme.palette.mode === 'dark' ? '#e5c07b' : '#164',\n}));\n\nconst PromQLOperator = styled('span')(({ theme }) => ({\n color: theme.palette.mode === 'dark' ? '#56b6c2' : '#708',\n}));\n\nexport const labelNameList = (labels: string[]): React.ReactNode[] => {\n return labels.map((l, i) => {\n return (\n <span key={i}>\n {i !== 0 && ', '}\n <PromQLLabelName>{l}</PromQLLabelName>\n </span>\n );\n });\n};\n\nconst formatAtAndOffset = (timestamp: number | null, startOrEnd: StartOrEnd, offset: number): ReactNode => (\n <>\n {timestamp !== null ? (\n <>\n {' '}\n <PromQLOperator>@</PromQLOperator> <PromQLNumber>{(timestamp / 1000).toFixed(3)}</PromQLNumber>\n </>\n ) : startOrEnd !== null ? (\n <>\n {' '}\n <PromQLOperator>@</PromQLOperator> <PromQLKeyword>{startOrEnd}</PromQLKeyword>\n <span>(</span>\n <span>)</span>\n </>\n ) : (\n <></>\n )}\n {offset === 0 ? (\n <></>\n ) : offset > 0 ? (\n <>\n {' '}\n <PromQLKeyword>offset</PromQLKeyword>{' '}\n <PromQLDuration>{formatDuration(msToPrometheusDuration(offset))}</PromQLDuration>\n </>\n ) : (\n <>\n {' '}\n <PromQLKeyword>offset</PromQLKeyword>{' '}\n <PromQLDuration>-{formatDuration(msToPrometheusDuration(-offset))}</PromQLDuration>\n </>\n )}\n </>\n);\n\nconst formatSelector = (node: VectorSelector | MatrixSelector): ReactElement => {\n const matchLabels = node.matchers\n .filter((m) => !(m.name === '__name__' && m.type === matchType.equal && m.value === node.name))\n .map((m, i) => (\n <span key={i}>\n {i !== 0 && ','}\n <PromQLLabelName>{m.name}</PromQLLabelName>\n {m.type}\n <PromQLString>&quot;{escapeString(m.value)}&quot;</PromQLString>\n </span>\n ));\n\n return (\n <>\n <PromQLMetricName>{node.name}</PromQLMetricName>\n {matchLabels.length > 0 && (\n <>\n {'{'}\n <span>{matchLabels}</span>\n {'}'}\n </>\n )}\n {node.type === nodeType.matrixSelector && (\n <>\n [<PromQLDuration>{formatDuration(msToPrometheusDuration(node.range))}</PromQLDuration>]\n </>\n )}\n {formatAtAndOffset(node.timestamp, node.startOrEnd, node.offset)}\n </>\n );\n};\n\nconst ellipsis = <PromQLEllipsis>…</PromQLEllipsis>;\n\nconst formatNodeInternal = (node: ASTNode, showChildren: boolean, maxDepth?: number): React.ReactNode => {\n if (maxDepth === 0) {\n return ellipsis;\n }\n\n const childMaxDepth = maxDepth === undefined ? undefined : maxDepth - 1;\n\n switch (node.type) {\n case nodeType.aggregation:\n return (\n <>\n <PromQLOperator>{node.op}</PromQLOperator>\n {node.without ? (\n <>\n {' '}\n <PromQLKeyword>without</PromQLKeyword>\n <span>(</span>\n {labelNameList(node.grouping)}\n <span>)</span>{' '}\n </>\n ) : (\n node.grouping.length > 0 && (\n <>\n {' '}\n <PromQLKeyword>by</PromQLKeyword>\n <span>(</span>\n {labelNameList(node.grouping)}\n <span>)</span>{' '}\n </>\n )\n )}\n {showChildren && (\n <>\n <span>(</span>\n {node.param !== null && <>{formatNode(node.param, showChildren, childMaxDepth)}, </>}\n {formatNode(node.expr, showChildren, childMaxDepth)}\n <span>)</span>\n </>\n )}\n </>\n );\n case nodeType.subquery:\n return (\n <>\n {showChildren && formatNode(node.expr, showChildren, childMaxDepth)}[\n <PromQLDuration>{formatDuration(msToPrometheusDuration(node.range))}</PromQLDuration>:\n {node.step !== 0 && <PromQLDuration>{formatDuration(msToPrometheusDuration(node.step))}</PromQLDuration>}]\n {formatAtAndOffset(node.timestamp, node.startOrEnd, node.offset)}\n </>\n );\n case nodeType.parenExpr:\n return (\n <>\n <span>(</span>\n {showChildren && formatNode(node.expr, showChildren, childMaxDepth)}\n <span>)</span>\n </>\n );\n case nodeType.call: {\n const children =\n childMaxDepth === undefined || childMaxDepth > 0\n ? node.args.map((arg, i) => (\n <span key={i}>\n {i !== 0 && ', '}\n {formatNode(arg, showChildren)}\n </span>\n ))\n : node.args.length > 0\n ? ellipsis\n : '';\n\n return (\n <>\n <PromQLFunction>{node.func.name}</PromQLFunction>\n {showChildren && (\n <>\n <span>(</span>\n {children}\n <span>)</span>\n </>\n )}\n </>\n );\n }\n case nodeType.matrixSelector:\n return formatSelector(node);\n case nodeType.vectorSelector:\n return formatSelector(node);\n case nodeType.numberLiteral:\n return <PromQLNumber>{node.val}</PromQLNumber>;\n case nodeType.stringLiteral:\n return <PromQLString>&quot;{escapeString(node.val)}&quot;</PromQLString>;\n case nodeType.unaryExpr:\n return (\n <>\n <PromQLOperator>{node.op}</PromQLOperator>\n {showChildren && formatNode(node.expr, showChildren, childMaxDepth)}\n </>\n );\n case nodeType.binaryExpr: {\n let matching = <></>;\n let grouping = <></>;\n const vm = node.matching;\n if (vm !== null && (vm.labels.length > 0 || vm.on)) {\n if (vm.on) {\n matching = (\n <>\n {' '}\n <PromQLKeyword>on</PromQLKeyword>\n <span>(</span>\n {labelNameList(vm.labels)}\n <span>)</span>\n </>\n );\n } else {\n matching = (\n <>\n {' '}\n <PromQLKeyword>ignoring</PromQLKeyword>\n <span>(</span>\n {labelNameList(vm.labels)}\n <span>)</span>\n </>\n );\n }\n\n if (vm.card === vectorMatchCardinality.manyToOne || vm.card === vectorMatchCardinality.oneToMany) {\n grouping = (\n <>\n <PromQLKeyword>\n {' '}\n group_\n {vm.card === vectorMatchCardinality.manyToOne ? 'left' : 'right'}\n </PromQLKeyword>\n <span>(</span>\n {labelNameList(vm.include)}\n <span>)</span>\n </>\n );\n }\n }\n\n return (\n <>\n {showChildren && formatNode(maybeParenthesizeBinopChild(node.op, node.lhs), showChildren, childMaxDepth)}{' '}\n {['atan2', 'and', 'or', 'unless'].includes(node.op) ? (\n <PromQLOperator>{node.op}</PromQLOperator>\n ) : (\n <PromQLOperator>{node.op}</PromQLOperator>\n )}\n {node.bool && (\n <>\n {' '}\n <PromQLKeyword>bool</PromQLKeyword>\n </>\n )}\n {matching}\n {grouping}{' '}\n {showChildren && formatNode(maybeParenthesizeBinopChild(node.op, node.rhs), showChildren, childMaxDepth)}\n </>\n );\n }\n case nodeType.placeholder:\n // TODO: Include possible children of placeholders somehow?\n return ellipsis;\n default:\n throw new Error('unsupported node type');\n }\n};\n\nexport const formatNode = (node: ASTNode, showChildren: boolean, maxDepth?: number): React.ReactElement => (\n <PromQLCode>{formatNodeInternal(node, showChildren, maxDepth)}</PromQLCode>\n);\n"],"names":["React","styled","formatDuration","msToPrometheusDuration","matchType","vectorMatchCardinality","nodeType","maybeParenthesizeBinopChild","escapeString","PromQLCode","fontFamily","PromQLKeyword","theme","color","palette","mode","PromQLFunction","PromQLMetricName","PromQLLabelName","PromQLString","PromQLEllipsis","PromQLDuration","PromQLNumber","PromQLOperator","labelNameList","labels","map","l","i","span","formatAtAndOffset","timestamp","startOrEnd","offset","toFixed","formatSelector","node","matchLabels","matchers","filter","m","name","type","equal","value","length","matrixSelector","range","ellipsis","formatNodeInternal","showChildren","maxDepth","childMaxDepth","undefined","aggregation","op","without","grouping","param","formatNode","expr","subquery","step","parenExpr","call","children","args","arg","func","vectorSelector","numberLiteral","val","stringLiteral","unaryExpr","binaryExpr","matching","vm","on","card","manyToOne","oneToMany","include","lhs","includes","bool","rhs","placeholder","Error"],"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,6IAA6I;;AAE7I,OAAOA,WAAwC,QAAQ;AACvD,SAASC,MAAM,QAAQ,gBAAgB;AACvC,SAASC,cAAc,EAAEC,sBAAsB,QAAQ,mBAAmB;AAC1E,SAEEC,SAAS,EACTC,sBAAsB,EACtBC,QAAQ,QAGH,QAAQ;AACf,SAASC,2BAA2B,EAAEC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G;QACA,KAAK9C,SAASgF,WAAW;YACvB,2DAA2D;YAC3D,OAAOtC;QACT;YACE,MAAM,IAAIuC,MAAM;IACpB;AACF;AAEA,OAAO,MAAM5B,aAAa,CAACvB,MAAec,cAAuBC,yBAC/D,KAAC1C;kBAAYwC,mBAAmBb,MAAMc,cAAcC;OACpD"}
@@ -0,0 +1,5 @@
1
+ import ASTNode, { binaryOperatorType } from './ast';
2
+ export declare const maybeParenthesizeBinopChild: (op: binaryOperatorType, child: ASTNode) => ASTNode;
3
+ export declare const getNodeChildren: (node: ASTNode) => ASTNode[];
4
+ export declare const escapeString: (str: string) => string;
5
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/promql/utils.ts"],"names":[],"mappings":"AAeA,OAAO,OAAO,EAAE,EAAE,kBAAkB,EAAY,MAAM,OAAO,CAAC;AAqB9D,eAAO,MAAM,2BAA2B,OAAQ,kBAAkB,SAAS,OAAO,KAAG,OAepF,CAAC;AAEF,eAAO,MAAM,eAAe,SAAU,OAAO,KAAG,OAAO,EAwBtD,CAAC;AAEF,eAAO,MAAM,YAAY,QAAS,MAAM,WAEvC,CAAC"}