@perses-dev/prometheus-plugin 0.0.0-snapshot-scatter-chart-embed-8efdfab → 0.0.0-snapshot-scatterplot-fix-imports-95e1b59
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 +1 -1
- package/dist/cjs/index.js +7 -7
- package/dist/cjs/model/index.js +0 -1
- package/dist/cjs/model/parse-sample-values.js +3 -3
- package/dist/cjs/model/prometheus-client.js +8 -8
- package/dist/cjs/model/prometheus-selectors.js +3 -3
- package/dist/cjs/model/time.js +4 -4
- package/dist/cjs/plugins/MatcherEditor.js +1 -1
- package/dist/cjs/plugins/PrometheusDatasourceEditor.js +24 -26
- package/dist/cjs/plugins/prometheus-datasource.js +2 -2
- package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +67 -40
- package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +3 -3
- package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +6 -6
- package/dist/cjs/plugins/prometheus-variables.js +10 -10
- package/dist/cjs/utils/utils.js +4 -4
- package/dist/components/PromQL.d.ts +2 -3
- package/dist/components/PromQL.d.ts.map +1 -1
- package/dist/components/PromQL.js +1 -1
- package/dist/components/PromQL.js.map +1 -1
- package/dist/model/api-types.d.ts +11 -11
- package/dist/model/api-types.d.ts.map +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 +0 -1
- package/dist/model/index.js.map +1 -1
- package/dist/model/parse-sample-values.d.ts +1 -1
- package/dist/model/parse-sample-values.d.ts.map +1 -1
- package/dist/model/parse-sample-values.js.map +1 -1
- package/dist/model/prometheus-client.js +3 -3
- package/dist/model/prometheus-client.js.map +1 -1
- package/dist/model/prometheus-selectors.js.map +1 -1
- package/dist/model/time.js +1 -1
- package/dist/model/time.js.map +1 -1
- package/dist/plugins/MatcherEditor.d.ts +2 -3
- package/dist/plugins/MatcherEditor.d.ts.map +1 -1
- package/dist/plugins/MatcherEditor.js +1 -1
- package/dist/plugins/MatcherEditor.js.map +1 -1
- package/dist/plugins/PrometheusDatasourceEditor.d.ts +1 -2
- package/dist/plugins/PrometheusDatasourceEditor.d.ts.map +1 -1
- package/dist/plugins/PrometheusDatasourceEditor.js +21 -25
- package/dist/plugins/PrometheusDatasourceEditor.js.map +1 -1
- package/dist/plugins/prometheus-datasource.js +2 -2
- package/dist/plugins/prometheus-datasource.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts +1 -2
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +70 -43
- package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +3 -3
- package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +1 -1
- 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.d.ts +2 -2
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
- package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +3 -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 +10 -10
- package/dist/plugins/prometheus-variables.js.map +1 -1
- package/dist/plugins/types.d.ts +3 -3
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/plugins/variable.d.ts +2 -2
- package/dist/plugins/variable.d.ts.map +1 -1
- package/dist/plugins/variable.js.map +1 -1
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.d.ts.map +1 -1
- package/dist/utils/utils.js +1 -1
- package/dist/utils/utils.js.map +1 -1
- package/package.json +4 -4
- package/dist/cjs/model/templating.js +0 -28
- package/dist/cjs/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.js +0 -88
- package/dist/cjs/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.js +0 -123
- package/dist/model/templating.d.ts +0 -6
- package/dist/model/templating.d.ts.map +0 -1
- package/dist/model/templating.js +0 -20
- package/dist/model/templating.js.map +0 -1
- package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.d.ts +0 -21
- package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.d.ts.map +0 -1
- package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.js +0 -80
- package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.js.map +0 -1
- package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.d.ts +0 -21
- package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.d.ts.map +0 -1
- package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.js +0 -115
- package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.js.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DurationString } from '@perses-dev/core';
|
|
2
|
-
import { PrometheusDatasourceSelector
|
|
2
|
+
import { PrometheusDatasourceSelector } from '../../model';
|
|
3
3
|
/**
|
|
4
4
|
* The spec/options for the PrometheusTimeSeriesQuery plugin.
|
|
5
5
|
*/
|
|
6
6
|
export interface PrometheusTimeSeriesQuerySpec {
|
|
7
|
-
query:
|
|
7
|
+
query: string;
|
|
8
8
|
seriesNameFormat?: string;
|
|
9
9
|
minStep?: DurationString;
|
|
10
10
|
resolution?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-series-query-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,
|
|
1
|
+
{"version":3,"file":"time-series-query-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C"}
|
|
@@ -10,6 +10,8 @@
|
|
|
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
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The spec/options for the PrometheusTimeSeriesQuery plugin.
|
|
15
|
+
*/ export { };
|
|
14
16
|
|
|
15
17
|
//# sourceMappingURL=time-series-query-model.js.map
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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 } from '../../model';\n\n/**\n * The spec/options for the PrometheusTimeSeriesQuery plugin.\n */\nexport interface PrometheusTimeSeriesQuerySpec {\n query: string;\n seriesNameFormat?: string;\n minStep?: 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;AAKjC;;CAEC,GACD,WAMC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAML,cAAc,
|
|
1
|
+
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAML,cAAc,EAIf,MAAM,2BAA2B,CAAC;AAcnC,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AA+LjB,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"}
|
|
@@ -18,8 +18,8 @@ import { DEFAULT_PROM, getPrometheusTimeRange, isDefaultPromSelector, isPromethe
|
|
|
18
18
|
import { PromQLEditor } from '../components';
|
|
19
19
|
import { MatcherEditor } from './MatcherEditor';
|
|
20
20
|
function PrometheusLabelValuesVariableEditor(props) {
|
|
21
|
-
const { onChange
|
|
22
|
-
const { datasource
|
|
21
|
+
const { onChange, value } = props;
|
|
22
|
+
const { datasource } = value;
|
|
23
23
|
const selectedDatasource = datasource !== null && datasource !== void 0 ? datasource : DEFAULT_PROM;
|
|
24
24
|
const handleDatasourceChange = (next)=>{
|
|
25
25
|
if (isPrometheusDatasourceSelector(next)) {
|
|
@@ -80,8 +80,8 @@ function PrometheusLabelValuesVariableEditor(props) {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
function PrometheusLabelNamesVariableEditor(props) {
|
|
83
|
-
const { onChange
|
|
84
|
-
const { datasource
|
|
83
|
+
const { onChange, value } = props;
|
|
84
|
+
const { datasource } = value;
|
|
85
85
|
const selectedDatasource = datasource !== null && datasource !== void 0 ? datasource : DEFAULT_PROM;
|
|
86
86
|
const handleDatasourceChange = (next)=>{
|
|
87
87
|
if (isPrometheusDatasourceSelector(next)) {
|
|
@@ -128,10 +128,10 @@ function PrometheusLabelNamesVariableEditor(props) {
|
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
function PrometheusPromQLVariableEditor(props) {
|
|
131
|
-
const { onChange
|
|
132
|
-
const { datasource
|
|
131
|
+
const { onChange, value } = props;
|
|
132
|
+
const { datasource } = value;
|
|
133
133
|
const selectedDatasource = datasource !== null && datasource !== void 0 ? datasource : DEFAULT_PROM;
|
|
134
|
-
const { data: client
|
|
134
|
+
const { data: client } = useDatasourceClient(selectedDatasource);
|
|
135
135
|
const promURL = client === null || client === void 0 ? void 0 : client.options.datasourceUrl;
|
|
136
136
|
const handleDatasourceChange = (next)=>{
|
|
137
137
|
if (isPrometheusDatasourceSelector(next)) {
|
|
@@ -230,7 +230,7 @@ export const PrometheusLabelNamesVariable = {
|
|
|
230
230
|
const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
|
|
231
231
|
const match = spec.matchers ? spec.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
|
|
232
232
|
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
233
|
-
const { data: options
|
|
233
|
+
const { data: options } = await client.labelNames({
|
|
234
234
|
'match[]': match,
|
|
235
235
|
...timeRange
|
|
236
236
|
});
|
|
@@ -254,7 +254,7 @@ export const PrometheusLabelValuesVariable = {
|
|
|
254
254
|
const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
|
|
255
255
|
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
|
|
256
256
|
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
257
|
-
const { data: options
|
|
257
|
+
const { data: options } = await client.labelValues({
|
|
258
258
|
labelName: replaceTemplateVariables(pluginDef.labelName, ctx.variables),
|
|
259
259
|
'match[]': match,
|
|
260
260
|
...timeRange
|
|
@@ -279,7 +279,7 @@ export const PrometheusPromQLVariable = {
|
|
|
279
279
|
var _spec_datasource;
|
|
280
280
|
const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
|
|
281
281
|
// TODO we may want to manage a range query as well.
|
|
282
|
-
const { data: options
|
|
282
|
+
const { data: options } = await client.instantQuery({
|
|
283
283
|
query: replaceTemplateVariables(spec.expr, ctx.variables)
|
|
284
284
|
});
|
|
285
285
|
const labelName = replaceTemplateVariables(spec.labelName, ctx.variables);
|
|
@@ -1 +1 @@
|
|
|
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 {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n VariablePlugin,\n parseTemplateVariables,\n replaceTemplateVariables,\n} from '@perses-dev/plugin-system';\nimport { FormControl, InputLabel, Stack, TextField } from '@mui/material';\nimport { produce } from 'immer';\nimport {\n DEFAULT_PROM,\n getPrometheusTimeRange,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n VectorData,\n} from '../model';\nimport { PromQLEditor } from '../components';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\nimport { MatcherEditor } from './MatcherEditor';\n\nfunction PrometheusLabelValuesVariableEditor(props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n readOnly={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <TextField\n label=\"Label Name\"\n required\n value={props.value.labelName}\n onChange={(e) => {\n props.onChange({ ...props.value, labelName: e.target.value });\n }}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n />\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n isReadonly={props.isReadonly}\n />\n </Stack>\n );\n}\n\nfunction PrometheusLabelNamesVariableEditor(props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n disabled={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n isReadonly={props.isReadonly}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\n}\n\nfunction PrometheusPromQLVariableEditor(props: OptionsEditorProps<PrometheusPromQLVariableOptions>) {\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 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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n disabled={props.isReadonly}\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={value.expr}\n onChange={(query) => {\n props.onChange({ ...props.value, expr: query });\n }}\n readOnly={props.isReadonly}\n width=\"100%\"\n />\n <TextField\n label=\"Label Name\"\n value={props.value.labelName}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n onChange={(e) => {\n props.onChange({ ...props.value, labelName: e.target.value });\n }}\n />\n </Stack>\n );\n}\n\nfunction capturingMatrix(matrix: MatrixData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of matrix.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\nfunction capturingVector(vector: VectorData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of vector.result) {\n const value = sample.metric[labelName];\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.labelName, 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.labelName)) || [],\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ labelName: '' }),\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.labelName, 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.labelName)) };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', labelName: '' }),\n};\n"],"names":["DatasourceSelect","useDatasourceClient","parseTemplateVariables","replaceTemplateVariables","FormControl","InputLabel","Stack","TextField","produce","DEFAULT_PROM","getPrometheusTimeRange","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","PromQLEditor","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","handleDatasourceChange","next","draft","undefined","Error","spacing","margin","id","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","labelName","e","target","InputProps","matchers","PrometheusLabelNamesVariableEditor","disabled","PrometheusPromQLVariableEditor","data","client","promURL","options","datasourceUrl","completeConfig","remote","url","expr","query","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","datasourceStore","getDatasourceClient","match","m","variables","timeRange","labelNames","dependsOn","flat","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","concat","PrometheusPromQL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,MAAM,EAAEmC,MAAMG,QAAO,EAAE,GAAG,MAAMF,OAAO6C,aAAa;YAClDrC,OAAOlD,yBAAyBqE,KAAKpB,MAAMqB,IAAIK;QACjD;QACA,MAAM1C,YAAYjC,yBAAyBqE,KAAKpC,WAAWqC,IAAIK;QAC/D,IAAIb,SAAmB,EAAE;QACzB,IAAIlB,CAAAA,oBAAAA,qBAAAA,KAAAA,IAAAA,QAAS4C,UAAS,MAAM,UAAU;YACpC1B,SAASV,gBAAgBR,SAASX;QACpC,OAAO,IAAIW,CAAAA,oBAAAA,qBAAAA,KAAAA,IAAAA,QAAS4C,UAAS,MAAM,UAAU;YAC3C1B,SAASC,gBAAgBnB,SAASX;QACpC;QAEA,OAAO;YACLQ,MAAMwB,6BAA6BH;QACrC;IACF;IACAgB,WAAW,CAACT;QACV,OAAO;YAAEM,WAAW5E,uBAAuBsE,KAAKpB,MAAMoC,OAAOtF,uBAAuBsE,KAAKpC;QAAY;IACvG;IACA+C,wBAAwBxC;IACxByC,sBAAsB,IAAO,CAAA;YAAEhC,MAAM;YAAIhB,WAAW;QAAG,CAAA;AACzD,EAAE"}
|
|
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 {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n VariablePlugin,\n parseTemplateVariables,\n replaceTemplateVariables,\n GetVariableOptionsContext,\n} from '@perses-dev/plugin-system';\nimport { FormControl, InputLabel, Stack, TextField } from '@mui/material';\nimport { produce } from 'immer';\nimport {\n DEFAULT_PROM,\n getPrometheusTimeRange,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n VectorData,\n} from '../model';\nimport { PromQLEditor } from '../components';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\nimport { MatcherEditor } from './MatcherEditor';\n\nfunction PrometheusLabelValuesVariableEditor(props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n readOnly={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <TextField\n label=\"Label Name\"\n required\n value={props.value.labelName}\n onChange={(e) => {\n props.onChange({ ...props.value, labelName: e.target.value });\n }}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n />\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n isReadonly={props.isReadonly}\n />\n </Stack>\n );\n}\n\nfunction PrometheusLabelNamesVariableEditor(props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n disabled={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n isReadonly={props.isReadonly}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\n}\n\nfunction PrometheusPromQLVariableEditor(props: OptionsEditorProps<PrometheusPromQLVariableOptions>) {\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 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 draft.datasource = isDefaultPromSelector(next) ? undefined : next;\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 <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n disabled={props.isReadonly}\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={value.expr}\n onChange={(query) => {\n props.onChange({ ...props.value, expr: query });\n }}\n readOnly={props.isReadonly}\n width=\"100%\"\n />\n <TextField\n label=\"Label Name\"\n value={props.value.labelName}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n onChange={(e) => {\n props.onChange({ ...props.value, labelName: e.target.value });\n }}\n />\n </Stack>\n );\n}\n\nfunction capturingMatrix(matrix: MatrixData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of matrix.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\nfunction capturingVector(vector: VectorData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of vector.result) {\n const value = sample.metric[labelName];\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: PrometheusLabelNamesVariableOptions, ctx: GetVariableOptionsContext) => {\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: PrometheusLabelNamesVariableOptions) => {\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: PrometheusLabelValuesVariableOptions, ctx: GetVariableOptionsContext) => {\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.labelName, ctx.variables),\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelValuesVariableOptions) => {\n return {\n variables:\n spec.matchers\n ?.map((m) => parseTemplateVariables(m))\n .flat()\n .concat(parseTemplateVariables(spec.labelName)) || [],\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ labelName: '' }),\n};\n\nexport const PrometheusPromQLVariable: VariablePlugin<PrometheusPromQLVariableOptions> = {\n getVariableOptions: async (spec: PrometheusPromQLVariableOptions, ctx: GetVariableOptionsContext) => {\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.labelName, 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: PrometheusPromQLVariableOptions) => {\n return { variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.labelName)) };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', labelName: '' }),\n};\n"],"names":["DatasourceSelect","useDatasourceClient","parseTemplateVariables","replaceTemplateVariables","FormControl","InputLabel","Stack","TextField","produce","DEFAULT_PROM","getPrometheusTimeRange","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","PromQLEditor","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","handleDatasourceChange","next","draft","undefined","Error","spacing","margin","id","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","labelName","e","target","InputProps","matchers","PrometheusLabelNamesVariableEditor","disabled","PrometheusPromQLVariableEditor","data","client","promURL","options","datasourceUrl","completeConfig","remote","url","expr","query","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","datasourceStore","getDatasourceClient","match","m","variables","timeRange","labelNames","dependsOn","flat","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","concat","PrometheusPromQLVariable","instantQuery","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,SACEA,gBAAgB,EAGhBC,mBAAmB,EAGnBC,sBAAsB,EACtBC,wBAAwB,QAEnB,4BAA4B;AACnC,SAASC,WAAW,EAAEC,UAAU,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC1E,SAASC,OAAO,QAAQ,QAAQ;AAChC,SACEC,YAAY,EACZC,sBAAsB,EACtBC,qBAAqB,EACrBC,8BAA8B,EAE9BC,oBAAoB,QAGf,WAAW;AAClB,SAASC,YAAY,QAAQ,gBAAgB;AAM7C,SAASC,aAAa,QAAQ,kBAAkB;AAEhD,SAASC,oCAAoCC,KAA+D;IAC1G,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;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AAU,MAAK,UAAU;YACpC1B,SAASV,gBAAgBR,SAASX;QACpC,OAAO,IAAIW,CAAAA,oBAAAA,8BAAAA,QAAS4C,UAAU,MAAK,UAAU;YAC3C1B,SAASC,gBAAgBnB,SAASX;QACpC;QAEA,OAAO;YACLQ,MAAMwB,6BAA6BH;QACrC;IACF;IACAgB,WAAW,CAACT;QACV,OAAO;YAAEM,WAAW5E,uBAAuBsE,KAAKpB,IAAI,EAAEoC,MAAM,CAACtF,uBAAuBsE,KAAKpC,SAAS;QAAG;IACvG;IACA+C,wBAAwBxC;IACxByC,sBAAsB,IAAO,CAAA;YAAEhC,MAAM;YAAIhB,WAAW;QAAG,CAAA;AACzD,EAAE"}
|
package/dist/plugins/types.d.ts
CHANGED
|
@@ -9,14 +9,14 @@ export interface PrometheusDatasourceSpec {
|
|
|
9
9
|
export interface PrometheusVariableOptionsBase {
|
|
10
10
|
datasource?: PrometheusDatasourceSelector;
|
|
11
11
|
}
|
|
12
|
-
export
|
|
12
|
+
export type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {
|
|
13
13
|
matchers?: string[];
|
|
14
14
|
};
|
|
15
|
-
export
|
|
15
|
+
export type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {
|
|
16
16
|
labelName: string;
|
|
17
17
|
matchers?: string[];
|
|
18
18
|
};
|
|
19
|
-
export
|
|
19
|
+
export type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {
|
|
20
20
|
expr: string;
|
|
21
21
|
labelName: string;
|
|
22
22
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,uBAAuB,EAAE,cAAqB,CAAC;AAE5D,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAED,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,uBAAuB,EAAE,cAAqB,CAAC;AAE5D,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAED,MAAM,MAAM,mCAAmC,GAAG,6BAA6B,GAAG;IAChF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG,6BAA6B,GAAG;IACjF,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,6BAA6B,GAAG;IAE5E,IAAI,EAAE,MAAM,CAAC;IAGb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VariablePlugin, VariableOption } from '@perses-dev/plugin-system';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type StaticListOption = string | VariableOption;
|
|
3
|
+
type StaticListVariableOptions = {
|
|
4
4
|
values: StaticListOption[];
|
|
5
5
|
};
|
|
6
6
|
export declare const StaticListVariable: VariablePlugin<StaticListVariableOptions>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../src/plugins/variable.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,2BAA2B,CAAC;AAG/F,
|
|
1
|
+
{"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../src/plugins/variable.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,2BAA2B,CAAC;AAG/F,KAAK,gBAAgB,GAAG,MAAM,GAAG,cAAc,CAAC;AAEhD,KAAK,yBAAyB,GAAG;IAC/B,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAmDF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,yBAAyB,CAiBxE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
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 } 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 readOnly={props.isReadonly}\n renderInput={(params) => (\n <TextField\n {...params}\n label=\"Values\"\n placeholder=\"Values\"\n helperText='Type new value then press \"Enter\" to add.'\n />\n )}\n />\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","StaticListVariableOptionEditor","props","value","values","map","v","onChange","__","label","div","onPaste","e","clipboardData","getData","split","concat","preventDefault","multiple","options","freeSolo","clearOnBlur","readOnly","isReadonly","renderInput","params","placeholder","helperText","StaticListVariable","getVariableOptions","spec","data","dependsOn","variables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,YAAY,EAAEC,SAAS,QAAQ,gBAAgB;AAQxD,SAASC,+BAA+BC,KAAoD;IAC1F,MAAMC,QAAQD,MAAMC,
|
|
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 } 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 readOnly={props.isReadonly}\n renderInput={(params) => (\n <TextField\n {...params}\n label=\"Values\"\n placeholder=\"Values\"\n helperText='Type new value then press \"Enter\" to add.'\n />\n )}\n />\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","StaticListVariableOptionEditor","props","value","values","map","v","onChange","__","label","div","onPaste","e","clipboardData","getData","split","concat","preventDefault","multiple","options","freeSolo","clearOnBlur","readOnly","isReadonly","renderInput","params","placeholder","helperText","StaticListVariable","getVariableOptions","spec","data","dependsOn","variables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,YAAY,EAAEC,SAAS,QAAQ,gBAAgB;AAQxD,SAASC,+BAA+BC,KAAoD;IAC1F,MAAMC,QAAQD,MAAMC,KAAK,CAACC,MAAM,CAACC,GAAG,CAAC,CAACC;QACpC,IAAI,OAAOA,MAAM,UAAU;YACzB,OAAOA;QACT,OAAO;YACL,OAAOA,EAAEH,KAAK;QAChB;IACF;IAEA,MAAMI,WAAW,CAACC,IAAaL;QAC7BD,MAAMK,QAAQ,CAAC;YACbH,QAAQD,MAAME,GAAG,CAAC,CAACC;gBACjB,OAAO;oBAAEH,OAAOG;oBAAGG,OAAOH;gBAAE;YAC9B;QACF;IACF;IAEA,qBACE,KAACI;kBACC,cAAA,KAACX;YACCY,SAAS,CAACC;gBACR,6BAA6B;gBAC7B,MAAMN,IAAIM,EAAEC,aAAa,CAACC,OAAO,CAAC;gBAClC,IAAIR,GAAG;oBACL,MAAMF,SAASE,EAAES,KAAK,CAAC;oBACvBR,SAAS,MAAMJ,MAAMa,MAAM,CAACZ;oBAC5BQ,EAAEK,cAAc;gBAClB;YACF;YACAC,QAAQ;YACRf,OAAOA;YACPI,UAAUA;YACVY,SAAS,EAAE;YACXC,QAAQ;YACRC,WAAW;YACXC,UAAUpB,MAAMqB,UAAU;YAC1BC,aAAa,CAACC,uBACZ,KAACzB;oBACE,GAAGyB,MAAM;oBACVhB,OAAM;oBACNiB,aAAY;oBACZC,YAAW;;;;AAMvB;AAEA,OAAO,MAAMC,qBAAgE;IAC3EC,oBAAoB,OAAOC;YACVA;QAAf,MAAM1B,UAAS0B,eAAAA,KAAK1B,MAAM,cAAX0B,mCAAAA,aAAazB,GAAG,CAAC,CAACC;YAC/B,IAAI,OAAOA,MAAM,UAAU;gBACzB,OAAO;oBAAEG,OAAOH;oBAAGH,OAAOG;gBAAE;YAC9B;YACA,OAAOA;QACT;QACA,OAAO;YACLyB,MAAM3B;QACR;IACF;IACA4B,WAAW;QACT,OAAO;YAAEC,WAAW,EAAE;QAAC;IACzB;IACAC,wBAAwBjC;IACxBkC,sBAAsB,IAAO,CAAA;YAAE/B,QAAQ,EAAE;QAAC,CAAA;AAC5C,EAAE"}
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Metric } from '../model/api-types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Types for metric labels, used in seriesNameFormat implementation
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type SeriesLabels = Record<string, string>;
|
|
6
6
|
export declare function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string;
|
|
7
7
|
export declare function getUniqueKeyForPrometheusResult(metricLabels: {
|
|
8
8
|
[key: string]: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,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
|
@@ -41,7 +41,7 @@ import { isEmptyObject } from '@perses-dev/core';
|
|
|
41
41
|
}
|
|
42
42
|
/*
|
|
43
43
|
* Metric labels formattter which checks for __name__ and outputs valid PromQL for series name
|
|
44
|
-
*/ export function getUniqueKeyForPrometheusResult(metricLabels, { removeExprWrap
|
|
44
|
+
*/ export function getUniqueKeyForPrometheusResult(metricLabels, { removeExprWrap } = {}) {
|
|
45
45
|
const metricNameKey = '__name__';
|
|
46
46
|
if (metricLabels) {
|
|
47
47
|
if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {
|
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 } from '@perses-dev/core';\nimport { Metric } from '../model/api-types';\n\n/**\n * Types for metric labels, used in seriesNameFormat 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 seriesNameFormat 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","formatSeriesName","inputFormat","seriesLabels","resolveLabelsRegex","replace","_match","token","resolvedValue","stringifyPrometheusMetricLabels","labels","removeExprWrap","labelStrings","Object","keys","sort","forEach","labelName","labelValue","undefined","push","join","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,QAAQ,mBAAmB;AAQjD;;;;CAIC,GACD,OAAO,SAASC,iBAAiBC,WAAmB,EAAEC,YAA0B;IAC9E,MAAMC,qBAAqB;IAC3B,OAAOF,YAAYG,
|
|
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 } from '@perses-dev/core';\nimport { Metric } from '../model/api-types';\n\n/**\n * Types for metric labels, used in seriesNameFormat 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 seriesNameFormat 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","formatSeriesName","inputFormat","seriesLabels","resolveLabelsRegex","replace","_match","token","resolvedValue","stringifyPrometheusMetricLabels","labels","removeExprWrap","labelStrings","Object","keys","sort","forEach","labelName","labelValue","undefined","push","join","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,QAAQ,mBAAmB;AAQjD;;;;CAIC,GACD,OAAO,SAASC,iBAAiBC,WAAmB,EAAEC,YAA0B;IAC9E,MAAMC,qBAAqB;IAC3B,OAAOF,YAAYG,OAAO,CAACD,oBAAoB,CAACE,QAAQC;YAChCJ;QAAtB,MAAMK,gBAAgBL,CAAAA,sBAAAA,YAAY,CAACI,MAAM,cAAnBJ,iCAAAA,sBAAuB;QAC7C,OAAOK;IACT;AACF;AAEA;;CAEC,GACD,SAASC,gCAAgCC,MAAkC,EAAEC,cAAwB;IACnG,MAAMC,eAAyB,EAAE;IACjCC,OAAOC,IAAI,CAACJ,QACTK,IAAI,GACJC,OAAO,CAAC,CAACC;QACR,MAAMC,aAAaR,MAAM,CAACO,UAAU;QACpC,IAAIC,eAAeC,WAAW;YAC5B,IAAIR,gBAAgB;gBAClBC,aAAaQ,IAAI,CAAC,CAAC,CAAC,EAAEH,UAAU,GAAG,EAAEC,WAAW,CAAC,CAAC;YACpD,OAAO;gBACLN,aAAaQ,IAAI,CAAC,CAAC,EAAEH,UAAU,EAAE,EAAEC,WAAW,CAAC,CAAC;YAClD;QACF;IACF;IACF,OAAO,CAAC,CAAC,EAAEN,aAAaS,IAAI,CAAC,KAAK,CAAC,CAAC;AACtC;AAEA;;CAEC,GACD,OAAO,SAASC,gCACdC,YAEC,EACD,EAAEZ,cAAc,EAAgC,GAAG,CAAC,CAAC;IAErD,MAAMa,gBAAgB;IACtB,IAAID,cAAc;QAChB,IAAIV,OAAOY,SAAS,CAACC,cAAc,CAACC,IAAI,CAACJ,cAAcC,gBAAgB;YACrE,MAAMI,oBAAoBnB,gCACxB;gBACE,GAAGc,YAAY;gBACf,CAACC,cAAc,EAAEL;YACnB,GACAR;YAEF,IAAIA,mBAAmB,MAAM;gBAC3B,OAAO,CAAC,EAAEiB,kBAAkB,CAAC;YAC/B,OAAO;gBACL,OAAO,CAAC,EAAEL,YAAY,CAACC,cAAc,CAAC,EAAEI,kBAAkB,CAAC;YAC7D;QACF;QACA,OAAOnB,gCAAgCc,cAAcZ;IACvD;IACA,OAAO;AACT;AAEA;;CAEC,GACD,OAAO,SAASkB,iCAAiCC,KAAa,EAAEC,MAAc,EAAEC,SAAkB;IAChG,sDAAsD;IACtD,yDAAyD;IACzD,IAAIC,OAAOX,gCAAgCS;IAC3C,IAAIE,SAAS,MAAMjC,cAAc+B,SAAS;QACxCE,OAAOH;IACT;IAEA,2EAA2E;IAC3E,wEAAwE;IACxE,MAAMI,gBAAgBF,YAAY/B,iBAAiB+B,WAAWD,UAAUE;IACxE,OAAO;QAAEA;QAAMC;IAAc;AAC/B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/prometheus-plugin",
|
|
3
|
-
"version": "0.0.0-snapshot-
|
|
3
|
+
"version": "0.0.0-snapshot-scatterplot-fix-imports-95e1b59",
|
|
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.0.0-snapshot-
|
|
35
|
-
"@perses-dev/core": "0.0.0-snapshot-
|
|
36
|
-
"@perses-dev/plugin-system": "0.0.0-snapshot-
|
|
34
|
+
"@perses-dev/components": "0.0.0-snapshot-scatterplot-fix-imports-95e1b59",
|
|
35
|
+
"@perses-dev/core": "0.0.0-snapshot-scatterplot-fix-imports-95e1b59",
|
|
36
|
+
"@perses-dev/plugin-system": "0.0.0-snapshot-scatterplot-fix-imports-95e1b59",
|
|
37
37
|
"@prometheus-io/codemirror-promql": "^0.43.0",
|
|
38
38
|
"@uiw/react-codemirror": "^4.19.1",
|
|
39
39
|
"date-fns": "^2.28.0",
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "useReplaceTemplateString", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function() {
|
|
20
|
-
return useReplaceTemplateString;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
24
|
-
function useReplaceTemplateString(templateString) {
|
|
25
|
-
const templateVariablesInTemplate = (0, _pluginsystem.parseTemplateVariables)(templateString || '');
|
|
26
|
-
const variables = (0, _pluginsystem.useTemplateVariableValues)(templateVariablesInTemplate);
|
|
27
|
-
return (0, _pluginsystem.replaceTemplateVariables)(templateString || '', variables);
|
|
28
|
-
}
|
package/dist/cjs/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
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
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "DashboardPrometheusTimeSeriesQueryEditor", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function() {
|
|
20
|
-
return DashboardPrometheusTimeSeriesQueryEditor;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
-
const _material = require("@mui/material");
|
|
25
|
-
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
26
|
-
const _model = require("../../model");
|
|
27
|
-
const _components = require("../../components");
|
|
28
|
-
function DashboardPrometheusTimeSeriesQueryEditor(props) {
|
|
29
|
-
const { selectedDatasource , handleDatasourceChange , promURL , query , handleQueryChange , handleQueryBlur , format , handleFormatBlur , handleMinStepChange , handleFormatChange , handleMinStepBlur , minStepPlaceholder , minStep } = props;
|
|
30
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
31
|
-
spacing: 2,
|
|
32
|
-
children: [
|
|
33
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.FormControl, {
|
|
34
|
-
margin: "dense",
|
|
35
|
-
fullWidth: false,
|
|
36
|
-
children: [
|
|
37
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.InputLabel, {
|
|
38
|
-
id: "prom-datasource-label",
|
|
39
|
-
children: "Prometheus Datasource"
|
|
40
|
-
}),
|
|
41
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DatasourceSelect, {
|
|
42
|
-
datasourcePluginKind: _model.PROM_DATASOURCE_KIND,
|
|
43
|
-
value: selectedDatasource,
|
|
44
|
-
onChange: handleDatasourceChange,
|
|
45
|
-
labelId: "prom-datasource-label",
|
|
46
|
-
label: "Prometheus Datasource"
|
|
47
|
-
})
|
|
48
|
-
]
|
|
49
|
-
}),
|
|
50
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.PromQLEditor, {
|
|
51
|
-
completeConfig: {
|
|
52
|
-
remote: {
|
|
53
|
-
url: promURL
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
value: query,
|
|
57
|
-
onChange: handleQueryChange,
|
|
58
|
-
onBlur: handleQueryBlur
|
|
59
|
-
}),
|
|
60
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
61
|
-
direction: "row",
|
|
62
|
-
spacing: 2,
|
|
63
|
-
children: [
|
|
64
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
|
|
65
|
-
fullWidth: true,
|
|
66
|
-
label: "Legend Name",
|
|
67
|
-
placeholder: "Tip: Use {{label_name}}. Example: {{instance}} will be replaced with values such as 'webserver-123' and 'webserver-456'.",
|
|
68
|
-
helperText: "Name for each series in the legend and the tooltip.",
|
|
69
|
-
value: format !== null && format !== void 0 ? format : '',
|
|
70
|
-
onChange: (e)=>handleFormatChange(e.target.value),
|
|
71
|
-
onBlur: handleFormatBlur
|
|
72
|
-
}),
|
|
73
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
|
|
74
|
-
label: "Min Step",
|
|
75
|
-
placeholder: minStepPlaceholder,
|
|
76
|
-
helperText: "Step parameter of the query. Used by $__interval and $__rate_interval too.",
|
|
77
|
-
value: minStep,
|
|
78
|
-
onChange: (e)=>handleMinStepChange(e.target.value),
|
|
79
|
-
onBlur: handleMinStepBlur,
|
|
80
|
-
sx: {
|
|
81
|
-
width: '250px'
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
]
|
|
85
|
-
})
|
|
86
|
-
]
|
|
87
|
-
});
|
|
88
|
-
}
|
package/dist/cjs/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
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
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
Object.defineProperty(exports, "ExplorePrometheusTimeSeriesQueryEditor", {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function() {
|
|
20
|
-
return ExplorePrometheusTimeSeriesQueryEditor;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
24
|
-
const _material = require("@mui/material");
|
|
25
|
-
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
26
|
-
const _model = require("../../model");
|
|
27
|
-
const _components = require("../../components");
|
|
28
|
-
function ExplorePrometheusTimeSeriesQueryEditor(props) {
|
|
29
|
-
const { selectedDatasource , handleDatasourceChange , promURL , query , handleQueryChange , handleQueryBlur , format , handleFormatBlur , handleMinStepChange , handleFormatChange , handleMinStepBlur , minStepPlaceholder , minStep } = props;
|
|
30
|
-
const { project , setProject } = (0, _pluginsystem.useProjectStore)();
|
|
31
|
-
const handleProjectChange = (next)=>{
|
|
32
|
-
handleDatasourceChange(_model.DEFAULT_PROM);
|
|
33
|
-
return setProject(next);
|
|
34
|
-
};
|
|
35
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
36
|
-
spacing: 2,
|
|
37
|
-
children: [
|
|
38
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Grid, {
|
|
39
|
-
container: true,
|
|
40
|
-
spacing: 2,
|
|
41
|
-
children: [
|
|
42
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Grid, {
|
|
43
|
-
item: true,
|
|
44
|
-
xs: 2,
|
|
45
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.FormControl, {
|
|
46
|
-
margin: "dense",
|
|
47
|
-
fullWidth: true,
|
|
48
|
-
children: [
|
|
49
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.InputLabel, {
|
|
50
|
-
id: "project-label",
|
|
51
|
-
children: "Projects"
|
|
52
|
-
}),
|
|
53
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.ProjectSelect, {
|
|
54
|
-
labelId: "project-label",
|
|
55
|
-
label: "Projects",
|
|
56
|
-
value: project,
|
|
57
|
-
onChange: handleProjectChange
|
|
58
|
-
})
|
|
59
|
-
]
|
|
60
|
-
})
|
|
61
|
-
}),
|
|
62
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Grid, {
|
|
63
|
-
item: true,
|
|
64
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.FormControl, {
|
|
65
|
-
margin: "dense",
|
|
66
|
-
fullWidth: true,
|
|
67
|
-
children: [
|
|
68
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.InputLabel, {
|
|
69
|
-
id: "prom-datasource-label",
|
|
70
|
-
children: "Prometheus Datasource"
|
|
71
|
-
}),
|
|
72
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DatasourceSelect, {
|
|
73
|
-
datasourcePluginKind: _model.PROM_DATASOURCE_KIND,
|
|
74
|
-
value: selectedDatasource,
|
|
75
|
-
project: project.metadata.name,
|
|
76
|
-
onChange: handleDatasourceChange,
|
|
77
|
-
labelId: "prom-datasource-label",
|
|
78
|
-
label: "Prometheus Datasource"
|
|
79
|
-
})
|
|
80
|
-
]
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
]
|
|
84
|
-
}),
|
|
85
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.PromQLEditor, {
|
|
86
|
-
completeConfig: {
|
|
87
|
-
remote: {
|
|
88
|
-
url: promURL
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
value: query,
|
|
92
|
-
onChange: handleQueryChange,
|
|
93
|
-
onBlur: handleQueryBlur
|
|
94
|
-
}),
|
|
95
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
|
|
96
|
-
direction: "row",
|
|
97
|
-
spacing: 2,
|
|
98
|
-
children: [
|
|
99
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
|
|
100
|
-
fullWidth: true,
|
|
101
|
-
label: "Legend Name",
|
|
102
|
-
placeholder: "Tip: Use {{label_name}}. Example: {{instance}} will be replaced with values such as 'webserver-123' and 'webserver-456'.",
|
|
103
|
-
helperText: "Name for each series in the legend and the tooltip.",
|
|
104
|
-
value: format !== null && format !== void 0 ? format : '',
|
|
105
|
-
onChange: (e)=>handleFormatChange(e.target.value),
|
|
106
|
-
onBlur: handleFormatBlur
|
|
107
|
-
}),
|
|
108
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
|
|
109
|
-
label: "Min Step",
|
|
110
|
-
placeholder: minStepPlaceholder,
|
|
111
|
-
helperText: "Step parameter of the query. Used by $__interval and $__rate_interval too.",
|
|
112
|
-
value: minStep,
|
|
113
|
-
onChange: (e)=>handleMinStepChange(e.target.value),
|
|
114
|
-
onBlur: handleMinStepBlur,
|
|
115
|
-
sx: {
|
|
116
|
-
width: '250px'
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
]
|
|
120
|
-
})
|
|
121
|
-
]
|
|
122
|
-
});
|
|
123
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../src/model/templating.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,oBAAY,cAAc,GAAG,MAAM,CAAC;AAEpC,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc,UAIvE"}
|