@perses-dev/plugin-system 0.54.0-beta.1 → 0.54.0-beta.2

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 (193) hide show
  1. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +11 -15
  2. package/dist/cjs/components/PluginRegistry/getPluginSearchHelper.js +92 -0
  3. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +16 -13
  4. package/dist/cjs/components/Variables/variable-model.js +115 -29
  5. package/dist/cjs/context/ValidationProvider.js +3 -3
  6. package/dist/cjs/model/alerts-queries.js +16 -0
  7. package/dist/cjs/model/index.js +2 -0
  8. package/dist/cjs/model/log-volume-utils.js +10 -10
  9. package/dist/cjs/model/plugin-loading.js +24 -8
  10. package/dist/cjs/model/plugins.js +10 -0
  11. package/dist/cjs/model/silences-queries.js +16 -0
  12. package/dist/cjs/remote/PluginRuntime.js +38 -9
  13. package/dist/cjs/remote/remotePluginLoader.js +28 -5
  14. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +18 -2
  15. package/dist/cjs/runtime/DataQueriesProvider/model.js +30 -4
  16. package/dist/cjs/runtime/UsageMetricsProvider.js +2 -2
  17. package/dist/cjs/runtime/alerts-queries.js +101 -0
  18. package/dist/cjs/runtime/index.js +2 -0
  19. package/dist/cjs/runtime/item-actions.js +3 -3
  20. package/dist/cjs/runtime/log-queries.js +4 -1
  21. package/dist/cjs/runtime/plugin-registry.js +12 -3
  22. package/dist/cjs/runtime/profile-queries.js +4 -1
  23. package/dist/cjs/runtime/silences-queries.js +101 -0
  24. package/dist/cjs/runtime/time-series-queries.js +4 -1
  25. package/dist/cjs/runtime/trace-queries.js +4 -1
  26. package/dist/cjs/test/mock-data.js +51 -0
  27. package/dist/cjs/test/test-plugins/bert/index.js +9 -12
  28. package/dist/cjs/test/test-plugins/ernie/index.js +9 -12
  29. package/dist/cjs/test/test-plugins/index.js +2 -2
  30. package/dist/cjs/test-utils/mock-plugin-registry.js +8 -2
  31. package/dist/components/CalculationSelector/CalculationSelector.js +1 -1
  32. package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
  33. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +1 -1
  34. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  35. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +1 -1
  36. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  37. package/dist/components/DatasourceSelect/DatasourceSelect.js +2 -2
  38. package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -1
  39. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +1 -1
  40. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -1
  41. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +1 -1
  42. package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -1
  43. package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js +1 -1
  44. package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js.map +1 -1
  45. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +1 -1
  46. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  47. package/dist/components/MetricLabelInput/MetricLabelInput.js +1 -1
  48. package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -1
  49. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +1 -1
  50. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  51. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +1 -1
  52. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  53. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +1 -1
  54. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -1
  55. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js +1 -1
  56. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
  57. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js +1 -1
  58. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
  59. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +1 -1
  60. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  61. package/dist/components/PluginEditor/PluginEditor.js +1 -1
  62. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  63. package/dist/components/PluginKindSelect/PluginKindSelect.js +1 -1
  64. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  65. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
  66. package/dist/components/PluginRegistry/PluginRegistry.js +12 -16
  67. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  68. package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts +12 -0
  69. package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts.map +1 -0
  70. package/dist/components/PluginRegistry/getPluginSearchHelper.js +88 -0
  71. package/dist/components/PluginRegistry/getPluginSearchHelper.js.map +1 -0
  72. package/dist/components/PluginRegistry/plugin-indexes.d.ts +4 -6
  73. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  74. package/dist/components/PluginRegistry/plugin-indexes.js +15 -13
  75. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  76. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  77. package/dist/components/PluginSpecEditor/PluginSpecEditor.js +1 -1
  78. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  79. package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js +1 -1
  80. package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js.map +1 -1
  81. package/dist/components/TimeRangeControls/TimeRangeControls.js +1 -1
  82. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  83. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -1
  84. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  85. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +1 -1
  86. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  87. package/dist/components/Variables/variable-model.d.ts +9 -1
  88. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  89. package/dist/components/Variables/variable-model.js +117 -31
  90. package/dist/components/Variables/variable-model.js.map +1 -1
  91. package/dist/context/ValidationProvider.d.ts +1 -1
  92. package/dist/context/ValidationProvider.d.ts.map +1 -1
  93. package/dist/context/ValidationProvider.js +2 -2
  94. package/dist/context/ValidationProvider.js.map +1 -1
  95. package/dist/model/alerts-queries.d.ts +33 -0
  96. package/dist/model/alerts-queries.d.ts.map +1 -0
  97. package/dist/model/alerts-queries.js +15 -0
  98. package/dist/model/alerts-queries.js.map +1 -0
  99. package/dist/model/datasource.d.ts +1 -8
  100. package/dist/model/datasource.d.ts.map +1 -1
  101. package/dist/model/datasource.js +1 -1
  102. package/dist/model/datasource.js.map +1 -1
  103. package/dist/model/index.d.ts +2 -0
  104. package/dist/model/index.d.ts.map +1 -1
  105. package/dist/model/index.js +2 -0
  106. package/dist/model/index.js.map +1 -1
  107. package/dist/model/plugin-loading.d.ts.map +1 -1
  108. package/dist/model/plugin-loading.js +24 -8
  109. package/dist/model/plugin-loading.js.map +1 -1
  110. package/dist/model/plugins.d.ts +21 -0
  111. package/dist/model/plugins.d.ts.map +1 -1
  112. package/dist/model/plugins.js +4 -1
  113. package/dist/model/plugins.js.map +1 -1
  114. package/dist/model/silences-queries.d.ts +33 -0
  115. package/dist/model/silences-queries.d.ts.map +1 -0
  116. package/dist/model/silences-queries.js +15 -0
  117. package/dist/model/silences-queries.js.map +1 -0
  118. package/dist/remote/PersesPlugin.types.d.ts +2 -0
  119. package/dist/remote/PersesPlugin.types.d.ts.map +1 -1
  120. package/dist/remote/PersesPlugin.types.js.map +1 -1
  121. package/dist/remote/PluginLoaderComponent.js +1 -1
  122. package/dist/remote/PluginLoaderComponent.js.map +1 -1
  123. package/dist/remote/PluginRuntime.d.ts +7 -1
  124. package/dist/remote/PluginRuntime.d.ts.map +1 -1
  125. package/dist/remote/PluginRuntime.js +38 -9
  126. package/dist/remote/PluginRuntime.js.map +1 -1
  127. package/dist/remote/remotePluginLoader.d.ts.map +1 -1
  128. package/dist/remote/remotePluginLoader.js +28 -5
  129. package/dist/remote/remotePluginLoader.js.map +1 -1
  130. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  131. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +19 -3
  132. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  133. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  134. package/dist/runtime/DataQueriesProvider/model.js +30 -4
  135. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  136. package/dist/runtime/QueryCountProvider.js +1 -1
  137. package/dist/runtime/QueryCountProvider.js.map +1 -1
  138. package/dist/runtime/RouterProvider.js +1 -1
  139. package/dist/runtime/RouterProvider.js.map +1 -1
  140. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +1 -1
  141. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  142. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +1 -1
  143. package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -1
  144. package/dist/runtime/UsageMetricsProvider.js +2 -2
  145. package/dist/runtime/UsageMetricsProvider.js.map +1 -1
  146. package/dist/runtime/alerts-queries.d.ts +11 -0
  147. package/dist/runtime/alerts-queries.d.ts.map +1 -0
  148. package/dist/runtime/alerts-queries.js +89 -0
  149. package/dist/runtime/alerts-queries.js.map +1 -0
  150. package/dist/runtime/index.d.ts +2 -0
  151. package/dist/runtime/index.d.ts.map +1 -1
  152. package/dist/runtime/index.js +2 -0
  153. package/dist/runtime/index.js.map +1 -1
  154. package/dist/runtime/item-actions.js +1 -1
  155. package/dist/runtime/item-actions.js.map +1 -1
  156. package/dist/runtime/log-queries.js +4 -1
  157. package/dist/runtime/log-queries.js.map +1 -1
  158. package/dist/runtime/plugin-registry.d.ts +2 -1
  159. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  160. package/dist/runtime/plugin-registry.js +12 -3
  161. package/dist/runtime/plugin-registry.js.map +1 -1
  162. package/dist/runtime/profile-queries.js +4 -1
  163. package/dist/runtime/profile-queries.js.map +1 -1
  164. package/dist/runtime/silences-queries.d.ts +11 -0
  165. package/dist/runtime/silences-queries.d.ts.map +1 -0
  166. package/dist/runtime/silences-queries.js +89 -0
  167. package/dist/runtime/silences-queries.js.map +1 -0
  168. package/dist/runtime/time-series-queries.js +4 -1
  169. package/dist/runtime/time-series-queries.js.map +1 -1
  170. package/dist/runtime/trace-queries.js +4 -1
  171. package/dist/runtime/trace-queries.js.map +1 -1
  172. package/dist/test/mock-data.d.ts +3 -1
  173. package/dist/test/mock-data.d.ts.map +1 -1
  174. package/dist/test/mock-data.js +45 -0
  175. package/dist/test/mock-data.js.map +1 -1
  176. package/dist/test/render.js +1 -1
  177. package/dist/test/render.js.map +1 -1
  178. package/dist/test/test-plugins/bert/index.d.ts +12 -6
  179. package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
  180. package/dist/test/test-plugins/bert/index.js +6 -2
  181. package/dist/test/test-plugins/bert/index.js.map +1 -1
  182. package/dist/test/test-plugins/ernie/index.d.ts +8 -6
  183. package/dist/test/test-plugins/ernie/index.d.ts.map +1 -1
  184. package/dist/test/test-plugins/ernie/index.js +6 -2
  185. package/dist/test/test-plugins/ernie/index.js.map +1 -1
  186. package/dist/test/test-plugins/index.js +2 -2
  187. package/dist/test/test-plugins/index.js.map +1 -1
  188. package/dist/test/utils.js +1 -1
  189. package/dist/test/utils.js.map +1 -1
  190. package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
  191. package/dist/test-utils/mock-plugin-registry.js +8 -2
  192. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  193. package/package.json +6 -5
@@ -25,6 +25,7 @@ const _react = require("react");
25
25
  const _runtime = require("../../runtime");
26
26
  const _utils = require("../../utils");
27
27
  const _pluginindexes = require("./plugin-indexes");
28
+ const _getPluginSearchHelper = require("./getPluginSearchHelper");
28
29
  function PluginRegistry(props) {
29
30
  const { pluginLoader: { getInstalledPlugins, importPluginModule }, children, defaultPluginKinds } = props;
30
31
  const getPluginIndexes = (0, _pluginindexes.usePluginIndexes)(getInstalledPlugins);
@@ -42,23 +43,18 @@ function PluginRegistry(props) {
42
43
  }
43
44
  return request;
44
45
  });
45
- const getPlugin = (0, _react.useCallback)(async (kind, name)=>{
46
- // Get the indexes of the installed plugins
46
+ const getPlugin = (0, _react.useCallback)(async (compoundKeyObj)=>{
47
47
  const pluginIndexes = await getPluginIndexes();
48
- // Figure out what module the plugin is in by looking in the index
49
- const typeAndKindKey = (0, _pluginindexes.getTypeAndKindKey)(kind, name);
50
- const resource = pluginIndexes.pluginResourcesByNameAndKind.get(typeAndKindKey);
51
- if (resource === undefined) {
52
- throw new Error(`A ${name} plugin for kind '${kind}' is not installed`);
48
+ const { kind, name } = compoundKeyObj;
49
+ const candidateKeys = (0, _getPluginSearchHelper.resolvePluginKeys)(pluginIndexes.pluginResourcesByNameKindRegistryVersion.keys(), compoundKeyObj);
50
+ for (const resourceKey of candidateKeys){
51
+ const resource = pluginIndexes.pluginResourcesByNameKindRegistryVersion.get(resourceKey);
52
+ if (!resource) continue;
53
+ const pluginModule = await loadPluginModule(resource);
54
+ const plugin = pluginModule?.[resourceKey];
55
+ if (plugin) return plugin;
53
56
  }
54
- // Treat the plugin module as a bunch of named exports that have plugins
55
- const pluginModule = await loadPluginModule(resource);
56
- // We currently assume that plugin modules will have named exports that match the kinds they handle
57
- const plugin = pluginModule[name];
58
- if (plugin === undefined) {
59
- throw new Error(`The ${name} plugin for kind '${kind}' is missing from the ${resource.metadata.name} plugin module`);
60
- }
61
- return plugin;
57
+ throw new Error(`A ${name} plugin for kind '${kind}' is not installed`);
62
58
  }, [
63
59
  getPluginIndexes,
64
60
  loadPluginModule
@@ -0,0 +1,92 @@
1
+ // Copyright The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "resolvePluginKeys", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return resolvePluginKeys;
21
+ }
22
+ });
23
+ const _semver = require("semver");
24
+ const _model = require("../../model");
25
+ const PLUGIN_LOOKUP_PRECEDENCE_LOGIC = {
26
+ registryOverVersion: false
27
+ };
28
+ const resolvePluginKeys = (allKeys, query, precedenceLogic = PLUGIN_LOOKUP_PRECEDENCE_LOGIC)=>{
29
+ const { kind, name, version, registry } = query;
30
+ const candidates = [];
31
+ // Exact match first when version or registry is specified
32
+ if (version || registry) {
33
+ candidates.push((0, _model.getPluginModuleCompoundKey)({
34
+ kind,
35
+ name,
36
+ registry,
37
+ version
38
+ }));
39
+ }
40
+ const latestWithRegistry = {
41
+ key: '',
42
+ version: ''
43
+ };
44
+ const latestWithoutRegistry = {
45
+ key: '',
46
+ version: ''
47
+ };
48
+ const prefix = `${kind}:${name}:`;
49
+ for (const key of allKeys){
50
+ if (!key.startsWith(prefix)) continue;
51
+ const split = key.split(':');
52
+ if (split.length !== 4) {
53
+ console.warn(`An invalid Plugin Resource key detected during default plugin lookup: ${key}`);
54
+ continue;
55
+ }
56
+ const [, , reg, ver] = split;
57
+ if (!ver) {
58
+ console.warn(`An invalid Plugin Resource key detected during default plugin lookup: ${key}`);
59
+ continue;
60
+ }
61
+ if (reg) {
62
+ if (!latestWithRegistry.key || (0, _semver.gt)(ver, latestWithRegistry.version)) {
63
+ latestWithRegistry.key = key;
64
+ latestWithRegistry.version = ver;
65
+ }
66
+ } else {
67
+ if (!latestWithoutRegistry.key || (0, _semver.gt)(ver, latestWithoutRegistry.version)) {
68
+ latestWithoutRegistry.key = key;
69
+ latestWithoutRegistry.version = ver;
70
+ }
71
+ }
72
+ }
73
+ // Determine the best fallback key from the two buckets
74
+ let fallbackKey;
75
+ if (latestWithRegistry.key && latestWithoutRegistry.key) {
76
+ const { registryOverVersion } = precedenceLogic;
77
+ if ((0, _semver.gt)(latestWithRegistry.version, latestWithoutRegistry.version)) {
78
+ fallbackKey = latestWithRegistry.key;
79
+ } else if ((0, _semver.gt)(latestWithoutRegistry.version, latestWithRegistry.version)) {
80
+ fallbackKey = latestWithoutRegistry.key;
81
+ } else {
82
+ // Versions are equal — use the tie-breaker
83
+ fallbackKey = registryOverVersion ? latestWithRegistry.key : latestWithoutRegistry.key;
84
+ }
85
+ } else {
86
+ fallbackKey = latestWithRegistry.key || latestWithoutRegistry.key || undefined;
87
+ }
88
+ if (fallbackKey && !candidates.includes(fallbackKey)) {
89
+ candidates.push(fallbackKey);
90
+ }
91
+ return candidates;
92
+ };
@@ -21,14 +21,15 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- get getTypeAndKindKey () {
25
- return getTypeAndKindKey;
24
+ get getPluginModuleCompoundKey () {
25
+ return _model.getPluginModuleCompoundKey;
26
26
  },
27
27
  get usePluginIndexes () {
28
28
  return usePluginIndexes;
29
29
  }
30
30
  });
31
31
  const _react = require("react");
32
+ const _model = require("../../model");
32
33
  const _utils = require("../../utils");
33
34
  function usePluginIndexes(getInstalledPlugins) {
34
35
  // Creates indexes from the installed plugins data (does useEvent because this accesses the getInstalledPlugins prop
@@ -36,17 +37,22 @@ function usePluginIndexes(getInstalledPlugins) {
36
37
  const createPluginIndexes = (0, _utils.useEvent)(async ()=>{
37
38
  const installedPlugins = await getInstalledPlugins();
38
39
  // Create the two indexes from the installed plugins
39
- const pluginResourcesByNameAndKind = new Map();
40
+ const pluginResourcesByNameKindRegistryVersion = new Map();
40
41
  const pluginMetadataByKind = new Map();
41
42
  for (const resource of installedPlugins){
43
+ const { metadata: { version, registry } } = resource;
42
44
  for (const pluginMetadata of resource.spec.plugins){
43
45
  const { kind, spec: { name } } = pluginMetadata;
44
- // Index the plugin by type and kind to point at the module that contains it
45
- const key = getTypeAndKindKey(kind, name);
46
- if (pluginResourcesByNameAndKind.has(key)) {
47
- console.warn(`Got more than one ${kind} plugin for kind ${name}`);
46
+ const key = (0, _model.getPluginModuleCompoundKey)({
47
+ kind,
48
+ name,
49
+ registry,
50
+ version
51
+ });
52
+ if (pluginResourcesByNameKindRegistryVersion.has(key)) {
53
+ console.warn(`Got more than one ${kind} plugin for kind ${name}, registry '${registry || 'undefined'}', and version '${version || 'undefined'}'`);
48
54
  }
49
- pluginResourcesByNameAndKind.set(key, resource);
55
+ pluginResourcesByNameKindRegistryVersion.set(key, resource);
50
56
  // Index the metadata by plugin type
51
57
  let list = pluginMetadataByKind.get(kind);
52
58
  if (list === undefined) {
@@ -60,7 +66,7 @@ function usePluginIndexes(getInstalledPlugins) {
60
66
  }
61
67
  }
62
68
  return {
63
- pluginResourcesByNameAndKind,
69
+ pluginResourcesByNameKindRegistryVersion,
64
70
  pluginMetadataByKind
65
71
  };
66
72
  });
@@ -72,7 +78,7 @@ function usePluginIndexes(getInstalledPlugins) {
72
78
  request = createPluginIndexes();
73
79
  pluginIndexesCache.current = request;
74
80
  // Remove failed requests from the cache so they can potentially be retried
75
- request.catch(()=>pluginIndexesCache.current === undefined);
81
+ request.catch(()=>pluginIndexesCache.current = undefined);
76
82
  }
77
83
  return request;
78
84
  }, [
@@ -80,6 +86,3 @@ function usePluginIndexes(getInstalledPlugins) {
80
86
  ]);
81
87
  return getPluginIndexes;
82
88
  }
83
- function getTypeAndKindKey(kind, name) {
84
- return `${kind}:${name}`;
85
- }
@@ -32,9 +32,13 @@ _export(exports, {
32
32
  },
33
33
  get useListVariablePluginValues () {
34
34
  return useListVariablePluginValues;
35
+ },
36
+ get useResolveListVariableValues () {
37
+ return useResolveListVariableValues;
35
38
  }
36
39
  });
37
40
  const _reactquery = require("@tanstack/react-query");
41
+ const _react = require("react");
38
42
  const _runtime = require("../../runtime");
39
43
  function filterVariableList(data, capturedRegexp) {
40
44
  const result = [];
@@ -61,54 +65,136 @@ function filterVariableList(data, capturedRegexp) {
61
65
  }
62
66
  return result;
63
67
  }
64
- function useListVariablePluginValues(definition) {
65
- const { data: variablePlugin } = (0, _runtime.usePlugin)('Variable', definition.spec.plugin.kind);
68
+ function useVariablePluginContext() {
66
69
  const datasourceStore = (0, _runtime.useDatasourceStore)();
67
70
  const allVariables = (0, _runtime.useAllVariableValues)();
68
71
  const { absoluteTimeRange: timeRange } = (0, _runtime.useTimeRange)();
69
- const variablePluginCtx = {
72
+ return {
70
73
  timeRange,
71
74
  datasourceStore,
72
75
  variables: allVariables
73
76
  };
74
- const spec = definition.spec.plugin.spec;
77
+ }
78
+ const getVariableQueryConfig = (definition, variablePluginCtx, variablePlugin, enabled, onFetched)=>{
75
79
  const capturingRegexp = definition.spec.capturingRegexp !== undefined ? new RegExp(definition.spec.capturingRegexp, 'g') : undefined;
76
- let dependsOnVariables = Object.keys(allVariables); // Default to all variables
77
- if (variablePlugin?.dependsOn) {
78
- const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);
79
- dependsOnVariables = dependencies.variables ? dependencies.variables : dependsOnVariables;
80
- }
81
- // Exclude self variable to avoid circular dependency
82
- dependsOnVariables = dependsOnVariables.filter((v)=>v !== definition.spec.name);
83
- const variables = (0, _runtime.useAllVariableValues)(dependsOnVariables);
84
- let waitToLoad = false;
85
- if (dependsOnVariables) {
86
- waitToLoad = dependsOnVariables.some((v)=>variables[v]?.loading);
87
- }
88
- const variablesValueKey = getVariableValuesKey(variables);
89
- return (0, _reactquery.useQuery)({
80
+ const variablesValueKey = getVariableValuesKey(variablePluginCtx.variables);
81
+ return {
90
82
  queryKey: [
91
83
  'variable',
92
84
  definition,
93
- timeRange,
85
+ variablePluginCtx.timeRange,
94
86
  variablesValueKey
95
87
  ],
96
88
  queryFn: async ({ signal })=>{
97
- const resp = await variablePlugin?.getVariableOptions(spec, {
98
- datasourceStore,
99
- variables,
100
- timeRange
101
- }, signal);
89
+ const resp = await variablePlugin?.getVariableOptions(definition.spec.plugin.spec, variablePluginCtx, signal);
102
90
  if (!resp?.data?.length) {
91
+ onFetched?.(definition.spec.name, [], definition);
103
92
  return [];
104
93
  }
105
- if (!capturingRegexp) {
106
- return resp.data;
107
- }
108
- return filterVariableList(resp.data, capturingRegexp);
94
+ const options = capturingRegexp ? filterVariableList(resp.data, capturingRegexp) : resp.data;
95
+ onFetched?.(definition.spec.name, options, definition);
96
+ return options;
109
97
  },
110
- enabled: !!variablePlugin || waitToLoad
98
+ enabled
99
+ };
100
+ };
101
+ function resolveDependsOnVariables(variablePlugin, variablePluginCtx, definition) {
102
+ if (variablePlugin?.dependsOn) {
103
+ const dependencies = variablePlugin.dependsOn(definition.spec.plugin.spec, variablePluginCtx);
104
+ return dependencies.variables ? dependencies.variables.filter((v)=>v !== definition.spec.name) : []; // Exclude self variable to avoid circular dependency and default to empty array to avoid deadlock
105
+ }
106
+ return [];
107
+ }
108
+ function useListVariablePluginValues(definition) {
109
+ const { data: variablePlugin } = (0, _runtime.usePlugin)('Variable', definition.spec.plugin.kind);
110
+ const variablePluginCtx = useVariablePluginContext();
111
+ const dependsOnVariables = resolveDependsOnVariables(variablePlugin, variablePluginCtx, definition);
112
+ const dependentVariables = (0, _runtime.useAllVariableValues)(dependsOnVariables);
113
+ const waitToLoad = dependsOnVariables.some((v)=>dependentVariables[v]?.loading);
114
+ const ctx = {
115
+ ...variablePluginCtx,
116
+ variables: dependentVariables
117
+ };
118
+ return (0, _reactquery.useQuery)(getVariableQueryConfig(definition, ctx, variablePlugin, !!variablePlugin && !waitToLoad));
119
+ }
120
+ function resolveDefaultValue(definition, options) {
121
+ const { defaultValue, allowMultiple } = definition.spec;
122
+ if (defaultValue !== undefined && defaultValue !== null) {
123
+ return defaultValue;
124
+ }
125
+ if (options[0]?.value) {
126
+ const first = options[0].value;
127
+ return allowMultiple ? [
128
+ first
129
+ ] : first;
130
+ }
131
+ return allowMultiple ? [] : '';
132
+ }
133
+ function useResolveListVariableValues(variableDefinitions) {
134
+ const { timeRange, datasourceStore, variables: outerVariableValues } = useVariablePluginContext();
135
+ const listVariables = (0, _react.useMemo)(()=>variableDefinitions.filter((v)=>v.kind === 'ListVariable'), [
136
+ variableDefinitions
137
+ ]);
138
+ const pluginResults = (0, _runtime.usePlugins)('Variable', listVariables.map((d)=>({
139
+ kind: d.spec.plugin.kind
140
+ })));
141
+ // Resolved variable state. Updated by onFetched when queries resolve.
142
+ // Needed because of dependencies between variables that require multiple rounds of fetching.
143
+ const [resolvedVariables, setResolvedVariables] = (0, _react.useState)({});
144
+ const allVariables = (0, _react.useMemo)(()=>{
145
+ return {
146
+ ...outerVariableValues,
147
+ ...resolvedVariables
148
+ };
149
+ }, [
150
+ outerVariableValues,
151
+ resolvedVariables
152
+ ]);
153
+ const onFetched = (0, _react.useCallback)((name, options, definition)=>{
154
+ setResolvedVariables((prev)=>({
155
+ ...prev,
156
+ [name]: {
157
+ value: resolveDefaultValue(definition, options),
158
+ loading: false,
159
+ options
160
+ }
161
+ }));
162
+ }, []);
163
+ const queryResults = (0, _reactquery.useQueries)({
164
+ queries: listVariables.map((definition, index)=>{
165
+ const plugin = pluginResults[index]?.data;
166
+ const isPluginLoading = pluginResults[index]?.isLoading ?? true;
167
+ const dependsOn = resolveDependsOnVariables(plugin, {
168
+ timeRange,
169
+ datasourceStore,
170
+ variables: allVariables
171
+ }, definition);
172
+ const hasPendingDeps = dependsOn.some((v)=>resolvedVariables[v] === undefined && listVariables.some((lv)=>lv.spec.name === v) || allVariables[v]?.loading);
173
+ const dependentVariables = {};
174
+ for (const v of dependsOn){
175
+ const state = allVariables[v];
176
+ if (state) {
177
+ dependentVariables[v] = state;
178
+ }
179
+ }
180
+ const ctx = {
181
+ timeRange,
182
+ datasourceStore,
183
+ variables: dependentVariables
184
+ };
185
+ return getVariableQueryConfig(definition, ctx, plugin, !hasPendingDeps && !isPluginLoading, onFetched);
186
+ })
111
187
  });
188
+ const initialVariableValues = (0, _react.useMemo)(()=>Object.fromEntries(Object.entries(allVariables).filter(([, state])=>state?.value !== undefined).map(([name, state])=>[
189
+ name,
190
+ state.value
191
+ ])), [
192
+ allVariables
193
+ ]);
194
+ return {
195
+ initialVariableValues,
196
+ isLoading: queryResults.some((r)=>r.isLoading)
197
+ };
112
198
  }
113
199
  function getVariableValuesKey(v) {
114
200
  return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
@@ -34,7 +34,7 @@ _export(exports, {
34
34
  const _jsxruntime = require("react/jsx-runtime");
35
35
  const _react = require("react");
36
36
  const _spec = require("@perses-dev/spec");
37
- const _core = require("@perses-dev/core");
37
+ const _client = require("@perses-dev/client");
38
38
  const ValidationSchemasContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
39
39
  function useValidationSchemas() {
40
40
  const ctx = (0, _react.useContext)(ValidationSchemasContext);
@@ -44,11 +44,11 @@ function useValidationSchemas() {
44
44
  return ctx;
45
45
  }
46
46
  function ValidationProvider({ children }) {
47
- const [datasourceEditorSchema, setDatasourceEditorSchema] = (0, _react.useState)(_core.datasourceDefinitionSchema);
47
+ const [datasourceEditorSchema, setDatasourceEditorSchema] = (0, _react.useState)(_client.datasourceDefinitionSchema);
48
48
  const [panelEditorSchema, setPanelEditorSchema] = (0, _react.useState)(_spec.panelEditorSchema); // TODO I don't get why this does not compile
49
49
  const [variableEditorSchema, setVariableEditorSchema] = (0, _react.useState)(_spec.variableDefinitionSchema);
50
50
  function setDatasourceEditorSchemaPlugin(pluginSchema) {
51
- setDatasourceEditorSchema((0, _core.buildDatasourceDefinitionSchema)(pluginSchema));
51
+ setDatasourceEditorSchema((0, _client.buildDatasourceDefinitionSchema)(pluginSchema));
52
52
  }
53
53
  function setPanelEditorSchemaPlugin(pluginSchema) {
54
54
  setPanelEditorSchema((0, _spec.buildPanelEditorSchema)(pluginSchema));
@@ -0,0 +1,16 @@
1
+ // Copyright 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
+ });
@@ -27,6 +27,8 @@ _export_star(require("./trace-queries"), exports);
27
27
  _export_star(require("./profile-queries"), exports);
28
28
  _export_star(require("./variables"), exports);
29
29
  _export_star(require("./calculations"), exports);
30
+ _export_star(require("./alerts-queries"), exports);
31
+ _export_star(require("./silences-queries"), exports);
30
32
  function _export_star(from, to) {
31
33
  Object.keys(from).forEach(function(k) {
32
34
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -1,3 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "calculateVolumeInterval", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return calculateVolumeInterval;
9
+ }
10
+ });
1
11
  // Copyright The Perses Authors
2
12
  // Licensed under the Apache License, Version 2.0 (the "License");
3
13
  // you may not use this file except in compliance with the License.
@@ -11,16 +21,6 @@
11
21
  // See the License for the specific language governing permissions and
12
22
  // limitations under the License.
13
23
  // Target number of bars for log volume histogram
14
- "use strict";
15
- Object.defineProperty(exports, "__esModule", {
16
- value: true
17
- });
18
- Object.defineProperty(exports, "calculateVolumeInterval", {
19
- enumerable: true,
20
- get: function() {
21
- return calculateVolumeInterval;
22
- }
23
- });
24
24
  const TARGET_HISTOGRAM_BARS = 40;
25
25
  // Standard intervals for histogram calculations (in milliseconds)
26
26
  const STANDARD_INTERVALS = [
@@ -20,21 +20,37 @@ Object.defineProperty(exports, "dynamicImportPluginLoader", {
20
20
  return dynamicImportPluginLoader;
21
21
  }
22
22
  });
23
+ const _plugins = require("./plugins");
23
24
  function dynamicImportPluginLoader(plugins) {
24
- const importMap = new Map(plugins.map((plugin)=>[
25
- plugin.resource,
26
- plugin.importPlugin
27
- ]));
25
+ const importMap = new Map();
26
+ for (const p of plugins){
27
+ const { resource, resource: { kind, metadata: { name, registry, version } }, importPlugin } = p;
28
+ importMap.set((0, _plugins.getPluginModuleCompoundKey)({
29
+ kind,
30
+ name,
31
+ registry,
32
+ version
33
+ }), {
34
+ resource,
35
+ importPlugin
36
+ });
37
+ }
28
38
  return {
29
39
  async getInstalledPlugins () {
30
- return Promise.resolve(Array.from(importMap.keys()));
40
+ return Promise.resolve(Array.from(importMap.values()).map((v)=>v.resource));
31
41
  },
32
42
  importPluginModule (resource) {
33
- const importFn = importMap.get(resource);
34
- if (importFn === undefined) {
43
+ const { kind, metadata: { name, version, registry } } = resource;
44
+ const { importPlugin } = importMap.get((0, _plugins.getPluginModuleCompoundKey)({
45
+ kind,
46
+ name,
47
+ registry,
48
+ version
49
+ })) || {};
50
+ if (importPlugin === undefined) {
35
51
  throw new Error('Plugin not found');
36
52
  }
37
- return importFn();
53
+ return importPlugin();
38
54
  }
39
55
  };
40
56
  }
@@ -14,3 +14,13 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
+ Object.defineProperty(exports, "getPluginModuleCompoundKey", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return getPluginModuleCompoundKey;
21
+ }
22
+ });
23
+ function getPluginModuleCompoundKey(compoundKey) {
24
+ const { kind, name, registry, version } = compoundKey;
25
+ return `${kind}:${name}:${registry ?? ''}:${version ?? ''}`;
26
+ }
@@ -0,0 +1,16 @@
1
+ // Copyright 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
+ });
@@ -156,6 +156,14 @@ const getPluginRuntime = ()=>{
156
156
  requiredVersion: '^0.53.1'
157
157
  }
158
158
  },
159
+ '@perses-dev/client': {
160
+ version: '0.54.0-beta.1',
161
+ lib: ()=>require('@perses-dev/client'),
162
+ shareConfig: {
163
+ singleton: true,
164
+ requiredVersion: '^0.54.0-beta.1'
165
+ }
166
+ },
159
167
  '@perses-dev/components': {
160
168
  version: '0.53.1',
161
169
  lib: ()=>require('@perses-dev/components'),
@@ -268,28 +276,49 @@ const getPluginRuntime = ()=>{
268
276
  }
269
277
  return instance;
270
278
  };
271
- const registerRemote = (name, baseURL)=>{
279
+ function getModuleFederationRemoteName(name, registry, version) {
280
+ return `${name}:${registry ?? ''}:${version ?? ''}`;
281
+ }
282
+ const registerRemote = (name, registry, version, baseURL)=>{
272
283
  const pluginRuntime = getPluginRuntime();
273
- const existingRemote = pluginRuntime.options.remotes.find((remote)=>remote.name === name);
284
+ const registryName = getModuleFederationRemoteName(name, registry, version);
285
+ const existingRemote = pluginRuntime.options.remotes.find((remote)=>remote.name === registryName);
274
286
  if (!existingRemote) {
275
- const remoteEntryURL = baseURL ? `${baseURL}/${name}/mf-manifest.json` : `/plugins/${name}/mf-manifest.json`;
287
+ const nameVersionRegistry = [
288
+ name,
289
+ version,
290
+ registry
291
+ ].filter(Boolean).join('~');
292
+ const prefix = baseURL || '/plugins';
293
+ const remoteEntryURL = `${prefix}/${nameVersionRegistry}/mf-manifest.json`;
276
294
  pluginRuntime.registerRemotes([
277
295
  {
278
- name,
296
+ name: registryName,
279
297
  entry: remoteEntryURL,
280
- alias: name
298
+ alias: registryName
281
299
  }
282
300
  ]);
283
301
  }
284
302
  };
285
- const loadPlugin = async (moduleName, pluginName, baseURL)=>{
286
- registerRemote(moduleName, baseURL);
303
+ const loadPlugin = async (target)=>{
304
+ const { moduleName, pluginName, registry, version, baseURL } = target;
305
+ registerRemote(moduleName, registry, version, baseURL);
287
306
  const pluginRuntime = getPluginRuntime();
288
- return pluginRuntime.loadRemote(`${moduleName}/${pluginName}`);
307
+ const registryName = getModuleFederationRemoteName(moduleName, registry, version);
308
+ return pluginRuntime.loadRemote(`${registryName}/${pluginName}`);
289
309
  };
290
310
  function usePluginRuntime({ plugin }) {
291
311
  return {
292
312
  pluginRuntime: getPluginRuntime(),
293
- loadPlugin: ()=>loadPlugin(plugin.moduleName, plugin.name, plugin.baseURL)
313
+ loadPlugin: ()=>{
314
+ const { moduleName, name: pluginName, registry, version, baseURL } = plugin;
315
+ return loadPlugin({
316
+ moduleName,
317
+ pluginName,
318
+ registry,
319
+ version,
320
+ baseURL
321
+ });
322
+ }
294
323
  };
295
324
  }