@perses-dev/prometheus-plugin 0.48.0 → 0.49.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/cjs/components/PromQLEditor.js +209 -0
  2. package/dist/cjs/components/TreeNode.js +147 -0
  3. package/dist/cjs/components/index.js +1 -1
  4. package/dist/cjs/components/parse.js +42 -0
  5. package/dist/cjs/components/promql/ast.js +143 -0
  6. package/dist/cjs/components/promql/format.js +432 -0
  7. package/dist/cjs/components/promql/utils.js +109 -0
  8. package/dist/cjs/model/prometheus-client.js +10 -2
  9. package/dist/cjs/plugins/PrometheusDatasourceEditor.js +4 -0
  10. package/dist/cjs/plugins/prometheus-datasource.js +4 -0
  11. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +6 -5
  12. package/dist/cjs/plugins/prometheus-variables.js +4 -2
  13. package/dist/components/PromQLEditor.d.ts +9 -0
  14. package/dist/components/PromQLEditor.d.ts.map +1 -0
  15. package/dist/components/PromQLEditor.js +196 -0
  16. package/dist/components/PromQLEditor.js.map +1 -0
  17. package/dist/components/TreeNode.d.ts +10 -0
  18. package/dist/components/TreeNode.d.ts.map +1 -0
  19. package/dist/components/TreeNode.js +139 -0
  20. package/dist/components/TreeNode.js.map +1 -0
  21. package/dist/components/index.d.ts +1 -1
  22. package/dist/components/index.d.ts.map +1 -1
  23. package/dist/components/index.js +1 -1
  24. package/dist/components/index.js.map +1 -1
  25. package/dist/components/parse.d.ts +4 -0
  26. package/dist/components/parse.d.ts.map +1 -0
  27. package/dist/components/parse.js +34 -0
  28. package/dist/components/parse.js.map +1 -0
  29. package/dist/components/promql/ast.d.ts +161 -0
  30. package/dist/components/promql/ast.d.ts.map +1 -0
  31. package/dist/components/promql/ast.js +106 -0
  32. package/dist/components/promql/ast.js.map +1 -0
  33. package/dist/components/promql/format.d.ts +5 -0
  34. package/dist/components/promql/format.d.ts.map +1 -0
  35. package/dist/components/promql/format.js +411 -0
  36. package/dist/components/promql/format.js.map +1 -0
  37. package/dist/components/promql/utils.d.ts +5 -0
  38. package/dist/components/promql/utils.d.ts.map +1 -0
  39. package/dist/components/promql/utils.js +90 -0
  40. package/dist/components/promql/utils.js.map +1 -0
  41. package/dist/model/api-types.d.ts +5 -0
  42. package/dist/model/api-types.d.ts.map +1 -1
  43. package/dist/model/api-types.js.map +1 -1
  44. package/dist/model/prometheus-client.d.ts +6 -1
  45. package/dist/model/prometheus-client.d.ts.map +1 -1
  46. package/dist/model/prometheus-client.js +9 -2
  47. package/dist/model/prometheus-client.js.map +1 -1
  48. package/dist/plugins/PrometheusDatasourceEditor.d.ts.map +1 -1
  49. package/dist/plugins/PrometheusDatasourceEditor.js +4 -0
  50. package/dist/plugins/PrometheusDatasourceEditor.js.map +1 -1
  51. package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
  52. package/dist/plugins/prometheus-datasource.js +5 -1
  53. package/dist/plugins/prometheus-datasource.js.map +1 -1
  54. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  55. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +6 -5
  56. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  57. package/dist/plugins/prometheus-variables.d.ts.map +1 -1
  58. package/dist/plugins/prometheus-variables.js +4 -2
  59. package/dist/plugins/prometheus-variables.js.map +1 -1
  60. package/package.json +4 -4
  61. package/dist/cjs/components/PromQL.js +0 -58
  62. package/dist/components/PromQL.d.ts +0 -7
  63. package/dist/components/PromQL.d.ts.map +0 -1
  64. package/dist/components/PromQL.js +0 -45
  65. package/dist/components/PromQL.js.map +0 -1
@@ -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 { DatasourceSelect, DatasourceSelectProps, useDatasource, useDatasourceClient } from '@perses-dev/plugin-system';\nimport { FormControl, InputLabel, Stack, TextField } from '@mui/material';\nimport {\n DEFAULT_PROM,\n DurationString,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\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) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n const datasourceSelectLabelID = `prom-datasource-label-${selectedDatasource.name || 'default'}`;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n const { data: datasourceResource } = useDatasource(selectedDatasource);\n\n const { query, 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 <InputLabel id={datasourceSelectLabelID}>Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId={datasourceSelectLabelID}\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={query}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n />\n <Stack direction=\"row\" spacing={2}>\n <TextField\n fullWidth\n label=\"Legend Name\"\n placeholder=\"Tip: Use {{label_name}}. Example: {{instance}} will be replaced with values such as 'webserver-123' and 'webserver-456'.\"\n helperText=\"Name for each series in the legend and the tooltip.\"\n value={format ?? ''}\n onChange={(e) => handleFormatChange(e.target.value)}\n onBlur={handleFormatBlur}\n />\n <TextField\n label=\"Min Step\"\n placeholder={minStepPlaceholder}\n helperText=\"Step parameter of the query. Used by $__interval and $__rate_interval too.\"\n value={minStep}\n onChange={(e) => handleMinStepChange(e.target.value as DurationString)}\n onBlur={handleMinStepBlur}\n sx={{ width: '250px' }}\n />\n </Stack>\n </Stack>\n );\n}\n"],"names":["produce","DatasourceSelect","useDatasource","useDatasourceClient","FormControl","InputLabel","Stack","TextField","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","DEFAULT_SCRAPE_INTERVAL","PromQLEditor","useQueryState","useFormatState","useMinStepState","PrometheusTimeSeriesQueryEditor","props","onChange","value","datasource","selectedDatasource","datasourceSelectLabelID","name","data","client","promURL","options","datasourceUrl","datasourceResource","query","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","minStep","handleMinStepChange","handleMinStepBlur","minStepPlaceholder","plugin","spec","scrapeInterval","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","spacing","margin","fullWidth","id","datasourcePluginKind","labelId","label","completeConfig","remote","url","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,SAASC,gBAAgB,EAAyBC,aAAa,EAAEC,mBAAmB,QAAQ,4BAA4B;AACxH,SAASC,WAAW,EAAEC,UAAU,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC1E,SACEC,YAAY,EAEZC,qBAAqB,EACrBC,8BAA8B,EAC9BC,oBAAoB,QAEf,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,qBAAqBD,uBAAAA,wBAAAA,aAAcb;IACzC,MAAMe,0BAA0B,CAAC,sBAAsB,EAAED,mBAAmBE,IAAI,IAAI,UAAU,CAAC;IAE/F,MAAM,EAAEC,MAAMC,MAAM,EAAE,GAAGvB,oBAAsCmB;IAC/D,MAAMK,UAAUD,mBAAAA,6BAAAA,OAAQE,OAAO,CAACC,aAAa;IAC7C,MAAM,EAAEJ,MAAMK,kBAAkB,EAAE,GAAG5B,cAAcoB;IAEnD,MAAM,EAAES,KAAK,EAAEC,iBAAi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M;wBACNM,aAAatB;wBACbuB,YAAW;wBACX3C,OAAOiB;wBACPlB,UAAU,CAAC6C,IAAM1B,oBAAoB0B,EAAEC,MAAM,CAAC7C,KAAK;wBACnDwC,QAAQrB;wBACR2B,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 { DatasourceSelect, DatasourceSelectProps, useDatasource, useDatasourceClient } from '@perses-dev/plugin-system';\nimport { FormControl, InputLabel, Stack, TextField } from '@mui/material';\nimport {\n DEFAULT_PROM,\n DurationString,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\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) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n const datasourceSelectLabelID = `prom-datasource-label-${selectedDatasource.name || 'default'}`;\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 <InputLabel id={datasourceSelectLabelID}>Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId={datasourceSelectLabelID}\n label=\"Prometheus Datasource\"\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=\"Step parameter of the query. Used by $__interval and $__rate_interval too.\"\n value={minStep}\n onChange={(e) => handleMinStepChange(e.target.value as DurationString)}\n onBlur={handleMinStepBlur}\n sx={{ width: '250px' }}\n />\n </Stack>\n </Stack>\n );\n}\n"],"names":["produce","DatasourceSelect","useDatasource","useDatasourceClient","FormControl","InputLabel","Stack","TextField","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","DEFAULT_SCRAPE_INTERVAL","PromQLEditor","useQueryState","useFormatState","useMinStepState","PrometheusTimeSeriesQueryEditor","props","onChange","value","datasource","selectedDatasource","datasourceSelectLabelID","name","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","id","datasourcePluginKind","labelId","label","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,SAASC,gBAAgB,EAAyBC,aAAa,EAAEC,mBAAmB,QAAQ,4BAA4B;AACxH,SAASC,WAAW,EAAEC,UAAU,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC1E,SACEC,YAAY,EAEZC,qBAAqB,EACrBC,8BAA8B,EAC9BC,oBAAoB,QAEf,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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BAAEC,QAAQ;wBAAEC,KAAK/B;oBAAQ;gBAAE;gBAC3CP,OAAOA,MAAMuC,KAAK;gBAClBtC,YAAYC;gBACZH,UAAUY;gBACV6B,QAAQ5B;;0BAEV,MAAC1B;gBAAMuD,WAAU;gBAAMZ,SAAS;;kCAC9B,KAAC1C;wBACC4C,SAAS;wBACTI,OAAM;wBACNO,aAAY;wBACZC,YAAW;wBACX3C,OAAOa,mBAAAA,oBAAAA,SAAU;wBACjBd,UAAU,CAAC6C,IAAM9B,mBAAmB8B,EAAEC,MAAM,CAAC7C,KAAK;wBAClDwC,QAAQzB;;kCAEV,KAAC5B;wBACCgD,OAAM;wBACNO,aAAavB;wBACbwB,YAAW;wBACX3C,OAAOgB;wBACPjB,UAAU,CAAC6C,IAAM3B,oBAAoB2B,EAAEC,MAAM,CAAC7C,KAAK;wBACnDwC,QAAQtB;wBACR4B,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":"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,CA4B9F,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,+BAA+B,CAwBpF,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;AAgMjB,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAgB5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CA4B9F,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,+BAA+B,CAwBpF,CAAC"}
@@ -170,10 +170,12 @@ function PrometheusPromQLVariableEditor(props) {
170
170
  }
171
171
  },
172
172
  value: value.expr,
173
- onChange: (query)=>{
173
+ datasource: selectedDatasource,
174
+ onBlur: (event)=>{
175
+ var _event_target_textContent;
174
176
  props.onChange({
175
177
  ...props.value,
176
- expr: query
178
+ expr: (_event_target_textContent = event.target.textContent) !== null && _event_target_textContent !== void 0 ? _event_target_textContent : ''
177
179
  });
178
180
  },
179
181
  readOnly: props.isReadonly,
@@ -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 {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n VariablePlugin,\n parseVariables,\n replaceVariables,\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) => replaceVariables(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) => parseVariables(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 ? pluginDef.matchers.map((m) => replaceVariables(m, ctx.variables)) : undefined;\n\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues({\n labelName: replaceVariables(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) => parseVariables(m))\n .flat()\n .concat(parseVariables(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: replaceVariables(spec.expr, ctx.variables),\n });\n const labelName = replaceVariables(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: parseVariables(spec.expr).concat(parseVariables(spec.labelName)) };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', labelName: '' }),\n};\n"],"names":["DatasourceSelect","useDatasourceClient","parseVariables","replaceVariables","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,cAAc,EACdC,gBAAgB,QAEX,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;IAC5B,MAAM,EAAEG,UAAU,EAAE,GAAGD;IACvB,MAAME,qBAAqBD,uBAAAA,wBAAAA,aAAcX;IAEzC,MAAMa,yBAA4D,CAACC;QACjE,IAAIX,+BAA+BW,OAAO;YACxCL,SACEV,QAAQW,OAAO,CAACK;gBACd,sFAAsF;gBACtFA,MAAMJ,UAAU,GAAGT,sBAAsBY,QAAQE,YAAYF;YAC/D;Y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KpB,IAAI,EAAEoC,MAAM,CAACtF,eAAesE,KAAKpC,SAAS;QAAG;IACvF;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 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 {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n VariablePlugin,\n parseVariables,\n replaceVariables,\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 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\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) => replaceVariables(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) => parseVariables(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 ? pluginDef.matchers.map((m) => replaceVariables(m, ctx.variables)) : undefined;\n\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues({\n labelName: replaceVariables(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) => parseVariables(m))\n .flat()\n .concat(parseVariables(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: replaceVariables(spec.expr, ctx.variables),\n });\n const labelName = replaceVariables(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: parseVariables(spec.expr).concat(parseVariables(spec.labelName)) };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', labelName: '' }),\n};\n"],"names":["DatasourceSelect","useDatasourceClient","parseVariables","replaceVariables","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","onBlur","event","textContent","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","query","resultType"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AACjC,SACEA,gBAAgB,EAGhBC,mBAAmB,EAGnBC,cAAc,EACdC,gBAAgB,QAEX,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;IAC5B,MAAM,EAAEG,UAAU,EAAE,GAAGD;IACvB,MAAME,qBAAqBD,uBAAAA,wBAAAA,aAAcX;IAEzC,MAAMa,yBAA4D,CAACC;QACjE,IAAIX,+BAA+BW,OAAO;YACxCL,SACEV,QAAQW,OAAO,CAACK;gBACd,sFAAsF;gBACtFA,MAAMJ,UAAU,GAAGT,sBAAsBY,QAAQE,YAAYF;YAC/D;YAEF;QACF;QAEA,MAAM,IAAIG,MAAM;IAClB;QA2BgBT;IAzBhB,qBACE,MAACX;QAAMqB,SAAS;;0BACd,MAACvB;gBAAYwB,QAAO;;kCAClB,KAACvB;wBAAWwB,IAAG;kCAAwB;;kCACvC,KAAC7B;wBACC8B,sBAAqB;wBACrBX,OAAOE;wBACPH,UAAUI;wBACVS,UAAUd,MAAMe,UAAU;wBAC1BC,SAAQ;wBACRC,OAAM;;;;0BAGV,KAAC3B;gBACC2B,OAAM;gBACNC,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/prometheus-plugin",
3
- "version": "0.48.0",
3
+ "version": "0.49.0-rc.0",
4
4
  "description": "Prometheus plugin for Perses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -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.48.0",
35
- "@perses-dev/core": "0.48.0",
36
- "@perses-dev/plugin-system": "0.48.0",
34
+ "@perses-dev/components": "0.49.0-rc.0",
35
+ "@perses-dev/core": "0.49.0-rc.0",
36
+ "@perses-dev/plugin-system": "0.49.0-rc.0",
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,58 +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, "PromQLEditor", {
18
- enumerable: true,
19
- get: function() {
20
- return PromQLEditor;
21
- }
22
- });
23
- const _jsxruntime = require("react/jsx-runtime");
24
- const _reactcodemirror = /*#__PURE__*/ _interop_require_default(require("@uiw/react-codemirror"));
25
- const _codemirrorpromql = require("@prometheus-io/codemirror-promql");
26
- const _view = require("@codemirror/view");
27
- const _material = require("@mui/material");
28
- const _react = require("react");
29
- function _interop_require_default(obj) {
30
- return obj && obj.__esModule ? obj : {
31
- default: obj
32
- };
33
- }
34
- function PromQLEditor({ completeConfig, ...rest }) {
35
- const theme = (0, _material.useTheme)();
36
- const isDarkMode = theme.palette.mode === 'dark';
37
- const promQLExtension = (0, _react.useMemo)(()=>{
38
- return new _codemirrorpromql.PromQLExtension().activateLinter(false).setComplete(completeConfig).asExtension();
39
- }, [
40
- completeConfig
41
- ]);
42
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_reactcodemirror.default, {
43
- ...rest,
44
- style: {
45
- border: `1px solid ${theme.palette.divider}`
46
- },
47
- theme: isDarkMode ? 'dark' : 'light',
48
- basicSetup: {
49
- highlightActiveLine: false,
50
- highlightActiveLineGutter: false,
51
- foldGutter: false
52
- },
53
- extensions: [
54
- _view.EditorView.lineWrapping,
55
- promQLExtension
56
- ]
57
- });
58
- }
@@ -1,7 +0,0 @@
1
- import { ReactCodeMirrorProps } from '@uiw/react-codemirror';
2
- import { CompleteConfiguration } from '@prometheus-io/codemirror-promql';
3
- export type PromQLEditorProps = {
4
- completeConfig: CompleteConfiguration;
5
- } & Omit<ReactCodeMirrorProps, 'theme' | 'extensions'>;
6
- export declare function PromQLEditor({ completeConfig, ...rest }: PromQLEditorProps): import("react/jsx-runtime").JSX.Element;
7
- //# sourceMappingURL=PromQL.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PromQL.d.ts","sourceRoot":"","sources":["../../src/components/PromQL.tsx"],"names":[],"mappings":"AAaA,OAAmB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAmB,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAK1F,MAAM,MAAM,iBAAiB,GAAG;IAAE,cAAc,EAAE,qBAAqB,CAAA;CAAE,GAAG,IAAI,CAC9E,oBAAoB,EACpB,OAAO,GAAG,YAAY,CACvB,CAAC;AAEF,wBAAgB,YAAY,CAAC,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,EAAE,iBAAiB,2CAqB1E"}
@@ -1,45 +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
- import { jsx as _jsx } from "react/jsx-runtime";
14
- import CodeMirror from '@uiw/react-codemirror';
15
- import { PromQLExtension } from '@prometheus-io/codemirror-promql';
16
- import { EditorView } from '@codemirror/view';
17
- import { useTheme } from '@mui/material';
18
- import { useMemo } from 'react';
19
- export function PromQLEditor({ completeConfig, ...rest }) {
20
- const theme = useTheme();
21
- const isDarkMode = theme.palette.mode === 'dark';
22
- const promQLExtension = useMemo(()=>{
23
- return new PromQLExtension().activateLinter(false).setComplete(completeConfig).asExtension();
24
- }, [
25
- completeConfig
26
- ]);
27
- return /*#__PURE__*/ _jsx(CodeMirror, {
28
- ...rest,
29
- style: {
30
- border: `1px solid ${theme.palette.divider}`
31
- },
32
- theme: isDarkMode ? 'dark' : 'light',
33
- basicSetup: {
34
- highlightActiveLine: false,
35
- highlightActiveLineGutter: false,
36
- foldGutter: false
37
- },
38
- extensions: [
39
- EditorView.lineWrapping,
40
- promQLExtension
41
- ]
42
- });
43
- }
44
-
45
- //# sourceMappingURL=PromQL.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/PromQL.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 CodeMirror, { ReactCodeMirrorProps } from '@uiw/react-codemirror';\nimport { PromQLExtension, CompleteConfiguration } from '@prometheus-io/codemirror-promql';\nimport { EditorView } from '@codemirror/view';\nimport { useTheme } from '@mui/material';\nimport { useMemo } from 'react';\n\nexport type PromQLEditorProps = { completeConfig: CompleteConfiguration } & Omit<\n ReactCodeMirrorProps,\n 'theme' | 'extensions'\n>;\n\nexport function PromQLEditor({ completeConfig, ...rest }: PromQLEditorProps) {\n const theme = useTheme();\n const isDarkMode = theme.palette.mode === 'dark';\n\n const promQLExtension = useMemo(() => {\n return new PromQLExtension().activateLinter(false).setComplete(completeConfig).asExtension();\n }, [completeConfig]);\n\n return (\n <CodeMirror\n {...rest}\n style={{ border: `1px solid ${theme.palette.divider}` }}\n theme={isDarkMode ? 'dark' : 'light'}\n basicSetup={{\n highlightActiveLine: false,\n highlightActiveLineGutter: false,\n foldGutter: false,\n }}\n extensions={[EditorView.lineWrapping, promQLExtension]}\n />\n );\n}\n"],"names":["CodeMirror","PromQLExtension","EditorView","useTheme","useMemo","PromQLEditor","completeConfig","rest","theme","isDarkMode","palette","mode","promQLExtension","activateLinter","setComplete","asExtension","style","border","divider","basicSetup","highlightActiveLine","highlightActiveLineGutter","foldGutter","extensions","lineWrapping"],"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,OAAOA,gBAA0C,wBAAwB;AACzE,SAASC,eAAe,QAA+B,mCAAmC;AAC1F,SAASC,UAAU,QAAQ,mBAAmB;AAC9C,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAASC,OAAO,QAAQ,QAAQ;AAOhC,OAAO,SAASC,aAAa,EAAEC,cAAc,EAAE,GAAGC,MAAyB;IACzE,MAAMC,QAAQL;IACd,MAAMM,aAAaD,MAAME,OAAO,CAACC,IAAI,KAAK;IAE1C,MAAMC,kBAAkBR,QAAQ;QAC9B,OAAO,IAAIH,kBAAkBY,cAAc,CAAC,OAAOC,WAAW,CAACR,gBAAgBS,WAAW;IAC5F,GAAG;QAACT;KAAe;IAEnB,qBACE,KAACN;QACE,GAAGO,IAAI;QACRS,OAAO;YAAEC,QAAQ,CAAC,UAAU,EAAET,MAAME,OAAO,CAACQ,OAAO,CAAC,CAAC;QAAC;QACtDV,OAAOC,aAAa,SAAS;QAC7BU,YAAY;YACVC,qBAAqB;YACrBC,2BAA2B;YAC3BC,YAAY;QACd;QACAC,YAAY;YAACrB,WAAWsB,YAAY;YAAEZ;SAAgB;;AAG5D"}