@perses-dev/prometheus-plugin 0.52.1 → 0.53.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mf/js/Prometheus.c0c6219f.js +5 -0
- package/__mf/js/async/1101.9cf067ee.js +73 -0
- package/__mf/js/async/1441.c735f7dd.js +1 -0
- package/__mf/js/async/1576.8eac7ce9.js +1 -0
- package/__mf/js/async/1964.1d168a86.js +2 -0
- package/__mf/js/async/212.69f85c2b.js +1 -0
- package/__mf/js/async/2188.d2c5eadd.js +1 -0
- package/__mf/js/async/2292.57d8fd0d.js +2 -0
- package/__mf/js/async/2675.27451820.js +1 -0
- package/__mf/js/async/3224.b63f87bf.js +1 -0
- package/__mf/js/async/3507.f1653337.js +101 -0
- package/__mf/js/async/3863.7192dfdf.js +2 -0
- package/__mf/js/async/3960.3eedafbd.js +2 -0
- package/__mf/js/async/3980.0b0d272c.js +2 -0
- package/__mf/js/async/4062.06f48b93.js +1 -0
- package/__mf/js/async/4075.88e3f633.js +1 -0
- package/__mf/js/async/4238.422a1b1c.js +1 -0
- package/__mf/js/async/4323.fdf7d039.js +1 -0
- package/__mf/js/async/4368.5aeca58a.js +2 -0
- package/__mf/js/async/4368.5aeca58a.js.LICENSE.txt +15 -0
- package/__mf/js/async/4421.39621b12.js +1 -0
- package/__mf/js/async/4535.f24704ea.js +1 -0
- package/__mf/js/async/4665.cad36935.js +1 -0
- package/__mf/js/async/5214.0fca84ed.js +1 -0
- package/__mf/js/async/5257.ce463cb7.js +1 -0
- package/__mf/js/async/537.82230699.js +1 -0
- package/__mf/js/async/5409.955ffd51.js +1 -0
- package/__mf/js/async/5614.cce8ba96.js +1 -0
- package/__mf/js/async/5724.794828e3.js +1 -0
- package/__mf/js/async/5774.a3fae698.js +1 -0
- package/__mf/js/async/5790.a9b31ca8.js +1 -0
- package/__mf/js/async/5876.1976752d.js +2 -0
- package/__mf/js/async/{3057.e568f9b6.js.LICENSE.txt → 5876.1976752d.js.LICENSE.txt} +1 -23
- package/__mf/js/async/5981.eb502d27.js +2 -0
- package/__mf/js/async/6292.2afe0c6d.js +1 -0
- package/__mf/js/async/6377.c40920f2.js +2 -0
- package/__mf/js/async/6441.38c30276.js +7 -0
- package/__mf/js/async/6441.38c30276.js.LICENSE.txt +21 -0
- package/__mf/js/async/6770.7099bb3b.js +1 -0
- package/__mf/js/async/684.f7b5c16e.js +1 -0
- package/__mf/js/async/694.8462a746.js +1 -0
- package/__mf/js/async/7272.6fa2f127.js +1 -0
- package/__mf/js/async/7376.2e948f2b.js +1 -0
- package/__mf/js/async/738.a1ffff79.js +1 -0
- package/__mf/js/async/7740.a8777825.js +1 -0
- package/__mf/js/async/8045.7f554a45.js +10 -0
- package/__mf/js/async/8216.e689c178.js +1 -0
- package/__mf/js/async/8488.cbbe542b.js +1 -0
- package/__mf/js/async/8587.40df6f5c.js +1 -0
- package/__mf/js/async/8706.9a6f6579.js +1 -0
- package/__mf/js/async/8930.700a5439.js +1 -0
- package/__mf/js/async/9173.915b80af.js +2 -0
- package/__mf/js/async/9550.642ce5ad.js +38 -0
- package/__mf/js/async/9817.70eae424.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusDatasource.71aecfaf.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusExplorer.80dd9b47.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.86bf76a6.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.e5e35f24.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.b2270799.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.c29461ad.js +1 -0
- package/__mf/js/main.afd47409.js +5 -0
- package/lib/cjs/components/PromQLEditor.js +1 -0
- package/lib/cjs/components/TreeNode.js +9 -1
- package/lib/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +48 -10
- package/lib/cjs/plugins/prometheus-variables.js +108 -46
- package/lib/components/PromQLEditor.d.ts.map +1 -1
- package/lib/components/PromQLEditor.js +1 -0
- package/lib/components/PromQLEditor.js.map +1 -1
- package/lib/components/TreeNode.js +9 -1
- package/lib/components/TreeNode.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +48 -10
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/lib/plugins/prometheus-variables.d.ts.map +1 -1
- package/lib/plugins/prometheus-variables.js +115 -47
- package/lib/plugins/prometheus-variables.js.map +1 -1
- package/lib/plugins/test/setup-tests.d.ts.map +1 -0
- package/lib/plugins/test/setup-tests.js.map +1 -0
- package/mf-manifest.json +262 -483
- package/mf-stats.json +270 -491
- package/package.json +8 -8
- package/__mf/js/622.cc663737.js +0 -5
- package/__mf/js/Prometheus.6aae9c64.js +0 -5
- package/__mf/js/async/1465.3b5e12d5.js +0 -1
- package/__mf/js/async/1620.6376bd14.js +0 -2
- package/__mf/js/async/1964.95da06f6.js +0 -2
- package/__mf/js/async/212.bd5d617a.js +0 -1
- package/__mf/js/async/2285.15378f70.js +0 -1
- package/__mf/js/async/2569.daf868a6.js +0 -10
- package/__mf/js/async/2675.99cf926f.js +0 -1
- package/__mf/js/async/3057.e568f9b6.js +0 -7
- package/__mf/js/async/3090.9fb5fe73.js +0 -2
- package/__mf/js/async/3224.23f0dccf.js +0 -1
- package/__mf/js/async/3355.a4dbcdb0.js +0 -1
- package/__mf/js/async/3818.dde21d04.js +0 -1
- package/__mf/js/async/3871.6915e369.js +0 -1
- package/__mf/js/async/3960.129d5ef5.js +0 -2
- package/__mf/js/async/3980.7cea5715.js +0 -2
- package/__mf/js/async/4062.3ab7f987.js +0 -1
- package/__mf/js/async/4075.b77ca1c7.js +0 -1
- package/__mf/js/async/4238.8e4d29d5.js +0 -1
- package/__mf/js/async/4323.4266fd6a.js +0 -1
- package/__mf/js/async/4421.42e889f6.js +0 -1
- package/__mf/js/async/5214.027c4332.js +0 -1
- package/__mf/js/async/528.d364bb0e.js +0 -1
- package/__mf/js/async/5345.1f4fc17b.js +0 -1
- package/__mf/js/async/537.6911ea2e.js +0 -1
- package/__mf/js/async/5503.a728b5d7.js +0 -1
- package/__mf/js/async/5724.6ee6ec51.js +0 -1
- package/__mf/js/async/5769.f14c9663.js +0 -1
- package/__mf/js/async/5774.9b0b6be1.js +0 -1
- package/__mf/js/async/5790.2273e061.js +0 -1
- package/__mf/js/async/5913.4e5abd09.js +0 -73
- package/__mf/js/async/5914.bd342d22.js +0 -74
- package/__mf/js/async/5981.40bed0d0.js +0 -2
- package/__mf/js/async/6292.7b8efa78.js +0 -1
- package/__mf/js/async/6377.ca974d89.js +0 -2
- package/__mf/js/async/6770.adb1c939.js +0 -1
- package/__mf/js/async/684.ca510333.js +0 -1
- package/__mf/js/async/694.f861d67c.js +0 -1
- package/__mf/js/async/7272.a763aa92.js +0 -1
- package/__mf/js/async/7376.c7eb05b9.js +0 -1
- package/__mf/js/async/738.aca54e25.js +0 -1
- package/__mf/js/async/7740.0c5363fd.js +0 -1
- package/__mf/js/async/8488.5237550f.js +0 -1
- package/__mf/js/async/8587.4891ea90.js +0 -1
- package/__mf/js/async/8930.9fbbc975.js +0 -1
- package/__mf/js/async/8980.afe002d4.js +0 -28
- package/__mf/js/async/9173.e8fbead5.js +0 -2
- package/__mf/js/async/9550.e19763f8.js +0 -38
- package/__mf/js/async/__federation_expose_PrometheusDatasource.f9c8cf41.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusExplorer.171d04eb.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.8551745e.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.a4085adb.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.46f99477.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.fc3c5730.js +0 -1
- package/__mf/js/main.1c9e712b.js +0 -1
- package/lib/test/setup-tests.d.ts.map +0 -1
- package/lib/test/setup-tests.js.map +0 -1
- /package/__mf/css/async/{5263.dacad691.css → 1576.dacad691.css} +0 -0
- /package/__mf/css/async/{6759.dacad691.css → 2188.dacad691.css} +0 -0
- /package/__mf/js/async/{5913.4e5abd09.js.LICENSE.txt → 1101.9cf067ee.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{1964.95da06f6.js.LICENSE.txt → 1964.1d168a86.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{3090.9fb5fe73.js.LICENSE.txt → 2292.57d8fd0d.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{1620.6376bd14.js.LICENSE.txt → 3863.7192dfdf.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{3960.129d5ef5.js.LICENSE.txt → 3960.3eedafbd.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{3980.7cea5715.js.LICENSE.txt → 3980.0b0d272c.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{5981.40bed0d0.js.LICENSE.txt → 5981.eb502d27.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{6377.ca974d89.js.LICENSE.txt → 6377.c40920f2.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{2569.daf868a6.js.LICENSE.txt → 8045.7f554a45.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{9173.e8fbead5.js.LICENSE.txt → 9173.915b80af.js.LICENSE.txt} +0 -0
- /package/lib/cjs/{test → plugins/test}/setup-tests.js +0 -0
- /package/lib/{test → plugins/test}/setup-tests.d.ts +0 -0
- /package/lib/{test → plugins/test}/setup-tests.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { produce } from 'immer';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n useDatasource,\n useDatasourceClient,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { useId } from '@perses-dev/components';\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport { ReactElement } from 'react';\nimport {\n DEFAULT_PROM,\n DurationString,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n PrometheusDatasourceSelector,\n} from '../../model';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PromQLEditor } from '../../components';\nimport {\n PrometheusTimeSeriesQueryEditorProps,\n useQueryState,\n useFormatState,\n useMinStepState,\n} from './query-editor-model';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): ReactElement {\n const { onChange, value } = props;\n const { datasource } = value;\n const datasourceSelectValue = datasource ?? DEFAULT_PROM;\n\n const datasourceSelectLabelID = useId('prom-datasource-label'); // for panels with multiple queries, this component is rendered multiple times on the same page\n\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n PROM_DATASOURCE_KIND\n ) as PrometheusDatasourceSelector;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n const { data: datasourceResource } = useDatasource(selectedDatasource);\n\n const { handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\n const { minStep, handleMinStepChange, handleMinStepBlur } = useMinStepState(props);\n const minStepPlaceholder =\n minStep ??\n (datasourceResource && (datasourceResource?.plugin.spec as PrometheusDatasourceSpec).scrapeInterval) ??\n DEFAULT_SCRAPE_INTERVAL;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\" fullWidth={false}>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={datasourceSelectValue}\n onChange={handleDatasourceChange}\n labelId={datasourceSelectLabelID}\n label=\"Prometheus Datasource\"\n notched\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={value.query} // here we are passing `value.query` and not `query` from useQueryState in order to get updates only on onBlur events\n datasource={selectedDatasource}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n />\n <Stack direction=\"row\" spacing={2}>\n <TextField\n fullWidth\n label=\"Legend\"\n placeholder=\"Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...\"\n helperText=\"Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.\"\n value={format ?? ''}\n onChange={(e) => handleFormatChange(e.target.value)}\n onBlur={handleFormatBlur}\n />\n <TextField\n label=\"Min Step\"\n placeholder={minStepPlaceholder}\n helperText=\"Lower bound for the step. If not provided, the scrape interval of the datasource is used.\"\n value={minStep ?? ''}\n onChange={(e) => handleMinStepChange(e.target.value ? (e.target.value as DurationString) : undefined)}\n onBlur={handleMinStepBlur}\n sx={{ width: '250px' }}\n />\n </Stack>\n </Stack>\n );\n}\n"],"names":["produce","DatasourceSelect","useDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","useId","FormControl","Stack","TextField","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","DEFAULT_SCRAPE_INTERVAL","PromQLEditor","useQueryState","useFormatState","useMinStepState","PrometheusTimeSeriesQueryEditor","props","onChange","value","datasource","datasourceSelectValue","datasourceSelectLabelID","selectedDatasource","data","client","promURL","options","datasourceUrl","datasourceResource","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","minStep","handleMinStepChange","handleMinStepBlur","minStepPlaceholder","plugin","spec","scrapeInterval","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","spacing","margin","fullWidth","datasourcePluginKind","labelId","label","notched","completeConfig","remote","url","query","onBlur","direction","placeholder","helperText","e","target","sx","width"],"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,OAAO,QAAQ,QAAQ;AAChC,SACEC,gBAAgB,EAEhBC,aAAa,EACbC,mBAAmB,EACnBC,kCAAkC,QAC7B,4BAA4B;AACnC,SAASC,KAAK,QAAQ,yBAAyB;AAC/C,SAASC,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAE9D,SACEC,YAAY,EAEZC,qBAAqB,EACrBC,8BAA8B,EAC9BC,oBAAoB,QAGf,cAAc;AACrB,SAASC,uBAAuB,QAAkC,WAAW;AAC7E,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAEEC,aAAa,EACbC,cAAc,EACdC,eAAe,QACV,uBAAuB;AAE9B;;CAEC,GACD,OAAO,SAASC,gCAAgCC,KAA2C;IACzF,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAC5B,MAAM,EAAEG,UAAU,EAAE,GAAGD;IACvB,MAAME,wBAAwBD,cAAcb;IAE5C,MAAMe,0BAA0BnB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AS;wBACTG,OAAM;wBACNQ,aAAY;wBACZC,YAAW;wBACX3C,OAAOa,UAAU;wBACjBd,UAAU,CAAC6C,IAAM9B,mBAAmB8B,EAAEC,MAAM,CAAC7C,KAAK;wBAClDwC,QAAQzB;;kCAEV,KAAC5B;wBACC+C,OAAM;wBACNQ,aAAavB;wBACbwB,YAAW;wBACX3C,OAAOgB,WAAW;wBAClBjB,UAAU,CAAC6C,IAAM3B,oBAAoB2B,EAAEC,MAAM,CAAC7C,KAAK,GAAI4C,EAAEC,MAAM,CAAC7C,KAAK,GAAsB2B;wBAC3Fa,QAAQtB;wBACR4B,IAAI;4BAAEC,OAAO;wBAAQ;;;;;;AAK/B"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { produce } from 'immer';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n useDatasource,\n useDatasourceClient,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { useId } from '@perses-dev/components';\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport { ReactElement, useCallback } from 'react';\nimport {\n DEFAULT_PROM,\n DurationString,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n PrometheusDatasourceSelector,\n} from '../../model';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PromQLEditor } from '../../components';\nimport {\n PrometheusTimeSeriesQueryEditorProps,\n useQueryState,\n useFormatState,\n useMinStepState,\n} from './query-editor-model';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): ReactElement {\n const {\n onChange,\n value,\n value: { query, datasource },\n queryHandlerSettings,\n } = props;\n\n const datasourceSelectValue = datasource ?? DEFAULT_PROM;\n\n const datasourceSelectLabelID = useId('prom-datasource-label'); // for panels with multiple queries, this component is rendered multiple times on the same page\n\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n PROM_DATASOURCE_KIND\n ) as PrometheusDatasourceSelector;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n const { data: datasourceResource } = useDatasource(selectedDatasource);\n\n const { handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\n const { minStep, handleMinStepChange, handleMinStepBlur } = useMinStepState(props);\n const minStepPlaceholder =\n minStep ??\n (datasourceResource && (datasourceResource?.plugin.spec as PrometheusDatasourceSpec).scrapeInterval) ??\n DEFAULT_SCRAPE_INTERVAL;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n /* Good to know: The usage of onchange here causes an immediate spec update which eventually updates the panel\n This was probably intentional to allow for quick switching between datasources.\n Could have been triggered only with Run Query button as well.\n */\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, datasource: next });\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n const handlePromQlEditorChanges = useCallback(\n (e: string) => {\n handleQueryChange(e);\n if (queryHandlerSettings?.watchQueryChanges) {\n queryHandlerSettings?.watchQueryChanges(e);\n }\n },\n [queryHandlerSettings, handleQueryChange]\n );\n\n const handleLegendSpecChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n handleFormatChange(e.target.value);\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, seriesNameFormat: e.target.value });\n },\n [queryHandlerSettings, handleFormatChange, value]\n );\n\n const handleMinStepSpecChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n handleMinStepChange(e.target.value ? (e.target.value as DurationString) : undefined);\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, minStep: e.target.value });\n },\n [queryHandlerSettings, handleMinStepChange, value]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\" fullWidth={false}>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={datasourceSelectValue}\n onChange={handleDatasourceChange}\n labelId={datasourceSelectLabelID}\n label=\"Prometheus Datasource\"\n notched\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={query} // here we are passing `value.query` and not `query` from useQueryState in order to get updates only on onBlur events\n datasource={selectedDatasource}\n onChange={handlePromQlEditorChanges}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined}\n />\n <Stack direction=\"row\" spacing={2}>\n <TextField\n fullWidth\n label=\"Legend\"\n placeholder=\"Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...\"\n helperText=\"Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.\"\n value={format ?? ''}\n onChange={handleLegendSpecChange}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleFormatBlur : undefined}\n />\n <TextField\n label=\"Min Step\"\n placeholder={minStepPlaceholder}\n helperText=\"Lower bound for the step. If not provided, the scrape interval of the datasource is used.\"\n value={minStep ?? ''}\n onChange={handleMinStepSpecChange}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleMinStepBlur : undefined}\n sx={{ width: '250px' }}\n />\n </Stack>\n </Stack>\n );\n}\n"],"names":["produce","DatasourceSelect","useDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","useId","FormControl","Stack","TextField","useCallback","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","DEFAULT_SCRAPE_INTERVAL","PromQLEditor","useQueryState","useFormatState","useMinStepState","PrometheusTimeSeriesQueryEditor","props","onChange","value","query","datasource","queryHandlerSettings","datasourceSelectValue","datasourceSelectLabelID","selectedDatasource","data","client","promURL","options","datasourceUrl","datasourceResource","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","minStep","handleMinStepChange","handleMinStepBlur","minStepPlaceholder","plugin","spec","scrapeInterval","handleDatasourceChange","next","draft","nextDatasource","undefined","setWatchOtherSpecs","Error","handlePromQlEditorChanges","e","watchQueryChanges","handleLegendSpecChange","target","seriesNameFormat","handleMinStepSpecChange","spacing","margin","fullWidth","datasourcePluginKind","labelId","label","notched","completeConfig","remote","url","onBlur","runWithOnBlur","direction","placeholder","helperText","sx","width"],"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,OAAO,QAAQ,QAAQ;AAChC,SACEC,gBAAgB,EAEhBC,aAAa,EACbC,mBAAmB,EACnBC,kCAAkC,QAC7B,4BAA4B;AACnC,SAASC,KAAK,QAAQ,yBAAyB;AAC/C,SAASC,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC9D,SAAuBC,WAAW,QAAQ,QAAQ;AAClD,SACEC,YAAY,EAEZC,qBAAqB,EACrBC,8BAA8B,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OAAM;wBACNQ,aAAY;wBACZC,YAAW;wBACXrD,OAAOe,UAAU;wBACjBhB,UAAUoC;wBACVc,QAAQ9C,sBAAsB+C,gBAAgBjC,mBAAmBY;;kCAEnE,KAAC3C;wBACC0D,OAAM;wBACNQ,aAAa/B;wBACbgC,YAAW;wBACXrD,OAAOkB,WAAW;wBAClBnB,UAAUuC;wBACVW,QAAQ9C,sBAAsB+C,gBAAgB9B,oBAAoBS;wBAClEyB,IAAI;4BAAEC,OAAO;wBAAQ;;;;;;AAK/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAaA,OAAO,EAGL,kBAAkB,EAElB,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAaA,OAAO,EAGL,kBAAkB,EAElB,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAyB,MAAM,OAAO,CAAC;AAE5D,OAAO,EAIL,UAAU,EAGV,UAAU,EACX,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AAUjB,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,kBAAkB,CAAC,oCAAoC,CAAC,GAC9D,YAAY,CAsEd;AAED,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,kBAAkB,CAAC,mCAAmC,CAAC,GAC7D,YAAY,CAsDd;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,kBAAkB,CAAC,+BAA+B,CAAC,GACzD,YAAY,CAsFd;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAS/E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAS/E;AAED;;GAEG;AACH,eAAO,MAAM,4BAA4B,GAAI,SAAS,MAAM,EAAE,KAAG,cAAc,EAM9E,CAAC"}
|
|
@@ -14,23 +14,59 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
import { FormControl, Stack, TextField } from '@mui/material';
|
|
15
15
|
import { DatasourceSelect, useDatasourceClient } from '@perses-dev/plugin-system';
|
|
16
16
|
import { produce } from 'immer';
|
|
17
|
+
import { useCallback, useState } from 'react';
|
|
17
18
|
import { PromQLEditor } from '../components';
|
|
18
19
|
import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PROM_DATASOURCE_KIND } from '../model';
|
|
19
20
|
import { MatcherEditor } from './MatcherEditor';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
/* TODO:
|
|
22
|
+
Open Question for later improvement
|
|
23
|
+
The usage of direct onchange here causes an immediate spec update which eventually updates the panel
|
|
24
|
+
This was probably intentional to allow for quick switching between values.
|
|
25
|
+
Shouldn't we update the panel only through the Run Query Button?
|
|
26
|
+
I think we should only track the changes and let the button to Run the query
|
|
27
|
+
*/ export function PrometheusLabelValuesVariableEditor(props) {
|
|
28
|
+
const { onChange, value, value: { datasource }, queryHandlerSettings } = props;
|
|
23
29
|
const selectedDatasource = datasource ?? DEFAULT_PROM;
|
|
24
|
-
const
|
|
30
|
+
const [labelValue, setLabelValue] = useState(props.value.labelName);
|
|
31
|
+
const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);
|
|
32
|
+
const handleDatasourceChange = useCallback((next)=>{
|
|
25
33
|
if (isPrometheusDatasourceSelector(next)) {
|
|
26
34
|
onChange(produce(value, (draft)=>{
|
|
27
35
|
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
28
36
|
draft.datasource = isDefaultPromSelector(next) ? undefined : next;
|
|
29
37
|
}));
|
|
38
|
+
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
|
|
39
|
+
...value,
|
|
40
|
+
datasource: next
|
|
41
|
+
});
|
|
30
42
|
return;
|
|
31
43
|
}
|
|
32
44
|
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
33
|
-
}
|
|
45
|
+
}, [
|
|
46
|
+
onChange,
|
|
47
|
+
queryHandlerSettings,
|
|
48
|
+
value
|
|
49
|
+
]);
|
|
50
|
+
const handleLabelChange = useCallback((e)=>{
|
|
51
|
+
setLabelValue(e.target.value);
|
|
52
|
+
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
|
|
53
|
+
...value,
|
|
54
|
+
labelName: e.target.value
|
|
55
|
+
});
|
|
56
|
+
}, [
|
|
57
|
+
value,
|
|
58
|
+
queryHandlerSettings
|
|
59
|
+
]);
|
|
60
|
+
const handleMatchEditorsChange = useCallback((e)=>{
|
|
61
|
+
setMatchersValues(e);
|
|
62
|
+
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
|
|
63
|
+
...value,
|
|
64
|
+
matchers: e
|
|
65
|
+
});
|
|
66
|
+
}, [
|
|
67
|
+
value,
|
|
68
|
+
queryHandlerSettings
|
|
69
|
+
]);
|
|
34
70
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
35
71
|
spacing: 2,
|
|
36
72
|
children: [
|
|
@@ -48,44 +84,54 @@ export function PrometheusLabelValuesVariableEditor(props) {
|
|
|
48
84
|
/*#__PURE__*/ _jsx(TextField, {
|
|
49
85
|
label: "Label Name",
|
|
50
86
|
required: true,
|
|
51
|
-
value:
|
|
52
|
-
onChange:
|
|
53
|
-
props.onChange({
|
|
54
|
-
...props.value,
|
|
55
|
-
labelName: e.target.value
|
|
56
|
-
});
|
|
57
|
-
},
|
|
87
|
+
value: labelValue,
|
|
88
|
+
onChange: handleLabelChange,
|
|
58
89
|
InputProps: {
|
|
59
90
|
readOnly: props.isReadonly
|
|
60
91
|
}
|
|
61
92
|
}),
|
|
62
93
|
/*#__PURE__*/ _jsx(MatcherEditor, {
|
|
63
|
-
matchers:
|
|
64
|
-
onChange:
|
|
65
|
-
props.onChange({
|
|
66
|
-
...props.value,
|
|
67
|
-
matchers: e
|
|
68
|
-
});
|
|
69
|
-
},
|
|
94
|
+
matchers: matchersValues,
|
|
95
|
+
onChange: handleMatchEditorsChange,
|
|
70
96
|
isReadonly: props.isReadonly
|
|
71
97
|
})
|
|
72
98
|
]
|
|
73
99
|
});
|
|
74
100
|
}
|
|
75
101
|
export function PrometheusLabelNamesVariableEditor(props) {
|
|
76
|
-
const { onChange, value } = props;
|
|
77
|
-
const { datasource } = value;
|
|
102
|
+
const { onChange, value, value: { datasource }, queryHandlerSettings } = props;
|
|
78
103
|
const selectedDatasource = datasource ?? DEFAULT_PROM;
|
|
79
|
-
const
|
|
104
|
+
const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);
|
|
105
|
+
const handleDatasourceChange = useCallback((next)=>{
|
|
80
106
|
if (isPrometheusDatasourceSelector(next)) {
|
|
81
107
|
onChange(produce(value, (draft)=>{
|
|
82
108
|
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
83
109
|
draft.datasource = isDefaultPromSelector(next) ? undefined : next;
|
|
84
110
|
}));
|
|
111
|
+
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
|
|
112
|
+
...value,
|
|
113
|
+
datasource: next
|
|
114
|
+
});
|
|
85
115
|
return;
|
|
86
116
|
}
|
|
87
117
|
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
88
|
-
}
|
|
118
|
+
}, [
|
|
119
|
+
onChange,
|
|
120
|
+
queryHandlerSettings,
|
|
121
|
+
value
|
|
122
|
+
]);
|
|
123
|
+
const handleMatchEditorChange = useCallback((e)=>{
|
|
124
|
+
setMatchersValues(e);
|
|
125
|
+
if (queryHandlerSettings?.setWatchOtherSpecs) {
|
|
126
|
+
queryHandlerSettings.setWatchOtherSpecs({
|
|
127
|
+
...value,
|
|
128
|
+
matchers: e
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}, [
|
|
132
|
+
value,
|
|
133
|
+
queryHandlerSettings
|
|
134
|
+
]);
|
|
89
135
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
90
136
|
spacing: 2,
|
|
91
137
|
children: [
|
|
@@ -101,34 +147,65 @@ export function PrometheusLabelNamesVariableEditor(props) {
|
|
|
101
147
|
})
|
|
102
148
|
}),
|
|
103
149
|
/*#__PURE__*/ _jsx(MatcherEditor, {
|
|
104
|
-
matchers:
|
|
150
|
+
matchers: matchersValues,
|
|
105
151
|
isReadonly: props.isReadonly,
|
|
106
|
-
onChange:
|
|
107
|
-
props.onChange({
|
|
108
|
-
...props.value,
|
|
109
|
-
matchers: e
|
|
110
|
-
});
|
|
111
|
-
}
|
|
152
|
+
onChange: handleMatchEditorChange
|
|
112
153
|
})
|
|
113
154
|
]
|
|
114
155
|
});
|
|
115
156
|
}
|
|
116
157
|
export function PrometheusPromQLVariableEditor(props) {
|
|
117
|
-
const { onChange, value } = props;
|
|
118
|
-
const { datasource } = value;
|
|
158
|
+
const { onChange, value, value: { datasource }, queryHandlerSettings } = props;
|
|
119
159
|
const selectedDatasource = datasource ?? DEFAULT_PROM;
|
|
120
160
|
const { data: client } = useDatasourceClient(selectedDatasource);
|
|
121
161
|
const promURL = client?.options.datasourceUrl;
|
|
122
|
-
const
|
|
162
|
+
const [labelValue, setLableValue] = useState(props.value.labelName);
|
|
163
|
+
const handleDatasourceChange = useCallback((next)=>{
|
|
123
164
|
if (isPrometheusDatasourceSelector(next)) {
|
|
124
165
|
onChange(produce(value, (draft)=>{
|
|
125
166
|
// If they're using the default, just omit the datasource prop (i.e. set to undefined)
|
|
126
167
|
draft.datasource = isDefaultPromSelector(next) ? undefined : next;
|
|
127
168
|
}));
|
|
169
|
+
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
|
|
170
|
+
...value,
|
|
171
|
+
datasource: next
|
|
172
|
+
});
|
|
128
173
|
return;
|
|
129
174
|
}
|
|
130
175
|
throw new Error('Got unexpected non-Prometheus datasource selector');
|
|
131
|
-
}
|
|
176
|
+
}, [
|
|
177
|
+
value,
|
|
178
|
+
onChange,
|
|
179
|
+
queryHandlerSettings
|
|
180
|
+
]);
|
|
181
|
+
const handleOnBlurPromQlChange = useCallback((e)=>{
|
|
182
|
+
onChange({
|
|
183
|
+
...value,
|
|
184
|
+
expr: e.target.textContent ?? ''
|
|
185
|
+
});
|
|
186
|
+
}, [
|
|
187
|
+
onChange,
|
|
188
|
+
value
|
|
189
|
+
]);
|
|
190
|
+
const trackPromQlChanges = useCallback((e)=>{
|
|
191
|
+
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
|
|
192
|
+
...value,
|
|
193
|
+
expr: e.target.textContent ?? ''
|
|
194
|
+
});
|
|
195
|
+
}, [
|
|
196
|
+
queryHandlerSettings,
|
|
197
|
+
value
|
|
198
|
+
]);
|
|
199
|
+
const handleLabelNameChange = useCallback((e)=>{
|
|
200
|
+
setLableValue(e.target.value);
|
|
201
|
+
if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
|
|
202
|
+
...value,
|
|
203
|
+
labelName: e.target.value
|
|
204
|
+
});
|
|
205
|
+
}, [
|
|
206
|
+
queryHandlerSettings,
|
|
207
|
+
value
|
|
208
|
+
]);
|
|
132
209
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
133
210
|
spacing: 2,
|
|
134
211
|
children: [
|
|
@@ -151,27 +228,18 @@ export function PrometheusPromQLVariableEditor(props) {
|
|
|
151
228
|
},
|
|
152
229
|
value: value.expr,
|
|
153
230
|
datasource: selectedDatasource,
|
|
154
|
-
onBlur:
|
|
155
|
-
props.onChange({
|
|
156
|
-
...props.value,
|
|
157
|
-
expr: event.target.textContent ?? ''
|
|
158
|
-
});
|
|
159
|
-
},
|
|
231
|
+
onBlur: queryHandlerSettings?.runWithOnBlur ? handleOnBlurPromQlChange : trackPromQlChanges,
|
|
160
232
|
readOnly: props.isReadonly,
|
|
161
233
|
width: "100%"
|
|
162
234
|
}),
|
|
163
235
|
/*#__PURE__*/ _jsx(TextField, {
|
|
164
236
|
label: "Label Name",
|
|
165
|
-
|
|
237
|
+
required: true,
|
|
238
|
+
value: labelValue,
|
|
166
239
|
InputProps: {
|
|
167
240
|
readOnly: props.isReadonly
|
|
168
241
|
},
|
|
169
|
-
onChange:
|
|
170
|
-
props.onChange({
|
|
171
|
-
...props.value,
|
|
172
|
-
labelName: e.target.value
|
|
173
|
-
});
|
|
174
|
-
}
|
|
242
|
+
onChange: handleLabelNameChange
|
|
175
243
|
})
|
|
176
244
|
]
|
|
177
245
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-variables.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport { ReactElement } from 'react';\nimport { PromQLEditor } from '../components';\nimport {\n DEFAULT_PROM,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n VectorData,\n} from '../model';\nimport { MatcherEditor } from './MatcherEditor';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\n\nexport function PrometheusLabelValuesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>\n): ReactElement {\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 <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\nexport function PrometheusLabelNamesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>\n): ReactElement {\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 <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\nexport function PrometheusPromQLVariableEditor(\n props: OptionsEditorProps<PrometheusPromQLVariableOptions>\n): ReactElement {\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 <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 datasource={selectedDatasource}\n onBlur={(event) => {\n props.onChange({ ...props.value, expr: event.target.textContent ?? '' });\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\nexport function 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\nexport function 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 */\nexport const stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n"],"names":["FormControl","Stack","TextField","DatasourceSelect","useDatasourceClient","produce","PromQLEditor","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","handleDatasourceChange","next","draft","undefined","Error","spacing","margin","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","labelName","e","target","InputProps","matchers","PrometheusLabelNamesVariableEditor","disabled","PrometheusPromQLVariableEditor","data","client","promURL","options","datasourceUrl","completeConfig","remote","url","expr","onBlur","event","textContent","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map"],"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,SAASA,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC9D,SACEC,gBAAgB,EAGhBC,mBAAmB,QAEd,4BAA4B;AACnC,SAASC,OAAO,QAAQ,QAAQ;AAEhC,SAASC,Y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C,SAASK,GAAG,CAAC5C;QACf;IACF;IACA,OAAO6C,MAAMC,IAAI,CAACP,SAASQ,MAAM;AACnC;AAEA;;CAEC,GACD,OAAO,MAAMG,+BAA+B,CAACH;IAC3C,IAAI,CAACA,QAAQ,OAAO,EAAE;IACtB,OAAOA,OAAOI,GAAG,CAAC,CAACnD,QAAW,CAAA;YAC5BA;YACAc,OAAOd;QACT,CAAA;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-variables.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport { ReactElement, useCallback, useState } from 'react';\nimport { PromQLEditor } from '../components';\nimport {\n DEFAULT_PROM,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n VectorData,\n} from '../model';\nimport { MatcherEditor } from './MatcherEditor';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\n\n/* TODO: \nOpen Question for later improvement\nThe usage of direct onchange here causes an immediate spec update which eventually updates the panel\nThis was probably intentional to allow for quick switching between values.\nShouldn't we update the panel only through the Run Query Button? \nI think we should only track the changes and let the button to Run the query\n*/\n\nexport function PrometheusLabelValuesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n queryHandlerSettings,\n } = props;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n const [labelValue, setLabelValue] = useState(props.value.labelName);\n const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (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 if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, datasource: next });\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [onChange, queryHandlerSettings, value]\n );\n\n const handleLabelChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLabelValue(e.target.value);\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, labelName: e.target.value });\n },\n [value, queryHandlerSettings]\n );\n\n const handleMatchEditorsChange = useCallback(\n (e: string[]) => {\n setMatchersValues(e);\n if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({ ...value, matchers: e });\n },\n [value, queryHandlerSettings]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\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={labelValue}\n onChange={handleLabelChange}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n />\n <MatcherEditor matchers={matchersValues} onChange={handleMatchEditorsChange} isReadonly={props.isReadonly} />\n </Stack>\n );\n}\n\nexport function PrometheusLabelNamesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n queryHandlerSettings,\n } = props;\n\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (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 if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, datasource: next });\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [onChange, queryHandlerSettings, value]\n );\n\n const handleMatchEditorChange = useCallback(\n (e: string[]) => {\n setMatchersValues(e);\n if (queryHandlerSettings?.setWatchOtherSpecs) {\n queryHandlerSettings.setWatchOtherSpecs({ ...value, matchers: e });\n }\n },\n [value, queryHandlerSettings]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\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 matchers={matchersValues} isReadonly={props.isReadonly} onChange={handleMatchEditorChange} />\n </Stack>\n );\n}\n\nexport function PrometheusPromQLVariableEditor(\n props: OptionsEditorProps<PrometheusPromQLVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n queryHandlerSettings,\n } = props;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n const [labelValue, setLableValue] = useState(props.value.labelName);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (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 if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings?.setWatchOtherSpecs({ ...value, datasource: next });\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [value, onChange, queryHandlerSettings]\n );\n\n const handleOnBlurPromQlChange = useCallback(\n (e: React.FocusEvent<HTMLDivElement, Element>) => {\n onChange({ ...value, expr: e.target.textContent ?? '' });\n },\n [onChange, value]\n );\n\n const trackPromQlChanges = useCallback(\n (e: React.FocusEvent<HTMLDivElement, Element>) => {\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings?.setWatchOtherSpecs({ ...value, expr: e.target.textContent ?? '' });\n },\n [queryHandlerSettings, value]\n );\n\n const handleLabelNameChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLableValue(e.target.value);\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings?.setWatchOtherSpecs({ ...value, labelName: e.target.value });\n },\n [queryHandlerSettings, value]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\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 datasource={selectedDatasource}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleOnBlurPromQlChange : trackPromQlChanges}\n readOnly={props.isReadonly}\n width=\"100%\"\n />\n <TextField\n label=\"Label Name\"\n required\n value={labelValue}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n onChange={handleLabelNameChange}\n />\n </Stack>\n );\n}\n\nexport function 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\nexport function 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 */\nexport const stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n"],"names":["FormControl","Stack","TextField","DatasourceSelect","useDatasourceClient","produce","useCallback","useState","PromQLEditor","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","queryHandlerSettings","selectedDatasource","labelValue","setLabelValue","labelName","matchersValues","setMatchersValues","matchers","handleDatasourceChange","next","draft","undefined","setWatchOtherSpecs","Error","handleLabelChange","e","target","handleMatchEditorsChange","spacing","margin","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","InputProps","PrometheusLabelNamesVariableEditor","handleMatchEditorChange","disabled","PrometheusPromQLVariableEditor","data","client","promURL","options","datasourceUrl","setLableValue","handleOnBlurPromQlChange","expr","textContent","trackPromQlChanges","handleLabelNameChange","completeConfig","remote","url","onBlur","runWithOnBlur","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map"],"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,SAASA,WAAW,EAAEC,KAAK,EAAEC,SA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AClD,UAAU;QACtC,IAAIN,UAAUa,WAAW;YACvBuC,SAASK,GAAG,CAACzD;QACf;IACF;IACA,OAAO0D,MAAMC,IAAI,CAACP,SAASQ,MAAM;AACnC;AAEA,OAAO,SAASC,gBAAgBC,MAAkB,EAAExD,SAAiB;IACnE,MAAM8C,WAAW,IAAIC;IACrB,KAAK,MAAMC,UAAUQ,OAAOP,MAAM,CAAE;QAClC,MAAMvD,QAAQsD,OAAOE,MAAM,CAAClD,UAAU;QACtC,IAAIN,UAAUa,WAAW;YACvBuC,SAASK,GAAG,CAACzD;QACf;IACF;IACA,OAAO0D,MAAMC,IAAI,CAACP,SAASQ,MAAM;AACnC;AAEA;;CAEC,GACD,OAAO,MAAMG,+BAA+B,CAACH;IAC3C,IAAI,CAACA,QAAQ,OAAO,EAAE;IACtB,OAAOA,OAAOI,GAAG,CAAC,CAAChE,QAAW,CAAA;YAC5BA;YACA0B,OAAO1B;QACT,CAAA;AACF,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-tests.d.ts","sourceRoot":"","sources":["../../../../src/plugins/test/setup-tests.ts"],"names":[],"mappings":"AAaA,OAAO,yCAAyC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/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,0CAA0C"}
|