@perses-dev/prometheus-plugin 0.0.0-snapshot-panel-extra-content-3-17f9c42 → 0.0.0-snapshot-scatterplot-fix-imports-95e1b59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/cjs/components/PromQL.js +10 -8
  2. package/dist/cjs/components/index.js +10 -8
  3. package/dist/cjs/index.js +33 -19
  4. package/dist/cjs/model/index.js +14 -13
  5. package/dist/cjs/model/parse-sample-values.js +6 -2
  6. package/dist/cjs/model/prometheus-client.js +43 -8
  7. package/dist/cjs/model/prometheus-selectors.js +12 -4
  8. package/dist/cjs/model/time.js +15 -9
  9. package/dist/cjs/plugins/MatcherEditor.js +14 -12
  10. package/dist/cjs/plugins/PrometheusDatasourceEditor.js +610 -0
  11. package/dist/cjs/plugins/prometheus-datasource.js +59 -8
  12. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +10 -8
  13. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +49 -24
  14. package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +44 -24
  15. package/dist/cjs/plugins/prometheus-time-series-query/index.js +10 -8
  16. package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +44 -11
  17. package/dist/cjs/plugins/prometheus-variables.js +69 -63
  18. package/dist/cjs/plugins/types.js +7 -0
  19. package/dist/cjs/plugins/variable.js +9 -7
  20. package/dist/cjs/utils/index.js +10 -8
  21. package/dist/cjs/utils/utils.js +13 -7
  22. package/dist/components/PromQL.d.ts +2 -3
  23. package/dist/components/PromQL.d.ts.map +1 -1
  24. package/dist/components/PromQL.js +1 -1
  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/api-types.d.ts +11 -11
  29. package/dist/model/api-types.d.ts.map +1 -1
  30. package/dist/model/api-types.js.map +1 -1
  31. package/dist/model/index.d.ts +0 -1
  32. package/dist/model/index.d.ts.map +1 -1
  33. package/dist/model/index.js +0 -1
  34. package/dist/model/index.js.map +1 -1
  35. package/dist/model/parse-sample-values.d.ts +1 -1
  36. package/dist/model/parse-sample-values.d.ts.map +1 -1
  37. package/dist/model/parse-sample-values.js.map +1 -1
  38. package/dist/model/prometheus-client.d.ts +4 -0
  39. package/dist/model/prometheus-client.d.ts.map +1 -1
  40. package/dist/model/prometheus-client.js +27 -3
  41. package/dist/model/prometheus-client.js.map +1 -1
  42. package/dist/model/prometheus-selectors.js.map +1 -1
  43. package/dist/model/time.js +2 -2
  44. package/dist/model/time.js.map +1 -1
  45. package/dist/plugins/MatcherEditor.d.ts +2 -3
  46. package/dist/plugins/MatcherEditor.d.ts.map +1 -1
  47. package/dist/plugins/MatcherEditor.js +1 -1
  48. package/dist/plugins/MatcherEditor.js.map +1 -1
  49. package/dist/plugins/{PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts → PrometheusDatasourceEditor.d.ts} +1 -2
  50. package/dist/plugins/PrometheusDatasourceEditor.d.ts.map +1 -0
  51. package/dist/plugins/PrometheusDatasourceEditor.js +556 -0
  52. package/dist/plugins/PrometheusDatasourceEditor.js.map +1 -0
  53. package/dist/plugins/prometheus-datasource.d.ts +2 -7
  54. package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
  55. package/dist/plugins/prometheus-datasource.js +55 -6
  56. package/dist/plugins/prometheus-datasource.js.map +1 -1
  57. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
  58. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
  59. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts +1 -2
  60. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  61. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +41 -18
  62. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  63. package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
  64. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +37 -19
  65. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
  66. package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
  67. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts +11 -2
  68. package/dist/plugins/prometheus-time-series-query/query-editor-model.d.ts.map +1 -1
  69. package/dist/plugins/prometheus-time-series-query/query-editor-model.js +38 -10
  70. package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
  71. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts +4 -4
  72. package/dist/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
  73. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +3 -1
  74. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
  75. package/dist/plugins/prometheus-variables.d.ts.map +1 -1
  76. package/dist/plugins/prometheus-variables.js +37 -37
  77. package/dist/plugins/prometheus-variables.js.map +1 -1
  78. package/dist/plugins/types.d.ts +12 -5
  79. package/dist/plugins/types.d.ts.map +1 -1
  80. package/dist/plugins/types.js +1 -1
  81. package/dist/plugins/types.js.map +1 -1
  82. package/dist/plugins/variable.d.ts +2 -2
  83. package/dist/plugins/variable.d.ts.map +1 -1
  84. package/dist/plugins/variable.js +2 -2
  85. package/dist/plugins/variable.js.map +1 -1
  86. package/dist/test/setup-tests.js.map +1 -1
  87. package/dist/utils/index.js.map +1 -1
  88. package/dist/utils/utils.d.ts +2 -2
  89. package/dist/utils/utils.d.ts.map +1 -1
  90. package/dist/utils/utils.js +4 -4
  91. package/dist/utils/utils.js.map +1 -1
  92. package/package.json +6 -6
  93. package/dist/cjs/model/templating.js +0 -26
  94. package/dist/cjs/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +0 -392
  95. package/dist/cjs/plugins/PrometheusDatasourceEditor/index.js +0 -29
  96. package/dist/cjs/plugins/PrometheusDatasourceEditor/types.js +0 -16
  97. package/dist/model/templating.d.ts +0 -6
  98. package/dist/model/templating.d.ts.map +0 -1
  99. package/dist/model/templating.js +0 -20
  100. package/dist/model/templating.js.map +0 -1
  101. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.d.ts.map +0 -1
  102. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js +0 -342
  103. package/dist/plugins/PrometheusDatasourceEditor/PrometheusDatasourceEditor.js.map +0 -1
  104. package/dist/plugins/PrometheusDatasourceEditor/index.d.ts +0 -3
  105. package/dist/plugins/PrometheusDatasourceEditor/index.d.ts.map +0 -1
  106. package/dist/plugins/PrometheusDatasourceEditor/index.js +0 -16
  107. package/dist/plugins/PrometheusDatasourceEditor/index.js.map +0 -1
  108. package/dist/plugins/PrometheusDatasourceEditor/types.d.ts +0 -20
  109. package/dist/plugins/PrometheusDatasourceEditor/types.d.ts.map +0 -1
  110. package/dist/plugins/PrometheusDatasourceEditor/types.js +0 -15
  111. package/dist/plugins/PrometheusDatasourceEditor/types.js.map +0 -1
@@ -18,7 +18,7 @@ import { produce } from 'immer';
18
18
  * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview
19
19
  * every time the user types.
20
20
  */ export function useQueryState(props) {
21
- const { onChange , value } = props;
21
+ const { onChange, value } = props;
22
22
  // Local copy of the query's value
23
23
  const [query, setQuery] = useState(value.query);
24
24
  // This is basically "getDerivedStateFromProps" to make sure if spec's value changes external to this component,
@@ -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
- const { onChange , value } = props;
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,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,OAAO,QAAQ,OAAO,CAAC;AAMhC;;;;;CAKC,GACD,OAAO,SAASC,aAAa,CAACC,KAA2C,EAAE;IACzE,MAAM,EAAEC,QAAQ,CAAA,EAAEC,KAAK,CAAA,EAAE,GAAGF,KAAK,AAAC;IAElC,kCAAkC;IAClC,MAAM,CAACG,KAAK,EAAEC,QAAQ,CAAC,GAAGP,QAAQ,CAACK,KAAK,CAACC,KAAK,CAAC,AAAC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BAAkB,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,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAE5B,kCAAkC;IAClC,MAAM,CAACG,OAAOC,SAAS,GAAGP,SAASK,MAAMC,KAAK;IAE9C,gHAAgH;IAChH,kCAAkC;IAClC,MAAM,CAACE,iBAAiBC,mBAAmB,GAAGT,SAASK,MAAMC,KAAK;IAClE,IAAID,MAAMC,KAAK,KAAKE,iBAAiB;QACnCD,SAASF,MAAMC,KAAK;QACpBG,mBAAmBJ,MAAMC,KAAK;IAChC;IAEA,kDAAkD;IAClD,MAAMI,oBAAoB,CAACC;QACzBJ,SAASI;IACX;IAEA,iHAAiH;IACjH,eAAe;IACf,MAAMC,kBAAkB;QAC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,QAAQI,OAAO,CAACQ;YACdA,MAAMU,OAAO,GAAGA;QAClB;IAEJ;IAEA,OAAO;QAAEA;QAASI;QAAqBC;IAAkB;AAC3D"}
@@ -1,12 +1,12 @@
1
1
  import { DurationString } from '@perses-dev/core';
2
- import { PrometheusDatasourceSelector, TemplateString } from '../../model';
2
+ import { PrometheusDatasourceSelector } from '../../model';
3
3
  /**
4
4
  * The spec/options for the PrometheusTimeSeriesQuery plugin.
5
5
  */
6
6
  export interface PrometheusTimeSeriesQuerySpec {
7
- query: TemplateString;
8
- series_name_format?: string;
9
- min_step?: DurationString;
7
+ query: string;
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,MAAM,aAAa,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C"}
@@ -10,6 +10,8 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- export { };
13
+ /**
14
+ * The spec/options for the PrometheusTimeSeriesQuery plugin.
15
+ */ export { };
14
16
 
15
17
  //# sourceMappingURL=time-series-query-model.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/time-series-query-model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport { PrometheusDatasourceSelector, 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 } from '../../model';\n\n/**\n * The spec/options for the PrometheusTimeSeriesQuery plugin.\n */\nexport interface PrometheusTimeSeriesQuerySpec {\n query: string;\n seriesNameFormat?: string;\n minStep?: DurationString;\n resolution?: number;\n datasource?: PrometheusDatasourceSelector;\n}\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAKjC;;CAEC,GACD,WAMC"}
@@ -1 +1 @@
1
- {"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAML,cAAc,EAGf,MAAM,2BAA2B,CAAC;AAcnC,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AA+LjB,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAgB5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CA8B9F,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,+BAA+B,CAwBpF,CAAC"}
1
+ {"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAYA,OAAO,EAML,cAAc,EAIf,MAAM,2BAA2B,CAAC;AAcnC,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AA+LjB,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAgB5F,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CA8B9F,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,+BAA+B,CAwBpF,CAAC"}
@@ -18,8 +18,8 @@ import { DEFAULT_PROM, getPrometheusTimeRange, isDefaultPromSelector, isPromethe
18
18
  import { PromQLEditor } from '../components';
19
19
  import { MatcherEditor } from './MatcherEditor';
20
20
  function PrometheusLabelValuesVariableEditor(props) {
21
- const { onChange , value } = props;
22
- const { datasource } = value;
21
+ const { onChange, value } = props;
22
+ const { datasource } = value;
23
23
  const selectedDatasource = datasource !== null && datasource !== void 0 ? datasource : DEFAULT_PROM;
24
24
  const handleDatasourceChange = (next)=>{
25
25
  if (isPrometheusDatasourceSelector(next)) {
@@ -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,
@@ -80,8 +80,8 @@ function PrometheusLabelValuesVariableEditor(props) {
80
80
  });
81
81
  }
82
82
  function PrometheusLabelNamesVariableEditor(props) {
83
- const { onChange , value } = props;
84
- const { datasource } = value;
83
+ const { onChange, value } = props;
84
+ const { datasource } = value;
85
85
  const selectedDatasource = datasource !== null && datasource !== void 0 ? datasource : DEFAULT_PROM;
86
86
  const handleDatasourceChange = (next)=>{
87
87
  if (isPrometheusDatasourceSelector(next)) {
@@ -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({
@@ -128,10 +128,10 @@ function PrometheusLabelNamesVariableEditor(props) {
128
128
  });
129
129
  }
130
130
  function PrometheusPromQLVariableEditor(props) {
131
- const { onChange , value } = props;
132
- const { datasource } = value;
131
+ const { onChange, value } = props;
132
+ const { datasource } = value;
133
133
  const selectedDatasource = datasource !== null && datasource !== void 0 ? datasource : DEFAULT_PROM;
134
- const { data: client } = useDatasourceClient(selectedDatasource);
134
+ const { data: client } = useDatasourceClient(selectedDatasource);
135
135
  const promURL = client === null || client === void 0 ? void 0 : client.options.datasourceUrl;
136
136
  const handleDatasourceChange = (next)=>{
137
137
  if (isPrometheusDatasourceSelector(next)) {
@@ -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,11 +226,11 @@ 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
- const { data: options } = await client.labelNames({
233
+ const { data: options } = await client.labelNames({
234
234
  'match[]': match,
235
235
  ...timeRange
236
236
  });
@@ -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
- const { data: options } = await client.labelValues({
258
- labelName: replaceTemplateVariables(pluginDef.label_name, ctx.variables),
257
+ const { data: options } = await client.labelValues({
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
- const { data: options } = await client.instantQuery({
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
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/prometheus-variables.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n VariablePlugin,\n parseTemplateVariables,\n replaceTemplateVariables,\n} from '@perses-dev/plugin-system';\nimport { FormControl, InputLabel, Stack, TextField } from '@mui/material';\nimport { produce } from 'immer';\nimport {\n DEFAULT_PROM,\n getPrometheusTimeRange,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n VectorData,\n} from '../model';\nimport { PromQLEditor } from '../components';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\nimport { MatcherEditor } from './MatcherEditor';\n\nfunction PrometheusLabelValuesVariableEditor(props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n draft.datasource = isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n readOnly={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <TextField\n label=\"Label Name\"\n required\n value={props.value.label_name}\n onChange={(e) => {\n props.onChange({ ...props.value, label_name: 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.label_name}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n onChange={(e) => {\n props.onChange({ ...props.value, label_name: e.target.value });\n }}\n />\n </Stack>\n );\n}\n\nfunction capturingMatrix(matrix: MatrixData, label_name: string): string[] {\n const captured = new Set<string>();\n for (const sample of matrix.result) {\n const value = sample.metric[label_name];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\nfunction capturingVector(vector: VectorData, label_name: string): string[] {\n const captured = new Set<string>();\n for (const sample of vector.result) {\n const value = sample.metric[label_name];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\n/**\n * Takes a list of strings and returns a list of VariableOptions\n */\nconst stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n\nexport const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = spec.matchers ? spec.matchers.map((m) => replaceTemplateVariables(m, ctx.variables)) : undefined;\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelNames({ 'match[]': match, ...timeRange });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return { variables: spec.matchers?.map((m) => parseTemplateVariables(m)).flat() || [] };\n },\n OptionsEditorComponent: PrometheusLabelNamesVariableEditor,\n createInitialOptions: () => ({}),\n};\n\nexport const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const pluginDef = spec;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = pluginDef.matchers\n ? pluginDef.matchers.map((m) => replaceTemplateVariables(m, ctx.variables))\n : undefined;\n\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues({\n labelName: replaceTemplateVariables(pluginDef.label_name, ctx.variables),\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec) => {\n return {\n variables:\n spec.matchers\n ?.map((m) => parseTemplateVariables(m))\n .flat()\n .concat(parseTemplateVariables(spec.label_name)) || [],\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ label_name: '' }),\n};\n\nexport const PrometheusPromQLVariable: VariablePlugin<PrometheusPromQLVariableOptions> = {\n getVariableOptions: async (spec, ctx) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n // TODO we may want to manage a range query as well.\n const { data: options } = await client.instantQuery({\n query: replaceTemplateVariables(spec.expr, ctx.variables),\n });\n const labelName = replaceTemplateVariables(spec.label_name, ctx.variables);\n let values: string[] = [];\n if (options?.resultType === 'matrix') {\n values = capturingMatrix(options, labelName);\n } else if (options?.resultType === 'vector') {\n values = capturingVector(options, labelName);\n }\n\n return {\n data: stringArrayToVariableOptions(values),\n };\n },\n dependsOn: (spec) => {\n return { variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.label_name)) };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', label_name: '' }),\n};\n"],"names":["DatasourceSelect","useDatasourceClient","parseTemplateVariables","replaceTemplateVariables","FormControl","InputLabel","Stack","TextField","produce","DEFAULT_PROM","getPrometheusTimeRange","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","PromQLEditor","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","handleDatasourceChange","next","draft","undefined","Error","spacing","margin","id","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","label_name","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","labelName","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;AAAA,SACEA,gBAAgB,EAGhBC,mBAAmB,EAGnBC,sBAAsB,EACtBC,wBAAwB,QACnB,2BAA2B,CAAC;AACnC,SAASC,WAAW,EAAEC,UAAU,EAAEC,KAAK,EAAEC,SAAS,QAAQ,eAAe,CAAC;AAC1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,GAAG,CAACK,SAAS,CAAC,AAAC;QAC3E,IAAIb,MAAM,GAAa,EAAE,AAAC;QAC1B,IAAIlB,CAAAA,OAAO,aAAPA,OAAO,WAAY,GAAnBA,KAAAA,CAAmB,GAAnBA,OAAO,CAAE6C,UAAU,CAAA,KAAK,QAAQ,EAAE;YACpC3B,MAAM,GAAGV,eAAe,CAACR,OAAO,EAAEyC,SAAS,CAAC,CAAC;QAC/C,OAAO,IAAIzC,CAAAA,OAAO,aAAPA,OAAO,WAAY,GAAnBA,KAAAA,CAAmB,GAAnBA,OAAO,CAAE6C,UAAU,CAAA,KAAK,QAAQ,EAAE;YAC3C3B,MAAM,GAAGC,eAAe,CAACnB,OAAO,EAAEyC,SAAS,CAAC,CAAC;QAC/C,CAAC;QAED,OAAO;YACL5C,IAAI,EAAEwB,4BAA4B,CAACH,MAAM,CAAC;SAC3C,CAAC;IACJ,CAAC;IACDgB,SAAS,EAAE,CAACT,IAAI,GAAK;QACnB,OAAO;YAAEM,SAAS,EAAE5E,sBAAsB,CAACsE,IAAI,CAACpB,IAAI,CAAC,CAACqC,MAAM,CAACvF,sBAAsB,CAACsE,IAAI,CAACpC,UAAU,CAAC,CAAC;SAAE,CAAC;IAC1G,CAAC;IACD+C,sBAAsB,EAAExC,8BAA8B;IACtDyC,oBAAoB,EAAE,IAAO,CAAA;YAAEhC,IAAI,EAAE,EAAE;YAAEhB,UAAU,EAAE,EAAE;SAAE,CAAA,AAAC;CAC3D,CAAC"}
1
+ {"version":3,"sources":["../../src/plugins/prometheus-variables.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n OptionsEditorProps,\n useDatasourceClient,\n VariableOption,\n VariablePlugin,\n parseTemplateVariables,\n replaceTemplateVariables,\n GetVariableOptionsContext,\n} from '@perses-dev/plugin-system';\nimport { FormControl, InputLabel, Stack, TextField } from '@mui/material';\nimport { produce } from 'immer';\nimport {\n DEFAULT_PROM,\n getPrometheusTimeRange,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n VectorData,\n} from '../model';\nimport { PromQLEditor } from '../components';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\nimport { MatcherEditor } from './MatcherEditor';\n\nfunction PrometheusLabelValuesVariableEditor(props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n draft.datasource = isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n readOnly={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <TextField\n label=\"Label Name\"\n required\n value={props.value.labelName}\n onChange={(e) => {\n props.onChange({ ...props.value, labelName: e.target.value });\n }}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n />\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n isReadonly={props.isReadonly}\n />\n </Stack>\n );\n}\n\nfunction PrometheusLabelNamesVariableEditor(props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n draft.datasource = isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n disabled={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n isReadonly={props.isReadonly}\n onChange={(e) => {\n props.onChange({ ...props.value, matchers: e });\n }}\n />\n </Stack>\n );\n}\n\nfunction PrometheusPromQLVariableEditor(props: OptionsEditorProps<PrometheusPromQLVariableOptions>) {\n const { onChange, value } = props;\n const { datasource } = value;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n draft.datasource = isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <InputLabel id=\"prom-datasource-label\">Prometheus Datasource</InputLabel>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n disabled={props.isReadonly}\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={value.expr}\n onChange={(query) => {\n props.onChange({ ...props.value, expr: query });\n }}\n readOnly={props.isReadonly}\n width=\"100%\"\n />\n <TextField\n label=\"Label Name\"\n value={props.value.labelName}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n onChange={(e) => {\n props.onChange({ ...props.value, labelName: e.target.value });\n }}\n />\n </Stack>\n );\n}\n\nfunction capturingMatrix(matrix: MatrixData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of matrix.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\nfunction capturingVector(vector: VectorData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of vector.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\n/**\n * Takes a list of strings and returns a list of VariableOptions\n */\nconst stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n\nexport const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelNamesVariableOptions, ctx: GetVariableOptionsContext) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = spec.matchers ? spec.matchers.map((m) => replaceTemplateVariables(m, ctx.variables)) : undefined;\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelNames({ 'match[]': match, ...timeRange });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelNamesVariableOptions) => {\n return { variables: spec.matchers?.map((m) => parseTemplateVariables(m)).flat() || [] };\n },\n OptionsEditorComponent: PrometheusLabelNamesVariableEditor,\n createInitialOptions: () => ({}),\n};\n\nexport const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelValuesVariableOptions, ctx: GetVariableOptionsContext) => {\n const pluginDef = spec;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n const match = pluginDef.matchers\n ? pluginDef.matchers.map((m) => replaceTemplateVariables(m, ctx.variables))\n : undefined;\n\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues({\n labelName: replaceTemplateVariables(pluginDef.labelName, ctx.variables),\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelValuesVariableOptions) => {\n return {\n variables:\n spec.matchers\n ?.map((m) => parseTemplateVariables(m))\n .flat()\n .concat(parseTemplateVariables(spec.labelName)) || [],\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ labelName: '' }),\n};\n\nexport const PrometheusPromQLVariable: VariablePlugin<PrometheusPromQLVariableOptions> = {\n getVariableOptions: async (spec: PrometheusPromQLVariableOptions, ctx: GetVariableOptionsContext) => {\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n // TODO we may want to manage a range query as well.\n const { data: options } = await client.instantQuery({\n query: replaceTemplateVariables(spec.expr, ctx.variables),\n });\n const labelName = replaceTemplateVariables(spec.labelName, ctx.variables);\n let values: string[] = [];\n if (options?.resultType === 'matrix') {\n values = capturingMatrix(options, labelName);\n } else if (options?.resultType === 'vector') {\n values = capturingVector(options, labelName);\n }\n\n return {\n data: stringArrayToVariableOptions(values),\n };\n },\n dependsOn: (spec: PrometheusPromQLVariableOptions) => {\n return { variables: parseTemplateVariables(spec.expr).concat(parseTemplateVariables(spec.labelName)) };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', labelName: '' }),\n};\n"],"names":["DatasourceSelect","useDatasourceClient","parseTemplateVariables","replaceTemplateVariables","FormControl","InputLabel","Stack","TextField","produce","DEFAULT_PROM","getPrometheusTimeRange","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","PromQLEditor","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","handleDatasourceChange","next","draft","undefined","Error","spacing","margin","id","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","labelName","e","target","InputProps","matchers","PrometheusLabelNamesVariableEditor","disabled","PrometheusPromQLVariableEditor","data","client","promURL","options","datasourceUrl","completeConfig","remote","url","expr","query","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","datasourceStore","getDatasourceClient","match","m","variables","timeRange","labelNames","dependsOn","flat","OptionsEditorComponent","createInitialOptions","PrometheusLabelValuesVariable","pluginDef","labelValues","concat","PrometheusPromQLVariable","instantQuery","resultType"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AACjC,SACEA,gBAAgB,EAGhBC,mBAAmB,EAGnBC,sBAAsB,EACtBC,wBAAwB,QAEnB,4BAA4B;AACnC,SAASC,WAAW,EAAEC,UAAU,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC1E,SAASC,OAAO,QAAQ,QAAQ;AAChC,SACEC,YAAY,EACZC,sBAAsB,EACt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rC,OAAOlD,yBAAyBqE,KAAKpB,IAAI,EAAEqB,IAAIK,SAAS;QAC1D;QACA,MAAM1C,YAAYjC,yBAAyBqE,KAAKpC,SAAS,EAAEqC,IAAIK,SAAS;QACxE,IAAIb,SAAmB,EAAE;QACzB,IAAIlB,CAAAA,oBAAAA,8BAAAA,QAAS4C,UAAU,MAAK,UAAU;YACpC1B,SAASV,gBAAgBR,SAASX;QACpC,OAAO,IAAIW,CAAAA,oBAAAA,8BAAAA,QAAS4C,UAAU,MAAK,UAAU;YAC3C1B,SAASC,gBAAgBnB,SAASX;QACpC;QAEA,OAAO;YACLQ,MAAMwB,6BAA6BH;QACrC;IACF;IACAgB,WAAW,CAACT;QACV,OAAO;YAAEM,WAAW5E,uBAAuBsE,KAAKpB,IAAI,EAAEoC,MAAM,CAACtF,uBAAuBsE,KAAKpC,SAAS;QAAG;IACvG;IACA+C,wBAAwBxC;IACxByC,sBAAsB,IAAO,CAAA;YAAEhC,MAAM;YAAIhB,WAAW;QAAG,CAAA;AACzD,EAAE"}
@@ -1,16 +1,23 @@
1
+ import { DurationString, HTTPProxy } from '@perses-dev/core';
1
2
  import { PrometheusDatasourceSelector } from '../model';
3
+ export declare const DEFAULT_SCRAPE_INTERVAL: DurationString;
4
+ export interface PrometheusDatasourceSpec {
5
+ directUrl?: string;
6
+ proxy?: HTTPProxy;
7
+ scrapeInterval?: DurationString;
8
+ }
2
9
  export interface PrometheusVariableOptionsBase {
3
10
  datasource?: PrometheusDatasourceSelector;
4
11
  }
5
- export declare type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {
12
+ export type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {
6
13
  matchers?: string[];
7
14
  };
8
- export declare type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {
9
- label_name: string;
15
+ export type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {
16
+ labelName: string;
10
17
  matchers?: string[];
11
18
  };
12
- export declare type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {
19
+ export type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {
13
20
  expr: string;
14
- label_name: string;
21
+ labelName: string;
15
22
  };
16
23
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAED,oBAAY,mCAAmC,GAAG,6BAA6B,GAAG;IAChF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,oBAAY,oCAAoC,GAAG,6BAA6B,GAAG;IACjF,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,oBAAY,+BAA+B,GAAG,6BAA6B,GAAG;IAE5E,IAAI,EAAE,MAAM,CAAC;IAGb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,uBAAuB,EAAE,cAAqB,CAAC;AAE5D,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,4BAA4B,CAAC;CAC3C;AAED,MAAM,MAAM,mCAAmC,GAAG,6BAA6B,GAAG;IAChF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG,6BAA6B,GAAG;IACjF,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,6BAA6B,GAAG;IAE5E,IAAI,EAAE,MAAM,CAAC;IAGb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
@@ -10,6 +10,6 @@
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
- export { };
13
+ export const DEFAULT_SCRAPE_INTERVAL = '1m';
14
14
 
15
15
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PrometheusDatasourceSelector } from '../model';\n\nexport interface PrometheusVariableOptionsBase {\n datasource?: PrometheusDatasourceSelector;\n}\n\nexport type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {\n matchers?: string[];\n};\n\nexport type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n label_name: string;\n matchers?: string[];\n};\n\nexport type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {\n // expr is the PromQL expression.\n expr: string;\n // label_name is the name of the label that will be used after the PromQL query is performed to select the label value.\n // Note: This field is not part of the Prometheus API.\n label_name: string;\n};\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAqBE"}
1
+ {"version":3,"sources":["../../src/plugins/types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString, HTTPProxy } from '@perses-dev/core';\nimport { PrometheusDatasourceSelector } from '../model';\n\nexport const DEFAULT_SCRAPE_INTERVAL: DurationString = '1m';\n\nexport interface PrometheusDatasourceSpec {\n directUrl?: string;\n proxy?: HTTPProxy;\n scrapeInterval?: DurationString; // default to 1m\n}\n\nexport interface PrometheusVariableOptionsBase {\n datasource?: PrometheusDatasourceSelector;\n}\n\nexport type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {\n matchers?: string[];\n};\n\nexport type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n labelName: string;\n matchers?: string[];\n};\n\nexport type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {\n // expr is the PromQL expression.\n expr: string;\n // labelName is the name of the label that will be used after the PromQL query is performed to select the label value.\n // Note: This field is not part of the Prometheus API.\n labelName: string;\n};\n"],"names":["DEFAULT_SCRAPE_INTERVAL"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAKjC,OAAO,MAAMA,0BAA0C,KAAK"}
@@ -1,6 +1,6 @@
1
1
  import { VariablePlugin, VariableOption } from '@perses-dev/plugin-system';
2
- declare type StaticListOption = string | VariableOption;
3
- declare type StaticListVariableOptions = {
2
+ type StaticListOption = string | VariableOption;
3
+ type StaticListVariableOptions = {
4
4
  values: StaticListOption[];
5
5
  };
6
6
  export declare const StaticListVariable: VariablePlugin<StaticListVariableOptions>;
@@ -1 +1 @@
1
- {"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../src/plugins/variable.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,2BAA2B,CAAC;AAG/F,aAAK,gBAAgB,GAAG,MAAM,GAAG,cAAc,CAAC;AAEhD,aAAK,yBAAyB,GAAG;IAC/B,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAmDF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,yBAAyB,CAiBxE,CAAC"}
1
+ {"version":3,"file":"variable.d.ts","sourceRoot":"","sources":["../../src/plugins/variable.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAsB,MAAM,2BAA2B,CAAC;AAG/F,KAAK,gBAAgB,GAAG,MAAM,GAAG,cAAc,CAAC;AAEhD,KAAK,yBAAyB,GAAG;IAC/B,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAmDF,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,yBAAyB,CAiBxE,CAAC"}
@@ -59,8 +59,8 @@ function StaticListVariableOptionEditor(props) {
59
59
  }
60
60
  export const StaticListVariable = {
61
61
  getVariableOptions: async (spec)=>{
62
- var ref;
63
- const values = (ref = spec.values) === null || ref === void 0 ? void 0 : ref.map((v)=>{
62
+ var _spec_values;
63
+ const values = (_spec_values = spec.values) === null || _spec_values === void 0 ? void 0 : _spec_values.map((v)=>{
64
64
  if (typeof v === 'string') {
65
65
  return {
66
66
  label: v,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/variable.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { VariablePlugin, VariableOption, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Autocomplete, TextField } from '@mui/material';\n\ntype StaticListOption = string | VariableOption;\n\ntype StaticListVariableOptions = {\n values: StaticListOption[];\n};\n\nfunction StaticListVariableOptionEditor(props: OptionsEditorProps<StaticListVariableOptions>) {\n const value = props.value.values.map((v) => {\n if (typeof v === 'string') {\n return v;\n } else {\n return v.value;\n }\n });\n\n const onChange = (__: unknown, value: string[]) => {\n props.onChange({\n values: value.map((v) => {\n return { value: v, label: v };\n }),\n });\n };\n\n return (\n <div>\n <Autocomplete\n onPaste={(e) => {\n // Append new values on paste\n const v = e.clipboardData.getData('text/plain');\n if (v) {\n const values = v.split(',');\n onChange(null, value.concat(values));\n e.preventDefault();\n }\n }}\n multiple\n value={value}\n onChange={onChange}\n options={[]}\n freeSolo\n clearOnBlur\n readOnly={props.isReadonly}\n renderInput={(params) => (\n <TextField\n {...params}\n label=\"Values\"\n placeholder=\"Values\"\n helperText='Type new value then press \"Enter\" to add.'\n />\n )}\n />\n </div>\n );\n}\n\nexport const StaticListVariable: VariablePlugin<StaticListVariableOptions> = {\n getVariableOptions: async (spec) => {\n const values = spec.values?.map((v) => {\n if (typeof v === 'string') {\n return { label: v, value: v };\n }\n return v;\n });\n return {\n data: values,\n };\n },\n dependsOn: () => {\n return { variables: [] };\n },\n OptionsEditorComponent: StaticListVariableOptionEditor,\n createInitialOptions: () => ({ values: [] }),\n};\n"],"names":["Autocomplete","TextField","StaticListVariableOptionEditor","props","value","values","map","v","onChange","__","label","div","onPaste","e","clipboardData","getData","split","concat","preventDefault","multiple","options","freeSolo","clearOnBlur","readOnly","isReadonly","renderInput","params","placeholder","helperText","StaticListVariable","getVariableOptions","spec","data","dependsOn","variables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AACA,SAASA,YAAY,EAAEC,SAAS,QAAQ,eAAe,CAAC;AAQxD,SAASC,8BAA8B,CAACC,KAAoD,EAAE;IAC5F,MAAMC,KAAK,GAAGD,KAAK,CAACC,KAAK,CAACC,MAAM,CAACC,GAAG,CAAC,CAACC,CAAC,GAAK;QAC1C,IAAI,OAAOA,CAAC,KAAK,QAAQ,EAAE;YACzB,OAAOA,CAAC,CAAC;QACX,OAAO;YACL,OAAOA,CAAC,CAACH,KAAK,CAAC;QACjB,CAAC;IACH,CAAC,CAAC,AAAC;IAEH,MAAMI,QAAQ,GAAG,CAACC,EAAW,EAAEL,KAAe,GAAK;QACjDD,KAAK,CAACK,QAAQ,CAAC;YACbH,MAAM,EAAED,KAAK,CAACE,GAAG,CAAC,CAACC,CAAC,GAAK;gBACvB,OAAO;oBAAEH,KAAK,EAAEG,CAAC;oBAAEG,KAAK,EAAEH,CAAC;iBAAE,CAAC;YAChC,CAAC,CAAC;SACH,CAAC,CAAC;IACL,CAAC,AAAC;IAEF,qBACE,KAACI,KAAG;kBACF,cAAA,KAACX,YAAY;YACXY,OAAO,EAAE,CAACC,CAAC,GAAK;gBACd,6BAA6B;gBAC7B,MAAMN,CAAC,GAAGM,CAAC,CAACC,aAAa,CAACC,OAAO,CAAC,YAAY,CAAC,AAAC;gBAChD,IAAIR,CAAC,EAAE;oBACL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MAAM,EAAE,EAAE;SAAE,CAAA,AAAC;CAC7C,CAAC"}
1
+ {"version":3,"sources":["../../src/plugins/variable.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { VariablePlugin, VariableOption, OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { Autocomplete, TextField } from '@mui/material';\n\ntype StaticListOption = string | VariableOption;\n\ntype StaticListVariableOptions = {\n values: StaticListOption[];\n};\n\nfunction StaticListVariableOptionEditor(props: OptionsEditorProps<StaticListVariableOptions>) {\n const value = props.value.values.map((v) => {\n if (typeof v === 'string') {\n return v;\n } else {\n return v.value;\n }\n });\n\n const onChange = (__: unknown, value: string[]) => {\n props.onChange({\n values: value.map((v) => {\n return { value: v, label: v };\n }),\n });\n };\n\n return (\n <div>\n <Autocomplete\n onPaste={(e) => {\n // Append new values on paste\n const v = e.clipboardData.getData('text/plain');\n if (v) {\n const values = v.split(',');\n onChange(null, value.concat(values));\n e.preventDefault();\n }\n }}\n multiple\n value={value}\n onChange={onChange}\n options={[]}\n freeSolo\n clearOnBlur\n readOnly={props.isReadonly}\n renderInput={(params) => (\n <TextField\n {...params}\n label=\"Values\"\n placeholder=\"Values\"\n helperText='Type new value then press \"Enter\" to add.'\n />\n )}\n />\n </div>\n );\n}\n\nexport const StaticListVariable: VariablePlugin<StaticListVariableOptions> = {\n getVariableOptions: async (spec) => {\n const values = spec.values?.map((v) => {\n if (typeof v === 'string') {\n return { label: v, value: v };\n }\n return v;\n });\n return {\n data: values,\n };\n },\n dependsOn: () => {\n return { variables: [] };\n },\n OptionsEditorComponent: StaticListVariableOptionEditor,\n createInitialOptions: () => ({ values: [] }),\n};\n"],"names":["Autocomplete","TextField","StaticListVariableOptionEditor","props","value","values","map","v","onChange","__","label","div","onPaste","e","clipboardData","getData","split","concat","preventDefault","multiple","options","freeSolo","clearOnBlur","readOnly","isReadonly","renderInput","params","placeholder","helperText","StaticListVariable","getVariableOptions","spec","data","dependsOn","variables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,YAAY,EAAEC,SAAS,QAAQ,gBAAgB;AAQxD,SAASC,+BAA+BC,KAAoD;IAC1F,MAAMC,QAAQD,MAAMC,KAAK,CAACC,MAAM,CAACC,GAAG,CAAC,CAACC;QACpC,IAAI,OAAOA,MAAM,UAAU;YACzB,OAAOA;QACT,OAAO;YACL,OAAOA,EAAEH,KAAK;QAChB;IACF;IAEA,MAAMI,WAAW,CAACC,IAAaL;QAC7BD,MAAMK,QAAQ,CAAC;YACbH,QAAQD,MAAME,GAAG,CAAC,CAACC;gBACjB,OAAO;oBAAEH,OAAOG;oBAAGG,OAAOH;gBAAE;YAC9B;QACF;IACF;IAEA,qBACE,KAACI;kBACC,cAAA,KAACX;YACCY,SAAS,CAACC;gBACR,6BAA6B;gBAC7B,MAAMN,IAAIM,EAAEC,aAAa,CAACC,OAAO,CAAC;gBAClC,IAAIR,GAAG;oBACL,MAAMF,SAASE,EAAES,KAAK,CAAC;oBACvBR,SAAS,MAAMJ,MAAMa,MAAM,CAACZ;oBAC5BQ,EAAEK,cAAc;gBAClB;YACF;YACAC,QAAQ;YACRf,OAAOA;YACPI,UAAUA;YACVY,SAAS,EAAE;YACXC,QAAQ;YACRC,WAAW;YACXC,UAAUpB,MAAMqB,UAAU;YAC1BC,aAAa,CAACC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