@perses-dev/prometheus-plugin 0.0.0-snapshot-panel-extra-content-2-2767e21 → 0.0.0-snapshot-scatter-chart-embed-8efdfab

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 (84) hide show
  1. package/dist/cjs/components/PromQL.js +9 -7
  2. package/dist/cjs/components/index.js +10 -8
  3. package/dist/cjs/index.js +33 -19
  4. package/dist/cjs/model/index.js +15 -13
  5. package/dist/cjs/model/parse-sample-values.js +6 -2
  6. package/dist/cjs/model/prometheus-client.js +40 -5
  7. package/dist/cjs/model/prometheus-selectors.js +12 -4
  8. package/dist/cjs/model/templating.js +7 -5
  9. package/dist/cjs/model/time.js +14 -8
  10. package/dist/cjs/plugins/MatcherEditor.js +13 -11
  11. package/dist/cjs/plugins/PrometheusDatasourceEditor.js +612 -0
  12. package/dist/cjs/plugins/prometheus-datasource.js +58 -6
  13. package/dist/cjs/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.js +88 -0
  14. package/dist/cjs/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.js +123 -0
  15. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +10 -8
  16. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +48 -50
  17. package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +41 -21
  18. package/dist/cjs/plugins/prometheus-time-series-query/index.js +10 -8
  19. package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +42 -9
  20. package/dist/cjs/plugins/prometheus-variables.js +60 -54
  21. package/dist/cjs/plugins/types.js +7 -0
  22. package/dist/cjs/plugins/variable.js +9 -7
  23. package/dist/cjs/utils/index.js +10 -8
  24. package/dist/cjs/utils/utils.js +12 -6
  25. package/dist/components/PromQL.js.map +1 -1
  26. package/dist/components/index.js.map +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/model/index.js.map +1 -1
  29. package/dist/model/parse-sample-values.js.map +1 -1
  30. package/dist/model/prometheus-client.d.ts +4 -0
  31. package/dist/model/prometheus-client.d.ts.map +1 -1
  32. package/dist/model/prometheus-client.js +24 -0
  33. package/dist/model/prometheus-client.js.map +1 -1
  34. package/dist/model/prometheus-selectors.js.map +1 -1
  35. package/dist/model/templating.js.map +1 -1
  36. package/dist/model/time.js +1 -1
  37. package/dist/model/time.js.map +1 -1
  38. package/dist/plugins/MatcherEditor.js.map +1 -1
  39. package/dist/plugins/PrometheusDatasourceEditor.d.ts +9 -0
  40. package/dist/plugins/PrometheusDatasourceEditor.d.ts.map +1 -0
  41. package/dist/plugins/PrometheusDatasourceEditor.js +560 -0
  42. package/dist/plugins/PrometheusDatasourceEditor.js.map +1 -0
  43. package/dist/plugins/prometheus-datasource.d.ts +1 -5
  44. package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
  45. package/dist/plugins/prometheus-datasource.js +56 -6
  46. package/dist/plugins/prometheus-datasource.js.map +1 -1
  47. package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.d.ts +21 -0
  48. package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.d.ts.map +1 -0
  49. package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.js +80 -0
  50. package/dist/plugins/prometheus-time-series-query/DashboardPrometheusTimeSeriesQueryEditor.js.map +1 -0
  51. package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.d.ts +21 -0
  52. package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.d.ts.map +1 -0
  53. package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.js +115 -0
  54. package/dist/plugins/prometheus-time-series-query/ExplorePrometheusTimeSeriesQueryEditor.js.map +1 -0
  55. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
  56. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
  57. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  58. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +43 -47
  59. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  60. package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
  61. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +34 -16
  62. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
  63. package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
  64. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +10 -1
  65. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -1
  66. package/dist/plugins/prometheus-time-series-query/query-editor-model.js +36 -8
  67. package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
  68. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts +2 -2
  69. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
  70. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
  71. package/dist/plugins/prometheus-variables.js +27 -27
  72. package/dist/plugins/prometheus-variables.js.map +1 -1
  73. package/dist/plugins/types.d.ts +9 -2
  74. package/dist/plugins/types.d.ts.map +1 -1
  75. package/dist/plugins/types.js +1 -1
  76. package/dist/plugins/types.js.map +1 -1
  77. package/dist/plugins/variable.js +2 -2
  78. package/dist/plugins/variable.js.map +1 -1
  79. package/dist/test/setup-tests.js.map +1 -1
  80. package/dist/utils/index.js.map +1 -1
  81. package/dist/utils/utils.d.ts +1 -1
  82. package/dist/utils/utils.js +3 -3
  83. package/dist/utils/utils.js.map +1 -1
  84. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { produce } from 'immer';\nimport { Stack, TextField, FormControl, InputLabel } from '@mui/material';\nimport { DatasourceSelect, DatasourceSelectProps, useDatasourceClient } from '@perses-dev/plugin-system';\nimport {\n DEFAULT_PROM,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n} from '../../model';\nimport { PromQLEditor } from '../../components';\nimport { PrometheusTimeSeriesQueryEditorProps, useQueryState, useFormatState } from './query-editor-model';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\" fullWidth={false}>\n {/* TODO: How do we ensure unique ID values if there are multiple of these? Can we use React 18 useId and\n maintain 17 compatibility somehow with a polyfill/shim? */}\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\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 <TextField\n fullWidth\n label=\"Legend Name\"\n placeholder=\"Tip: Use {{label_name}}. Example: {{instance}} will be replaced with values such as 'webserver-123' and 'webserver-456'.\"\n helperText=\"Set the name for each series in the legend and the tooltip.\"\n value={format ?? ''}\n onChange={(e) => handleFormatChange(e.target.value)}\n onBlur={handleFormatBlur}\n />\n </Stack>\n );\n}\n"],"names":["produce","Stack","TextField","FormControl","InputLabel","DatasourceSelect","useDatasourceClient","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","PromQLEditor","useQueryState","useFormatState","PrometheusTimeSeriesQueryEditor","props","onChange","value","datasource","selectedDatasource","data","client","promURL","options","datasourceUrl","query","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","spacing","margin","fullWidth","id","datasourcePluginKind","labelId","label","completeConfig","remote","url","onBlur","placeholder","helperText","e","target"],"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;AAAA,SAASA,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,KAAK,EAAEC,SAAS,EAAEC,WAAW,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAC1E,SAASC,gBAAgB,EAAyBC,mBAAmB,QA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AAC;YACpC,CAAC,CAAC,CACH,CAAC;YACF,OAAO;QACT,CAAC;QAED,MAAM,IAAIE,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC,AAAC;IAEF,qBACE,MAACnC,KAAK;QAACoC,OAAO,EAAE,CAAC;;0BACf,MAAClC,WAAW;gBAACmC,MAAM,EAAC,OAAO;gBAACC,SAAS,EAAE,KAAK;;kCAG1C,KAACnC,UAAU;wBAACoC,EAAE,EAAC,uBAAuB;kCAAC,uBAAqB;sBAAa;kCACzE,KAACnC,gBAAgB;wBACfoC,oBAAoB,EAAE/B,oBAAoB;wBAC1CO,KAAK,EAAEE,kBAAkB;wBACzBH,QAAQ,EAAEe,sBAAsB;wBAChCW,OAAO,EAAC,uBAAuB;wBAC/BC,KAAK,EAAC,uBAAuB;sBAC7B;;cACU;0BACd,KAAChC,YAAY;gBACXiC,cAAc,EAAE;oBAAEC,MAAM,EAAE;wBAAEC,GAAG,EAAExB,OAAO;qBAAE;iBAAE;gBAC5CL,KAAK,EAAEQ,KAAK;gBACZT,QAAQ,EAAEU,iBAAiB;gBAC3BqB,MAAM,EAAEpB,eAAe;cACvB;0BACF,KAACzB,SAAS;gBACRqC,SAAS;gBACTI,KAAK,EAAC,aAAa;gBACnBK,WAAW,EAAC,0HAA0H;gBACtIC,UAAU,EAAC,6DAA6D;gBACxEhC,KAAK,EAAEW,MAAM,aAANA,MAAM,cAANA,MAAM,GAAI,EAAE;gBACnBZ,QAAQ,EAAE,CAACkC,CAAC,GAAKrB,kBAAkB,CAACqB,CAAC,CAACC,MAAM,CAAClC,KAAK,CAAC;gBACnD8B,MAAM,EAAEjB,gBAAgB;cACxB;;MACI,CACR;AACJ,CAAC"}
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 { DatasourceSelectProps, useDatasource, useDatasourceClient } from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PrometheusClient } from '../../model';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport {\n PrometheusTimeSeriesQueryEditorProps,\n useQueryState,\n useFormatState,\n useMinStepState,\n} from './query-editor-model';\nimport { DashboardPrometheusTimeSeriesQueryEditor } from './DashboardPrometheusTimeSeriesQueryEditor';\nimport { ExplorePrometheusTimeSeriesQueryEditor } from './ExplorePrometheusTimeSeriesQueryEditor';\n\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value, isExplore } = 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 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 if (isExplore) {\n return (\n <ExplorePrometheusTimeSeriesQueryEditor\n selectedDatasource={selectedDatasource}\n handleDatasourceChange={handleDatasourceChange}\n promURL={promURL}\n query={query}\n handleQueryChange={handleQueryChange}\n handleQueryBlur={handleQueryBlur}\n format={format}\n handleFormatChange={handleFormatChange}\n handleFormatBlur={handleFormatBlur}\n minStepPlaceholder={minStepPlaceholder}\n minStep={minStep}\n handleMinStepChange={handleMinStepChange}\n handleMinStepBlur={handleMinStepBlur}\n />\n );\n }\n\n return (\n <DashboardPrometheusTimeSeriesQueryEditor\n selectedDatasource={selectedDatasource}\n handleDatasourceChange={handleDatasourceChange}\n promURL={promURL}\n query={query}\n handleQueryChange={handleQueryChange}\n handleQueryBlur={handleQueryBlur}\n format={format}\n handleFormatChange={handleFormatChange}\n handleFormatBlur={handleFormatBlur}\n minStepPlaceholder={minStepPlaceholder}\n minStep={minStep}\n handleMinStepChange={handleMinStepChange}\n handleMinStepBlur={handleMinStepBlur}\n />\n );\n}\n"],"names":["produce","useDatasource","useDatasourceClient","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","DEFAULT_SCRAPE_INTERVAL","useQueryState","useFormatState","useMinStepState","DashboardPrometheusTimeSeriesQueryEditor","ExplorePrometheusTimeSeriesQueryEditor","PrometheusTimeSeriesQueryEditor","props","onChange","value","isExplore","datasource","selectedDatasource","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"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,s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ACxCzB,SACEd,QAAQe,OAAO,CAACyB;gBACd,sFAAsF;gBACtF,MAAMC,iBAAiBrC,sBAAsBmC,QAAQG,YAAYH;gBACjEC,MAAMvB,aAAawB;YACrB;YAEF;QACF;QAEA,MAAM,IAAIE,MAAM;IAClB;IAEA,IAAI3B,WAAW;QACb,qBACE,KAACL;YACCO,oBAAoBA;YACpBoB,wBAAwBA;YACxBjB,SAASA;YACTI,OAAOA;YACPC,mBAAmBA;YACnBC,iBAAiBA;YACjBC,QAAQA;YACRC,oBAAoBA;YACpBC,kBAAkBA;YAClBI,oBAAoBA;YACpBH,SAASA;YACTC,qBAAqBA;YACrBC,mBAAmBA;;IAGzB;IAEA,qBACE,KAACvB;QACCQ,oBAAoBA;QACpBoB,wBAAwBA;QACxBjB,SAASA;QACTI,OAAOA;QACPC,mBAAmBA;QACnBC,iBAAiBA;QACjBC,QAAQA;QACRC,oBAAoBA;QACpBC,kBAAkBA;QAClBI,oBAAoBA;QACpBH,SAASA;QACTC,qBAAqBA;QACrBC,mBAAmBA;;AAGzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,qBAAqB,EAA4B,MAAM,2BAA2B,CAAC;AAW5F,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CAqFvG,CAAC"}
1
+ {"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,qBAAqB,EAAqD,MAAM,2BAA2B,CAAC;AAYrH,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CA0GvG,CAAC"}
@@ -10,21 +10,30 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { replaceTemplateVariables } from '@perses-dev/plugin-system';
14
- import { fromUnixTime } from 'date-fns';
13
+ import { formatDuration, msToPrometheusDuration, parseDurationString } from '@perses-dev/core';
14
+ import { replaceTemplateVariables, replaceTemplateVariable } from '@perses-dev/plugin-system';
15
+ import { fromUnixTime, milliseconds } from 'date-fns';
15
16
  import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getRangeStep, DEFAULT_PROM } from '../../model';
16
17
  import { getFormattedPrometheusSeriesName } from '../../utils';
18
+ import { DEFAULT_SCRAPE_INTERVAL } from '../types';
17
19
  export const getTimeSeriesData = async (spec, context)=>{
18
- var ref;
20
+ var _response_data;
19
21
  if (spec.query === undefined || spec.query === null || spec.query === '') {
20
22
  // Do not make a request to the backend, instead return an empty TimeSeriesData
21
23
  return {
22
24
  series: []
23
25
  };
24
26
  }
25
- const minStep = getDurationStringSeconds(spec.min_step);
27
+ var _spec_datasource;
28
+ const datasource = await context.datasourceStore.getDatasource((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
29
+ var _datasource_plugin_spec_scrapeInterval;
30
+ const datasourceScrapeInterval = Math.trunc(milliseconds(parseDurationString((_datasource_plugin_spec_scrapeInterval = datasource.plugin.spec.scrapeInterval) !== null && _datasource_plugin_spec_scrapeInterval !== void 0 ? _datasource_plugin_spec_scrapeInterval : DEFAULT_SCRAPE_INTERVAL)) / 1000);
31
+ var _getDurationStringSeconds;
32
+ const minStep = (_getDurationStringSeconds = getDurationStringSeconds(// resolve any variable that may have been provided
33
+ // TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here
34
+ replaceTemplateVariables(spec.minStep, context.variableState))) !== null && _getDurationStringSeconds !== void 0 ? _getDurationStringSeconds : datasourceScrapeInterval;
26
35
  const timeRange = getPrometheusTimeRange(context.timeRange);
27
- const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs);
36
+ const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution
28
37
  // Align the time range so that it's a multiple of the step
29
38
  let { start , end } = timeRange;
30
39
  const utcOffsetSec = new Date().getTimezoneOffset() * 60;
@@ -32,17 +41,26 @@ export const getTimeSeriesData = async (spec, context)=>{
32
41
  const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
33
42
  start = alignedStart;
34
43
  end = alignedEnd;
44
+ var _context_suggestedStepMs;
35
45
  // Replace template variable placeholders in PromQL query
36
- let query = spec.query.replace('$__rate_interval', `15s`);
46
+ const intervalMs = (_context_suggestedStepMs = context.suggestedStepMs) !== null && _context_suggestedStepMs !== void 0 ? _context_suggestedStepMs : step * 1000; // Step is in seconds
47
+ let query = replaceTemplateVariable(spec.query, '__interval_ms', intervalMs.toString());
48
+ query = replaceTemplateVariable(spec.query, '__interval', formatDuration(msToPrometheusDuration(intervalMs)));
49
+ const scrapeIntervalMs = minStep * 1000;
50
+ // The $__rate_interval variable is meant to be used in the rate function.
51
+ // It is defined as max($__interval + Scrape interval, 4 * Scrape interval), where Scrape interval is the Min step setting (a setting per PromQL query),
52
+ // if any is set, and otherwise the Scrape interval as set in the Prometheus datasource
53
+ const rateIntervalMs = Math.max(intervalMs + scrapeIntervalMs, 4 * scrapeIntervalMs);
54
+ query = replaceTemplateVariable(query, '__rate_interval', formatDuration(msToPrometheusDuration(rateIntervalMs)));
37
55
  query = replaceTemplateVariables(query, context.variableState);
38
- let seriesNameFormat = spec.series_name_format;
56
+ let seriesNameFormat = spec.seriesNameFormat;
39
57
  // if series name format is defined, replace template variable placeholders in series name format
40
58
  if (seriesNameFormat) {
41
59
  seriesNameFormat = replaceTemplateVariables(seriesNameFormat, context.variableState);
42
60
  }
43
- var _datasource;
61
+ var _spec_datasource1;
44
62
  // Get the datasource, using the default Prom Datasource if one isn't specified in the query
45
- const client = await context.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
63
+ const client = await context.datasourceStore.getDatasourceClient((_spec_datasource1 = spec.datasource) !== null && _spec_datasource1 !== void 0 ? _spec_datasource1 : DEFAULT_PROM);
46
64
  // Make the request to Prom
47
65
  const response = await client.rangeQuery({
48
66
  query,
@@ -50,16 +68,16 @@ export const getTimeSeriesData = async (spec, context)=>{
50
68
  end,
51
69
  step
52
70
  });
53
- var ref1;
71
+ var _response_data_result;
54
72
  // TODO: What about error responses from Prom that have a response body?
55
- const result = (ref1 = (ref = response.data) === null || ref === void 0 ? void 0 : ref.result) !== null && ref1 !== void 0 ? ref1 : [];
73
+ const result = (_response_data_result = (_response_data = response.data) === null || _response_data === void 0 ? void 0 : _response_data.result) !== null && _response_data_result !== void 0 ? _response_data_result : [];
56
74
  // Custom display for response header warnings, configurable error responses display coming next
57
75
  const notices = [];
58
76
  if (response.status === 'success') {
59
- var _warnings;
60
- const warnings = (_warnings = response.warnings) !== null && _warnings !== void 0 ? _warnings : [];
61
- var ref2;
62
- const warningMessage = (ref2 = warnings[0]) !== null && ref2 !== void 0 ? ref2 : '';
77
+ var _response_warnings;
78
+ const warnings = (_response_warnings = response.warnings) !== null && _response_warnings !== void 0 ? _response_warnings : [];
79
+ var _warnings_;
80
+ const warningMessage = (_warnings_ = warnings[0]) !== null && _warnings_ !== void 0 ? _warnings_ : '';
63
81
  if (warningMessage !== '') {
64
82
  notices.push({
65
83
  type: 'warning',
@@ -77,7 +95,7 @@ export const getTimeSeriesData = async (spec, context)=>{
77
95
  stepMs: step * 1000,
78
96
  series: result.map((value)=>{
79
97
  const { metric , values } = value;
80
- // Account for series_name_format from query editor when determining name to show in legend, tooltip, etc.
98
+ // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.
81
99
  const { name , formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);
82
100
  return {
83
101
  name,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Notice, TimeSeriesData } from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceTemplateVariables } from '@perses-dev/plugin-system';\nimport { fromUnixTime } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const minStep = getDurationStringSeconds(spec.min_step);\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs);\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n // Replace template variable placeholders in PromQL query\n let query = spec.query.replace('$__rate_interval', `15s`);\n query = replaceTemplateVariables(query, context.variableState);\n\n let seriesNameFormat = spec.series_name_format;\n // if series name format is defined, replace template variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceTemplateVariables(seriesNameFormat, context.variableState);\n }\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n\n // Make the request to Prom\n const response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data?.result ?? [];\n\n // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n series: result.map((value) => {\n const { metric, values } = value;\n\n // Account for series_name_format from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n labels: metric,\n };\n }),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n"],"names":["replaceTemplateVariables","fromUnixTime","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getFormattedPrometheusSeriesName","getTimeSeriesData","spec","context","response","query","undefined","series","minStep","min_step","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","Math","floor","alignedStart","replace","variableState","seriesNameFormat","series_name_format","client","datasourceStore","getDatasourceClient","datasource","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","map","value","metric","values","name","formattedName","labels","metadata","executedQueryString"],"mappings":"AAAA,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mB,EAAE7C,KAAK;SAC3B;KACF,AAAC;IAEF,OAAOmC,SAAS,CAAC;AACnB,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n DatasourceSpec,\n DurationString,\n formatDuration,\n msToPrometheusDuration,\n Notice,\n parseDurationString,\n TimeSeriesData,\n} from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceTemplateVariables, replaceTemplateVariable } from '@perses-dev/plugin-system';\nimport { fromUnixTime, milliseconds } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const datasource = (await context.datasourceStore.getDatasource(\n spec.datasource ?? DEFAULT_PROM\n )) as DatasourceSpec<PrometheusDatasourceSpec>;\n const datasourceScrapeInterval = Math.trunc(\n milliseconds(parseDurationString(datasource.plugin.spec.scrapeInterval ?? DEFAULT_SCRAPE_INTERVAL)) / 1000\n );\n\n const minStep =\n getDurationStringSeconds(\n // resolve any variable that may have been provided\n // TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here\n replaceTemplateVariables(spec.minStep as string, context.variableState) as DurationString\n ) ?? datasourceScrapeInterval;\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n // Replace template variable placeholders in PromQL query\n const intervalMs = context.suggestedStepMs ?? step * 1000; // Step is in seconds\n let query = replaceTemplateVariable(spec.query, '__interval_ms', intervalMs.toString());\n query = replaceTemplateVariable(spec.query, '__interval', formatDuration(msToPrometheusDuration(intervalMs)));\n\n const scrapeIntervalMs = minStep * 1000;\n // The $__rate_interval variable is meant to be used in the rate function.\n // It is defined as max($__interval + Scrape interval, 4 * Scrape interval), where Scrape interval is the Min step setting (a setting per PromQL query),\n // if any is set, and otherwise the Scrape interval as set in the Prometheus datasource\n const rateIntervalMs = Math.max(intervalMs + scrapeIntervalMs, 4 * scrapeIntervalMs);\n query = replaceTemplateVariable(query, '__rate_interval', formatDuration(msToPrometheusDuration(rateIntervalMs)));\n query = replaceTemplateVariables(query, context.variableState);\n\n let seriesNameFormat = spec.seriesNameFormat;\n // if series name format is defined, replace template variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceTemplateVariables(seriesNameFormat, context.variableState);\n }\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n\n // Make the request to Prom\n const response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data?.result ?? [];\n\n // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n series: result.map((value) => {\n const { metric, values } = value;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n labels: metric,\n };\n }),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n"],"names":["formatDuration","msToPrometheusDuration","parseDurationString","replaceTemplateVariables","replaceTemplateVariable","fromUnixTime","milliseconds","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getFormattedPrometheusSeriesName","DEFAULT_SCRAPE_INTERVAL","getTimeSeriesData","spec","context","response","query","undefined","series","datasource","datasourceStore","getDatasource","datasourceScrapeInterval","Math","trunc","plugin","scrapeInterval","minStep","variableState","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","floor","alignedStart","intervalMs","toString","scrapeIntervalMs","rateIntervalMs","max","seriesNameFormat","client","getDatasourceClient","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","map","value","metric","values","name","formattedName","labels","metadata","executedQueryString"],"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,SAGEA,cAAc,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D,CAAAA,aAAAA,QAAQ,CAAC,EAAE,cAAXA,wBAAAA,aAAe;QACtC,IAAIC,mBAAmB,IAAI;YACzBH,QAAQI,KAAK;gBACXC,MAAM;gBACNC,SAASH;YACX;QACF;IACF;IAEA,qBAAqB;IACrB,MAAMI,YAA4B;QAChC,gEAAgE;QAChE7B,WAAW;YAAEG,OAAO7B,aAAa6B;YAAQC,KAAK9B,aAAa8B;QAAK;QAChE0B,QAAQ7B,OAAO;QAEfZ,QAAQ+B,OAAOW,IAAI,CAACC;YAClB,MAAM,EAAEC,OAAM,EAAEC,OAAM,EAAE,GAAGF;YAE3B,wGAAwG;YACxG,MAAM,EAAEG,KAAI,EAAEC,cAAa,EAAE,GAAGvD,iCAAiCM,OAAO8C,QAAQjB;YAEhF,OAAO;gBACLmB;gBACAD,QAAQA,OAAOH,IAAIvD;gBACnB4D;gBACAC,QAAQJ;YACV;QACF;QACAK,UAAU;YACRhB;YACAiB,qBAAqBpD;QACvB;IACF;IAEA,OAAO0C;AACT,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './PrometheusTimeSeriesQuery';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './PrometheusTimeSeriesQuery';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,8BAA8B"}
@@ -1,4 +1,5 @@
1
1
  import { OptionsEditorProps } from '@perses-dev/plugin-system';
2
+ import { DurationString } from '@perses-dev/core';
2
3
  import { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';
3
4
  export declare type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;
4
5
  /**
@@ -13,11 +14,19 @@ export declare function useQueryState(props: PrometheusTimeSeriesQueryEditorProp
13
14
  handleQueryBlur: () => void;
14
15
  };
15
16
  /**
16
- * Hook to manage `series_name_format` state to ensure panel preview does not rerender until text input is blurred
17
+ * Hook to manage `seriesNameFormat` state to ensure panel preview does not rerender until text input is blurred
17
18
  */
18
19
  export declare function useFormatState(props: PrometheusTimeSeriesQueryEditorProps): {
19
20
  format: string | undefined;
20
21
  handleFormatChange: (e: string) => void;
21
22
  handleFormatBlur: () => void;
22
23
  };
24
+ /**
25
+ * Hook to manage `minStep` state to ensure panel preview does not rerender until text input is blurred
26
+ */
27
+ export declare function useMinStepState(props: PrometheusTimeSeriesQueryEditorProps): {
28
+ minStep: `${number}y` | `${number}w` | `${number}d` | `${number}h` | `${number}m` | `${number}s` | `${number}ms` | `${number}s${number}ms` | `${number}m${number}ms` | `${number}m${number}s` | `${number}m${number}s${number}ms` | `${number}h${number}ms` | `${number}h${number}s` | `${number}h${number}s${number}ms` | `${number}h${number}m` | `${number}h${number}m${number}ms` | `${number}h${number}m${number}s` | `${number}h${number}m${number}s${number}ms` | `${number}d${number}ms` | `${number}d${number}s` | `${number}d${number}s${number}ms` | `${number}d${number}m` | `${number}d${number}m${number}ms` | `${number}d${number}m${number}s` | `${number}d${number}m${number}s${number}ms` | `${number}d${number}h` | `${number}d${number}h${number}ms` | `${number}d${number}h${number}s` | `${number}d${number}h${number}s${number}ms` | `${number}d${number}h${number}m` | `${number}d${number}h${number}m${number}ms` | `${number}d${number}h${number}m${number}s` | `${number}d${number}h${number}m${number}s${number}ms` | `${number}w${number}ms` | `${number}w${number}s` | `${number}w${number}s${number}ms` | `${number}w${number}m` | `${number}w${number}m${number}ms` | `${number}w${number}m${number}s` | `${number}w${number}m${number}s${number}ms` | `${number}w${number}h` | `${number}w${number}h${number}ms` | `${number}w${number}h${number}s` | `${number}w${number}h${number}s${number}ms` | `${number}w${number}h${number}m` | `${number}w${number}h${number}m${number}ms` | `${number}w${number}h${number}m${number}s` | `${number}w${number}h${number}m${number}s${number}ms` | `${number}w${number}d` | `${number}w${number}d${number}ms` | `${number}w${number}d${number}s` | `${number}w${number}d${number}s${number}ms` | `${number}w${number}d${number}m` | `${number}w${number}d${number}m${number}ms` | `${number}w${number}d${number}m${number}s` | `${number}w${number}d${number}m${number}s${number}ms` | `${number}w${number}d${number}h` | `${number}w${number}d${number}h${number}ms` | `${number}w${number}d${number}h${number}s` | `${number}w${number}d${number}h${number}s${number}ms` | `${number}w${number}d${number}h${number}m` | `${number}w${number}d${number}h${number}m${number}ms` | `${number}w${number}d${number}h${number}m${number}s` | `${number}w${number}d${number}h${number}m${number}s${number}ms` | `${number}y${number}ms` | `${number}y${number}s` | `${number}y${number}s${number}ms` | `${number}y${number}m` | `${number}y${number}m${number}ms` | `${number}y${number}m${number}s` | `${number}y${number}m${number}s${number}ms` | `${number}y${number}h` | `${number}y${number}h${number}ms` | `${number}y${number}h${number}s` | `${number}y${number}h${number}s${number}ms` | `${number}y${number}h${number}m` | `${number}y${number}h${number}m${number}ms` | `${number}y${number}h${number}m${number}s` | `${number}y${number}h${number}m${number}s${number}ms` | `${number}y${number}d` | `${number}y${number}d${number}ms` | `${number}y${number}d${number}s` | `${number}y${number}d${number}s${number}ms` | `${number}y${number}d${number}m` | `${number}y${number}d${number}m${number}ms` | `${number}y${number}d${number}m${number}s` | `${number}y${number}d${number}m${number}s${number}ms` | `${number}y${number}d${number}h` | `${number}y${number}d${number}h${number}ms` | `${number}y${number}d${number}h${number}s` | `${number}y${number}d${number}h${number}s${number}ms` | `${number}y${number}d${number}h${number}m` | `${number}y${number}d${number}h${number}m${number}ms` | `${number}y${number}d${number}h${number}m${number}s` | `${number}y${number}d${number}h${number}m${number}s${number}ms` | `${number}y${number}w` | `${number}y${number}w${number}ms` | `${number}y${number}w${number}s` | `${number}y${number}w${number}s${number}ms` | `${number}y${number}w${number}m` | `${number}y${number}w${number}m${number}ms` | `${number}y${number}w${number}m${number}s` | `${number}y${number}w${number}m${number}s${number}ms` | `${number}y${number}w${number}h` | `${number}y${number}w${number}h${number}ms` | `${number}y${number}w${number}h${number}s` | `${number}y${number}w${number}h${number}s${number}ms` | `${number}y${number}w${number}h${number}m` | `${number}y${number}w${number}h${number}m${number}ms` | `${number}y${number}w${number}h${number}m${number}s` | `${number}y${number}w${number}h${number}m${number}s${number}ms` | `${number}y${number}w${number}d` | `${number}y${number}w${number}d${number}ms` | `${number}y${number}w${number}d${number}s` | `${number}y${number}w${number}d${number}s${number}ms` | `${number}y${number}w${number}d${number}m` | `${number}y${number}w${number}d${number}m${number}ms` | `${number}y${number}w${number}d${number}m${number}s` | `${number}y${number}w${number}d${number}m${number}s${number}ms` | `${number}y${number}w${number}d${number}h` | `${number}y${number}w${number}d${number}h${number}ms` | `${number}y${number}w${number}d${number}h${number}s` | `${number}y${number}w${number}d${number}h${number}s${number}ms` | `${number}y${number}w${number}d${number}h${number}m` | `${number}y${number}w${number}d${number}h${number}m${number}ms` | `${number}y${number}w${number}d${number}h${number}m${number}s` | `${number}y${number}w${number}d${number}h${number}m${number}s${number}ms` | undefined;
29
+ handleMinStepChange: (e: DurationString) => void;
30
+ handleMinStepBlur: () => void;
31
+ };
23
32
  //# sourceMappingURL=query-editor-model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-editor-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,oBAAY,oCAAoC,GAAG,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AAErG;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,oCAAoC;;2BAezC,MAAM;;EAgBrC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,oCAAoC;;4BAYzC,MAAM;;EAetC"}
1
+ {"version":3,"file":"query-editor-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,oBAAY,oCAAoC,GAAG,kBAAkB,CAAC,6BAA6B,CAAC,CAAC;AAErG;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,oCAAoC;;2BAezC,MAAM;;EAgBrC;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,oCAAoC;;4BAYzC,MAAM;;EAetC;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oCAAoC;;6BAYzC,cAAc;;EAe/C"}
@@ -47,25 +47,25 @@ import { produce } from 'immer';
47
47
  };
48
48
  }
49
49
  /**
50
- * Hook to manage `series_name_format` state to ensure panel preview does not rerender until text input is blurred
50
+ * Hook to manage `seriesNameFormat` state to ensure panel preview does not rerender until text input is blurred
51
51
  */ export function useFormatState(props) {
52
52
  const { onChange , value } = props;
53
53
  // TODO: reusable hook or helper util instead of duplicating from useQueryState
54
- const [format, setFormat] = useState(value.series_name_format);
55
- const [lastSyncedFormat, setLastSyncedFormat] = useState(value.series_name_format);
56
- if (value.series_name_format !== lastSyncedFormat) {
57
- setFormat(value.series_name_format);
58
- setLastSyncedFormat(value.series_name_format);
54
+ const [format, setFormat] = useState(value.seriesNameFormat);
55
+ const [lastSyncedFormat, setLastSyncedFormat] = useState(value.seriesNameFormat);
56
+ if (value.seriesNameFormat !== lastSyncedFormat) {
57
+ setFormat(value.seriesNameFormat);
58
+ setLastSyncedFormat(value.seriesNameFormat);
59
59
  }
60
60
  // Update our local state as the user types
61
61
  const handleFormatChange = (e)=>{
62
62
  setFormat(e);
63
63
  };
64
- // Propagate changes to the panel preview component when series_name_format TextField is blurred
64
+ // Propagate changes to the panel preview component when seriesNameFormat TextField is blurred
65
65
  const handleFormatBlur = ()=>{
66
66
  setLastSyncedFormat(format);
67
67
  onChange(produce(value, (draft)=>{
68
- draft.series_name_format = format;
68
+ draft.seriesNameFormat = format;
69
69
  }));
70
70
  };
71
71
  return {
@@ -74,5 +74,33 @@ import { produce } from 'immer';
74
74
  handleFormatBlur
75
75
  };
76
76
  }
77
+ /**
78
+ * Hook to manage `minStep` state to ensure panel preview does not rerender until text input is blurred
79
+ */ export function useMinStepState(props) {
80
+ const { onChange , value } = props;
81
+ // TODO: reusable hook or helper util instead of duplicating from useQueryState
82
+ const [minStep, setMinStep] = useState(value.minStep);
83
+ const [lastSyncedMinStep, setLastSyncedMinStep] = useState(value.minStep);
84
+ if (value.minStep !== lastSyncedMinStep) {
85
+ setMinStep(value.minStep);
86
+ setLastSyncedMinStep(value.minStep);
87
+ }
88
+ // Update our local state as the user types
89
+ const handleMinStepChange = (e)=>{
90
+ setMinStep(e);
91
+ };
92
+ // Propagate changes to the panel preview component when minStep TextField is blurred
93
+ const handleMinStepBlur = ()=>{
94
+ setLastSyncedMinStep(minStep);
95
+ onChange(produce(value, (draft)=>{
96
+ draft.minStep = minStep;
97
+ }));
98
+ };
99
+ return {
100
+ minStep,
101
+ handleMinStepChange,
102
+ handleMinStepBlur
103
+ };
104
+ }
77
105
 
78
106
  //# sourceMappingURL=query-editor-model.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useState } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\n/**\n * A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with\n * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those\n * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview\n * every time the user types.\n */\nexport function useQueryState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // Local copy of the query's value\n const [query, setQuery] = useState(value.query);\n\n // This is basically \"getDerivedStateFromProps\" to make sure if spec's value changes external to this component,\n // we render with the latest value\n const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);\n if (value.query !== lastSyncedQuery) {\n setQuery(value.query);\n setLastSyncedQuery(value.query);\n }\n\n // Update our local state's copy as the user types\n const handleQueryChange = (e: string) => {\n setQuery(e);\n };\n\n // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the\n // PanelPreview\n const handleQueryBlur = () => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n\n/**\n * Hook to manage `series_name_format` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useFormatState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [format, setFormat] = useState(value.series_name_format);\n const [lastSyncedFormat, setLastSyncedFormat] = useState(value.series_name_format);\n if (value.series_name_format !== lastSyncedFormat) {\n setFormat(value.series_name_format);\n setLastSyncedFormat(value.series_name_format);\n }\n\n // Update our local state as the user types\n const handleFormatChange = (e: string) => {\n setFormat(e);\n };\n\n // Propagate changes to the panel preview component when series_name_format TextField is blurred\n const handleFormatBlur = () => {\n setLastSyncedFormat(format);\n onChange(\n produce(value, (draft) => {\n draft.series_name_format = format;\n })\n );\n };\n\n return { format, handleFormatChange, handleFormatBlur };\n}\n"],"names":["useState","produce","useQueryState","props","onChange","value","query","setQuery","lastSyncedQuery","setLastSyncedQuery","handleQueryChange","e","handleQueryBlur","draft","useFormatState","format","setFormat","series_name_format","lastSyncedFormat","setLastSyncedFormat","handleFormatChange","handleFormatBlur"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,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IAC/E,MAAM,CAACY,MAAM,EAAEC,SAAS,CAAC,GAAGhB,QAAQ,CAACK,KAAK,CAACY,kBAAkB,CAAC,AAAC;IAC/D,MAAM,CAACC,gBAAgB,EAAEC,mBAAmB,CAAC,GAAGnB,QAAQ,CAACK,KAAK,CAACY,kBAAkB,CAAC,AAAC;IACnF,IAAIZ,KAAK,CAACY,kBAAkB,KAAKC,gBAAgB,EAAE;QACjDF,SAAS,CAACX,KAAK,CAACY,kBAAkB,CAAC,CAAC;QACpCE,mBAAmB,CAACd,KAAK,CAACY,kBAAkB,CAAC,CAAC;IAChD,CAAC;IAED,2CAA2C;IAC3C,MAAMG,kBAAkB,GAAG,CAACT,CAAS,GAAK;QACxCK,SAAS,CAACL,CAAC,CAAC,CAAC;IACf,CAAC,AAAC;IAEF,gGAAgG;IAChG,MAAMU,gBAAgB,GAAG,IAAM;QAC7BF,mBAAmB,CAACJ,MAAM,CAAC,CAAC;QAC5BX,QAAQ,CACNH,OAAO,CAACI,KAAK,EAAE,CAACQ,KAAK,GAAK;YACxBA,KAAK,CAACI,kBAAkB,GAAGF,MAAM,CAAC;QACpC,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,OAAO;QAAEA,MAAM;QAAEK,kBAAkB;QAAEC,gBAAgB;KAAE,CAAC;AAC1D,CAAC"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useState } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { DurationString } from '@perses-dev/core';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\n/**\n * A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with\n * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those\n * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview\n * every time the user types.\n */\nexport function useQueryState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // Local copy of the query's value\n const [query, setQuery] = useState(value.query);\n\n // This is basically \"getDerivedStateFromProps\" to make sure if spec's value changes external to this component,\n // we render with the latest value\n const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);\n if (value.query !== lastSyncedQuery) {\n setQuery(value.query);\n setLastSyncedQuery(value.query);\n }\n\n // Update our local state's copy as the user types\n const handleQueryChange = (e: string) => {\n setQuery(e);\n };\n\n // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the\n // PanelPreview\n const handleQueryBlur = () => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n\n/**\n * Hook to manage `seriesNameFormat` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useFormatState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [format, setFormat] = useState(value.seriesNameFormat);\n const [lastSyncedFormat, setLastSyncedFormat] = useState(value.seriesNameFormat);\n if (value.seriesNameFormat !== lastSyncedFormat) {\n setFormat(value.seriesNameFormat);\n setLastSyncedFormat(value.seriesNameFormat);\n }\n\n // Update our local state as the user types\n const handleFormatChange = (e: string) => {\n setFormat(e);\n };\n\n // Propagate changes to the panel preview component when seriesNameFormat TextField is blurred\n const handleFormatBlur = () => {\n setLastSyncedFormat(format);\n onChange(\n produce(value, (draft) => {\n draft.seriesNameFormat = format;\n })\n );\n };\n\n return { format, handleFormatChange, handleFormatBlur };\n}\n\n/**\n * Hook to manage `minStep` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useMinStepState(props: PrometheusTimeSeriesQueryEditorProps) {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [minStep, setMinStep] = useState(value.minStep);\n const [lastSyncedMinStep, setLastSyncedMinStep] = useState(value.minStep);\n if (value.minStep !== lastSyncedMinStep) {\n setMinStep(value.minStep);\n setLastSyncedMinStep(value.minStep);\n }\n\n // Update our local state as the user types\n const handleMinStepChange = (e: DurationString) => {\n setMinStep(e);\n };\n\n // Propagate changes to the panel preview component when minStep TextField is blurred\n const handleMinStepBlur = () => {\n setLastSyncedMinStep(minStep);\n onChange(\n produce(value, (draft) => {\n draft.minStep = minStep;\n })\n );\n };\n\n return { minStep, handleMinStepChange, handleMinStepBlur };\n}\n"],"names":["useState","produce","useQueryState","props","onChange","value","query","setQuery","lastSyncedQuery","setLastSyncedQuery","handleQueryChange","e","handleQueryBlur","draft","useFormatState","format","setFormat","seriesNameFormat","lastSyncedFormat","setLastSyncedFormat","handleFormatChange","handleFormatBlur","useMinStepState","minStep","setMinStep","lastSyncedMinStep","setLastSyncedMinStep","handleMinStepChange","handleMinStepBlur"],"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,QAAQ,QAAQ,QAAQ;AACjC,SAASC,OAAO,QAAQ,QAAQ;AAOhC;;;;;CAKC,GACD,OAAO,SAASC,cAAcC,KAA2C;IACvE,MAAM,EAAEC,SAAQ,EAAEC,MAAK,EAAE,GAAGF;IAE5B,kCAAkC;IAClC,MAAM,CAACG,OA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AAMkB;IACjE,IAAIlB,MAAMkB,YAAYE,mBAAmB;QACvCD,WAAWnB,MAAMkB;QACjBG,qBAAqBrB,MAAMkB;IAC7B;IAEA,2CAA2C;IAC3C,MAAMI,sBAAsB,CAAChB;QAC3Ba,WAAWb;IACb;IAEA,qFAAqF;IACrF,MAAMiB,oBAAoB;QACxBF,qBAAqBH;QACrBnB,SACEH,QAAQI,OAAO,CAACQ;YACdA,MAAMU,UAAUA;QAClB;IAEJ;IAEA,OAAO;QAAEA;QAASI;QAAqBC;IAAkB;AAC3D"}
@@ -5,8 +5,8 @@ import { PrometheusDatasourceSelector, TemplateString } from '../../model';
5
5
  */
6
6
  export interface PrometheusTimeSeriesQuerySpec {
7
7
  query: TemplateString;
8
- series_name_format?: string;
9
- min_step?: DurationString;
8
+ seriesNameFormat?: string;
9
+ minStep?: DurationString;
10
10
  resolution?: number;
11
11
  datasource?: PrometheusDatasourceSelector;
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"time-series-query-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,cAAc,CAAC;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C"}
1
+ {"version":3,"file":"time-series-query-model.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,cAAc,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport { PrometheusDatasourceSelector, TemplateString } from '../../model';\n\n/**\n * The spec/options for the PrometheusTimeSeriesQuery plugin.\n */\nexport interface PrometheusTimeSeriesQuerySpec {\n query: TemplateString;\n series_name_format?: string;\n min_step?: DurationString;\n resolution?: number;\n datasource?: PrometheusDatasourceSelector;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAYC"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport { PrometheusDatasourceSelector, TemplateString } from '../../model';\n\n/**\n * The spec/options for the PrometheusTimeSeriesQuery plugin.\n */\nexport interface PrometheusTimeSeriesQuerySpec {\n query: TemplateString;\n seriesNameFormat?: string;\n minStep?: DurationString;\n resolution?: number;\n datasource?: PrometheusDatasourceSelector;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAYC"}
@@ -31,7 +31,7 @@ function PrometheusLabelValuesVariableEditor(props) {
31
31
  }
32
32
  throw new Error('Got unexpected non-Prometheus datasource selector');
33
33
  };
34
- var _matchers;
34
+ var _props_value_matchers;
35
35
  return /*#__PURE__*/ _jsxs(Stack, {
36
36
  spacing: 2,
37
37
  children: [
@@ -55,11 +55,11 @@ function PrometheusLabelValuesVariableEditor(props) {
55
55
  /*#__PURE__*/ _jsx(TextField, {
56
56
  label: "Label Name",
57
57
  required: true,
58
- value: props.value.label_name,
58
+ value: props.value.labelName,
59
59
  onChange: (e)=>{
60
60
  props.onChange({
61
61
  ...props.value,
62
- label_name: e.target.value
62
+ labelName: e.target.value
63
63
  });
64
64
  },
65
65
  InputProps: {
@@ -67,7 +67,7 @@ function PrometheusLabelValuesVariableEditor(props) {
67
67
  }
68
68
  }),
69
69
  /*#__PURE__*/ _jsx(MatcherEditor, {
70
- matchers: (_matchers = props.value.matchers) !== null && _matchers !== void 0 ? _matchers : [],
70
+ matchers: (_props_value_matchers = props.value.matchers) !== null && _props_value_matchers !== void 0 ? _props_value_matchers : [],
71
71
  onChange: (e)=>{
72
72
  props.onChange({
73
73
  ...props.value,
@@ -93,7 +93,7 @@ function PrometheusLabelNamesVariableEditor(props) {
93
93
  }
94
94
  throw new Error('Got unexpected non-Prometheus datasource selector');
95
95
  };
96
- var _matchers;
96
+ var _props_value_matchers;
97
97
  return /*#__PURE__*/ _jsxs(Stack, {
98
98
  spacing: 2,
99
99
  children: [
@@ -115,7 +115,7 @@ function PrometheusLabelNamesVariableEditor(props) {
115
115
  ]
116
116
  }),
117
117
  /*#__PURE__*/ _jsx(MatcherEditor, {
118
- matchers: (_matchers = props.value.matchers) !== null && _matchers !== void 0 ? _matchers : [],
118
+ matchers: (_props_value_matchers = props.value.matchers) !== null && _props_value_matchers !== void 0 ? _props_value_matchers : [],
119
119
  isReadonly: props.isReadonly,
120
120
  onChange: (e)=>{
121
121
  props.onChange({
@@ -181,34 +181,34 @@ function PrometheusPromQLVariableEditor(props) {
181
181
  }),
182
182
  /*#__PURE__*/ _jsx(TextField, {
183
183
  label: "Label Name",
184
- value: props.value.label_name,
184
+ value: props.value.labelName,
185
185
  InputProps: {
186
186
  readOnly: props.isReadonly
187
187
  },
188
188
  onChange: (e)=>{
189
189
  props.onChange({
190
190
  ...props.value,
191
- label_name: e.target.value
191
+ labelName: e.target.value
192
192
  });
193
193
  }
194
194
  })
195
195
  ]
196
196
  });
197
197
  }
198
- function capturingMatrix(matrix, label_name) {
198
+ function capturingMatrix(matrix, labelName) {
199
199
  const captured = new Set();
200
200
  for (const sample of matrix.result){
201
- const value = sample.metric[label_name];
201
+ const value = sample.metric[labelName];
202
202
  if (value !== undefined) {
203
203
  captured.add(value);
204
204
  }
205
205
  }
206
206
  return Array.from(captured.values());
207
207
  }
208
- function capturingVector(vector, label_name) {
208
+ function capturingVector(vector, labelName) {
209
209
  const captured = new Set();
210
210
  for (const sample of vector.result){
211
- const value = sample.metric[label_name];
211
+ const value = sample.metric[labelName];
212
212
  if (value !== undefined) {
213
213
  captured.add(value);
214
214
  }
@@ -226,8 +226,8 @@ function capturingVector(vector, label_name) {
226
226
  };
227
227
  export const PrometheusLabelNamesVariable = {
228
228
  getVariableOptions: async (spec, ctx)=>{
229
- var _datasource;
230
- const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
229
+ var _spec_datasource;
230
+ const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
231
231
  const match = spec.matchers ? spec.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
232
232
  const timeRange = getPrometheusTimeRange(ctx.timeRange);
233
233
  const { data: options } = await client.labelNames({
@@ -239,9 +239,9 @@ export const PrometheusLabelNamesVariable = {
239
239
  };
240
240
  },
241
241
  dependsOn: (spec)=>{
242
- var ref;
242
+ var _spec_matchers;
243
243
  return {
244
- variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>parseTemplateVariables(m)).flat()) || []
244
+ variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>parseTemplateVariables(m)).flat()) || []
245
245
  };
246
246
  },
247
247
  OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
@@ -250,12 +250,12 @@ export const PrometheusLabelNamesVariable = {
250
250
  export const PrometheusLabelValuesVariable = {
251
251
  getVariableOptions: async (spec, ctx)=>{
252
252
  const pluginDef = spec;
253
- var _datasource;
254
- const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
253
+ var _spec_datasource;
254
+ const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
255
255
  const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceTemplateVariables(m, ctx.variables)) : undefined;
256
256
  const timeRange = getPrometheusTimeRange(ctx.timeRange);
257
257
  const { data: options } = await client.labelValues({
258
- labelName: replaceTemplateVariables(pluginDef.label_name, ctx.variables),
258
+ labelName: replaceTemplateVariables(pluginDef.labelName, ctx.variables),
259
259
  'match[]': match,
260
260
  ...timeRange
261
261
  });
@@ -264,25 +264,25 @@ export const PrometheusLabelValuesVariable = {
264
264
  };
265
265
  },
266
266
  dependsOn: (spec)=>{
267
- var ref;
267
+ var _spec_matchers;
268
268
  return {
269
- variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>parseTemplateVariables(m)).flat().concat(parseTemplateVariables(spec.label_name))) || []
269
+ variables: ((_spec_matchers = spec.matchers) === null || _spec_matchers === void 0 ? void 0 : _spec_matchers.map((m)=>parseTemplateVariables(m)).flat().concat(parseTemplateVariables(spec.labelName))) || []
270
270
  };
271
271
  },
272
272
  OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
273
273
  createInitialOptions: ()=>({
274
- label_name: ''
274
+ labelName: ''
275
275
  })
276
276
  };
277
277
  export const PrometheusPromQLVariable = {
278
278
  getVariableOptions: async (spec, ctx)=>{
279
- var _datasource;
280
- const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : DEFAULT_PROM);
279
+ var _spec_datasource;
280
+ const client = await ctx.datasourceStore.getDatasourceClient((_spec_datasource = spec.datasource) !== null && _spec_datasource !== void 0 ? _spec_datasource : DEFAULT_PROM);
281
281
  // TODO we may want to manage a range query as well.
282
282
  const { data: options } = await client.instantQuery({
283
283
  query: replaceTemplateVariables(spec.expr, ctx.variables)
284
284
  });
285
- const labelName = replaceTemplateVariables(spec.label_name, ctx.variables);
285
+ const labelName = replaceTemplateVariables(spec.labelName, ctx.variables);
286
286
  let values = [];
287
287
  if ((options === null || options === void 0 ? void 0 : options.resultType) === 'matrix') {
288
288
  values = capturingMatrix(options, labelName);
@@ -295,13 +295,13 @@ export const PrometheusPromQLVariable = {
295
295
  },
296
296
  dependsOn: (spec)=>{
297
297
  return {
298
- variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.label_name))
298
+ variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.labelName))
299
299
  };
300
300
  },
301
301
  OptionsEditorComponent: PrometheusPromQLVariableEditor,
302
302
  createInitialOptions: ()=>({
303
303
  expr: '',
304
- label_name: ''
304
+ labelName: ''
305
305
  })
306
306
  };
307
307