@perses-dev/plugin-system 0.23.1 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/model/calculations.js +6 -1
- package/dist/cjs/model/index.js +2 -2
- package/dist/cjs/runtime/time-series-queries.js +29 -6
- package/dist/model/calculations.d.ts +1 -1
- package/dist/model/calculations.d.ts.map +1 -1
- package/dist/model/calculations.js +7 -1
- package/dist/model/calculations.js.map +1 -1
- package/dist/model/datasource.d.ts +7 -0
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/index.d.ts +2 -2
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +2 -2
- package/dist/model/index.js.map +1 -1
- package/dist/model/time-series-queries.d.ts +10 -4
- package/dist/model/time-series-queries.d.ts.map +1 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts +13 -2
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +30 -6
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/package.json +5 -4
- package/dist/cjs/components/CalculationSelector/CalculationSelector.test.js +0 -65
- package/dist/cjs/components/OptionsEditorTabs/OptionsEditorTabs.test.js +0 -107
- package/dist/cjs/components/PluginEditor/PluginEditor.test.js +0 -150
- package/dist/cjs/components/PluginKindSelect.test.js +0 -86
- package/dist/cjs/components/PluginRegistry/PluginRegistry.test.js +0 -144
- package/dist/cjs/components/PluginSpecEditor.test.js +0 -92
- package/dist/components/CalculationSelector/CalculationSelector.test.d.ts +0 -2
- package/dist/components/CalculationSelector/CalculationSelector.test.d.ts.map +0 -1
- package/dist/components/CalculationSelector/CalculationSelector.test.js +0 -58
- package/dist/components/CalculationSelector/CalculationSelector.test.js.map +0 -1
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.d.ts +0 -2
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.d.ts.map +0 -1
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.js +0 -100
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.js.map +0 -1
- package/dist/components/PluginEditor/PluginEditor.test.d.ts +0 -2
- package/dist/components/PluginEditor/PluginEditor.test.d.ts.map +0 -1
- package/dist/components/PluginEditor/PluginEditor.test.js +0 -143
- package/dist/components/PluginEditor/PluginEditor.test.js.map +0 -1
- package/dist/components/PluginKindSelect.test.d.ts +0 -2
- package/dist/components/PluginKindSelect.test.d.ts.map +0 -1
- package/dist/components/PluginKindSelect.test.js +0 -79
- package/dist/components/PluginKindSelect.test.js.map +0 -1
- package/dist/components/PluginRegistry/PluginRegistry.test.d.ts +0 -2
- package/dist/components/PluginRegistry/PluginRegistry.test.d.ts.map +0 -1
- package/dist/components/PluginRegistry/PluginRegistry.test.js +0 -137
- package/dist/components/PluginRegistry/PluginRegistry.test.js.map +0 -1
- package/dist/components/PluginSpecEditor.test.d.ts +0 -2
- package/dist/components/PluginSpecEditor.test.d.ts.map +0 -1
- package/dist/components/PluginSpecEditor.test.js +0 -85
- package/dist/components/PluginSpecEditor.test.js.map +0 -1
|
@@ -73,5 +73,10 @@ function sum(values) {
|
|
|
73
73
|
return (0, _lodashEs.sumBy)(values, getValue);
|
|
74
74
|
}
|
|
75
75
|
function getValue(valueTuple) {
|
|
76
|
-
|
|
76
|
+
const value = valueTuple[1];
|
|
77
|
+
if (value !== null) {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
// TODO: refactor utils so null can be returned and LastNotNull supported
|
|
81
|
+
return NaN;
|
|
77
82
|
}
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -18,10 +18,10 @@ _exportStar(require("./calculations"), exports);
|
|
|
18
18
|
_exportStar(require("./datasource"), exports);
|
|
19
19
|
_exportStar(require("./panels"), exports);
|
|
20
20
|
_exportStar(require("./plugins"), exports);
|
|
21
|
-
_exportStar(require("./time-series-queries"), exports);
|
|
22
|
-
_exportStar(require("./variables"), exports);
|
|
23
21
|
_exportStar(require("./plugin-base"), exports);
|
|
24
22
|
_exportStar(require("./plugin-loading"), exports);
|
|
23
|
+
_exportStar(require("./time-series-queries"), exports);
|
|
24
|
+
_exportStar(require("./variables"), exports);
|
|
25
25
|
function _exportStar(from, to) {
|
|
26
26
|
Object.keys(from).forEach(function(k) {
|
|
27
27
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -21,14 +21,18 @@ function _export(target, all) {
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
_export(exports, {
|
|
24
|
+
TIME_SERIES_QUERY_KEY: ()=>TIME_SERIES_QUERY_KEY,
|
|
24
25
|
useTimeSeriesQuery: ()=>useTimeSeriesQuery,
|
|
25
|
-
useTimeSeriesQueries: ()=>useTimeSeriesQueries
|
|
26
|
+
useTimeSeriesQueries: ()=>useTimeSeriesQueries,
|
|
27
|
+
useActiveTimeSeriesQueries: ()=>useActiveTimeSeriesQueries,
|
|
28
|
+
getActiveTimeSeriesQueries: ()=>getActiveTimeSeriesQueries
|
|
26
29
|
});
|
|
27
30
|
const _reactQuery = require("@tanstack/react-query");
|
|
28
31
|
const _templateVariables = require("./template-variables");
|
|
29
32
|
const _timeRangeProvider = require("./TimeRangeProvider");
|
|
30
33
|
const _datasources = require("./datasources");
|
|
31
34
|
const _pluginRegistry = require("./plugin-registry");
|
|
35
|
+
const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';
|
|
32
36
|
/**
|
|
33
37
|
* Returns a serialized string of the current state of variable values.
|
|
34
38
|
*/ function getVariableValuesKey(v) {
|
|
@@ -70,7 +74,7 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
70
74
|
};
|
|
71
75
|
}
|
|
72
76
|
const useTimeSeriesQuery = (definition, options)=>{
|
|
73
|
-
const { data: plugin } = (0, _pluginRegistry.usePlugin)(
|
|
77
|
+
const { data: plugin } = (0, _pluginRegistry.usePlugin)(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
|
|
74
78
|
const context = useTimeSeriesQueryContext();
|
|
75
79
|
const { queryEnabled , queryKey } = getQueryOptions({
|
|
76
80
|
plugin,
|
|
@@ -97,7 +101,7 @@ const useTimeSeriesQuery = (definition, options)=>{
|
|
|
97
101
|
function useTimeSeriesQueries(definitions, options) {
|
|
98
102
|
const { getPlugin } = (0, _pluginRegistry.usePluginRegistry)();
|
|
99
103
|
const context = useTimeSeriesQueryContext();
|
|
100
|
-
const pluginLoaderResponse = (0, _pluginRegistry.usePlugins)(
|
|
104
|
+
const pluginLoaderResponse = (0, _pluginRegistry.usePlugins)(TIME_SERIES_QUERY_KEY, definitions.map((d)=>({
|
|
101
105
|
kind: d.spec.plugin.kind
|
|
102
106
|
})));
|
|
103
107
|
return (0, _reactQuery.useQueries)({
|
|
@@ -118,7 +122,7 @@ function useTimeSeriesQueries(definitions, options) {
|
|
|
118
122
|
...context,
|
|
119
123
|
suggestedStepMs: options === null || options === void 0 ? void 0 : options.suggestedStepMs
|
|
120
124
|
};
|
|
121
|
-
const plugin = await getPlugin(
|
|
125
|
+
const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
|
|
122
126
|
const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);
|
|
123
127
|
return data;
|
|
124
128
|
}
|
|
@@ -126,8 +130,9 @@ function useTimeSeriesQueries(definitions, options) {
|
|
|
126
130
|
})
|
|
127
131
|
});
|
|
128
132
|
}
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Build the time series query context object from data available at runtime
|
|
135
|
+
*/ function useTimeSeriesQueryContext() {
|
|
131
136
|
const { absoluteTimeRange , refreshKey } = (0, _timeRangeProvider.useTimeRange)();
|
|
132
137
|
const variableState = (0, _templateVariables.useTemplateVariableValues)();
|
|
133
138
|
const datasourceStore = (0, _datasources.useDatasourceStore)();
|
|
@@ -138,3 +143,21 @@ function useTimeSeriesQueryContext() {
|
|
|
138
143
|
refreshKey
|
|
139
144
|
};
|
|
140
145
|
}
|
|
146
|
+
function useActiveTimeSeriesQueries() {
|
|
147
|
+
const queryClient = (0, _reactQuery.useQueryClient)();
|
|
148
|
+
const queryCache = queryClient.getQueryCache();
|
|
149
|
+
return getActiveTimeSeriesQueries(queryCache);
|
|
150
|
+
}
|
|
151
|
+
function getActiveTimeSeriesQueries(cache) {
|
|
152
|
+
const queries = [];
|
|
153
|
+
for (const query of cache.findAll({
|
|
154
|
+
type: 'active'
|
|
155
|
+
})){
|
|
156
|
+
var ref;
|
|
157
|
+
const firstPart = (ref = query.queryKey) === null || ref === void 0 ? void 0 : ref[0];
|
|
158
|
+
if ((firstPart === null || firstPart === void 0 ? void 0 : firstPart.kind) && firstPart.kind.startsWith(TIME_SERIES_QUERY_KEY)) {
|
|
159
|
+
queries.push(query);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return queries;
|
|
163
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,oBAAoB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"calculations.d.ts","sourceRoot":"","sources":["../../src/model/calculations.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAGxD,eAAO,MAAM,eAAe;;;;;;CAM3B,CAAC;AAEF,oBAAY,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAE3D,oBAAY,iBAAiB,GAAG;IAC9B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AACF,eAAO,MAAM,mBAAmB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAgB3E,CAAC;AAEX,eAAO,MAAM,mBAAmB,EAAE,eAAuB,CAAC;AAE1D,iBAAS,KAAK,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,GAAG,SAAS,CAGjE;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,GAAG,SAAS,CAKhE;AAED,iBAAS,UAAU,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,GAAG,SAAS,CAGtE;AAED,iBAAS,IAAI,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,GAAG,SAAS,CAGhE;AAED,iBAAS,GAAG,CAAC,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,GAAG,SAAS,CAG/D"}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { findLast, meanBy, sumBy } from 'lodash-es';
|
|
14
|
+
// TODO: move this file and calculations.test.ts to @perses-dev/core
|
|
14
15
|
export const CalculationsMap = {
|
|
15
16
|
First: first,
|
|
16
17
|
Last: last,
|
|
@@ -58,7 +59,12 @@ function sum(values) {
|
|
|
58
59
|
return sumBy(values, getValue);
|
|
59
60
|
}
|
|
60
61
|
function getValue(valueTuple) {
|
|
61
|
-
|
|
62
|
+
const value = valueTuple[1];
|
|
63
|
+
if (value !== null) {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
// TODO: refactor utils so null can be returned and LastNotNull supported
|
|
67
|
+
return NaN;
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
//# sourceMappingURL=calculations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/calculations.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 { findLast, meanBy, sumBy } from 'lodash-es';\nimport { TimeSeriesValueTuple } from '
|
|
1
|
+
{"version":3,"sources":["../../src/model/calculations.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 { findLast, meanBy, sumBy } from 'lodash-es';\nimport { TimeSeriesValueTuple } from '@perses-dev/core';\n\n// TODO: move this file and calculations.test.ts to @perses-dev/core\nexport const CalculationsMap = {\n First: first,\n Last: last,\n LastNumber: lastNumber,\n Mean: mean,\n Sum: sum,\n};\n\nexport type CalculationType = keyof typeof CalculationsMap;\n\nexport type CalculationConfig = {\n label: string;\n};\nexport const CALCULATIONS_CONFIG: Readonly<Record<CalculationType, CalculationConfig>> = {\n First: {\n label: 'First',\n },\n Last: {\n label: 'Last',\n },\n LastNumber: {\n label: 'Last number',\n },\n Mean: {\n label: 'Mean',\n },\n Sum: {\n label: 'Sum',\n },\n} as const;\n\nexport const DEFAULT_CALCULATION: CalculationType = 'Sum';\n\nfunction first(values: TimeSeriesValueTuple[]): number | undefined {\n const tuple = values[0];\n return tuple === undefined ? undefined : getValue(tuple);\n}\n\nfunction last(values: TimeSeriesValueTuple[]): number | undefined {\n if (values.length <= 0) return undefined;\n\n const tuple = values[values.length - 1];\n return tuple === undefined ? undefined : getValue(tuple);\n}\n\nfunction lastNumber(values: TimeSeriesValueTuple[]): number | undefined {\n const tuple = findLast(values, (tuple) => isNaN(getValue(tuple)) === false);\n return tuple === undefined ? undefined : getValue(tuple);\n}\n\nfunction mean(values: TimeSeriesValueTuple[]): number | undefined {\n if (values.length <= 0) return undefined;\n return meanBy(values, getValue);\n}\n\nfunction sum(values: TimeSeriesValueTuple[]): number | undefined {\n if (values.length <= 0) return undefined;\n return sumBy(values, getValue);\n}\n\nfunction getValue(valueTuple: TimeSeriesValueTuple) {\n const value = valueTuple[1];\n if (value !== null) {\n return value;\n }\n // TODO: refactor utils so null can be returned and LastNotNull supported\n return NaN;\n}\n"],"names":["findLast","meanBy","sumBy","CalculationsMap","First","first","Last","last","LastNumber","lastNumber","Mean","mean","Sum","sum","CALCULATIONS_CONFIG","label","DEFAULT_CALCULATION","values","tuple","undefined","getValue","length","isNaN","valueTuple","value","NaN"],"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,EAAEC,MAAM,EAAEC,KAAK,QAAQ,WAAW,CAAC;AAGpD,oEAAoE;AACpE,OAAO,MAAMC,eAAe,GAAG;IAC7BC,KAAK,EAAEC,KAAK;IACZC,IAAI,EAAEC,IAAI;IACVC,UAAU,EAAEC,UAAU;IACtBC,IAAI,EAAEC,IAAI;IACVC,GAAG,EAAEC,GAAG;CACT,CAAC;AAOF,OAAO,MAAMC,mBAAmB,GAAyD;IACvFV,KAAK,EAAE;QACLW,KAAK,EAAE,OAAO;KACf;IACDT,IAAI,EAAE;QACJS,KAAK,EAAE,MAAM;KACd;IACDP,UAAU,EAAE;QACVO,KAAK,EAAE,aAAa;KACrB;IACDL,IAAI,EAAE;QACJK,KAAK,EAAE,MAAM;KACd;IACDH,GAAG,EAAE;QACHG,KAAK,EAAE,KAAK;KACb;CACF,AAAS,CAAC;AAEX,OAAO,MAAMC,mBAAmB,GAAoB,KAAK,CAAC;AAE1D,SAASX,KAAK,CAACY,MAA8B,EAAsB;IACjE,MAAMC,KAAK,GAAGD,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E,OAAOC,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -9,4 +9,11 @@ export interface DatasourcePlugin<Spec = UnknownSpec, Client = unknown> extends
|
|
|
9
9
|
export interface DatasourceClientOptions {
|
|
10
10
|
proxyUrl?: string;
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Common properties for all clients
|
|
14
|
+
*/
|
|
15
|
+
export interface DatasourceClient {
|
|
16
|
+
kind?: string;
|
|
17
|
+
healthCheck?: () => Promise<boolean>;
|
|
18
|
+
}
|
|
12
19
|
//# sourceMappingURL=datasource.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/model/datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,IAAI,GAAG,WAAW,EAAE,MAAM,GAAG,OAAO,CAAE,SAAQ,MAAM,CAAC,IAAI,CAAC;IAC1F,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,uBAAuB,KAAK,MAAM,CAAC;CACxE;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
1
|
+
{"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/model/datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,IAAI,GAAG,WAAW,EAAE,MAAM,GAAG,OAAO,CAAE,SAAQ,MAAM,CAAC,IAAI,CAAC;IAC1F,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,uBAAuB,KAAK,MAAM,CAAC;CACxE;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAE/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;CACtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/datasource.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 { UnknownSpec } from '@perses-dev/core';\nimport { Plugin } from './plugin-base';\n\n/**\n * Plugin that defines options for an external system that Perses talks to for data.\n */\nexport interface DatasourcePlugin<Spec = UnknownSpec, Client = unknown> extends Plugin<Spec> {\n createClient: (spec: Spec, options: DatasourceClientOptions) => Client;\n}\n\nexport interface DatasourceClientOptions {\n proxyUrl?: 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,
|
|
1
|
+
{"version":3,"sources":["../../src/model/datasource.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 { UnknownSpec } from '@perses-dev/core';\nimport { Plugin } from './plugin-base';\n\n/**\n * Plugin that defines options for an external system that Perses talks to for data.\n */\nexport interface DatasourcePlugin<Spec = UnknownSpec, Client = unknown> extends Plugin<Spec> {\n createClient: (spec: Spec, options: DatasourceClientOptions) => Client;\n}\n\nexport interface DatasourceClientOptions {\n proxyUrl?: string;\n}\n\n/**\n * Common properties for all clients\n */\nexport interface DatasourceClient {\n // TODO: set kind and define healthCheck function\n kind?: string;\n healthCheck?: () => Promise<boolean>;\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,WAqBC"}
|
package/dist/model/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export * from './calculations';
|
|
|
2
2
|
export * from './datasource';
|
|
3
3
|
export * from './panels';
|
|
4
4
|
export * from './plugins';
|
|
5
|
-
export * from './time-series-queries';
|
|
6
|
-
export * from './variables';
|
|
7
5
|
export * from './plugin-base';
|
|
8
6
|
export * from './plugin-loading';
|
|
7
|
+
export * from './time-series-queries';
|
|
8
|
+
export * from './variables';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
package/dist/model/index.js
CHANGED
|
@@ -14,9 +14,9 @@ export * from './calculations';
|
|
|
14
14
|
export * from './datasource';
|
|
15
15
|
export * from './panels';
|
|
16
16
|
export * from './plugins';
|
|
17
|
-
export * from './time-series-queries';
|
|
18
|
-
export * from './variables';
|
|
19
17
|
export * from './plugin-base';
|
|
20
18
|
export * from './plugin-loading';
|
|
19
|
+
export * from './time-series-queries';
|
|
20
|
+
export * from './variables';
|
|
21
21
|
|
|
22
22
|
//# sourceMappingURL=index.js.map
|
package/dist/model/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/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 './calculations';\nexport * from './datasource';\nexport * from './panels';\nexport * from './plugins';\nexport * from './
|
|
1
|
+
{"version":3,"sources":["../../src/model/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 './calculations';\nexport * from './datasource';\nexport * from './panels';\nexport * from './plugins';\nexport * from './plugin-base';\nexport * from './plugin-loading';\nexport * from './time-series-queries';\nexport * from './variables';\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,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Query, QueryKey } from '@tanstack/react-query';
|
|
2
|
+
import { AbsoluteTimeRange, TimeSeriesValueTuple, UnknownSpec, Labels, Notice } from '@perses-dev/core';
|
|
2
3
|
import { DatasourceStore, VariableStateMap } from '../runtime';
|
|
3
4
|
import { Plugin } from './plugin-base';
|
|
4
5
|
/**
|
|
@@ -30,13 +31,18 @@ export interface TimeSeriesQueryContext {
|
|
|
30
31
|
export interface TimeSeriesData {
|
|
31
32
|
timeRange?: AbsoluteTimeRange;
|
|
32
33
|
stepMs?: number;
|
|
33
|
-
series:
|
|
34
|
+
series: TimeSeries[];
|
|
35
|
+
metadata?: TimeSeriesMetadata;
|
|
34
36
|
}
|
|
35
37
|
export interface TimeSeries {
|
|
36
38
|
name: string;
|
|
37
|
-
values:
|
|
39
|
+
values: TimeSeriesValueTuple[];
|
|
38
40
|
formattedName?: string;
|
|
41
|
+
labels?: Labels;
|
|
39
42
|
}
|
|
40
|
-
export
|
|
43
|
+
export interface TimeSeriesMetadata {
|
|
44
|
+
notices?: Notice[];
|
|
45
|
+
}
|
|
46
|
+
export declare type TimeSeriesDataQuery = Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>;
|
|
41
47
|
export {};
|
|
42
48
|
//# sourceMappingURL=time-series-queries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/model/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/model/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACxG,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;GAEG;AACH,aAAK,iCAAiC,GAAG;IACvC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,IAAI,GAAG,WAAW,CAAE,SAAQ,MAAM,CAAC,IAAI,CAAC;IAC7E,iBAAiB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,sBAAsB,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAExF,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,sBAAsB,KAAK,iCAAiC,CAAC;CAC5F;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,iBAAiB,CAAC;IAC7B,aAAa,EAAE,gBAAgB,CAAC;IAChC,eAAe,EAAE,eAAe,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,QAAQ,CAAC,EAAE,kBAAkB,CAAC;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,oBAAY,mBAAmB,GAAG,KAAK,CAAC,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/model/time-series-queries.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 { AbsoluteTimeRange,
|
|
1
|
+
{"version":3,"sources":["../../src/model/time-series-queries.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 { Query, QueryKey } from '@tanstack/react-query';\nimport { AbsoluteTimeRange, TimeSeriesValueTuple, UnknownSpec, Labels, Notice } from '@perses-dev/core';\nimport { DatasourceStore, VariableStateMap } from '../runtime';\nimport { Plugin } from './plugin-base';\n\n/**\n * An object containing all the dependencies of a TimeSeriesQuery.\n */\ntype TimeSeriesQueryPluginDependencies = {\n /**\n * Returns a list of variables name this time series query depends on.\n */\n variables?: string[];\n};\n\n/**\n * A plugin for running time series queries.\n */\nexport interface TimeSeriesQueryPlugin<Spec = UnknownSpec> extends Plugin<Spec> {\n getTimeSeriesData: (spec: Spec, ctx: TimeSeriesQueryContext) => Promise<TimeSeriesData>;\n\n dependsOn?: (spec: Spec, ctx: TimeSeriesQueryContext) => TimeSeriesQueryPluginDependencies;\n}\n\n/**\n * Context available to TimeSeriesQuery plugins at runtime.\n */\nexport interface TimeSeriesQueryContext {\n suggestedStepMs?: number;\n timeRange: AbsoluteTimeRange;\n variableState: VariableStateMap;\n datasourceStore: DatasourceStore;\n refreshKey: string;\n}\n\nexport interface TimeSeriesData {\n timeRange?: AbsoluteTimeRange;\n stepMs?: number;\n series: TimeSeries[];\n metadata?: TimeSeriesMetadata;\n}\n\nexport interface TimeSeries {\n name: string;\n values: TimeSeriesValueTuple[];\n formattedName?: string;\n labels?: Labels;\n}\n\nexport interface TimeSeriesMetadata {\n notices?: Notice[];\n}\n\nexport type TimeSeriesDataQuery = Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>;\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,WAqD2F"}
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
+
import { QueryCache } from '@tanstack/react-query';
|
|
1
2
|
import { TimeSeriesQueryDefinition } from '@perses-dev/core';
|
|
3
|
+
import { TimeSeriesData, TimeSeriesDataQuery } from '../model';
|
|
2
4
|
export interface UseTimeSeriesQueryOptions {
|
|
3
5
|
suggestedStepMs?: number;
|
|
4
6
|
}
|
|
7
|
+
export declare const TIME_SERIES_QUERY_KEY = "TimeSeriesQuery";
|
|
5
8
|
/**
|
|
6
9
|
* Runs a time series query using a plugin and returns the results.
|
|
7
10
|
*/
|
|
8
|
-
export declare const useTimeSeriesQuery: (definition: TimeSeriesQueryDefinition, options?: UseTimeSeriesQueryOptions) => import("@tanstack/react-query").UseQueryResult<
|
|
11
|
+
export declare const useTimeSeriesQuery: (definition: TimeSeriesQueryDefinition, options?: UseTimeSeriesQueryOptions) => import("@tanstack/react-query").UseQueryResult<TimeSeriesData, unknown>;
|
|
9
12
|
/**
|
|
10
13
|
* Runs multiple time series queries using plugins and returns the results.
|
|
11
14
|
*/
|
|
12
|
-
export declare function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions): import("@tanstack/react-query").UseQueryResult<
|
|
15
|
+
export declare function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions): import("@tanstack/react-query").UseQueryResult<TimeSeriesData, unknown>[];
|
|
16
|
+
/**
|
|
17
|
+
* Get active time series queries for query results summary
|
|
18
|
+
*/
|
|
19
|
+
export declare function useActiveTimeSeriesQueries(): TimeSeriesDataQuery[];
|
|
20
|
+
/**
|
|
21
|
+
* Filter all cached queries down to only active time series queries
|
|
22
|
+
*/
|
|
23
|
+
export declare function getActiveTimeSeriesQueries(cache: QueryCache): TimeSeriesDataQuery[];
|
|
13
24
|
//# sourceMappingURL=time-series-queries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,yBAAyB,
|
|
1
|
+
{"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAA+C,UAAU,EAAY,MAAM,uBAAuB,CAAC;AAC1G,OAAO,EAAE,yBAAyB,EAAe,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAiD,MAAM,UAAU,CAAC;AAO9G,MAAM,WAAW,yBAAyB;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAmDvD;;GAEG;AACH,eAAO,MAAM,kBAAkB,eAAgB,yBAAyB,YAAY,yBAAyB,4EAkB5G,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,yBAAyB,EAAE,EAAE,OAAO,CAAC,EAAE,yBAAyB,6EA0BjH;AAkBD;;GAEG;AACH,wBAAgB,0BAA0B,0BAIzC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,UAAU,yBAW3D"}
|
|
@@ -10,11 +10,12 @@
|
|
|
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 { useQuery, useQueries } from '@tanstack/react-query';
|
|
13
|
+
import { useQuery, useQueries, useQueryClient } from '@tanstack/react-query';
|
|
14
14
|
import { useTemplateVariableValues } from './template-variables';
|
|
15
15
|
import { useTimeRange } from './TimeRangeProvider';
|
|
16
16
|
import { useDatasourceStore } from './datasources';
|
|
17
17
|
import { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';
|
|
18
|
+
export const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';
|
|
18
19
|
/**
|
|
19
20
|
* Returns a serialized string of the current state of variable values.
|
|
20
21
|
*/ function getVariableValuesKey(v) {
|
|
@@ -58,7 +59,7 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
58
59
|
/**
|
|
59
60
|
* Runs a time series query using a plugin and returns the results.
|
|
60
61
|
*/ export const useTimeSeriesQuery = (definition, options)=>{
|
|
61
|
-
const { data: plugin } = usePlugin(
|
|
62
|
+
const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
|
|
62
63
|
const context = useTimeSeriesQueryContext();
|
|
63
64
|
const { queryEnabled , queryKey } = getQueryOptions({
|
|
64
65
|
plugin,
|
|
@@ -87,7 +88,7 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
87
88
|
*/ export function useTimeSeriesQueries(definitions, options) {
|
|
88
89
|
const { getPlugin } = usePluginRegistry();
|
|
89
90
|
const context = useTimeSeriesQueryContext();
|
|
90
|
-
const pluginLoaderResponse = usePlugins(
|
|
91
|
+
const pluginLoaderResponse = usePlugins(TIME_SERIES_QUERY_KEY, definitions.map((d)=>({
|
|
91
92
|
kind: d.spec.plugin.kind
|
|
92
93
|
})));
|
|
93
94
|
return useQueries({
|
|
@@ -108,7 +109,7 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
108
109
|
...context,
|
|
109
110
|
suggestedStepMs: options === null || options === void 0 ? void 0 : options.suggestedStepMs
|
|
110
111
|
};
|
|
111
|
-
const plugin = await getPlugin(
|
|
112
|
+
const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
|
|
112
113
|
const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);
|
|
113
114
|
return data;
|
|
114
115
|
}
|
|
@@ -116,8 +117,9 @@ function getQueryOptions({ plugin , definition , context }) {
|
|
|
116
117
|
})
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Build the time series query context object from data available at runtime
|
|
122
|
+
*/ function useTimeSeriesQueryContext() {
|
|
121
123
|
const { absoluteTimeRange , refreshKey } = useTimeRange();
|
|
122
124
|
const variableState = useTemplateVariableValues();
|
|
123
125
|
const datasourceStore = useDatasourceStore();
|
|
@@ -128,5 +130,27 @@ function useTimeSeriesQueryContext() {
|
|
|
128
130
|
refreshKey
|
|
129
131
|
};
|
|
130
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Get active time series queries for query results summary
|
|
135
|
+
*/ export function useActiveTimeSeriesQueries() {
|
|
136
|
+
const queryClient = useQueryClient();
|
|
137
|
+
const queryCache = queryClient.getQueryCache();
|
|
138
|
+
return getActiveTimeSeriesQueries(queryCache);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Filter all cached queries down to only active time series queries
|
|
142
|
+
*/ export function getActiveTimeSeriesQueries(cache) {
|
|
143
|
+
const queries = [];
|
|
144
|
+
for (const query of cache.findAll({
|
|
145
|
+
type: 'active'
|
|
146
|
+
})){
|
|
147
|
+
var ref;
|
|
148
|
+
const firstPart = (ref = query.queryKey) === null || ref === void 0 ? void 0 : ref[0];
|
|
149
|
+
if ((firstPart === null || firstPart === void 0 ? void 0 : firstPart.kind) && firstPart.kind.startsWith(TIME_SERIES_QUERY_KEY)) {
|
|
150
|
+
queries.push(query);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return queries;
|
|
154
|
+
}
|
|
131
155
|
|
|
132
156
|
//# sourceMappingURL=time-series-queries.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/time-series-queries.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 { TimeSeriesQueryDefinition } from '@perses-dev/core';\nimport { useQuery, useQueries } from '@tanstack/react-query';\nimport { TimeSeriesQueryContext } from '../model';\nimport { TimeSeriesQueryPlugin } from '../model';\nimport { VariableStateMap } from './template-variables';\nimport { useTemplateVariableValues } from './template-variables';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\n\nexport interface UseTimeSeriesQueryOptions {\n suggestedStepMs?: number;\n}\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nfunction getVariableValuesKey(v: VariableStateMap) {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n\nfunction filterVariableStateMap(v: VariableStateMap, names?: string[]) {\n if (!names) {\n return v;\n }\n return Object.fromEntries(Object.entries(v).filter(([name]) => names.includes(name)));\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: TimeSeriesQueryPlugin;\n definition: TimeSeriesQueryDefinition;\n context: TimeSeriesQueryContext;\n}) {\n const { timeRange, datasourceStore, suggestedStepMs, variableState, refreshKey } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n // Determine queryKey\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n const queryKey = [definition, timeRange, datasourceStore, suggestedStepMs, variablesValueKey, refreshKey] as const;\n\n // Determine queryEnabled\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n const queryEnabled = plugin !== undefined && !waitToLoad;\n\n return {\n queryKey,\n queryEnabled,\n };\n}\n\n/**\n * Runs a time series query using a plugin and returns the results.\n */\nexport const useTimeSeriesQuery = (definition: TimeSeriesQueryDefinition, options?: UseTimeSeriesQueryOptions) => {\n const { data: plugin } = usePlugin('TimeSeriesQuery', definition.spec.plugin.kind);\n const context = useTimeSeriesQueryContext();\n\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return useQuery({\n enabled: queryEnabled,\n queryKey: queryKey,\n queryFn: () => {\n // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking\n if (plugin === undefined) {\n throw new Error('Expected plugin to be loaded');\n }\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n },\n });\n};\n\n/**\n * Runs multiple time series queries using plugins and returns the results.\n */\nexport function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions) {\n const { getPlugin } = usePluginRegistry();\n const context = useTimeSeriesQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'TimeSeriesQuery',\n definitions.map((d) => ({ kind: d.spec.plugin.kind }))\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n queryFn: async () => {\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n const plugin = await getPlugin('TimeSeriesQuery', definition.spec.plugin.kind);\n const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n return data;\n },\n };\n }),\n });\n}\n\nfunction useTimeSeriesQueryContext(): TimeSeriesQueryContext {\n // Build the context object from data available at runtime\n const { absoluteTimeRange, refreshKey } = useTimeRange();\n const variableState = useTemplateVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n timeRange: absoluteTimeRange,\n variableState,\n datasourceStore,\n refreshKey,\n };\n}\n"],"names":["useQuery","useQueries","useTemplateVariableValues","useTimeRange","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","getVariableValuesKey","v","Object","values","map","JSON","stringify","value","join","filterVariableStateMap","names","fromEntries","entries","filter","name","includes","getQueryOptions","plugin","definition","context","timeRange","datasourceStore","suggestedStepMs","variableState","refreshKey","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariabledState","variablesValueKey","queryKey","waitToLoad","some","loading","queryEnabled","undefined","useTimeSeriesQuery","options","data","kind","useTimeSeriesQueryContext","enabled","queryFn","Error","ctx","getTimeSeriesData","useTimeSeriesQueries","definitions","getPlugin","pluginLoaderResponse","d","queries","idx","absoluteTimeRange"],"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,QAAQ,EAAEC,UAAU,QAAQ,uBAAuB,CAAC;AAI7D,SAASC,yBAAyB,QAAQ,sBAAsB,CAAC;AACjE,SAASC,YAAY,QAAQ,qBAAqB,CAAC;AACnD,SAASC,kBAAkB,QAAQ,eAAe,CAAC;AACnD,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,mBAAmB,CAAC;AAM7E;;CAEC,GACD,SAASC,oBAAoB,CAACC,CAAmB,EAAE;IACjD,OAAOC,MAAM,CAACC,MAAM,CAACF,CAAC,CAAC,CACpBG,GAAG,CAAC,CAACH,CAAC,GAAKI,IAAI,CAACC,SAAS,CAACL,CAAC,CAACM,KAAK,CAAC,CAAC,CACnCC,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,SAASC,sBAAsB,CAACR,CAAmB,EAAES,KAAgB,EAAE;IACrE,IAAI,CAACA,KAAK,EAAE;QACV,OAAOT,CAAC,CAAC;IACX,CAAC;IACD,OAAOC,MAAM,CAACS,WAAW,CAACT,MAAM,CAACU,OAAO,CAACX,CAAC,CAAC,CAACY,MAAM,CAAC,CAAC,CAACC,IAAI,CAAC,GA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EmB,GAAG,CAAC,AAAC;oBAC9E,OAAON,IAAI,CAAC;gBACd,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAED,SAASE,yBAAyB,GAA2B;IAC3D,0DAA0D;IAC1D,MAAM,EAAEa,iBAAiB,CAAA,EAAE/B,UAAU,CAAA,EAAE,GAAG7B,YAAY,EAAE,AAAC;IACzD,MAAM4B,aAAa,GAAG7B,yBAAyB,EAAE,AAAC;IAClD,MAAM2B,eAAe,GAAGzB,kBAAkB,EAAE,AAAC;IAE7C,OAAO;QACLwB,SAAS,EAAEmC,iBAAiB;QAC5BhC,aAAa;QACbF,eAAe;QACfG,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/time-series-queries.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 { useQuery, useQueries, useQueryClient, Query, QueryCache, QueryKey } from '@tanstack/react-query';\nimport { TimeSeriesQueryDefinition, UnknownSpec } from '@perses-dev/core';\nimport { TimeSeriesData, TimeSeriesDataQuery, TimeSeriesQueryContext, TimeSeriesQueryPlugin } from '../model';\nimport { VariableStateMap } from './template-variables';\nimport { useTemplateVariableValues } from './template-variables';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\n\nexport interface UseTimeSeriesQueryOptions {\n suggestedStepMs?: number;\n}\n\nexport const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nfunction getVariableValuesKey(v: VariableStateMap) {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n\nfunction filterVariableStateMap(v: VariableStateMap, names?: string[]) {\n if (!names) {\n return v;\n }\n return Object.fromEntries(Object.entries(v).filter(([name]) => names.includes(name)));\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: TimeSeriesQueryPlugin;\n definition: TimeSeriesQueryDefinition;\n context: TimeSeriesQueryContext;\n}) {\n const { timeRange, datasourceStore, suggestedStepMs, variableState, refreshKey } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n // Determine queryKey\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n const queryKey = [definition, timeRange, datasourceStore, suggestedStepMs, variablesValueKey, refreshKey] as const;\n\n // Determine queryEnabled\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n\n return {\n queryKey,\n queryEnabled,\n };\n}\n\n/**\n * Runs a time series query using a plugin and returns the results.\n */\nexport const useTimeSeriesQuery = (definition: TimeSeriesQueryDefinition, options?: UseTimeSeriesQueryOptions) => {\n const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const context = useTimeSeriesQueryContext();\n\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return useQuery({\n enabled: queryEnabled,\n queryKey: queryKey,\n queryFn: () => {\n // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking\n if (plugin === undefined) {\n throw new Error('Expected plugin to be loaded');\n }\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n },\n });\n};\n\n/**\n * Runs multiple time series queries using plugins and returns the results.\n */\nexport function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions) {\n const { getPlugin } = usePluginRegistry();\n const context = useTimeSeriesQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n TIME_SERIES_QUERY_KEY,\n definitions.map((d) => ({ kind: d.spec.plugin.kind }))\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n queryFn: async () => {\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n return data;\n },\n };\n }),\n });\n}\n\n/**\n * Build the time series query context object from data available at runtime\n */\nfunction useTimeSeriesQueryContext(): TimeSeriesQueryContext {\n const { absoluteTimeRange, refreshKey } = useTimeRange();\n const variableState = useTemplateVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n timeRange: absoluteTimeRange,\n variableState,\n datasourceStore,\n refreshKey,\n };\n}\n\n/**\n * Get active time series queries for query results summary\n */\nexport function useActiveTimeSeriesQueries() {\n const queryClient = useQueryClient();\n const queryCache = queryClient.getQueryCache();\n return getActiveTimeSeriesQueries(queryCache);\n}\n\n/**\n * Filter all cached queries down to only active time series queries\n */\nexport function getActiveTimeSeriesQueries(cache: QueryCache) {\n const queries: TimeSeriesDataQuery[] = [];\n\n for (const query of cache.findAll({ type: 'active' })) {\n const firstPart = query.queryKey?.[0] as UnknownSpec;\n if (firstPart?.kind && (firstPart.kind as string).startsWith(TIME_SERIES_QUERY_KEY)) {\n queries.push(query as Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>);\n }\n }\n\n return queries;\n}\n"],"names":["useQuery","useQueries","useQueryClient","useTemplateVariableValues","useTimeRange","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","TIME_SERIES_QUERY_KEY","getVariableValuesKey","v","Object","values","map","JSON","stringify","value","join","filterVariableStateMap","names","fromEntries","entries","filter","name","includes","getQueryOptions","plugin","definition","context","timeRange","datasourceStore","suggestedStepMs","variableState","refreshKey","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariabledState","variablesValueKey","queryKey","waitToLoad","some","loading","queryEnabled","undefined","useTimeSeriesQuery","options","data","kind","useTimeSeriesQueryContext","enabled","queryFn","Error","ctx","getTimeSeriesData","useTimeSeriesQueries","definitions","getPlugin","pluginLoaderResponse","d","queries","idx","absoluteTimeRange","useActiveTimeSeriesQueries","queryClient","queryCache","getQueryCache","getActiveTimeSeriesQueries","cache","query","findAll","type","firstPart","startsWith","push"],"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,EAAEC,UAAU,EAAEC,cAAc,QAAqC,uBAAuB,CAAC;AAI1G,SAASC,yBAAyB,QAAQ,sBAAsB,CAAC;AACjE,SAASC,YAAY,QAAQ,qBAAqB,CAAC;AACnD,SAASC,kBAAkB,QAAQ,eAAe,CAAC;AACnD,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,mBAAmB,CAAC;AAM7E,OAAO,MAAMC,qBAAqB,GAAG,iBAAiB,CAAC;AAEvD;;CAEC,GACD,SAASC,oBAAoB,CAACC,CAAmB,EAAE;IACjD,OAAOC,MAAM,CAACC,MAAM,CAACF,CAAC,CAAC,CACpBG,GAAG,CAAC,CAACH,CAAC,GAAKI,IAAI,CAACC,SAAS,CAACL,CAAC,C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9B,QAAQ,cAAd8B,GAAc,WAAK,GAAnBA,KAAAA,CAAmB,GAAnBA,GAAc,AAAE,CAAC,CAAC,CAAC,AAAe,AAAC;QACrD,IAAIG,CAAAA,SAAS,aAATA,SAAS,WAAM,GAAfA,KAAAA,CAAe,GAAfA,SAAS,CAAExB,IAAI,CAAA,IAAI,AAACwB,SAAS,CAACxB,IAAI,CAAYyB,UAAU,CAACnE,qBAAqB,CAAC,EAAE;YACnFsD,OAAO,CAACc,IAAI,CAACL,KAAK,CAA6D,CAAC;QAClF,CAAC;IACH,CAAC;IAED,OAAOT,OAAO,CAAC;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/plugin-system",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "The plugin feature in Pereses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -20,15 +20,16 @@
|
|
|
20
20
|
"build": "concurrently \"npm:build:*\"",
|
|
21
21
|
"build:cjs": "swc ./src -d dist/cjs --config-file ../.cjs.swcrc",
|
|
22
22
|
"build:esm": "swc ./src -d dist --config-file ../.swcrc",
|
|
23
|
-
"build:types": "tsc --
|
|
23
|
+
"build:types": "tsc --project tsconfig.build.json",
|
|
24
|
+
"type-check": "tsc --noEmit",
|
|
24
25
|
"start": "concurrently -P \"npm:build:* -- {*}\" -- --watch",
|
|
25
26
|
"test": "TZ=UTC jest",
|
|
26
27
|
"lint": "eslint src --ext .ts,.tsx",
|
|
27
28
|
"lint:fix": "eslint --fix src --ext .ts,.tsx"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@perses-dev/components": "0.
|
|
31
|
-
"@perses-dev/core": "0.
|
|
31
|
+
"@perses-dev/components": "0.25.0",
|
|
32
|
+
"@perses-dev/core": "0.25.0",
|
|
32
33
|
"immer": "^9.0.15",
|
|
33
34
|
"use-immer": "^0.7.0",
|
|
34
35
|
"use-query-params": "^2.1.2"
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
-
const _react = require("@testing-library/react");
|
|
19
|
-
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
20
|
-
const _calculationSelector = require("./CalculationSelector");
|
|
21
|
-
function _interopRequireDefault(obj) {
|
|
22
|
-
return obj && obj.__esModule ? obj : {
|
|
23
|
-
default: obj
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
describe('CalculationSelector', ()=>{
|
|
27
|
-
const renderCalculationSelector = (value, onChange = jest.fn())=>{
|
|
28
|
-
(0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
|
|
29
|
-
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_calculationSelector.CalculationSelector, {
|
|
30
|
-
value: value,
|
|
31
|
-
onChange: onChange
|
|
32
|
-
})
|
|
33
|
-
}));
|
|
34
|
-
};
|
|
35
|
-
const getCalculationSelector = ()=>{
|
|
36
|
-
return _react.screen.getByRole('combobox', {
|
|
37
|
-
name: 'Calculation'
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
it('can change the calculation by clicking', ()=>{
|
|
41
|
-
const onChange = jest.fn();
|
|
42
|
-
renderCalculationSelector('Last', onChange);
|
|
43
|
-
const calcSelector = getCalculationSelector();
|
|
44
|
-
_userEvent.default.click(calcSelector);
|
|
45
|
-
const sumOption = _react.screen.getByRole('option', {
|
|
46
|
-
name: 'Sum'
|
|
47
|
-
});
|
|
48
|
-
_userEvent.default.click(sumOption);
|
|
49
|
-
expect(onChange).toHaveBeenCalledWith('Sum');
|
|
50
|
-
});
|
|
51
|
-
it('can change the calculation using a keyboard', ()=>{
|
|
52
|
-
const onChange = jest.fn();
|
|
53
|
-
renderCalculationSelector('First', onChange);
|
|
54
|
-
const calcSelector = getCalculationSelector();
|
|
55
|
-
_userEvent.default.tab();
|
|
56
|
-
expect(calcSelector).toHaveFocus();
|
|
57
|
-
_userEvent.default.clear(calcSelector);
|
|
58
|
-
_userEvent.default.keyboard('first');
|
|
59
|
-
_react.screen.getByRole('option', {
|
|
60
|
-
name: 'First'
|
|
61
|
-
});
|
|
62
|
-
_userEvent.default.keyboard('{arrowup}{enter}');
|
|
63
|
-
expect(onChange).toHaveBeenCalledWith('First');
|
|
64
|
-
});
|
|
65
|
-
});
|