@perses-dev/prometheus-plugin 0.21.1 → 0.22.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/PromQL.js +56 -0
- package/dist/cjs/components/index.js +28 -0
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/model/api-types.js +1 -1
- package/dist/cjs/model/index.js +1 -2
- package/dist/cjs/model/parse-sample-values.js +1 -1
- package/dist/cjs/model/prometheus-client.js +1 -1
- package/dist/cjs/model/prometheus-selectors.js +1 -1
- package/dist/cjs/model/templating.js +2 -2
- package/dist/cjs/model/time.js +1 -1
- package/dist/cjs/plugins/MatcherEditor.js +1 -1
- package/dist/cjs/plugins/prometheus-datasource.js +4 -1
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +3 -3
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +14 -8
- package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +9 -7
- package/dist/cjs/plugins/prometheus-time-series-query/index.js +1 -1
- package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +3 -3
- package/dist/cjs/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
- package/dist/cjs/plugins/prometheus-variables.js +10 -9
- package/dist/cjs/plugins/types.js +1 -1
- package/dist/cjs/plugins/variable.js +1 -1
- package/dist/cjs/test/setup-tests.js +1 -1
- package/dist/cjs/utils/index.js +28 -0
- package/dist/cjs/{model → utils}/utils.js +37 -2
- package/dist/cjs/{model → utils}/utils.test.js +47 -1
- package/dist/components/PromQL.d.ts +8 -0
- package/dist/components/PromQL.d.ts.map +1 -0
- package/dist/components/PromQL.js +45 -0
- package/dist/components/PromQL.js.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +15 -0
- package/dist/components/index.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/model/api-types.js +1 -1
- package/dist/model/api-types.js.map +1 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -2
- package/dist/model/index.js.map +1 -1
- package/dist/model/parse-sample-values.js +1 -1
- package/dist/model/parse-sample-values.js.map +1 -1
- package/dist/model/prometheus-client.d.ts +5 -0
- package/dist/model/prometheus-client.d.ts.map +1 -1
- package/dist/model/prometheus-client.js +1 -1
- package/dist/model/prometheus-client.js.map +1 -1
- package/dist/model/prometheus-selectors.js +1 -1
- package/dist/model/prometheus-selectors.js.map +1 -1
- package/dist/model/templating.js +2 -2
- package/dist/model/templating.js.map +1 -1
- package/dist/model/time.js +1 -1
- package/dist/model/time.js.map +1 -1
- package/dist/plugins/MatcherEditor.js +1 -1
- package/dist/plugins/MatcherEditor.js.map +1 -1
- package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
- package/dist/plugins/prometheus-datasource.js +4 -1
- package/dist/plugins/prometheus-datasource.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +2 -2
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.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 +15 -9
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +8 -6
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/index.js +1 -1
- package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +4 -5
- package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js +3 -3
- package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
- package/dist/plugins/prometheus-variables.d.ts.map +1 -1
- package/dist/plugins/prometheus-variables.js +3 -2
- package/dist/plugins/prometheus-variables.js.map +1 -1
- package/dist/plugins/types.js +1 -1
- package/dist/plugins/types.js.map +1 -1
- package/dist/plugins/variable.js +1 -1
- package/dist/plugins/variable.js.map +1 -1
- package/dist/test/setup-tests.js +1 -1
- package/dist/test/setup-tests.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/{model → utils}/utils.d.ts +5 -0
- package/dist/{model → utils}/utils.d.ts.map +1 -1
- package/dist/{model → utils}/utils.js +37 -1
- package/dist/utils/utils.js.map +1 -0
- package/dist/{model → utils}/utils.test.d.ts +0 -0
- package/dist/{model → utils}/utils.test.d.ts.map +1 -1
- package/dist/{model → utils}/utils.test.js +48 -2
- package/dist/utils/utils.test.js.map +1 -0
- package/package.json +6 -3
- package/dist/model/utils.js.map +0 -1
- package/dist/model/utils.test.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.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 { TimeSeriesData, TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n} from '../../model';\nimport { getUniqueKeyForPrometheusResult, replaceTemplateVariables, formatSeriesName } from '../../utils';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\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, use the query\n let name = getUniqueKeyForPrometheusResult(metric);\n if (name === '') {\n name = query;\n }\n\n // query editor allows you to define an optional series_name_format\n // property to customize legend and tooltip display\n const formattedName = spec.series_name_format ? formatSeriesName(spec.series_name_format, metric) : name;\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n };\n }),\n };\n\n return chartData;\n};\n"],"names":["fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getUniqueKeyForPrometheusResult","replaceTemplateVariables","formatSeriesName","getTimeSeriesData","spec","context","response","query","undefined","series","minStep","min_step","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","Math","floor","alignedStart","replace","variableState","client","datasourceStore","getDatasourceClient","datasource","rangeQuery","result","data","chartData","stepMs","map","value","metric","values","name","formattedName","series_name_format"],"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,YAAY,QAAQ,UAAU,CAAC;AACxC,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,QACP,aAAa,CAAC;AACrB,SAASC,+BAA+B,EAAEC,wBAAwB,EAAEC,gBAAgB,QAAQ,aAAa,CAAC;AAG1G,OAAO,MAAMC,iBAAiB,GAA8E,OAC1GC,IAAI,EACJC,OAAO,GACJ;QAmCYC,GAAa;IAlC5B,IAAIF,IAAI,CAACG,KAAK,KAAKC,SAAS,IAAIJ,IAAI,CAACG,KAAK,KAAK,IAAI,IAAIH,IAAI,CAACG,KAAK,KAAK,EAAE,EAAE;QACxE,+EAA+E;QAC/E,OAAO;YAAE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AAC;IAEF,OAAOP,SAAS,CAAC;AACnB,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/index.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/index.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\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"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
3
2
|
import { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';
|
|
4
3
|
export declare type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;
|
|
@@ -10,15 +9,15 @@ export declare type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<Pr
|
|
|
10
9
|
*/
|
|
11
10
|
export declare function useQueryState(props: PrometheusTimeSeriesQueryEditorProps): {
|
|
12
11
|
query: string;
|
|
13
|
-
handleQueryChange:
|
|
14
|
-
handleQueryBlur:
|
|
12
|
+
handleQueryChange: (e: string) => void;
|
|
13
|
+
handleQueryBlur: () => void;
|
|
15
14
|
};
|
|
16
15
|
/**
|
|
17
16
|
* Hook to manage `series_name_format` state to ensure panel preview does not rerender until text input is blurred
|
|
18
17
|
*/
|
|
19
18
|
export declare function useFormatState(props: PrometheusTimeSeriesQueryEditorProps): {
|
|
20
19
|
format: string | undefined;
|
|
21
|
-
handleFormatChange:
|
|
22
|
-
handleFormatBlur:
|
|
20
|
+
handleFormatChange: (e: string) => void;
|
|
21
|
+
handleFormatBlur: () => void;
|
|
23
22
|
};
|
|
24
23
|
//# sourceMappingURL=query-editor-model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query-editor-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"query-editor-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"names":[],"mappings":"AAeA,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;;2BAezC,MAAM;;EAgBrC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,oCAAoC;;4BAYzC,MAAM;;EAetC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -30,7 +30,7 @@ import { produce } from 'immer';
|
|
|
30
30
|
}
|
|
31
31
|
// Update our local state's copy as the user types
|
|
32
32
|
const handleQueryChange = (e)=>{
|
|
33
|
-
setQuery(e
|
|
33
|
+
setQuery(e);
|
|
34
34
|
};
|
|
35
35
|
// Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the
|
|
36
36
|
// PanelPreview
|
|
@@ -59,7 +59,7 @@ import { produce } from 'immer';
|
|
|
59
59
|
}
|
|
60
60
|
// Update our local state as the user types
|
|
61
61
|
const handleFormatChange = (e)=>{
|
|
62
|
-
setFormat(e
|
|
62
|
+
setFormat(e);
|
|
63
63
|
};
|
|
64
64
|
// Propagate changes to the panel preview component when series_name_format TextField is blurred
|
|
65
65
|
const handleFormatBlur = ()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.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 { useState } from 'react';\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 = (e: string) => {\n setQuery(e);\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 = () => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n\n/**\n * Hook to manage `series_name_format` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useFormatState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [format, setFormat] = useState(value.series_name_format);\n const [lastSyncedFormat, setLastSyncedFormat] = useState(value.series_name_format);\n if (value.series_name_format !== lastSyncedFormat) {\n setFormat(value.series_name_format);\n setLastSyncedFormat(value.series_name_format);\n }\n\n // Update our local state as the user types\n const handleFormatChange = (e: string) => {\n setFormat(e);\n };\n\n // Propagate changes to the panel preview component when series_name_format TextField is blurred\n const handleFormatBlur = () => {\n setLastSyncedFormat(format);\n onChange(\n produce(value, (draft) => {\n draft.series_name_format = format;\n })\n );\n };\n\n return { format, handleFormatChange, handleFormatBlur };\n}\n"],"names":["useState","produce","useQueryState","props","onChange","value","query","setQuery","lastSyncedQuery","setLastSyncedQuery","handleQueryChange","e","handleQueryBlur","draft","useFormatState","format","setFormat","series_name_format","lastSyncedFormat","setLastSyncedFormat","handleFormatChange","handleFormatBlur"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sE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C/E,MAAM,CAACY,MAAM,EAAEC,SAAS,CAAC,GAAGhB,QAAQ,CAACK,KAAK,CAACY,kBAAkB,CAAC,AAAC;IAC/D,MAAM,CAACC,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGnB,QAAQ,CAACK,KAAK,CAACY,kBAAkB,CAAC,AAAC;IACnF,IAAIZ,KAAK,CAACY,kBAAkB,KAAKC,gBAAgB,EAAE;QACjDF,SAAS,CAACX,KAAK,CAACY,kBAAkB,CAAC,CAAC;QACpCE,mBAAmB,CAACd,KAAK,CAACY,kBAAkB,CAAC,CAAC;IAChD,CAAC;IAED,2CAA2C;IAC3C,MAAMG,kBAAkB,GAAG,CAACT,CAAS,GAAK;QACxCK,SAAS,CAACL,CAAC,CAAC,CAAC;IACf,CAAC,AAAC;IAEF,gGAAgG;IAChG,MAAMU,gBAAgB,GAAG,IAAM;QAC7BF,mBAAmB,CAACJ,MAAM,CAAC,CAAC;QAC5BX,QAAQ,CACNH,OAAO,CAACI,KAAK,EAAE,CAACQ,KAAK,GAAK;YACxBA,KAAK,CAACI,kBAAkB,GAAGF,MAAM,CAAC;QACpC,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,OAAO;QAAEA,MAAM;QAAEK,kBAAkB;QAAEC,gBAAgB;KAAE,CAAC;AAC1D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.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 { 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 series_name_format?: string;\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,WAYC"}
|
|
@@ -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;AAI/F,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AA6FjB,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAgB5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CA8B9F,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,+BAA+B,CAwBpF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -12,7 +12,8 @@
|
|
|
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 {
|
|
15
|
+
import { DEFAULT_PROM, getPrometheusTimeRange } from '../model';
|
|
16
|
+
import { replaceTemplateVariables, parseTemplateVariables } from '../utils';
|
|
16
17
|
import { MatcherEditor } from './MatcherEditor';
|
|
17
18
|
function PrometheusLabelValuesVariableEditor(props) {
|
|
18
19
|
var _matchers;
|
|
@@ -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 {\n replaceTemplateVariables,\n parseTemplateVariables,\n PrometheusClient,\n DEFAULT_PROM,\n getPrometheusTimeRange,\n MatrixData,\n VectorData,\n} from '../model';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} 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 matchers={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 matchers={props.value.matchers ?? []}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\n}\n\nfunction PrometheusPromQLVariableEditor(props: OptionsEditorProps<PrometheusPromQLVariableOptions>) {\n return (\n <Stack spacing={1}>\n <TextField\n sx={{ mb: 1 }}\n label=\"PromQL Expression\"\n value={props.value.expr}\n onChange={(e) => {\n props.onChange({ ...props.value, expr: e.target.value });\n }}\n />\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 </Stack>\n );\n}\n\nfunction capturingMatrix(matrix: MatrixData, label_name: string): string[] {\n const captured = new Set<string>();\n for (const sample of matrix.result) {\n const value = sample.metric[label_name];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\nfunction capturingVector(vector: VectorData, label_name: string): string[] {\n const captured = new Set<string>();\n for (const sample of vector.result) {\n const value = sample.metric[label_name];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\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: (spec) => {\n return { variables: spec.matchers?.map((m) => parseTemplateVariables(m)).flat() || [] };\n },\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: replaceTemplateVariables(pluginDef.label_name, ctx.variables),\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return {\n variables:\n spec.matchers\n ?.map((m) => parseTemplateVariables(m))\n .flat()\n .concat(parseTemplateVariables(spec.label_name)) || [],\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ label_name: '' }),\n};\n\nexport const PrometheusPromQLVariable: VariablePlugin<PrometheusPromQLVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n // TODO we may want to manage a range query as well.\n const { data: options } = await client.instantQuery({\n query: replaceTemplateVariables(spec.expr, ctx.variables),\n });\n const labelName = replaceTemplateVariables(spec.label_name, ctx.variables);\n let values: string[] = [];\n if (options?.resultType === 'matrix') {\n values = capturingMatrix(options, labelName);\n } else if (options?.resultType === 'vector') {\n values = capturingVector(options, labelName);\n }\n\n return {\n data: stringArrayToVariableOptions(values),\n };\n },\n dependsOn: (spec) => {\n return { variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.label_name)) };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', 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","matchers","PrometheusLabelNamesVariableEditor","PrometheusPromQLVariableEditor","expr","capturingMatrix","matrix","captured","Set","sample","result","metric","undefined","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","client","datasourceStore","getDatasourceClient","datasource","match","m","variables","timeRange","data","options","labelNames","dependsOn","flat","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","labelName","concat","PrometheusPromQLVariable","instantQuery","query","resultType"],"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,QAGjB,UAAU,CAAC;AAMlB,SAASC,aAAa,QAAQ,iBAAiB,CAAC;AAEhD,SAASC,mCAAmC,CAACC,KAA+D,EAAE;QAY5FA,SAAoB;IAXpC,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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ACpChC,MAAM,GAAGX,eAAe,CAAC6B,OAAO,EAAES,SAAS,CAAC,CAAC;QAC/C,OAAO,IAAIT,CAAAA,OAAO,aAAPA,OAAO,WAAY,GAAnBA,KAAAA,CAAmB,GAAnBA,OAAO,CAAEc,UAAU,CAAA,KAAK,QAAQ,EAAE;YAC3ChC,MAAM,GAAGC,eAAe,CAACiB,OAAO,EAAES,SAAS,CAAC,CAAC;QAC/C,CAAC;QAED,OAAO;YACLV,IAAI,EAAEd,4BAA4B,CAACH,MAAM,CAAC;SAC3C,CAAC;IACJ,CAAC;IACDoB,SAAS,EAAE,CAACb,IAAI,GAAK;QACnB,OAAO;YAAEQ,SAAS,EAAE7C,sBAAsB,CAACqC,IAAI,CAACnB,IAAI,CAAC,CAACwC,MAAM,CAAC1D,sBAAsB,CAACqC,IAAI,CAAC1B,UAAU,CAAC,CAAC;SAAE,CAAC;IAC1G,CAAC;IACDyC,sBAAsB,EAAEnC,8BAA8B;IACtDoC,oBAAoB,EAAE,IAAO,CAAA;YAAEnC,IAAI,EAAE,EAAE;YAAEP,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CAC3D,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/prometheus-variables.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.\nimport { VariablePlugin, VariableOption, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Stack, TextField } from '@mui/material';\nimport { PrometheusClient, DEFAULT_PROM, getPrometheusTimeRange, MatrixData, VectorData } from '../model';\nimport { replaceTemplateVariables, parseTemplateVariables } from '../utils';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} 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 matchers={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 matchers={props.value.matchers ?? []}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\n}\n\nfunction PrometheusPromQLVariableEditor(props: OptionsEditorProps<PrometheusPromQLVariableOptions>) {\n return (\n <Stack spacing={1}>\n <TextField\n sx={{ mb: 1 }}\n label=\"PromQL Expression\"\n value={props.value.expr}\n onChange={(e) => {\n props.onChange({ ...props.value, expr: e.target.value });\n }}\n />\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 </Stack>\n );\n}\n\nfunction capturingMatrix(matrix: MatrixData, label_name: string): string[] {\n const captured = new Set<string>();\n for (const sample of matrix.result) {\n const value = sample.metric[label_name];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\nfunction capturingVector(vector: VectorData, label_name: string): string[] {\n const captured = new Set<string>();\n for (const sample of vector.result) {\n const value = sample.metric[label_name];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\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: (spec) => {\n return { variables: spec.matchers?.map((m) => parseTemplateVariables(m)).flat() || [] };\n },\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: replaceTemplateVariables(pluginDef.label_name, ctx.variables),\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return {\n variables:\n spec.matchers\n ?.map((m) => parseTemplateVariables(m))\n .flat()\n .concat(parseTemplateVariables(spec.label_name)) || [],\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ label_name: '' }),\n};\n\nexport const PrometheusPromQLVariable: VariablePlugin<PrometheusPromQLVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n // TODO we may want to manage a range query as well.\n const { data: options } = await client.instantQuery({\n query: replaceTemplateVariables(spec.expr, ctx.variables),\n });\n const labelName = replaceTemplateVariables(spec.label_name, ctx.variables);\n let values: string[] = [];\n if (options?.resultType === 'matrix') {\n values = capturingMatrix(options, labelName);\n } else if (options?.resultType === 'vector') {\n values = capturingVector(options, labelName);\n }\n\n return {\n data: stringArrayToVariableOptions(values),\n };\n },\n dependsOn: (spec) => {\n return { variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.label_name)) };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', label_name: '' }),\n};\n"],"names":["Stack","TextField","DEFAULT_PROM","getPrometheusTimeRange","replaceTemplateVariables","parseTemplateVariables","MatcherEditor","PrometheusLabelValuesVariableEditor","props","spacing","sx","mb","label","value","label_name","onChange","e","target","matchers","PrometheusLabelNamesVariableEditor","PrometheusPromQLVariableEditor","expr","capturingMatrix","matrix","captured","Set","sample","result","metric","undefined","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","client","datasourceStore","getDatasourceClient","datasource","match","m","variables","timeRange","data","options","labelNames","dependsOn","flat","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","labelName","concat","PrometheusPromQLVariable","instantQuery","query","resultType"],"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,SAA2BC,YAAY,EAAEC,sBAAsB,QAAgC,UAAU,CAAC;AAC1G,SAASC,wBAAwB,EAAEC,sBAAsB,QAAQ,UAAU,CAAC;AAM5E,S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wB,CAACoC,IAAI,CAACnB,IAAI,EAAEoB,GAAG,CAACO,SAAS,CAAC;SAC1D,CAAC,AAAC;QACH,MAAMY,SAAS,GAAGxD,wBAAwB,CAACoC,IAAI,CAAC1B,UAAU,EAAE2B,GAAG,CAACO,SAAS,CAAC,AAAC;QAC3E,IAAIf,MAAM,GAAa,EAAE,AAAC;QAC1B,IAAIkB,CAAAA,OAAO,aAAPA,OAAO,WAAY,GAAnBA,KAAAA,CAAmB,GAAnBA,OAAO,CAAEc,UAAU,CAAA,KAAK,QAAQ,EAAE;YACpChC,MAAM,GAAGX,eAAe,CAAC6B,OAAO,EAAES,SAAS,CAAC,CAAC;QAC/C,OAAO,IAAIT,CAAAA,OAAO,aAAPA,OAAO,WAAY,GAAnBA,KAAAA,CAAmB,GAAnBA,OAAO,CAAEc,UAAU,CAAA,KAAK,QAAQ,EAAE;YAC3ChC,MAAM,GAAGC,eAAe,CAACiB,OAAO,EAAES,SAAS,CAAC,CAAC;QAC/C,CAAC;QAED,OAAO;YACLV,IAAI,EAAEd,4BAA4B,CAACH,MAAM,CAAC;SAC3C,CAAC;IACJ,CAAC;IACDoB,SAAS,EAAE,CAACb,IAAI,GAAK;QACnB,OAAO;YAAEQ,SAAS,EAAE3C,sBAAsB,CAACmC,IAAI,CAACnB,IAAI,CAAC,CAACwC,MAAM,CAACxD,sBAAsB,CAACmC,IAAI,CAAC1B,UAAU,CAAC,CAAC;SAAE,CAAC;IAC1G,CAAC;IACDyC,sBAAsB,EAAEnC,8BAA8B;IACtDoC,oBAAoB,EAAE,IAAO,CAAA;YAAEnC,IAAI,EAAE,EAAE;YAAEP,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CAC3D,CAAC"}
|
package/dist/plugins/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/types.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/types.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 { PrometheusDatasourceSelector } from '../model';\n\nexport interface PrometheusVariableOptionsBase {\n datasource?: PrometheusDatasourceSelector;\n}\n\nexport type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {\n matchers?: string[];\n};\n\nexport type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n label_name: string;\n matchers?: string[];\n};\n\nexport type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {\n // expr is the PromQL expression.\n expr: string;\n // label_name is the name of the label that will be used after the PromQL query is performed to select the label value.\n // Note: This field is not part of the Prometheus API.\n label_name: string;\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,WAqBE"}
|
package/dist/plugins/variable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/variable.tsx"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/variable.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 { VariablePlugin, VariableOption, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Autocomplete, TextField, Typography } from '@mui/material';\n\ntype StaticListOption = string | VariableOption;\n\ntype StaticListVariableOptions = {\n values: StaticListOption[];\n};\n\nfunction StaticListVariableOptionEditor(props: OptionsEditorProps<StaticListVariableOptions>) {\n const value = props.value.values.map((v) => {\n if (typeof v === 'string') {\n return v;\n } else {\n return v.value;\n }\n });\n\n const onChange = (__: unknown, value: string[]) => {\n props.onChange({\n values: value.map((v) => {\n return { value: v, label: v };\n }),\n });\n };\n\n return (\n <div>\n <Autocomplete\n onPaste={(e) => {\n // Append new values on paste\n const v = e.clipboardData.getData('text/plain');\n if (v) {\n const values = v.split(',');\n onChange(null, value.concat(values));\n e.preventDefault();\n }\n }}\n multiple\n value={value}\n onChange={onChange}\n options={[]}\n freeSolo\n clearOnBlur\n renderInput={(params) => <TextField {...params} label=\"Values\" placeholder=\"Values\" />}\n />\n <Typography variant=\"caption\">\n Type new value then press {`\"`}Enter{`\"`} to add.\n </Typography>\n </div>\n );\n}\n\nexport const StaticListVariable: VariablePlugin<StaticListVariableOptions> = {\n getVariableOptions: async (spec) => {\n const values = spec.values?.map((v) => {\n if (typeof v === 'string') {\n return { label: v, value: v };\n }\n return v;\n });\n return {\n data: values,\n };\n },\n dependsOn: () => {\n return { variables: [] };\n },\n OptionsEditorComponent: StaticListVariableOptionEditor,\n createInitialOptions: () => ({ values: [] }),\n};\n"],"names":["Autocomplete","TextField","Typography","StaticListVariableOptionEditor","props","value","values","map","v","onChange","__","label","div","onPaste","e","clipboardData","getData","split","concat","preventDefault","multiple","options","freeSolo","clearOnBlur","renderInput","params","placeholder","variant","StaticListVariable","getVariableOptions","spec","data","dependsOn","variables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CA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BY,OAAO,EAAE,EAAE;gBACXC,QAAQ;gBACRC,WAAW;gBACXC,WAAW,EAAE,CAACC,MAAM,iBAAK,KAACxB,SAAS;wBAAE,GAAGwB,MAAM;wBAAEd,KAAK,EAAC,QAAQ;wBAACe,WAAW,EAAC,QAAQ;sBAAG;cACtF;0BACF,MAACxB,UAAU;gBAACyB,OAAO,EAAC,SAAS;;oBAAC,4BACF;oBAAC,CAAC,CAAC,CAAC;oBAAC,OAAK;oBAAC,CAAC,CAAC,CAAC;oBAAC,UAC3C;;cAAa;;MACT,CACN;AACJ,CAAC;AAED,OAAO,MAAMC,kBAAkB,GAA8C;IAC3EC,kBAAkB,EAAE,OAAOC,IAAI,GAAK;YACnBA,GAAW;QAA1B,MAAMxB,MAAM,GAAGwB,CAAAA,GAAW,GAAXA,IAAI,CAACxB,MAAM,cAAXwB,GAAW,WAAK,GAAhBA,KAAAA,CAAgB,GAAhBA,GAAW,CAAEvB,GAAG,CAAC,CAACC,CAAC,GAAK;YACrC,IAAI,OAAOA,CAAC,KAAK,QAAQ,EAAE;gBACzB,OAAO;oBAAEG,KAAK,EAAEH,CAAC;oBAAEH,KAAK,EAAEG,CAAC;iBAAE,CAAC;YAChC,CAAC;YACD,OAAOA,CAAC,CAAC;QACX,CAAC,CAAC,AAAC;QACH,OAAO;YACLuB,IAAI,EAAEzB,MAAM;SACb,CAAC;IACJ,CAAC;IACD0B,SAAS,EAAE,IAAM;QACf,OAAO;YAAEC,SAAS,EAAE,EAAE;SAAE,CAAC;IAC3B,CAAC;IACDC,sBAAsB,EAAE/B,8BAA8B;IACtDgC,oBAAoB,EAAE,IAAO,CAAA;YAAE7B,MAAM,EAAE,EAAE;SAAE,CAAA,AAAC;CAC7C,CAAC"}
|
package/dist/test/setup-tests.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/setup-tests.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../src/test/setup-tests.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 '@testing-library/jest-dom/extend-expect';\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,OAAO,yCAAyC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2023 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 './utils';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/index.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\nexport * from './utils';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS,CAAC"}
|
|
@@ -11,4 +11,9 @@ export declare const parseTemplateVariables: (text: string) => string[];
|
|
|
11
11
|
*/
|
|
12
12
|
export declare type SeriesLabels = Record<string, string>;
|
|
13
13
|
export declare function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string;
|
|
14
|
+
export declare function getUniqueKeyForPrometheusResult(metricLabels: {
|
|
15
|
+
[key: string]: string;
|
|
16
|
+
}, { removeExprWrap }?: {
|
|
17
|
+
removeExprWrap?: boolean;
|
|
18
|
+
}): string;
|
|
14
19
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,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;AAMlD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM,CAGxF;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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -56,5 +56,41 @@ const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?
|
|
|
56
56
|
const resolveLabelsRegex = /\{\{\s*(.+?)\s*\}\}/g;
|
|
57
57
|
return inputFormat.replace(resolveLabelsRegex, (_, g)=>seriesLabels[g] ? seriesLabels[g] : g);
|
|
58
58
|
}
|
|
59
|
+
/*
|
|
60
|
+
* Stringifies object of labels into valid PromQL for querying metric by label
|
|
61
|
+
*/ function stringifyPrometheusMetricLabels(labels, removeExprWrap) {
|
|
62
|
+
const labelStrings = [];
|
|
63
|
+
Object.keys(labels).sort().forEach((labelName)=>{
|
|
64
|
+
const labelValue = labels[labelName];
|
|
65
|
+
if (labelValue !== undefined) {
|
|
66
|
+
if (removeExprWrap) {
|
|
67
|
+
labelStrings.push(`"${labelName}":"${labelValue}"`);
|
|
68
|
+
} else {
|
|
69
|
+
labelStrings.push(`${labelName}="${labelValue}"`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return `{${labelStrings.join(',')}}`;
|
|
74
|
+
}
|
|
75
|
+
/*
|
|
76
|
+
* Metric labels formattter which checks for __name__ and outputs valid PromQL for series name
|
|
77
|
+
*/ export function getUniqueKeyForPrometheusResult(metricLabels, { removeExprWrap } = {}) {
|
|
78
|
+
const metricNameKey = '__name__';
|
|
79
|
+
if (metricLabels) {
|
|
80
|
+
if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {
|
|
81
|
+
const stringifiedLabels = stringifyPrometheusMetricLabels({
|
|
82
|
+
...metricLabels,
|
|
83
|
+
[metricNameKey]: undefined
|
|
84
|
+
}, removeExprWrap);
|
|
85
|
+
if (removeExprWrap === true) {
|
|
86
|
+
return `${stringifiedLabels}`;
|
|
87
|
+
} else {
|
|
88
|
+
return `${metricLabels[metricNameKey]}${stringifiedLabels}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);
|
|
92
|
+
}
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
59
95
|
|
|
60
96
|
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +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 { VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\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 */\nexport function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string {\n const resolveLabelsRegex = /\\{\\{\\s*(.+?)\\s*\\}\\}/g;\n return inputFormat.replace(resolveLabelsRegex, (_, g) => (seriesLabels[g] ? seriesLabels[g] : g));\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"],"names":["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","_","g","stringifyPrometheusMetricLabels","labels","removeExprWrap","labelStrings","Object","keys","sort","labelName","labelValue","undefined","push","getUniqueKeyForPrometheusResult","metricLabels","metricNameKey","prototype","hasOwnProperty","call","stringifiedLabels"],"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;AAKjC,OAAO,SAASA,wBAAwB,CAACC,IAAY,EAAEC,aAA+B,EAAU;IAC9F,MAAMC,SAAS,GAAGC,sBAAsB,CAACH,IAAI,CAAC,AAAC;IAC/C,IAAII,SAAS,GAAGJ,IAAI,AAAC;IACrBE,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D,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IACL,OAAO,CAAC,CAAC,EAAEL,YAAY,CAACtB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC;AAED;;CAEC,GACD,OAAO,SAAS8B,+BAA+B,CAC7CC,YAEC,EACD,EAAEV,cAAc,CAAA,EAAgC,GAAG,EAAE,EACrD;IACA,MAAMW,aAAa,GAAG,UAAU,AAAC;IACjC,IAAID,YAAY,EAAE;QAChB,IAAIR,MAAM,CAACU,SAAS,CAACC,cAAc,CAACC,IAAI,CAACJ,YAAY,EAAEC,aAAa,CAAC,EAAE;YACrE,MAAMI,iBAAiB,GAAGjB,+BAA+B,CACvD;gBACE,GAAGY,YAAY;gBACf,CAACC,aAAa,CAAC,EAAEJ,SAAS;aAC3B,EACDP,cAAc,CACf,AAAC;YACF,IAAIA,cAAc,KAAK,IAAI,EAAE;gBAC3B,OAAO,CAAC,EAAEe,iBAAiB,CAAC,CAAC,CAAC;YAChC,OAAO;gBACL,OAAO,CAAC,EAAEL,YAAY,CAACC,aAAa,CAAC,CAAC,EAAEI,iBAAiB,CAAC,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;QACD,OAAOjB,+BAA+B,CAACY,YAAY,EAAEV,cAAc,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"utils.test.d.ts","sourceRoot":"","sources":["../../src/utils/utils.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -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 { parseTemplateVariables, replaceTemplateVariable, replaceTemplateVariables, formatSeriesName } from './utils';
|
|
13
|
+
import { parseTemplateVariables, replaceTemplateVariable, replaceTemplateVariables, formatSeriesName, getUniqueKeyForPrometheusResult } from './utils';
|
|
14
14
|
describe('parseTemplateVariables()', ()=>{
|
|
15
15
|
const tests = [
|
|
16
16
|
{
|
|
@@ -120,5 +120,51 @@ describe('formatSeriesName', ()=>{
|
|
|
120
120
|
expect(formatSeriesName(inputFormat, metric)).toEqual(output);
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
|
+
describe('getUniqueKeyForPrometheusResult', ()=>{
|
|
124
|
+
let labels = {};
|
|
125
|
+
beforeEach(()=>{
|
|
126
|
+
labels = {};
|
|
127
|
+
});
|
|
128
|
+
it('should be a formatted prometheus string', ()=>{
|
|
129
|
+
labels = {
|
|
130
|
+
['foo']: 'bar'
|
|
131
|
+
};
|
|
132
|
+
const result = getUniqueKeyForPrometheusResult(labels);
|
|
133
|
+
expect(result).toEqual('{foo="bar"}');
|
|
134
|
+
});
|
|
135
|
+
it('should be formatted with "', ()=>{
|
|
136
|
+
labels = {
|
|
137
|
+
['foo']: 'bar'
|
|
138
|
+
};
|
|
139
|
+
const result = getUniqueKeyForPrometheusResult(labels, {
|
|
140
|
+
removeExprWrap: true
|
|
141
|
+
});
|
|
142
|
+
expect(result).toEqual('{"foo":"bar"}');
|
|
143
|
+
});
|
|
144
|
+
it('should be formatted with __name__ removed', ()=>{
|
|
145
|
+
labels = {
|
|
146
|
+
__name__: 'node_memory_Buffers_bytes',
|
|
147
|
+
env: 'demo',
|
|
148
|
+
instance: 'demo.do.prometheus.io:9100',
|
|
149
|
+
job: 'node'
|
|
150
|
+
};
|
|
151
|
+
const result = getUniqueKeyForPrometheusResult(labels, {
|
|
152
|
+
removeExprWrap: true
|
|
153
|
+
});
|
|
154
|
+
expect(result).toEqual('{"env":"demo","instance":"demo.do.prometheus.io:9100","job":"node"}');
|
|
155
|
+
});
|
|
156
|
+
it('should return a valid query to filter by label', ()=>{
|
|
157
|
+
labels = {
|
|
158
|
+
__name__: 'node_memory_Buffers_bytes',
|
|
159
|
+
env: 'demo',
|
|
160
|
+
instance: 'demo.do.prometheus.io:9100',
|
|
161
|
+
job: 'node'
|
|
162
|
+
};
|
|
163
|
+
const result = getUniqueKeyForPrometheusResult(labels, {
|
|
164
|
+
removeExprWrap: false
|
|
165
|
+
});
|
|
166
|
+
expect(result).toEqual('node_memory_Buffers_bytes{env="demo",instance="demo.do.prometheus.io:9100",job="node"}');
|
|
167
|
+
});
|
|
168
|
+
});
|
|
123
169
|
|
|
124
170
|
//# sourceMappingURL=utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/utils.test.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 {\n parseTemplateVariables,\n replaceTemplateVariable,\n replaceTemplateVariables,\n formatSeriesName,\n getUniqueKeyForPrometheusResult,\n} from './utils';\n\ndescribe('parseTemplateVariables()', () => {\n const tests = [\n {\n text: 'hello $var1 world $var2',\n variables: ['var1', 'var2'],\n },\n ];\n\n tests.forEach(({ text, variables }) => {\n it(`parses ${text}`, () => {\n expect(parseTemplateVariables(text)).toEqual(variables);\n });\n });\n});\n\ndescribe('replaceTemplateVariable()', () => {\n const tests = [\n {\n text: 'hello $var1',\n varName: 'var1',\n value: 'world',\n expected: 'hello world',\n },\n {\n text: 'hello $var1 $var1',\n varName: 'var1',\n value: 'world',\n expected: 'hello world world',\n },\n {\n text: 'hello $var1',\n varName: 'var1',\n value: ['world', 'w'],\n expected: 'hello (world|w)',\n },\n {\n text: 'hello $var1 $var1',\n varName: 'var1',\n value: ['world', 'w'],\n expected: 'hello (world|w) (world|w)',\n },\n ];\n\n tests.forEach(({ text, value, varName, expected }) => {\n it(`replaces ${text} ${value}`, () => {\n expect(replaceTemplateVariable(text, varName, value)).toEqual(expected);\n });\n });\n});\n\ndescribe('replaceTemplateVariables()', () => {\n const tests = [\n {\n text: 'hello $var1 $var2',\n state: {\n var1: { value: 'world', loading: false },\n var2: { value: 'world', loading: false },\n },\n expected: 'hello world world',\n },\n {\n text: 'hello $var1 $var2',\n state: {\n var1: { value: 'world', loading: false },\n var2: { value: ['a', 'b'], loading: false },\n },\n expected: 'hello world (a|b)',\n },\n ];\n\n tests.forEach(({ text, state, expected }) => {\n it(`replaces ${text} ${JSON.stringify(state)}`, () => {\n expect(replaceTemplateVariables(text, state)).toEqual(expected);\n });\n });\n});\n\ndescribe('formatSeriesName', () => {\n it('should resolve label name tokens to label values from query response', () => {\n // example from query: node_load15{instance=~\\\"(demo.do.prometheus.io:9100)\\\",job='$job'}\n const inputFormat = 'Test {{job}} {{instance}}';\n\n const metric = {\n __name__: 'node_load15',\n env: 'demo',\n instance: 'demo.do.prometheus.io:9100',\n job: 'node',\n };\n\n const output = 'Test node demo.do.prometheus.io:9100';\n\n expect(formatSeriesName(inputFormat, metric)).toEqual(output);\n });\n});\n\ndescribe('getUniqueKeyForPrometheusResult', () => {\n let labels: { [key: string]: string } = {};\n beforeEach(() => {\n labels = {};\n });\n\n it('should be a formatted prometheus string', () => {\n labels = { ['foo']: 'bar' };\n const result = getUniqueKeyForPrometheusResult(labels);\n expect(result).toEqual('{foo=\"bar\"}');\n });\n\n it('should be formatted with \"', () => {\n labels = { ['foo']: 'bar' };\n const result = getUniqueKeyForPrometheusResult(labels, { removeExprWrap: true });\n expect(result).toEqual('{\"foo\":\"bar\"}');\n });\n\n it('should be formatted with __name__ removed', () => {\n labels = {\n __name__: 'node_memory_Buffers_bytes',\n env: 'demo',\n instance: 'demo.do.prometheus.io:9100',\n job: 'node',\n };\n const result = getUniqueKeyForPrometheusResult(labels, { removeExprWrap: true });\n expect(result).toEqual('{\"env\":\"demo\",\"instance\":\"demo.do.prometheus.io:9100\",\"job\":\"node\"}');\n });\n\n it('should return a valid query to filter by label', () => {\n labels = {\n __name__: 'node_memory_Buffers_bytes',\n env: 'demo',\n instance: 'demo.do.prometheus.io:9100',\n job: 'node',\n };\n const result = getUniqueKeyForPrometheusResult(labels, { removeExprWrap: false });\n expect(result).toEqual('node_memory_Buffers_bytes{env=\"demo\",instance=\"demo.do.prometheus.io:9100\",job=\"node\"}');\n });\n});\n"],"names":["parseTemplateVariables","replaceTemplateVariable","replaceTemplateVariables","formatSeriesName","getUniqueKeyForPrometheusResult","describe","tests","text","variables","forEach","it","expect","toEqual","varName","value","expected","state","var1","loading","var2","JSON","stringify","inputFormat","metric","__name__","env","instance","job","output","labels","beforeEach","result","removeExprWrap"],"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,SACEA,sBAAsB,EACtBC,uBAAuB,EACvBC,wBAAwB,EACxBC,gBAAgB,EAChBC,+BAA+B,QAC1B,SAAS,CAAC;AAEjBC,QAAQ,CAAC,0BAA0B,EAAE,IAAM;IACzC,MAAMC,KAAK,GAAG;QACZ;YACEC,IAAI,EAAE,yBAAyB;YAC/BC,SAAS,EAAE;gBAAC,MAAM;gBAAE,MAAM;aAAC;SAC5B;KACF,AAAC;IAEFF,KAAK,CAACG,OAAO,CAAC,CAAC,EAAEF,IAAI,CAAA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;YAAEG,cAAc,EAAE,IAAI;SAAE,CAAC,AAAC;QACjFrB,MAAM,CAACoB,MAAM,CAAC,CAACnB,OAAO,CAAC,qEAAqE,CAAC,CAAC;IAChG,CAAC,CAAC,CAAC;IAEHF,EAAE,CAAC,gDAAgD,EAAE,IAAM;QACzDmB,MAAM,GAAG;YACPL,QAAQ,EAAE,2BAA2B;YACrCC,GAAG,EAAE,MAAM;YACXC,QAAQ,EAAE,4BAA4B;YACtCC,GAAG,EAAE,MAAM;SACZ,CAAC;QACF,MAAMI,MAAM,GAAG3B,+BAA+B,CAACyB,MAAM,EAAE;YAAEG,cAAc,EAAE,KAAK;SAAE,CAAC,AAAC;QAClFrB,MAAM,CAACoB,MAAM,CAAC,CAACnB,OAAO,CAAC,wFAAwF,CAAC,CAAC;IACnH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/prometheus-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.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",
|
|
@@ -30,9 +30,12 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@lezer/highlight": "^1.0.0",
|
|
32
32
|
"@lezer/lr": "^1.2.0",
|
|
33
|
-
"@perses-dev/
|
|
34
|
-
"@perses-dev/
|
|
33
|
+
"@perses-dev/components": "0.22.0",
|
|
34
|
+
"@perses-dev/core": "0.22.0",
|
|
35
|
+
"@perses-dev/plugin-system": "0.22.0",
|
|
36
|
+
"@prometheus-io/codemirror-promql": "^0.40.5",
|
|
35
37
|
"@prometheus-io/lezer-promql": "^0.37.0",
|
|
38
|
+
"@uiw/react-codemirror": "^4.19.1",
|
|
36
39
|
"date-fns": "^2.28.0",
|
|
37
40
|
"immer": "^9.0.15"
|
|
38
41
|
},
|
package/dist/model/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/utils.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 { VariableValue } from '@perses-dev/core';\nimport { VariableStateMap } from '@perses-dev/plugin-system';\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 */\nexport function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string {\n const resolveLabelsRegex = /\\{\\{\\s*(.+?)\\s*\\}\\}/g;\n return inputFormat.replace(resolveLabelsRegex, (_, g) => (seriesLabels[g] ? seriesLabels[g] : g));\n}\n"],"names":["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","_","g"],"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;AAKjC,OAAO,SAASA,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,GAAfA,QAAQ,CAAEC,KAAK,CAAC,CAAC;QACrE,CAAC;IACH,CAAC,CAAC,CAAC;IAEH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