@perses-dev/prometheus-plugin 0.28.0 → 0.29.1
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/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +4 -3
- package/dist/cjs/utils/utils.js +5 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +4 -3
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +8 -3
- package/dist/utils/utils.js.map +1 -1
- package/package.json +4 -4
|
@@ -59,11 +59,12 @@ function PrometheusTimeSeriesQueryEditor(props) {
|
|
|
59
59
|
}),
|
|
60
60
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
61
61
|
fullWidth: true,
|
|
62
|
-
label: "
|
|
62
|
+
label: "Legend Name",
|
|
63
|
+
placeholder: "Tip: Use {{label_name}}. Example: {{instance}} will be replaced with values such as 'webserver-123' and 'webserver-456'.",
|
|
64
|
+
helperText: "Set the name for each series in the legend and the tooltip.",
|
|
63
65
|
value: format !== null && format !== void 0 ? format : '',
|
|
64
66
|
onChange: (e)=>handleFormatChange(e.target.value),
|
|
65
|
-
onBlur: handleFormatBlur
|
|
66
|
-
margin: "dense"
|
|
67
|
+
onBlur: handleFormatBlur
|
|
67
68
|
}),
|
|
68
69
|
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
|
|
69
70
|
margin: "dense",
|
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -68,7 +68,11 @@ const parseTemplateVariables = (text)=>{
|
|
|
68
68
|
};
|
|
69
69
|
function formatSeriesName(inputFormat, seriesLabels) {
|
|
70
70
|
const resolveLabelsRegex = /\{\{\s*(.+?)\s*\}\}/g;
|
|
71
|
-
return inputFormat.replace(resolveLabelsRegex, (
|
|
71
|
+
return inputFormat.replace(resolveLabelsRegex, (_match, token)=>{
|
|
72
|
+
var _token;
|
|
73
|
+
const resolvedValue = (_token = seriesLabels[token]) !== null && _token !== void 0 ? _token : '';
|
|
74
|
+
return resolvedValue;
|
|
75
|
+
});
|
|
72
76
|
}
|
|
73
77
|
/*
|
|
74
78
|
* Stringifies object of labels into valid PromQL for querying metric by label
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,oCAAoC,EAAiC,MAAM,sBAAsB,CAAC;AAE3G;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,
|
|
1
|
+
{"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,oCAAoC,EAAiC,MAAM,sBAAsB,CAAC;AAE3G;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,eAyD1F"}
|
|
@@ -53,11 +53,12 @@ import { useQueryState, useFormatState } from './query-editor-model';
|
|
|
53
53
|
}),
|
|
54
54
|
/*#__PURE__*/ _jsx(TextField, {
|
|
55
55
|
fullWidth: true,
|
|
56
|
-
label: "
|
|
56
|
+
label: "Legend Name",
|
|
57
|
+
placeholder: "Tip: Use {{label_name}}. Example: {{instance}} will be replaced with values such as 'webserver-123' and 'webserver-456'.",
|
|
58
|
+
helperText: "Set the name for each series in the legend and the tooltip.",
|
|
57
59
|
value: format !== null && format !== void 0 ? format : '',
|
|
58
60
|
onChange: (e)=>handleFormatChange(e.target.value),
|
|
59
|
-
onBlur: handleFormatBlur
|
|
60
|
-
margin: "dense"
|
|
61
|
+
onBlur: handleFormatBlur
|
|
61
62
|
}),
|
|
62
63
|
/*#__PURE__*/ _jsxs(FormControl, {
|
|
63
64
|
margin: "dense",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2023 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 { Stack, TextField, FormControl, InputLabel } from '@mui/material';\nimport { DatasourceSelect, DatasourceSelectProps, useDatasourceClient } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PrometheusClient } from '../../model';\nimport { PromQLEditor } from '../../components';\nimport { PrometheusTimeSeriesQueryEditorProps, useQueryState, useFormatState } 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 const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(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 <Stack spacing={2}>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={query}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n />\n <TextField\n fullWidth\n label=\"
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2023 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 { Stack, TextField, FormControl, InputLabel } from '@mui/material';\nimport { DatasourceSelect, DatasourceSelectProps, useDatasourceClient } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PrometheusClient } from '../../model';\nimport { PromQLEditor } from '../../components';\nimport { PrometheusTimeSeriesQueryEditorProps, useQueryState, useFormatState } 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 const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(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 <Stack spacing={2}>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={query}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n />\n <TextField\n fullWidth\n label=\"Legend Name\"\n placeholder=\"Tip: Use {{label_name}}. Example: {{instance}} will be replaced with values such as 'webserver-123' and 'webserver-456'.\"\n helperText=\"Set the name for each series in the legend and the tooltip.\"\n value={format ?? ''}\n onChange={(e) => handleFormatChange(e.target.value)}\n onBlur={handleFormatBlur}\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={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n </Stack>\n );\n}\n"],"names":["produce","Stack","TextField","FormControl","InputLabel","DatasourceSelect","useDatasourceClient","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PromQLEditor","useQueryState","useFormatState","PrometheusTimeSeriesQueryEditor","props","onChange","value","datasource","selectedDatasource","data","client","promURL","options","datasourceUrl","query","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","spacing","completeConfig","remote","url","onBlur","fullWidth","label","placeholder","helperText","e","target","margin","id","datasourcePluginKind","labelId"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC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K,EAAC,uBAAuB;sBAC7B;;cACU;;MACR,CACR;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAiB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,MAAM,CAW9F;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,aAAa,UAW1G;AAMD;;GAEG;AACH,eAAO,MAAM,sBAAsB,SAAU,MAAM,aAYlD,CAAC;AAEF;;GAEG;AACH,oBAAY,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAiB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,gBAAgB,GAAG,MAAM,CAW9F;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,aAAa,UAW1G;AAMD;;GAEG;AACH,eAAO,MAAM,sBAAsB,SAAU,MAAM,aAYlD,CAAC;AAEF;;GAEG;AACH,oBAAY,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAOlD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM,CAMxF;AAyBD,wBAAgB,+BAA+B,CAC7C,YAAY,EAAE;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,EACD,EAAE,cAAc,EAAE,GAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAO,UAqBtD;AAKD,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;;;EAYjG"}
|
package/dist/utils/utils.js
CHANGED
|
@@ -51,11 +51,16 @@ const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?
|
|
|
51
51
|
return Array.from(matches.values());
|
|
52
52
|
};
|
|
53
53
|
/*
|
|
54
|
-
* Formatter used for series name display in legends and tooltips
|
|
55
|
-
* Regex replaces label {{ name }} with resolved label value
|
|
54
|
+
* Formatter used for series name display in legends and tooltips.
|
|
55
|
+
* Regex replaces label {{ name }} with resolved label value.
|
|
56
|
+
* If no resolved value, return empty string instead of the token inside double curly braces.
|
|
56
57
|
*/ export function formatSeriesName(inputFormat, seriesLabels) {
|
|
57
58
|
const resolveLabelsRegex = /\{\{\s*(.+?)\s*\}\}/g;
|
|
58
|
-
return inputFormat.replace(resolveLabelsRegex, (
|
|
59
|
+
return inputFormat.replace(resolveLabelsRegex, (_match, token)=>{
|
|
60
|
+
var _token;
|
|
61
|
+
const resolvedValue = (_token = seriesLabels[token]) !== null && _token !== void 0 ? _token : '';
|
|
62
|
+
return resolvedValue;
|
|
63
|
+
});
|
|
59
64
|
}
|
|
60
65
|
/*
|
|
61
66
|
* Stringifies object of labels into valid PromQL for querying metric by label
|
package/dist/utils/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/utils.ts"],"sourcesContent":["// Copyright 2023 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 { isEmptyObject, VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\nimport { Metric } from '../model/api-types';\n\nexport function replaceTemplateVariables(text: string, variableState: VariableStateMap): string {\n const variables = parseTemplateVariables(text);\n let finalText = text;\n variables.forEach((v) => {\n const variable = variableState[v];\n if (variable && variable?.value) {\n finalText = replaceTemplateVariable(finalText, v, variable?.value);\n }\n });\n\n return finalText;\n}\n\nexport function replaceTemplateVariable(text: string, varName: string, templateVariableValue: VariableValue) {\n const variableTemplate = '$' + varName;\n let replaceString = '';\n if (Array.isArray(templateVariableValue)) {\n replaceString = `(${templateVariableValue.join('|')})`; // regex style\n }\n if (typeof templateVariableValue === 'string') {\n replaceString = templateVariableValue;\n }\n\n return text.replaceAll(variableTemplate, replaceString);\n}\n\n// TODO: Fix this lint error\n// eslint-disable-next-line no-useless-escape\nconst TEMPLATE_VARIABLE_REGEX = /\\$(\\w+)|\\${(\\w+)(?:\\.([^:^\\}]+))?(?::([^\\}]+))?}/gm;\n\n/**\n * Returns a list of template variables\n */\nexport const parseTemplateVariables = (text: string) => {\n const regex = TEMPLATE_VARIABLE_REGEX;\n const matches = new Set<string>();\n let match;\n\n while ((match = regex.exec(text)) !== null) {\n if (match && match.length > 1 && match[1]) {\n matches.add(match[1]);\n }\n }\n // return unique matches\n return Array.from(matches.values());\n};\n\n/**\n * Types for metric labels, used in series_name_format implementation\n */\nexport type SeriesLabels = Record<string, string>;\n\n/*\n * Formatter used for series name display in legends and tooltips
|
|
1
|
+
{"version":3,"sources":["../../src/utils/utils.ts"],"sourcesContent":["// Copyright 2023 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 { isEmptyObject, VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\nimport { Metric } from '../model/api-types';\n\nexport function replaceTemplateVariables(text: string, variableState: VariableStateMap): string {\n const variables = parseTemplateVariables(text);\n let finalText = text;\n variables.forEach((v) => {\n const variable = variableState[v];\n if (variable && variable?.value) {\n finalText = replaceTemplateVariable(finalText, v, variable?.value);\n }\n });\n\n return finalText;\n}\n\nexport function replaceTemplateVariable(text: string, varName: string, templateVariableValue: VariableValue) {\n const variableTemplate = '$' + varName;\n let replaceString = '';\n if (Array.isArray(templateVariableValue)) {\n replaceString = `(${templateVariableValue.join('|')})`; // regex style\n }\n if (typeof templateVariableValue === 'string') {\n replaceString = templateVariableValue;\n }\n\n return text.replaceAll(variableTemplate, replaceString);\n}\n\n// TODO: Fix this lint error\n// eslint-disable-next-line no-useless-escape\nconst TEMPLATE_VARIABLE_REGEX = /\\$(\\w+)|\\${(\\w+)(?:\\.([^:^\\}]+))?(?::([^\\}]+))?}/gm;\n\n/**\n * Returns a list of template variables\n */\nexport const parseTemplateVariables = (text: string) => {\n const regex = TEMPLATE_VARIABLE_REGEX;\n const matches = new Set<string>();\n let match;\n\n while ((match = regex.exec(text)) !== null) {\n if (match && match.length > 1 && match[1]) {\n matches.add(match[1]);\n }\n }\n // return unique matches\n return Array.from(matches.values());\n};\n\n/**\n * Types for metric labels, used in series_name_format implementation\n */\nexport type SeriesLabels = Record<string, string>;\n\n/*\n * Formatter used for series name display in legends and tooltips.\n * Regex replaces label {{ name }} with resolved label value.\n * If no resolved value, return empty string instead of the token inside double curly braces.\n */\nexport function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string {\n const resolveLabelsRegex = /\\{\\{\\s*(.+?)\\s*\\}\\}/g;\n return inputFormat.replace(resolveLabelsRegex, (_match, token) => {\n const resolvedValue = seriesLabels[token] ?? '';\n return resolvedValue;\n });\n}\n\n/*\n * Stringifies object of labels into valid PromQL for querying metric by label\n */\nfunction stringifyPrometheusMetricLabels(labels: { [key: string]: unknown }, removeExprWrap?: boolean) {\n const labelStrings: string[] = [];\n Object.keys(labels)\n .sort()\n .forEach((labelName) => {\n const labelValue = labels[labelName];\n if (labelValue !== undefined) {\n if (removeExprWrap) {\n labelStrings.push(`\"${labelName}\":\"${labelValue}\"`);\n } else {\n labelStrings.push(`${labelName}=\"${labelValue}\"`);\n }\n }\n });\n return `{${labelStrings.join(',')}}`;\n}\n\n/*\n * Metric labels formattter which checks for __name__ and outputs valid PromQL for series name\n */\nexport function getUniqueKeyForPrometheusResult(\n metricLabels: {\n [key: string]: string;\n },\n { removeExprWrap }: { removeExprWrap?: boolean } = {}\n) {\n const metricNameKey = '__name__';\n if (metricLabels) {\n if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {\n const stringifiedLabels = stringifyPrometheusMetricLabels(\n {\n ...metricLabels,\n [metricNameKey]: undefined,\n },\n removeExprWrap\n );\n if (removeExprWrap === true) {\n return `${stringifiedLabels}`;\n } else {\n return `${metricLabels[metricNameKey]}${stringifiedLabels}`;\n }\n }\n return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);\n }\n return '';\n}\n\n/*\n * Determine human-readable series name to be used in legend and tooltip\n */\nexport function getFormattedPrometheusSeriesName(query: string, metric: Metric, formatter?: string) {\n // Name the series after the metric labels by default.\n // Use the query if no metric or metric labels are empty.\n let name = getUniqueKeyForPrometheusResult(metric);\n if (name === '' || isEmptyObject(metric)) {\n name = query;\n }\n\n // Query editor allows you to define an optional series_name_format property.\n // This controls the regex used to customize legend and tooltip display.\n const formattedName = formatter ? formatSeriesName(formatter, metric) : name;\n return { name, formattedName };\n}\n"],"names":["isEmptyObject","replaceTemplateVariables","text","variableState","variables","parseTemplateVariables","finalText","forEach","v","variable","value","replaceTemplateVariable","varName","templateVariableValue","variableTemplate","replaceString","Array","isArray","join","replaceAll","TEMPLATE_VARIABLE_REGEX","regex","matches","Set","match","exec","length","add","from","values","formatSeriesName","inputFormat","seriesLabels","resolveLabelsRegex","replace","_match","token","resolvedValue","stringifyPrometheusMetricLabels","labels","removeExprWrap","labelStrings","Object","keys","sort","labelName","labelValue","undefined","push","getUniqueKeyForPrometheusResult","metricLabels","metricNameKey","prototype","hasOwnProperty","call","stringifiedLabels","getFormattedPrometheusSeriesName","query","metric","formatter","name","formattedName"],"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,aAAa,QAAuB,kBAAkB,CAAC;AAIhE,OAAO,SAASC,wBAAwB,CAACC,IAAY,EAAEC,aAA+B,EAAU;IAC9F,MAAMC,SAAS,GAAGC,sBAAsB,CAACH,IAAI,CAAC,AAAC;IAC/C,IAAII,SAAS,GAAGJ,IAAI,AAAC;IACrBE,SAAS,CAACG,OAAO,CAAC,CAACC,CAAC,GAAK;QACvB,MAAMC,QAAQ,GAAGN,aAAa,CAACK,CAAC,CAAC,AAAC;QAClC,IAAIC,QAAQ,IAAIA,CAAAA,QAAQ,aAARA,QAAQ,WAAO,GAAfA,KAAAA,CAAe,GAAfA,QAAQ,CAAEC,KAAK,CAAA,EAAE;YAC/BJ,SAAS,GAAGK,uBAAuB,CAACL,SAAS,EAAEE,CAAC,EAAEC,QAAQ,aAARA,QAAQ,WAAO,GAAfA,KAAAA,CAAe,GAA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version": "0.29.1",
|
|
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",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@lezer/highlight": "^1.0.0",
|
|
33
33
|
"@lezer/lr": "^1.2.0",
|
|
34
|
-
"@perses-dev/components": "0.
|
|
35
|
-
"@perses-dev/core": "0.
|
|
36
|
-
"@perses-dev/plugin-system": "0.
|
|
34
|
+
"@perses-dev/components": "0.29.1",
|
|
35
|
+
"@perses-dev/core": "0.29.1",
|
|
36
|
+
"@perses-dev/plugin-system": "0.29.1",
|
|
37
37
|
"@prometheus-io/codemirror-promql": "^0.43.0",
|
|
38
38
|
"@uiw/react-codemirror": "^4.19.1",
|
|
39
39
|
"date-fns": "^2.28.0",
|