@perses-dev/plugin-system 0.54.0-beta.0 → 0.54.0-beta.10
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/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js +283 -0
- package/dist/cjs/components/Annotations/AnnotationEditorForm/AnnotationPreview.js +197 -0
- package/dist/cjs/components/Annotations/AnnotationEditorForm/index.js +30 -0
- package/dist/cjs/components/Annotations/constants.js +23 -0
- package/dist/cjs/components/Annotations/index.js +31 -0
- package/dist/cjs/components/CalculationSelector/CalculationSelector.js +3 -3
- package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +2 -3
- package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -5
- package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +97 -12
- package/dist/cjs/components/MultiQueryEditor/index.js +1 -0
- package/dist/cjs/{utils/action.js → components/MultiQueryEditor/utils.js} +8 -15
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +3 -6
- package/dist/cjs/components/PluginRegistry/PluginRegistry.js +11 -15
- package/dist/cjs/components/PluginRegistry/getPluginSearchHelper.js +92 -0
- package/dist/cjs/components/PluginRegistry/plugin-indexes.js +16 -13
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +2 -3
- package/dist/cjs/components/Variables/variable-model.js +115 -29
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/context/ValidationProvider.js +10 -4
- package/dist/cjs/model/alerts-queries.js +16 -0
- package/dist/cjs/model/annotations.js +16 -0
- package/dist/cjs/model/calculations.js +178 -0
- package/dist/cjs/model/index.js +4 -0
- package/dist/cjs/model/legend.js +6 -5
- package/dist/cjs/model/log-volume-utils.js +10 -10
- package/dist/cjs/model/plugin-loading.js +24 -8
- package/dist/cjs/model/plugins.js +10 -0
- package/dist/cjs/model/silences-queries.js +16 -0
- package/dist/cjs/model/time-series-queries.js +10 -0
- package/dist/cjs/remote/PluginRuntime.js +46 -10
- package/dist/cjs/remote/remotePluginLoader.js +28 -5
- package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +33 -24
- package/dist/cjs/runtime/DataQueriesProvider/model.js +3 -93
- package/dist/cjs/runtime/UsageMetricsProvider.js +2 -2
- package/dist/cjs/runtime/alerts-queries.js +101 -0
- package/dist/cjs/runtime/annotations.js +148 -0
- package/dist/cjs/runtime/index.js +3 -1
- package/dist/cjs/runtime/item-actions.js +3 -3
- package/dist/cjs/runtime/log-queries.js +4 -1
- package/dist/cjs/runtime/plugin-registry.js +12 -3
- package/dist/cjs/runtime/profile-queries.js +4 -1
- package/dist/cjs/runtime/silences-queries.js +101 -0
- package/dist/cjs/runtime/time-series-queries.js +4 -1
- package/dist/cjs/runtime/trace-queries.js +4 -1
- package/dist/cjs/test/mock-data.js +51 -0
- package/dist/cjs/test/test-plugins/bert/index.js +9 -12
- package/dist/cjs/test/test-plugins/ernie/index.js +9 -12
- package/dist/cjs/test/test-plugins/index.js +2 -2
- package/dist/cjs/test/utils.js +2 -2
- package/dist/cjs/test-utils/mock-plugin-registry.js +8 -2
- package/dist/cjs/utils/index.js +0 -1
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.d.ts +16 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.d.ts.map +1 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js +270 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationEditorForm.js.map +1 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.d.ts +8 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.d.ts.map +1 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.js +184 -0
- package/dist/components/Annotations/AnnotationEditorForm/AnnotationPreview.js.map +1 -0
- package/dist/components/Annotations/AnnotationEditorForm/index.d.ts +2 -0
- package/dist/components/Annotations/AnnotationEditorForm/index.d.ts.map +1 -0
- package/dist/{runtime/QueryCountProvider.js → components/Annotations/AnnotationEditorForm/index.js} +2 -13
- package/dist/components/Annotations/AnnotationEditorForm/index.js.map +1 -0
- package/dist/components/Annotations/constants.d.ts +2 -0
- package/dist/components/Annotations/constants.d.ts.map +1 -0
- package/dist/components/Annotations/constants.js +15 -0
- package/dist/components/Annotations/constants.js.map +1 -0
- package/dist/components/Annotations/index.d.ts +3 -0
- package/dist/components/Annotations/index.d.ts.map +1 -0
- package/dist/components/Annotations/index.js +16 -0
- package/dist/components/Annotations/index.js.map +1 -0
- package/dist/components/CalculationSelector/CalculationSelector.d.ts +1 -1
- package/dist/components/CalculationSelector/CalculationSelector.d.ts.map +1 -1
- package/dist/components/CalculationSelector/CalculationSelector.js +2 -2
- package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +2 -3
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
- package/dist/components/DatasourceSelect/DatasourceSelect.js +2 -2
- package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +2 -2
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -1
- package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js +1 -1
- package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +2 -3
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
- package/dist/components/MetricLabelInput/MetricLabelInput.js +1 -1
- package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js +100 -15
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
- package/dist/components/MultiQueryEditor/index.d.ts +1 -0
- package/dist/components/MultiQueryEditor/index.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/index.js +1 -0
- package/dist/components/MultiQueryEditor/index.js.map +1 -1
- package/dist/components/MultiQueryEditor/utils.d.ts +8 -0
- package/dist/components/MultiQueryEditor/utils.d.ts.map +1 -0
- package/dist/{utils/action.js → components/MultiQueryEditor/utils.js} +8 -12
- package/dist/components/MultiQueryEditor/utils.js.map +1 -0
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +1 -1
- package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -1
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js +1 -1
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js +1 -1
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +5 -8
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +1 -1
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js +12 -16
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts +12 -0
- package/dist/components/PluginRegistry/getPluginSearchHelper.d.ts.map +1 -0
- package/dist/components/PluginRegistry/getPluginSearchHelper.js +88 -0
- package/dist/components/PluginRegistry/getPluginSearchHelper.js.map +1 -0
- package/dist/components/PluginRegistry/plugin-indexes.d.ts +4 -6
- package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js +15 -13
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
- package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js +1 -1
- package/dist/components/SelectionOptionsEditor/SelectionOptionsEditor.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +2 -3
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/variable-model.d.ts +9 -1
- package/dist/components/Variables/variable-model.d.ts.map +1 -1
- package/dist/components/Variables/variable-model.js +117 -31
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/context/ValidationProvider.d.ts +4 -2
- package/dist/context/ValidationProvider.d.ts.map +1 -1
- package/dist/context/ValidationProvider.js +10 -4
- package/dist/context/ValidationProvider.js.map +1 -1
- package/dist/model/alerts-queries.d.ts +33 -0
- package/dist/model/alerts-queries.d.ts.map +1 -0
- package/dist/model/alerts-queries.js +15 -0
- package/dist/model/alerts-queries.js.map +1 -0
- package/dist/model/annotations.d.ts +28 -0
- package/dist/model/annotations.d.ts.map +1 -0
- package/dist/model/annotations.js +17 -0
- package/dist/model/annotations.js.map +1 -0
- package/dist/model/calculations.d.ts +45 -0
- package/dist/model/calculations.d.ts.map +1 -0
- package/dist/model/calculations.js +165 -0
- package/dist/model/calculations.js.map +1 -0
- package/dist/model/index.d.ts +4 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +4 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/legend.d.ts +3 -2
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +2 -1
- package/dist/model/legend.js.map +1 -1
- package/dist/model/log-queries.d.ts +2 -1
- package/dist/model/log-queries.d.ts.map +1 -1
- package/dist/model/log-queries.js.map +1 -1
- package/dist/model/plugin-loading.d.ts.map +1 -1
- package/dist/model/plugin-loading.js +24 -8
- package/dist/model/plugin-loading.js.map +1 -1
- package/dist/model/plugins.d.ts +23 -0
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js +4 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/model/silences-queries.d.ts +33 -0
- package/dist/model/silences-queries.d.ts.map +1 -0
- package/dist/model/silences-queries.js +15 -0
- package/dist/model/silences-queries.js.map +1 -0
- package/dist/model/time-series-queries.d.ts +11 -1
- package/dist/model/time-series-queries.d.ts.map +1 -1
- package/dist/model/time-series-queries.js +4 -1
- package/dist/model/time-series-queries.js.map +1 -1
- package/dist/model/trace-queries.d.ts +2 -3
- package/dist/model/trace-queries.d.ts.map +1 -1
- package/dist/model/trace-queries.js.map +1 -1
- package/dist/remote/PersesPlugin.types.d.ts +2 -0
- package/dist/remote/PersesPlugin.types.d.ts.map +1 -1
- package/dist/remote/PersesPlugin.types.js.map +1 -1
- package/dist/remote/PluginLoaderComponent.js +1 -1
- package/dist/remote/PluginLoaderComponent.js.map +1 -1
- package/dist/remote/PluginRuntime.d.ts +7 -1
- package/dist/remote/PluginRuntime.d.ts.map +1 -1
- package/dist/remote/PluginRuntime.js +46 -10
- package/dist/remote/PluginRuntime.js.map +1 -1
- package/dist/remote/remotePluginLoader.d.ts.map +1 -1
- package/dist/remote/remotePluginLoader.js +28 -5
- package/dist/remote/remotePluginLoader.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +35 -26
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts +4 -4
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js +0 -82
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/RouterProvider.js +1 -1
- package/dist/runtime/RouterProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -1
- package/dist/runtime/UsageMetricsProvider.js +2 -2
- package/dist/runtime/UsageMetricsProvider.js.map +1 -1
- package/dist/runtime/alerts-queries.d.ts +11 -0
- package/dist/runtime/alerts-queries.d.ts.map +1 -0
- package/dist/runtime/alerts-queries.js +89 -0
- package/dist/runtime/alerts-queries.js.map +1 -0
- package/dist/runtime/annotations.d.ts +6 -0
- package/dist/runtime/annotations.d.ts.map +1 -0
- package/dist/runtime/annotations.js +129 -0
- package/dist/runtime/annotations.js.map +1 -0
- package/dist/runtime/datasources.d.ts +6 -0
- package/dist/runtime/datasources.d.ts.map +1 -1
- package/dist/runtime/datasources.js.map +1 -1
- package/dist/runtime/index.d.ts +3 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +3 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/item-actions.js +1 -1
- package/dist/runtime/item-actions.js.map +1 -1
- package/dist/runtime/log-queries.js +4 -1
- package/dist/runtime/log-queries.js.map +1 -1
- package/dist/runtime/plugin-registry.d.ts +2 -2
- package/dist/runtime/plugin-registry.d.ts.map +1 -1
- package/dist/runtime/plugin-registry.js +12 -3
- package/dist/runtime/plugin-registry.js.map +1 -1
- package/dist/runtime/profile-queries.js +4 -1
- package/dist/runtime/profile-queries.js.map +1 -1
- package/dist/runtime/silences-queries.d.ts +11 -0
- package/dist/runtime/silences-queries.d.ts.map +1 -0
- package/dist/runtime/silences-queries.js +89 -0
- package/dist/runtime/silences-queries.js.map +1 -0
- package/dist/runtime/time-series-queries.js +4 -1
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/trace-queries.js +4 -1
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/test/mock-data.d.ts +3 -1
- package/dist/test/mock-data.d.ts.map +1 -1
- package/dist/test/mock-data.js +45 -0
- package/dist/test/mock-data.js.map +1 -1
- package/dist/test/render.js +1 -1
- package/dist/test/render.js.map +1 -1
- package/dist/test/test-plugins/bert/index.d.ts +12 -6
- package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
- package/dist/test/test-plugins/bert/index.js +6 -2
- package/dist/test/test-plugins/bert/index.js.map +1 -1
- package/dist/test/test-plugins/ernie/index.d.ts +8 -6
- package/dist/test/test-plugins/ernie/index.d.ts.map +1 -1
- package/dist/test/test-plugins/ernie/index.js +6 -2
- package/dist/test/test-plugins/ernie/index.js.map +1 -1
- package/dist/test/test-plugins/index.js +2 -2
- package/dist/test/test-plugins/index.js.map +1 -1
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +2 -2
- package/dist/test/utils.js.map +1 -1
- package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
- package/dist/test-utils/mock-plugin-registry.js +8 -2
- package/dist/test-utils/mock-plugin-registry.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +7 -6
- package/dist/cjs/runtime/QueryCountProvider.js +0 -83
- package/dist/runtime/QueryCountProvider.d.ts +0 -9
- package/dist/runtime/QueryCountProvider.d.ts.map +0 -1
- package/dist/runtime/QueryCountProvider.js.map +0 -1
- package/dist/utils/action.d.ts +0 -4
- package/dist/utils/action.d.ts.map +0 -1
- package/dist/utils/action.js.map +0 -1
|
@@ -83,7 +83,14 @@ const getPluginRuntime = ()=>{
|
|
|
83
83
|
requiredVersion: '^5.5.0'
|
|
84
84
|
}
|
|
85
85
|
},
|
|
86
|
-
|
|
86
|
+
'@perses-dev/spec': {
|
|
87
|
+
version: '0.2.0-beta.2',
|
|
88
|
+
lib: ()=>require('@perses-dev/spec'),
|
|
89
|
+
shareConfig: {
|
|
90
|
+
singleton: true,
|
|
91
|
+
requiredVersion: '^0.2.0-beta.2'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
87
94
|
'@perses-dev/core': {
|
|
88
95
|
version: '0.53.1',
|
|
89
96
|
lib: ()=>require('@perses-dev/core'),
|
|
@@ -92,6 +99,14 @@ const getPluginRuntime = ()=>{
|
|
|
92
99
|
requiredVersion: '^0.53.1'
|
|
93
100
|
}
|
|
94
101
|
},
|
|
102
|
+
'@perses-dev/client': {
|
|
103
|
+
version: '0.54.0-beta.1',
|
|
104
|
+
lib: ()=>require('@perses-dev/client'),
|
|
105
|
+
shareConfig: {
|
|
106
|
+
singleton: true,
|
|
107
|
+
requiredVersion: '^0.54.0-beta.1'
|
|
108
|
+
}
|
|
109
|
+
},
|
|
95
110
|
'@perses-dev/components': {
|
|
96
111
|
version: '0.53.1',
|
|
97
112
|
lib: ()=>require('@perses-dev/components'),
|
|
@@ -204,29 +219,50 @@ const getPluginRuntime = ()=>{
|
|
|
204
219
|
}
|
|
205
220
|
return instance;
|
|
206
221
|
};
|
|
207
|
-
|
|
222
|
+
function getModuleFederationRemoteName(name, registry, version) {
|
|
223
|
+
return `${name}:${registry ?? ''}:${version ?? ''}`;
|
|
224
|
+
}
|
|
225
|
+
const registerRemote = (name, registry, version, baseURL)=>{
|
|
208
226
|
const pluginRuntime = getPluginRuntime();
|
|
209
|
-
const
|
|
227
|
+
const registryName = getModuleFederationRemoteName(name, registry, version);
|
|
228
|
+
const existingRemote = pluginRuntime.options.remotes.find((remote)=>remote.name === registryName);
|
|
210
229
|
if (!existingRemote) {
|
|
211
|
-
const
|
|
230
|
+
const nameVersionRegistry = [
|
|
231
|
+
name,
|
|
232
|
+
version,
|
|
233
|
+
registry
|
|
234
|
+
].filter(Boolean).join('~');
|
|
235
|
+
const prefix = baseURL || '/plugins';
|
|
236
|
+
const remoteEntryURL = `${prefix}/${nameVersionRegistry}/mf-manifest.json`;
|
|
212
237
|
pluginRuntime.registerRemotes([
|
|
213
238
|
{
|
|
214
|
-
name,
|
|
239
|
+
name: registryName,
|
|
215
240
|
entry: remoteEntryURL,
|
|
216
|
-
alias:
|
|
241
|
+
alias: registryName
|
|
217
242
|
}
|
|
218
243
|
]);
|
|
219
244
|
}
|
|
220
245
|
};
|
|
221
|
-
export const loadPlugin = async (
|
|
222
|
-
|
|
246
|
+
export const loadPlugin = async (target)=>{
|
|
247
|
+
const { moduleName, pluginName, registry, version, baseURL } = target;
|
|
248
|
+
registerRemote(moduleName, registry, version, baseURL);
|
|
223
249
|
const pluginRuntime = getPluginRuntime();
|
|
224
|
-
|
|
250
|
+
const registryName = getModuleFederationRemoteName(moduleName, registry, version);
|
|
251
|
+
return pluginRuntime.loadRemote(`${registryName}/${pluginName}`);
|
|
225
252
|
};
|
|
226
253
|
export function usePluginRuntime({ plugin }) {
|
|
227
254
|
return {
|
|
228
255
|
pluginRuntime: getPluginRuntime(),
|
|
229
|
-
loadPlugin: ()=>
|
|
256
|
+
loadPlugin: ()=>{
|
|
257
|
+
const { moduleName, name: pluginName, registry, version, baseURL } = plugin;
|
|
258
|
+
return loadPlugin({
|
|
259
|
+
moduleName,
|
|
260
|
+
pluginName,
|
|
261
|
+
registry,
|
|
262
|
+
version,
|
|
263
|
+
baseURL
|
|
264
|
+
});
|
|
265
|
+
}
|
|
230
266
|
};
|
|
231
267
|
}
|
|
232
268
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/remote/PluginRuntime.tsx"],"sourcesContent":["// Copyright 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\n/* eslint-disable @typescript-eslint/no-require-imports */\n// Copyright 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 { createInstance, ModuleFederation } from '@module-federation/enhanced/runtime';\n\nimport * as ReactQuery from '@tanstack/react-query';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport * as ReactHookForm from 'react-hook-form';\nimport * as ReactRouterDOM from 'react-router-dom';\nimport { PersesPlugin, RemotePluginModule } from './PersesPlugin.types';\n\nlet instance: ModuleFederation | null = null;\n\nconst getPluginRuntime = (): ModuleFederation => {\n if (instance === null) {\n const pluginRuntime = createInstance({\n name: '@perses/perses-ui-host',\n remotes: [], // all remotes are loaded dynamically\n shared: {\n react: {\n version: React.version,\n lib: () => React,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n version: '18.3.1',\n lib: () => ReactDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: `^18.3.1`,\n },\n },\n 'react-router-dom': {\n version: '6.26.0',\n lib: () => ReactRouterDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: '^6.26.0',\n },\n },\n '@tanstack/react-query': {\n version: '4.39.1',\n lib: () => ReactQuery,\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.39.1',\n },\n },\n 'react-hook-form': {\n version: '7.52.2',\n lib: () => ReactHookForm,\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.52.2',\n },\n },\n echarts: {\n version: '5.5.0',\n lib: () => require('echarts'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^5.5.0',\n },\n },\n // TODO should we add @perses-dev/spec here ?\n '@perses-dev/core': {\n version: '0.53.1',\n lib: () => require('@perses-dev/core'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/components': {\n version: '0.53.1',\n lib: () => require('@perses-dev/components'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/plugin-system': {\n version: '0.53.1',\n lib: () => require('@perses-dev/plugin-system'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/explore': {\n version: '0.53.1',\n lib: () => require('@perses-dev/explore'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/dashboards': {\n version: '0.53.1',\n lib: () => require('@perses-dev/dashboards'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n // Below are the shared modules that are used by the plugins, this can be part of the SDK\n 'date-fns': {\n version: '4.1.0',\n lib: () => require('date-fns'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.1.0',\n },\n },\n 'date-fns-tz': {\n version: '3.2.0',\n lib: () => require('date-fns-tz'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.2.0',\n },\n },\n lodash: {\n version: '4.17.21',\n lib: () => require('lodash'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.17.21',\n },\n },\n '@emotion/react': {\n version: '11.11.3',\n lib: () => require('@emotion/react'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.3',\n },\n },\n '@emotion/styled': {\n version: '11.11.0',\n lib: () => require('@emotion/styled'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.0',\n },\n },\n '@hookform/resolvers/zod': {\n version: '3.3.4',\n lib: () => require('@hookform/resolvers/zod'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.3.4',\n },\n },\n 'use-resize-observer': {\n version: '9.1.0',\n lib: () => require('use-resize-observer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^9.1.0',\n },\n },\n 'mdi-material-ui': {\n version: '7.4.0',\n lib: () => require('mdi-material-ui'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.4.0',\n },\n },\n immer: {\n version: '10.1.1',\n lib: () => require('immer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^10.1.1',\n },\n },\n },\n });\n\n instance = pluginRuntime;\n\n return instance;\n }\n return instance;\n};\n\nconst registerRemote = (name: string, baseURL?: string): void => {\n const pluginRuntime = getPluginRuntime();\n const existingRemote = pluginRuntime.options.remotes.find((remote) => remote.name === name);\n if (!existingRemote) {\n const remoteEntryURL = baseURL ? `${baseURL}/${name}/mf-manifest.json` : `/plugins/${name}/mf-manifest.json`;\n pluginRuntime.registerRemotes([\n {\n name,\n entry: remoteEntryURL,\n alias: name,\n },\n ]);\n }\n};\n\nexport const loadPlugin = async (\n moduleName: string,\n pluginName: string,\n baseURL?: string\n): Promise<RemotePluginModule | null> => {\n registerRemote(moduleName, baseURL);\n\n const pluginRuntime = getPluginRuntime();\n\n return pluginRuntime.loadRemote<RemotePluginModule>(`${moduleName}/${pluginName}`);\n};\n\nexport function usePluginRuntime({ plugin }: { plugin: PersesPlugin }): {\n pluginRuntime: ModuleFederation;\n loadPlugin: () => Promise<RemotePluginModule | null>;\n} {\n return {\n pluginRuntime: getPluginRuntime(),\n loadPlugin: () => loadPlugin(plugin.moduleName, plugin.name, plugin.baseURL),\n };\n}\n"],"names":["createInstance","ReactQuery","React","ReactDOM","ReactHookForm","ReactRouterDOM","instance","getPluginRuntime","pluginRuntime","name","remotes","shared","react","version","lib","shareConfig","singleton","requiredVersion","echarts","require","lodash","immer","registerRemote","baseURL","existingRemote","options","find","remote","remoteEntryURL","registerRemotes","entry","alias","loadPlugin","moduleName","pluginName","loadRemote","usePluginRuntime","plugin"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,wDAAwD,GACxD,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,cAAc,QAA0B,sCAAsC;AAEvF,YAAYC,gBAAgB,wBAAwB;AACpD,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,cAAc,YAAY;AACjC,YAAYC,mBAAmB,kBAAkB;AACjD,YAAYC,oBAAoB,mBAAmB;AAGnD,IAAIC,WAAoC;AAExC,MAAMC,mBAAmB;IACvB,IAAID,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;IACT;IACA,OAAOA;AACT;AAEA,MAAMgB,iBAAiB,CAACb,MAAcc;IACpC,MAAMf,gBAAgBD;IACtB,MAAMiB,iBAAiBhB,cAAciB,OAAO,CAACf,OAAO,CAACgB,IAAI,CAAC,CAACC,SAAWA,OAAOlB,IAAI,KAAKA;IACtF,IAAI,CAACe,gBAAgB;QACnB,MAAMI,iBAAiBL,UAAU,GAAGA,QAAQ,CAAC,EAAEd,KAAK,iBAAiB,CAAC,GAAG,CAAC,SAAS,EAAEA,KAAK,iBAAiB,CAAC;QAC5GD,cAAcqB,eAAe,CAAC;YAC5B;gBACEpB;gBACAqB,OAAOF;gBACPG,OAAOtB;YACT;SACD;IACH;AACF;AAEA,OAAO,MAAMuB,aAAa,OACxBC,YACAC,YACAX;IAEAD,eAAeW,YAAYV;IAE3B,MAAMf,gBAAgBD;IAEtB,OAAOC,cAAc2B,UAAU,CAAqB,GAAGF,WAAW,CAAC,EAAEC,YAAY;AACnF,EAAE;AAEF,OAAO,SAASE,iBAAiB,EAAEC,MAAM,EAA4B;IAInE,OAAO;QACL7B,eAAeD;QACfyB,YAAY,IAAMA,WAAWK,OAAOJ,UAAU,EAAEI,OAAO5B,IAAI,EAAE4B,OAAOd,OAAO;IAC7E;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/remote/PluginRuntime.tsx"],"sourcesContent":["// Copyright 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\n/* eslint-disable @typescript-eslint/no-require-imports */\n// Copyright 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 { createInstance, ModuleFederation } from '@module-federation/enhanced/runtime';\n\nimport * as ReactQuery from '@tanstack/react-query';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport * as ReactHookForm from 'react-hook-form';\nimport * as ReactRouterDOM from 'react-router-dom';\nimport { PersesPlugin, RemotePluginModule } from './PersesPlugin.types';\n\nlet instance: ModuleFederation | null = null;\n\nconst getPluginRuntime = (): ModuleFederation => {\n if (instance === null) {\n const pluginRuntime = createInstance({\n name: '@perses/perses-ui-host',\n remotes: [], // all remotes are loaded dynamically\n shared: {\n react: {\n version: React.version,\n lib: () => React,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n version: '18.3.1',\n lib: () => ReactDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: `^18.3.1`,\n },\n },\n 'react-router-dom': {\n version: '6.26.0',\n lib: () => ReactRouterDOM,\n shareConfig: {\n singleton: true,\n requiredVersion: '^6.26.0',\n },\n },\n '@tanstack/react-query': {\n version: '4.39.1',\n lib: () => ReactQuery,\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.39.1',\n },\n },\n 'react-hook-form': {\n version: '7.52.2',\n lib: () => ReactHookForm,\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.52.2',\n },\n },\n echarts: {\n version: '5.5.0',\n lib: () => require('echarts'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^5.5.0',\n },\n },\n '@perses-dev/spec': {\n version: '0.2.0-beta.2',\n lib: () => require('@perses-dev/spec'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.2.0-beta.2',\n },\n },\n '@perses-dev/core': {\n version: '0.53.1',\n lib: () => require('@perses-dev/core'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/client': {\n version: '0.54.0-beta.1',\n lib: () => require('@perses-dev/client'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.54.0-beta.1',\n },\n },\n '@perses-dev/components': {\n version: '0.53.1',\n lib: () => require('@perses-dev/components'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/plugin-system': {\n version: '0.53.1',\n lib: () => require('@perses-dev/plugin-system'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/explore': {\n version: '0.53.1',\n lib: () => require('@perses-dev/explore'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n '@perses-dev/dashboards': {\n version: '0.53.1',\n lib: () => require('@perses-dev/dashboards'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^0.53.1',\n },\n },\n // Below are the shared modules that are used by the plugins, this can be part of the SDK\n 'date-fns': {\n version: '4.1.0',\n lib: () => require('date-fns'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.1.0',\n },\n },\n 'date-fns-tz': {\n version: '3.2.0',\n lib: () => require('date-fns-tz'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.2.0',\n },\n },\n lodash: {\n version: '4.17.21',\n lib: () => require('lodash'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^4.17.21',\n },\n },\n '@emotion/react': {\n version: '11.11.3',\n lib: () => require('@emotion/react'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.3',\n },\n },\n '@emotion/styled': {\n version: '11.11.0',\n lib: () => require('@emotion/styled'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^11.11.0',\n },\n },\n '@hookform/resolvers/zod': {\n version: '3.3.4',\n lib: () => require('@hookform/resolvers/zod'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^3.3.4',\n },\n },\n 'use-resize-observer': {\n version: '9.1.0',\n lib: () => require('use-resize-observer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^9.1.0',\n },\n },\n 'mdi-material-ui': {\n version: '7.4.0',\n lib: () => require('mdi-material-ui'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^7.4.0',\n },\n },\n immer: {\n version: '10.1.1',\n lib: () => require('immer'),\n shareConfig: {\n singleton: true,\n requiredVersion: '^10.1.1',\n },\n },\n },\n });\n\n instance = pluginRuntime;\n\n return instance;\n }\n return instance;\n};\n\nfunction getModuleFederationRemoteName(name: string, registry?: string, version?: string): string {\n return `${name}:${registry ?? ''}:${version ?? ''}`;\n}\n\nconst registerRemote = (name: string, registry?: string, version?: string, baseURL?: string): void => {\n const pluginRuntime = getPluginRuntime();\n const registryName = getModuleFederationRemoteName(name, registry, version);\n\n const existingRemote = pluginRuntime.options.remotes.find((remote) => remote.name === registryName);\n if (!existingRemote) {\n const nameVersionRegistry = [name, version, registry].filter(Boolean).join('~');\n const prefix = baseURL || '/plugins';\n const remoteEntryURL = `${prefix}/${nameVersionRegistry}/mf-manifest.json`;\n\n pluginRuntime.registerRemotes([\n {\n name: registryName,\n entry: remoteEntryURL,\n alias: registryName,\n },\n ]);\n }\n};\n\nexport const loadPlugin = async (target: {\n moduleName: string;\n pluginName: string;\n registry?: string;\n version?: string;\n baseURL?: string;\n}): Promise<RemotePluginModule | null> => {\n const { moduleName, pluginName, registry, version, baseURL } = target;\n registerRemote(moduleName, registry, version, baseURL);\n\n const pluginRuntime = getPluginRuntime();\n const registryName = getModuleFederationRemoteName(moduleName, registry, version);\n return pluginRuntime.loadRemote<RemotePluginModule>(`${registryName}/${pluginName}`);\n};\n\nexport function usePluginRuntime({ plugin }: { plugin: PersesPlugin }): {\n pluginRuntime: ModuleFederation;\n loadPlugin: () => Promise<RemotePluginModule | null>;\n} {\n return {\n pluginRuntime: getPluginRuntime(),\n loadPlugin: (): Promise<RemotePluginModule | null> => {\n const { moduleName, name: pluginName, registry, version, baseURL } = plugin;\n return loadPlugin({ moduleName, pluginName, registry, version, baseURL });\n },\n };\n}\n"],"names":["createInstance","ReactQuery","React","ReactDOM","ReactHookForm","ReactRouterDOM","instance","getPluginRuntime","pluginRuntime","name","remotes","shared","react","version","lib","shareConfig","singleton","requiredVersion","echarts","require","lodash","immer","getModuleFederationRemoteName","registry","registerRemote","baseURL","registryName","existingRemote","options","find","remote","nameVersionRegistry","filter","Boolean","join","prefix","remoteEntryURL","registerRemotes","entry","alias","loadPlugin","target","moduleName","pluginName","loadRemote","usePluginRuntime","plugin"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,wDAAwD,GACxD,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,cAAc,QAA0B,sCAAsC;AAEvF,YAAYC,gBAAgB,wBAAwB;AACpD,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,cAAc,YAAY;AACjC,YAAYC,mBAAmB,kBAAkB;AACjD,YAAYC,oBAAoB,mBAAmB;AAGnD,IAAIC,WAAoC;AAExC,MAAMC,mBAAmB;IACvB,IAAID,aAAa,MAAM;QACrB,MAAME,gBAAgBR,eAAe;YACnCS,MAAM;YACNC,SAAS,EAAE;YACXC,QAAQ;gBACNC,OAAO;oBACLC,SAASX,MAAMW,OAAO;oBACtBC,KAAK,IAAMZ;oBACXa,aAAa;wBACXC,WAAW;wBACXC,iBAAiB,CAAC,CAAC,EAAEf,MAAMW,OAAO,EAAE;oBACtC;gBACF;gBACA,aAAa;oBACXA,SAAS;oBACTC,KAAK,IAAMX;oBACXY,aAAa;wBACXC,WA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
|
|
|
1
|
-
{"version":3,"file":"remotePluginLoader.d.ts","sourceRoot":"","sources":["../../src/remote/remotePluginLoader.ts"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"remotePluginLoader.d.ts","sourceRoot":"","sources":["../../src/remote/remotePluginLoader.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,YAAY,EAKb,MAAM,2BAA2B,CAAC;AA8BnC,KAAK,yBAAyB,GAAG;IAC/B;;;QAGI;IACJ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;QAGI;IACJ,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAwBF;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,yBAAyB,GAAG,YAAY,CAyDpF"}
|
|
@@ -10,6 +10,7 @@
|
|
|
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 { getPluginModuleCompoundKey } from '@perses-dev/plugin-system';
|
|
13
14
|
import { loadPlugin } from './PluginRuntime';
|
|
14
15
|
const isPluginMetadata = (plugin)=>{
|
|
15
16
|
return typeof plugin === 'object' && plugin !== null && 'kind' in plugin && 'spec' in plugin && typeof plugin.spec === 'object' && plugin.spec !== null && 'name' in plugin.spec;
|
|
@@ -52,17 +53,39 @@ const paramToOptions = (options)=>{
|
|
|
52
53
|
return pluginModules;
|
|
53
54
|
},
|
|
54
55
|
importPluginModule: async (resource)=>{
|
|
55
|
-
const pluginModuleName = resource.metadata
|
|
56
|
+
const { name: pluginModuleName, version, registry } = resource.metadata;
|
|
56
57
|
const pluginModule = {};
|
|
57
|
-
|
|
58
|
-
const remotePluginModule = await loadPlugin(
|
|
58
|
+
const loadPromises = resource.spec.plugins.map(async (plugin)=>{
|
|
59
|
+
const remotePluginModule = await loadPlugin({
|
|
60
|
+
moduleName: pluginModuleName,
|
|
61
|
+
pluginName: plugin.spec.name,
|
|
62
|
+
registry,
|
|
63
|
+
version,
|
|
64
|
+
baseURL: pluginsAssetsPath
|
|
65
|
+
});
|
|
59
66
|
const remotePlugin = remotePluginModule?.[plugin.spec.name];
|
|
60
67
|
if (remotePlugin) {
|
|
61
|
-
|
|
68
|
+
return {
|
|
69
|
+
kind: plugin.kind,
|
|
70
|
+
name: plugin.spec.name,
|
|
71
|
+
remotePlugin
|
|
72
|
+
};
|
|
62
73
|
} else {
|
|
63
74
|
console.error(`RemotePluginLoader: Error loading plugin ${plugin.spec.name}`);
|
|
75
|
+
return null;
|
|
64
76
|
}
|
|
65
|
-
}
|
|
77
|
+
});
|
|
78
|
+
const loadedPlugins = await Promise.all(loadPromises);
|
|
79
|
+
loadedPlugins.forEach((item)=>{
|
|
80
|
+
if (item?.remotePlugin) {
|
|
81
|
+
pluginModule[getPluginModuleCompoundKey({
|
|
82
|
+
kind: item.kind,
|
|
83
|
+
name: item.name,
|
|
84
|
+
registry,
|
|
85
|
+
version
|
|
86
|
+
})] = item.remotePlugin;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
66
89
|
return pluginModule;
|
|
67
90
|
}
|
|
68
91
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/remote/remotePluginLoader.ts"],"sourcesContent":["// Copyright 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 {
|
|
1
|
+
{"version":3,"sources":["../../src/remote/remotePluginLoader.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n PluginLoader,\n PluginMetadata,\n PluginModuleResource,\n PluginType,\n getPluginModuleCompoundKey,\n} from '@perses-dev/plugin-system';\nimport { RemotePluginModule } from './PersesPlugin.types';\nimport { loadPlugin } from './PluginRuntime';\n\nconst isPluginMetadata = (plugin: unknown): plugin is PluginMetadata => {\n return (\n typeof plugin === 'object' &&\n plugin !== null &&\n 'kind' in plugin &&\n 'spec' in plugin &&\n typeof plugin.spec === 'object' &&\n plugin.spec !== null &&\n 'name' in plugin.spec\n );\n};\n\nconst isPluginModuleResource = (pluginModule: unknown): pluginModule is PluginModuleResource => {\n return (\n typeof pluginModule === 'object' &&\n pluginModule !== null &&\n 'metadata' in pluginModule &&\n 'spec' in pluginModule &&\n typeof pluginModule.spec === 'object' &&\n pluginModule.spec !== null &&\n 'plugins' in pluginModule.spec &&\n Array.isArray(pluginModule.spec.plugins) &&\n pluginModule.spec.plugins.every(isPluginMetadata)\n );\n};\n\ntype RemotePluginLoaderOptions = {\n /**\n * The API path for fetching available Perses plugins. Used to construct the full URL to the `/api/v1/plugins` endpoint.\n * @default ''\n **/\n apiPrefix?: string;\n /**\n * The base URL for loading plugin assets (e.g., JavaScript files). Used to construct the full URL to the `/plugins` directory\n * @default ''\n **/\n baseURL?: string;\n};\n\ntype ParsedPluginOptions = {\n pluginsApiPath: string;\n pluginsAssetsPath: string;\n};\n\nconst DEFAULT_PLUGINS_API_PATH = '/api/v1/plugins';\nconst DEFAULT_PLUGINS_ASSETS_PATH = '/plugins';\n\nconst paramToOptions = (options?: RemotePluginLoaderOptions): ParsedPluginOptions => {\n if (options === undefined) {\n return {\n pluginsApiPath: DEFAULT_PLUGINS_API_PATH,\n pluginsAssetsPath: DEFAULT_PLUGINS_ASSETS_PATH,\n };\n }\n\n return {\n pluginsApiPath: `${options?.apiPrefix ?? ''}${DEFAULT_PLUGINS_API_PATH}`,\n pluginsAssetsPath: `${options?.baseURL ?? ''}${DEFAULT_PLUGINS_ASSETS_PATH}`,\n };\n};\n\n/**\n * Get a PluginLoader that fetches the list of installed plugins from a remote server and loads them as needed.\n * @param options - Optional configuration options for the remote plugin loader.\n */\nexport function remotePluginLoader(options?: RemotePluginLoaderOptions): PluginLoader {\n const { pluginsApiPath, pluginsAssetsPath } = paramToOptions(options);\n\n return {\n getInstalledPlugins: async (): Promise<PluginModuleResource[]> => {\n const pluginsResponse = await fetch(pluginsApiPath);\n\n const plugins = await pluginsResponse.json();\n let pluginModules: PluginModuleResource[] = [];\n\n if (Array.isArray(plugins)) {\n pluginModules = plugins.filter(isPluginModuleResource);\n } else {\n console.error('RemotePluginLoader: Error loading plugins, response is not an array');\n }\n\n if (!pluginModules.length) {\n console.error('RemotePluginLoader: No valid plugins found');\n }\n\n return pluginModules;\n },\n importPluginModule: async (resource): Promise<RemotePluginModule> => {\n const { name: pluginModuleName, version, registry } = resource.metadata;\n\n const pluginModule: RemotePluginModule = {};\n\n const loadPromises = resource.spec.plugins.map(async (plugin) => {\n const remotePluginModule = await loadPlugin({\n moduleName: pluginModuleName,\n pluginName: plugin.spec.name,\n registry,\n version,\n baseURL: pluginsAssetsPath,\n });\n\n const remotePlugin = remotePluginModule?.[plugin.spec.name];\n if (remotePlugin) {\n return { kind: plugin.kind as PluginType, name: plugin.spec.name, remotePlugin };\n } else {\n console.error(`RemotePluginLoader: Error loading plugin ${plugin.spec.name}`);\n return null;\n }\n });\n\n const loadedPlugins = await Promise.all(loadPromises);\n\n loadedPlugins.forEach((item) => {\n if (item?.remotePlugin) {\n pluginModule[getPluginModuleCompoundKey({ kind: item.kind, name: item.name, registry, version })] =\n item.remotePlugin;\n }\n });\n\n return pluginModule;\n },\n };\n}\n"],"names":["getPluginModuleCompoundKey","loadPlugin","isPluginMetadata","plugin","spec","isPluginModuleResource","pluginModule","Array","isArray","plugins","every","DEFAULT_PLUGINS_API_PATH","DEFAULT_PLUGINS_ASSETS_PATH","paramToOptions","options","undefined","pluginsApiPath","pluginsAssetsPath","apiPrefix","baseURL","remotePluginLoader","getInstalledPlugins","pluginsResponse","fetch","json","pluginModules","filter","console","error","length","importPluginModule","resource","name","pluginModuleName","version","registry","metadata","loadPromises","map","remotePluginModule","moduleName","pluginName","remotePlugin","kind","loadedPlugins","Promise","all","forEach","item"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAKEA,0BAA0B,QACrB,4BAA4B;AAEnC,SAASC,UAAU,QAAQ,kBAAkB;AAE7C,MAAMC,mBAAmB,CAACC;IACxB,OACE,OAAOA,WAAW,YAClBA,WAAW,QACX,UAAUA,UACV,UAAUA,UACV,OAAOA,OAAOC,IAAI,KAAK,YACvBD,OAAOC,IAAI,KAAK,QAChB,UAAUD,OAAOC,IAAI;AAEzB;AAEA,MAAMC,yBAAyB,CAACC;IAC9B,OACE,OAAOA,iBAAiB,YACxBA,iBAAiB,QACjB,cAAcA,gBACd,UAAUA,gBACV,OAAOA,aAAaF,IAAI,KAAK,YAC7BE,aAAaF,IAAI,KAAK,QACtB,aAAaE,aAAaF,IAAI,IAC9BG,MAAMC,OAAO,CAACF,aAAaF,IAAI,CAACK,OAAO,KACvCH,aAAaF,IAAI,CAACK,OAAO,CAACC,KAAK,CAACR;AAEpC;AAoBA,MAAMS,2BAA2B;AACjC,MAAMC,8BAA8B;AAEpC,MAAMC,iBAAiB,CAACC;IACtB,IAAIA,YAAYC,WAAW;QACzB,OAAO;YACLC,gBAAgBL;YAChBM,mBAAmBL;QACrB;IACF;IAEA,OAAO;QACL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5E,OAAO;gBACT;YACF;YAEA,MAAMY,gBAAgB,MAAMC,QAAQC,GAAG,CAACT;YAExCO,cAAcG,OAAO,CAAC,CAACC;gBACrB,IAAIA,MAAMN,cAAc;oBACtBpC,YAAY,CAACN,2BAA2B;wBAAE2C,MAAMK,KAAKL,IAAI;wBAAEX,MAAMgB,KAAKhB,IAAI;wBAAEG;wBAAUD;oBAAQ,GAAG,GAC/Fc,KAAKN,YAAY;gBACrB;YACF;YAEA,OAAOpC;QACT;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataQueriesProvider.d.ts","sourceRoot":"","sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAiB,YAAY,EAAoC,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,SAAS,EAA6B,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"DataQueriesProvider.d.ts","sourceRoot":"","sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAiB,YAAY,EAAoC,MAAM,OAAO,CAAC;AACtF,OAAO,EAAE,SAAS,EAA6B,MAAM,kBAAkB,CAAC;AASxE,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EAEnB,sBAAsB,EAEvB,MAAM,SAAS,CAAC;AAEjB,eAAO,MAAM,kBAAkB,6DAA+D,CAAC;AAE/F,wBAAgB,qBAAqB,IAAI,sBAAsB,CAM9D;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,SAAS,EAAE,SAAS,EAAE,CAAC,GAAG,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAuBzG;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,YAAY,CA2FjF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
// Copyright The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,14 +11,15 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { createContext, useCallback, useContext, useMemo } from 'react';
|
|
15
15
|
import { useTimeSeriesQueries } from '../time-series-queries';
|
|
16
16
|
import { useTraceQueries } from '../trace-queries';
|
|
17
17
|
import { useProfileQueries } from '../profile-queries';
|
|
18
|
+
import { useAlertsQueries } from '../alerts-queries';
|
|
19
|
+
import { useSilencesQueries } from '../silences-queries';
|
|
18
20
|
import { useUsageMetrics } from '../UsageMetricsProvider';
|
|
19
21
|
import { useLogQueries } from '../log-queries';
|
|
20
|
-
import { transformQueryResults
|
|
22
|
+
import { transformQueryResults } from './model';
|
|
21
23
|
export const DataQueriesContext = /*#__PURE__*/ createContext(undefined);
|
|
22
24
|
export function useDataQueriesContext() {
|
|
23
25
|
const ctx = useContext(DataQueriesContext);
|
|
@@ -28,60 +30,61 @@ export function useDataQueriesContext() {
|
|
|
28
30
|
}
|
|
29
31
|
export function useDataQueries(queryType) {
|
|
30
32
|
const ctx = useDataQueriesContext();
|
|
33
|
+
// Filter query definitions based on the specified query type
|
|
34
|
+
const filteredQueryDefinitions = ctx.queryDefinitions.filter((definition)=>definition.kind === queryType);
|
|
31
35
|
// Filter the query results based on the specified query type
|
|
32
36
|
const filteredQueryResults = ctx.queryResults.filter((queryResult)=>queryResult?.definition?.kind === queryType);
|
|
33
37
|
// Filter the errors based on the specified query type
|
|
34
38
|
const filteredErrors = ctx.errors.filter((errors, index)=>ctx.queryResults[index]?.definition?.kind === queryType);
|
|
35
39
|
// Create a new context object with the filtered results and errors
|
|
36
|
-
|
|
40
|
+
return {
|
|
41
|
+
queryDefinitions: filteredQueryDefinitions,
|
|
37
42
|
queryResults: filteredQueryResults,
|
|
38
43
|
isFetching: filteredQueryResults.some((result)=>result.isFetching),
|
|
39
44
|
isLoading: filteredQueryResults.some((result)=>result.isLoading),
|
|
40
45
|
refetchAll: ctx.refetchAll,
|
|
41
46
|
errors: filteredErrors
|
|
42
47
|
};
|
|
43
|
-
return filteredCtx;
|
|
44
48
|
}
|
|
45
49
|
export function DataQueriesProvider(props) {
|
|
46
50
|
const { definitions, options, children, queryOptions } = props;
|
|
47
|
-
// Returns a query kind, for example "TimeSeriesQuery" = getQueryType("PrometheusTimeSeriesQuery")
|
|
48
|
-
const getQueryType = useQueryType();
|
|
49
|
-
const queryDefinitions = definitions.map((definition)=>{
|
|
50
|
-
const type = getQueryType(definition.kind);
|
|
51
|
-
return {
|
|
52
|
-
kind: type,
|
|
53
|
-
spec: {
|
|
54
|
-
plugin: definition
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
51
|
const usageMetrics = useUsageMetrics();
|
|
59
52
|
// Filter definitions for time series query and other future query plugins
|
|
60
|
-
const timeSeriesQueries =
|
|
53
|
+
const timeSeriesQueries = definitions.filter((definition)=>definition.kind === 'TimeSeriesQuery');
|
|
61
54
|
const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options, queryOptions);
|
|
62
|
-
const traceQueries =
|
|
55
|
+
const traceQueries = definitions.filter((definition)=>definition.kind === 'TraceQuery');
|
|
63
56
|
const traceResults = useTraceQueries(traceQueries);
|
|
64
|
-
const profileQueries =
|
|
57
|
+
const profileQueries = definitions.filter((definition)=>definition.kind === 'ProfileQuery');
|
|
65
58
|
const profileResults = useProfileQueries(profileQueries);
|
|
66
|
-
const logQueries =
|
|
59
|
+
const logQueries = definitions.filter((definition)=>definition.kind === 'LogQuery');
|
|
67
60
|
const logResults = useLogQueries(logQueries);
|
|
61
|
+
const alertsQueries = definitions.filter((definition)=>definition.kind === 'AlertsQuery');
|
|
62
|
+
const alertsResults = useAlertsQueries(alertsQueries);
|
|
63
|
+
const silencesQueries = definitions.filter((definition)=>definition.kind === 'SilencesQuery');
|
|
64
|
+
const silencesResults = useSilencesQueries(silencesQueries);
|
|
68
65
|
const refetchAll = useCallback(()=>{
|
|
69
66
|
timeSeriesResults.forEach((result)=>result.refetch());
|
|
70
67
|
traceResults.forEach((result)=>result.refetch());
|
|
71
68
|
profileResults.forEach((result)=>result.refetch());
|
|
72
69
|
logResults.forEach((result)=>result.refetch());
|
|
70
|
+
alertsResults.forEach((result)=>result.refetch());
|
|
71
|
+
silencesResults.forEach((result)=>result.refetch());
|
|
73
72
|
}, [
|
|
74
73
|
timeSeriesResults,
|
|
75
74
|
traceResults,
|
|
76
75
|
profileResults,
|
|
77
|
-
logResults
|
|
76
|
+
logResults,
|
|
77
|
+
alertsResults,
|
|
78
|
+
silencesResults
|
|
78
79
|
]);
|
|
79
80
|
const ctx = useMemo(()=>{
|
|
80
81
|
const mergedQueryResults = [
|
|
81
82
|
...transformQueryResults(timeSeriesResults, timeSeriesQueries),
|
|
82
83
|
...transformQueryResults(traceResults, traceQueries),
|
|
83
84
|
...transformQueryResults(profileResults, profileQueries),
|
|
84
|
-
...transformQueryResults(logResults, logQueries)
|
|
85
|
+
...transformQueryResults(logResults, logQueries),
|
|
86
|
+
...transformQueryResults(alertsResults, alertsQueries),
|
|
87
|
+
...transformQueryResults(silencesResults, silencesQueries)
|
|
85
88
|
];
|
|
86
89
|
if (queryOptions?.enabled) {
|
|
87
90
|
for (const result of mergedQueryResults){
|
|
@@ -95,6 +98,7 @@ export function DataQueriesProvider(props) {
|
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
return {
|
|
101
|
+
queryDefinitions: definitions,
|
|
98
102
|
queryResults: mergedQueryResults,
|
|
99
103
|
isFetching: mergedQueryResults.some((result)=>result.isFetching),
|
|
100
104
|
isLoading: mergedQueryResults.some((result)=>result.isLoading),
|
|
@@ -102,16 +106,21 @@ export function DataQueriesProvider(props) {
|
|
|
102
106
|
errors: mergedQueryResults.map((result)=>result.error)
|
|
103
107
|
};
|
|
104
108
|
}, [
|
|
109
|
+
alertsQueries,
|
|
110
|
+
alertsResults,
|
|
111
|
+
logQueries,
|
|
112
|
+
logResults,
|
|
113
|
+
profileQueries,
|
|
114
|
+
profileResults,
|
|
115
|
+
silencesQueries,
|
|
116
|
+
silencesResults,
|
|
105
117
|
timeSeriesQueries,
|
|
106
118
|
timeSeriesResults,
|
|
107
119
|
traceQueries,
|
|
108
120
|
traceResults,
|
|
109
|
-
|
|
110
|
-
profileResults,
|
|
111
|
-
logQueries,
|
|
112
|
-
logResults,
|
|
113
|
-
refetchAll,
|
|
121
|
+
definitions,
|
|
114
122
|
queryOptions?.enabled,
|
|
123
|
+
refetchAll,
|
|
115
124
|
usageMetrics
|
|
116
125
|
]);
|
|
117
126
|
return /*#__PURE__*/ _jsx(DataQueriesContext.Provider, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.tsx"],"sourcesContent":["// Copyright 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 { createContext, ReactElement, useCallback, useContext, useMemo } from 'react';\nimport { QueryType, TimeSeriesQueryDefinition } from '@perses-dev/spec';\nimport { useTimeSeriesQueries } from '../time-series-queries';\nimport { useTraceQueries, TraceQueryDefinition } from '../trace-queries';\nimport { useProfileQueries, ProfileQueryDefinition } from '../profile-queries';\n\nimport { useUsageMetrics } from '../UsageMetricsProvider';\nimport { LogQueryDefinition, useLogQueries } from '../log-queries';\nimport {\n DataQueriesProviderProps,\n UseDataQueryResults,\n transformQueryResults,\n DataQueriesContextType,\n QueryData,\n useQueryType,\n} from './model';\n\nexport const DataQueriesContext = createContext<DataQueriesContextType | undefined>(undefined);\n\nexport function useDataQueriesContext(): DataQueriesContextType {\n const ctx = useContext(DataQueriesContext);\n if (ctx === undefined) {\n throw new Error('No DataQueriesContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useDataQueries<T extends keyof QueryType>(queryType: T): UseDataQueryResults<QueryType[T]> {\n const ctx = useDataQueriesContext();\n\n // Filter the query results based on the specified query type\n const filteredQueryResults = ctx.queryResults.filter(\n (queryResult) => queryResult?.definition?.kind === queryType\n ) as Array<QueryData<QueryType[T]>>;\n\n // Filter the errors based on the specified query type\n const filteredErrors = ctx.errors.filter((errors, index) => ctx.queryResults[index]?.definition?.kind === queryType);\n\n // Create a new context object with the filtered results and errors\n const filteredCtx = {\n queryResults: filteredQueryResults,\n isFetching: filteredQueryResults.some((result) => result.isFetching),\n isLoading: filteredQueryResults.some((result) => result.isLoading),\n refetchAll: ctx.refetchAll,\n errors: filteredErrors,\n };\n\n return filteredCtx;\n}\n\nexport function DataQueriesProvider(props: DataQueriesProviderProps): ReactElement {\n const { definitions, options, children, queryOptions } = props;\n\n // Returns a query kind, for example \"TimeSeriesQuery\" = getQueryType(\"PrometheusTimeSeriesQuery\")\n const getQueryType = useQueryType();\n\n const queryDefinitions = definitions.map((definition) => {\n const type = getQueryType(definition.kind);\n return {\n kind: type,\n spec: {\n plugin: definition,\n },\n };\n });\n\n const usageMetrics = useUsageMetrics();\n\n // Filter definitions for time series query and other future query plugins\n const timeSeriesQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'TimeSeriesQuery'\n ) as TimeSeriesQueryDefinition[];\n const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options, queryOptions);\n\n const traceQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'TraceQuery'\n ) as TraceQueryDefinition[];\n const traceResults = useTraceQueries(traceQueries);\n\n const profileQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'ProfileQuery'\n ) as ProfileQueryDefinition[];\n const profileResults = useProfileQueries(profileQueries);\n\n const logQueries = queryDefinitions.filter((definition) => definition.kind === 'LogQuery') as LogQueryDefinition[];\n const logResults = useLogQueries(logQueries);\n\n const refetchAll = useCallback(() => {\n timeSeriesResults.forEach((result) => result.refetch());\n traceResults.forEach((result) => result.refetch());\n profileResults.forEach((result) => result.refetch());\n logResults.forEach((result) => result.refetch());\n }, [timeSeriesResults, traceResults, profileResults, logResults]);\n\n const ctx = useMemo(() => {\n const mergedQueryResults = [\n ...transformQueryResults(timeSeriesResults, timeSeriesQueries),\n ...transformQueryResults(traceResults, traceQueries),\n ...transformQueryResults(profileResults, profileQueries),\n ...transformQueryResults(logResults, logQueries),\n ];\n\n if (queryOptions?.enabled) {\n for (const result of mergedQueryResults) {\n if (!result.isLoading && !result.isFetching && !result.error) {\n usageMetrics.markQuery(result.definition, 'success');\n } else if (result.error) {\n usageMetrics.markQuery(result.definition, 'error');\n } else {\n usageMetrics.markQuery(result.definition, 'pending');\n }\n }\n }\n\n return {\n queryResults: mergedQueryResults,\n isFetching: mergedQueryResults.some((result) => result.isFetching),\n isLoading: mergedQueryResults.some((result) => result.isLoading),\n refetchAll,\n errors: mergedQueryResults.map((result) => result.error),\n };\n }, [\n timeSeriesQueries,\n timeSeriesResults,\n traceQueries,\n traceResults,\n profileQueries,\n profileResults,\n logQueries,\n logResults,\n refetchAll,\n queryOptions?.enabled,\n usageMetrics,\n ]);\n\n return <DataQueriesContext.Provider value={ctx}>{children}</DataQueriesContext.Provider>;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useTimeSeriesQueries","useTraceQueries","useProfileQueries","useUsageMetrics","useLogQueries","transformQueryResults","useQueryType","DataQueriesContext","undefined","useDataQueriesContext","ctx","Error","useDataQueries","queryType","filteredQueryResults","queryResults","filter","queryResult","definition","kind","filteredErrors","errors","index","filteredCtx","isFetching","some","result","isLoading","refetchAll","DataQueriesProvider","props","definitions","options","children","queryOptions","getQueryType","queryDefinitions","map","type","spec","plugin","usageMetrics","timeSeriesQueries","timeSeriesResults","traceQueries","traceResults","profileQueries","profileResults","logQueries","logResults","forEach","refetch","mergedQueryResults","enabled","error","markQuery","Provider","value"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,aAAa,EAAgBC,WAAW,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAEtF,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,eAAe,QAA8B,mBAAmB;AACzE,SAASC,iBAAiB,QAAgC,qBAAqB;AAE/E,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAA6BC,aAAa,QAAQ,iBAAiB;AACnE,SAGEC,qBAAqB,EAGrBC,YAAY,QACP,UAAU;AAEjB,OAAO,MAAMC,mCAAqBX,cAAkDY,WAAW;AAE/F,OAAO,SAASC;IACd,MAAMC,MAAMZ,WAAWS;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA,OAAO,SAASE,eAA0CC,SAAY;IACpE,MAAMH,MAAMD;IAEZ,6DAA6D;IAC7D,MAAMK,uBAAuBJ,IAAIK,YAAY,CAACC,MAAM,CAClD,CAACC,cAAgBA,aAAaC,YAAYC,SAASN;IAGrD,sDAAsD;IACtD,MAAMO,iBAAiBV,IAAIW,MAAM,CAACL,MAAM,CAAC,CAACK,QAAQC,QAAUZ,IAAIK,YAAY,CAACO,MAAM,EAAEJ,YAAYC,SAASN;IAE1G,mEAAmE;IACnE,MAAMU,cAAc;QAClBR,cAAcD;QACdU,YAAYV,qBAAqBW,IAAI,CAAC,CAACC,SAAWA,OAAOF,UAAU;QACnEG,WAAWb,qB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AAgBE;KAAW;IAEhE,MAAMvC,MAAMX,QAAQ;QAClB,MAAMqD,qBAAqB;eACtB/C,sBAAsBsC,mBAAmBD;eACzCrC,sBAAsBwC,cAAcD;eACpCvC,sBAAsB0C,gBAAgBD;eACtCzC,sBAAsB4C,YAAYD;SACtC;QAED,IAAId,cAAcmB,SAAS;YACzB,KAAK,MAAM3B,UAAU0B,mBAAoB;gBACvC,IAAI,CAAC1B,OAAOC,SAAS,IAAI,CAACD,OAAOF,UAAU,IAAI,CAACE,OAAO4B,KAAK,EAAE;oBAC5Db,aAAac,SAAS,CAAC7B,OAAOR,UAAU,EAAE;gBAC5C,OAAO,IAAIQ,OAAO4B,KAAK,EAAE;oBACvBb,aAAac,SAAS,CAAC7B,OAAOR,UAAU,EAAE;gBAC5C,OAAO;oBACLuB,aAAac,SAAS,CAAC7B,OAAOR,UAAU,EAAE;gBAC5C;YACF;QACF;QAEA,OAAO;YACLH,cAAcqC;YACd5B,YAAY4B,mBAAmB3B,IAAI,CAAC,CAACC,SAAWA,OAAOF,UAAU;YACjEG,WAAWyB,mBAAmB3B,IAAI,CAAC,CAACC,SAAWA,OAAOC,SAAS;YAC/DC;YACAP,QAAQ+B,mBAAmBf,GAAG,CAAC,CAACX,SAAWA,OAAO4B,KAAK;QACzD;IACF,GAAG;QACDZ;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACAC;QACArB;QACAM,cAAcmB;QACdZ;KACD;IAED,qBAAO,KAAClC,mBAAmBiD,QAAQ;QAACC,OAAO/C;kBAAMuB;;AACnD"}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.tsx"],"sourcesContent":["// Copyright 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 { createContext, ReactElement, useCallback, useContext, useMemo } from 'react';\nimport { QueryType, TimeSeriesQueryDefinition } from '@perses-dev/spec';\nimport { useTimeSeriesQueries } from '../time-series-queries';\nimport { useTraceQueries, TraceQueryDefinition } from '../trace-queries';\nimport { useProfileQueries, ProfileQueryDefinition } from '../profile-queries';\nimport { useAlertsQueries, AlertsQueryDefinition } from '../alerts-queries';\nimport { useSilencesQueries, SilencesQueryDefinition } from '../silences-queries';\n\nimport { useUsageMetrics } from '../UsageMetricsProvider';\nimport { LogQueryDefinition, useLogQueries } from '../log-queries';\nimport {\n DataQueriesProviderProps,\n UseDataQueryResults,\n transformQueryResults,\n DataQueriesContextType,\n QueryData,\n} from './model';\n\nexport const DataQueriesContext = createContext<DataQueriesContextType | undefined>(undefined);\n\nexport function useDataQueriesContext(): DataQueriesContextType {\n const ctx = useContext(DataQueriesContext);\n if (ctx === undefined) {\n throw new Error('No DataQueriesContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useDataQueries<T extends keyof QueryType>(queryType: T): UseDataQueryResults<QueryType[T]> {\n const ctx = useDataQueriesContext();\n\n // Filter query definitions based on the specified query type\n const filteredQueryDefinitions = ctx.queryDefinitions.filter((definition) => definition.kind === queryType);\n\n // Filter the query results based on the specified query type\n const filteredQueryResults = ctx.queryResults.filter(\n (queryResult) => queryResult?.definition?.kind === queryType\n ) as Array<QueryData<QueryType[T]>>;\n\n // Filter the errors based on the specified query type\n const filteredErrors = ctx.errors.filter((errors, index) => ctx.queryResults[index]?.definition?.kind === queryType);\n\n // Create a new context object with the filtered results and errors\n return {\n queryDefinitions: filteredQueryDefinitions,\n queryResults: filteredQueryResults,\n isFetching: filteredQueryResults.some((result) => result.isFetching),\n isLoading: filteredQueryResults.some((result) => result.isLoading),\n refetchAll: ctx.refetchAll,\n errors: filteredErrors,\n };\n}\n\nexport function DataQueriesProvider(props: DataQueriesProviderProps): ReactElement {\n const { definitions, options, children, queryOptions } = props;\n\n const usageMetrics = useUsageMetrics();\n\n // Filter definitions for time series query and other future query plugins\n const timeSeriesQueries = definitions.filter(\n (definition) => definition.kind === 'TimeSeriesQuery'\n ) as TimeSeriesQueryDefinition[];\n const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options, queryOptions);\n\n const traceQueries = definitions.filter((definition) => definition.kind === 'TraceQuery') as TraceQueryDefinition[];\n const traceResults = useTraceQueries(traceQueries);\n\n const profileQueries = definitions.filter(\n (definition) => definition.kind === 'ProfileQuery'\n ) as ProfileQueryDefinition[];\n const profileResults = useProfileQueries(profileQueries);\n\n const logQueries = definitions.filter((definition) => definition.kind === 'LogQuery') as LogQueryDefinition[];\n const logResults = useLogQueries(logQueries);\n\n const alertsQueries = definitions.filter(\n (definition) => definition.kind === 'AlertsQuery'\n ) as AlertsQueryDefinition[];\n const alertsResults = useAlertsQueries(alertsQueries);\n\n const silencesQueries = definitions.filter(\n (definition) => definition.kind === 'SilencesQuery'\n ) as SilencesQueryDefinition[];\n const silencesResults = useSilencesQueries(silencesQueries);\n\n const refetchAll = useCallback(() => {\n timeSeriesResults.forEach((result) => result.refetch());\n traceResults.forEach((result) => result.refetch());\n profileResults.forEach((result) => result.refetch());\n logResults.forEach((result) => result.refetch());\n alertsResults.forEach((result) => result.refetch());\n silencesResults.forEach((result) => result.refetch());\n }, [timeSeriesResults, traceResults, profileResults, logResults, alertsResults, silencesResults]);\n\n const ctx = useMemo(() => {\n const mergedQueryResults = [\n ...transformQueryResults(timeSeriesResults, timeSeriesQueries),\n ...transformQueryResults(traceResults, traceQueries),\n ...transformQueryResults(profileResults, profileQueries),\n ...transformQueryResults(logResults, logQueries),\n ...transformQueryResults(alertsResults, alertsQueries),\n ...transformQueryResults(silencesResults, silencesQueries),\n ];\n\n if (queryOptions?.enabled) {\n for (const result of mergedQueryResults) {\n if (!result.isLoading && !result.isFetching && !result.error) {\n usageMetrics.markQuery(result.definition, 'success');\n } else if (result.error) {\n usageMetrics.markQuery(result.definition, 'error');\n } else {\n usageMetrics.markQuery(result.definition, 'pending');\n }\n }\n }\n\n return {\n queryDefinitions: definitions,\n queryResults: mergedQueryResults,\n isFetching: mergedQueryResults.some((result) => result.isFetching),\n isLoading: mergedQueryResults.some((result) => result.isLoading),\n refetchAll,\n errors: mergedQueryResults.map((result) => result.error),\n };\n }, [\n alertsQueries,\n alertsResults,\n logQueries,\n logResults,\n profileQueries,\n profileResults,\n silencesQueries,\n silencesResults,\n timeSeriesQueries,\n timeSeriesResults,\n traceQueries,\n traceResults,\n definitions,\n queryOptions?.enabled,\n refetchAll,\n usageMetrics,\n ]);\n\n return <DataQueriesContext.Provider value={ctx}>{children}</DataQueriesContext.Provider>;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useTimeSeriesQueries","useTraceQueries","useProfileQueries","useAlertsQueries","useSilencesQueries","useUsageMetrics","useLogQueries","transformQueryResults","DataQueriesContext","undefined","useDataQueriesContext","ctx","Error","useDataQueries","queryType","filteredQueryDefinitions","queryDefinitions","filter","definition","kind","filteredQueryResults","queryResults","queryResult","filteredErrors","errors","index","isFetching","some","result","isLoading","refetchAll","DataQueriesProvider","props","definitions","options","children","queryOptions","usageMetrics","timeSeriesQueries","timeSeriesResults","traceQueries","traceResults","profileQueries","profileResults","logQueries","logResults","alertsQueries","alertsResults","silencesQueries","silencesResults","forEach","refetch","mergedQueryResults","enabled","error","markQuery","map","Provider","value"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,aAAa,EAAgBC,WAAW,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAEtF,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,eAAe,QAA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BsC,YAAYD;eAClCrC,sBAAsBwC,eAAeD;eACrCvC,sBAAsB0C,iBAAiBD;SAC3C;QAED,IAAIZ,cAAciB,SAAS;YACzB,KAAK,MAAMzB,UAAUwB,mBAAoB;gBACvC,IAAI,CAACxB,OAAOC,SAAS,IAAI,CAACD,OAAOF,UAAU,IAAI,CAACE,OAAO0B,KAAK,EAAE;oBAC5DjB,aAAakB,SAAS,CAAC3B,OAAOV,UAAU,EAAE;gBAC5C,OAAO,IAAIU,OAAO0B,KAAK,EAAE;oBACvBjB,aAAakB,SAAS,CAAC3B,OAAOV,UAAU,EAAE;gBAC5C,OAAO;oBACLmB,aAAakB,SAAS,CAAC3B,OAAOV,UAAU,EAAE;gBAC5C;YACF;QACF;QAEA,OAAO;YACLF,kBAAkBiB;YAClBZ,cAAc+B;YACd1B,YAAY0B,mBAAmBzB,IAAI,CAAC,CAACC,SAAWA,OAAOF,UAAU;YACjEG,WAAWuB,mBAAmBzB,IAAI,CAAC,CAACC,SAAWA,OAAOC,SAAS;YAC/DC;YACAN,QAAQ4B,mBAAmBI,GAAG,CAAC,CAAC5B,SAAWA,OAAO0B,KAAK;QACzD;IACF,GAAG;QACDR;QACAC;QACAH;QACAC;QACAH;QACAC;QACAK;QACAC;QACAX;QACAC;QACAC;QACAC;QACAR;QACAG,cAAciB;QACdvB;QACAO;KACD;IAED,qBAAO,KAAC7B,mBAAmBiD,QAAQ;QAACC,OAAO/C;kBAAMwB;;AACnD"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/spec';
|
|
2
2
|
import { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
4
|
export type QueryOptions = Record<string, unknown>;
|
|
5
|
-
export interface DataQueriesProviderProps<
|
|
6
|
-
definitions: Array<
|
|
5
|
+
export interface DataQueriesProviderProps<Kind = unknown, PluginSpec = UnknownSpec> {
|
|
6
|
+
definitions: Array<QueryDefinition<Kind, PluginSpec>>;
|
|
7
7
|
children?: ReactNode;
|
|
8
8
|
options?: QueryOptions;
|
|
9
9
|
queryOptions?: Omit<QueryObserverOptions, 'queryKey'>;
|
|
10
10
|
}
|
|
11
11
|
export interface DataQueriesContextType {
|
|
12
|
+
queryDefinitions: QueryDefinition[];
|
|
12
13
|
queryResults: QueryData[];
|
|
13
14
|
refetchAll: () => void;
|
|
14
15
|
isFetching: boolean;
|
|
@@ -27,5 +28,4 @@ export type QueryData<T = QueryDataType> = {
|
|
|
27
28
|
refetch?: () => void;
|
|
28
29
|
};
|
|
29
30
|
export declare function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]): QueryData[];
|
|
30
|
-
export declare function useQueryType(): (pluginKind: string) => string | undefined;
|
|
31
31
|
//# sourceMappingURL=model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/runtime/DataQueriesProvider/model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/runtime/DataQueriesProvider/model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACnD,MAAM,WAAW,wBAAwB,CAAC,IAAI,GAAG,OAAO,EAAE,UAAU,GAAG,WAAW;IAChF,WAAW,EAAE,KAAK,CAAC,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;IACtD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,YAAY,CAAC,EAAE,IAAI,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,eAAe,EAAE,CAAC;IACpC,YAAY,EAAE,SAAS,EAAE,CAAC;IAC1B,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,sBAAsB,EAAE,cAAc,CAAC;IAC1F,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,aAAa,IAAI;IACzC,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,UAAU,EAAE,eAAe,CAAC;IAC5B,KAAK,EAAE,KAAK,CAAC;IACb,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,GAAG,SAAS,EAAE,CAW5G"}
|
|
@@ -10,8 +10,6 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { useCallback, useMemo } from 'react';
|
|
14
|
-
import { useListPluginMetadata } from '../plugin-registry';
|
|
15
13
|
export function transformQueryResults(results, definitions) {
|
|
16
14
|
return results.map(({ data, isFetching, isLoading, refetch, error }, i)=>{
|
|
17
15
|
return {
|
|
@@ -24,85 +22,5 @@ export function transformQueryResults(results, definitions) {
|
|
|
24
22
|
};
|
|
25
23
|
});
|
|
26
24
|
}
|
|
27
|
-
export function useQueryType() {
|
|
28
|
-
const { data: timeSeriesQueryPlugins, isLoading: isTimeSeriesQueryLoading } = useListPluginMetadata([
|
|
29
|
-
'TimeSeriesQuery'
|
|
30
|
-
]);
|
|
31
|
-
const { data: traceQueryPlugins, isLoading: isTraceQueryPluginLoading } = useListPluginMetadata([
|
|
32
|
-
'TraceQuery'
|
|
33
|
-
]);
|
|
34
|
-
const { data: profileQueryPlugins, isLoading: isProfileQueryPluginLoading } = useListPluginMetadata([
|
|
35
|
-
'ProfileQuery'
|
|
36
|
-
]);
|
|
37
|
-
const { data: logQueries, isLoading: isLogQueryPluginLoading } = useListPluginMetadata([
|
|
38
|
-
'LogQuery'
|
|
39
|
-
]);
|
|
40
|
-
// For example, `map: {"TimeSeriesQuery":["PrometheusTimeSeriesQuery"],"TraceQuery":["TempoTraceQuery"]}`
|
|
41
|
-
const queryTypeMap = useMemo(()=>{
|
|
42
|
-
const map = {
|
|
43
|
-
TimeSeriesQuery: [],
|
|
44
|
-
TraceQuery: [],
|
|
45
|
-
ProfileQuery: [],
|
|
46
|
-
LogQuery: []
|
|
47
|
-
};
|
|
48
|
-
if (timeSeriesQueryPlugins) {
|
|
49
|
-
timeSeriesQueryPlugins.forEach((plugin)=>{
|
|
50
|
-
map[plugin.kind]?.push(plugin.spec.name);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (traceQueryPlugins) {
|
|
54
|
-
traceQueryPlugins.forEach((plugin)=>{
|
|
55
|
-
map[plugin.kind]?.push(plugin.spec.name);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
if (profileQueryPlugins) {
|
|
59
|
-
profileQueryPlugins.forEach((plugin)=>{
|
|
60
|
-
map[plugin.kind]?.push(plugin.spec.name);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
if (logQueries) {
|
|
64
|
-
logQueries.forEach((plugin)=>{
|
|
65
|
-
map[plugin.kind]?.push(plugin.spec.name);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
return map;
|
|
69
|
-
}, [
|
|
70
|
-
timeSeriesQueryPlugins,
|
|
71
|
-
traceQueryPlugins,
|
|
72
|
-
profileQueryPlugins,
|
|
73
|
-
logQueries
|
|
74
|
-
]);
|
|
75
|
-
const getQueryType = useCallback((pluginKind)=>{
|
|
76
|
-
const isLoading = (pluginKind)=>{
|
|
77
|
-
switch(pluginKind){
|
|
78
|
-
case 'PrometheusTimeSeriesQuery':
|
|
79
|
-
return isTimeSeriesQueryLoading;
|
|
80
|
-
case 'TempoTraceQuery':
|
|
81
|
-
return isTraceQueryPluginLoading;
|
|
82
|
-
case 'PyroscopeProfileQuery':
|
|
83
|
-
return isProfileQueryPluginLoading;
|
|
84
|
-
case 'LokiLogQuery':
|
|
85
|
-
return isLogQueryPluginLoading;
|
|
86
|
-
}
|
|
87
|
-
return isTraceQueryPluginLoading || isTimeSeriesQueryLoading || isProfileQueryPluginLoading || isLogQueryPluginLoading;
|
|
88
|
-
};
|
|
89
|
-
if (isLoading(pluginKind)) {
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
for(const queryType in queryTypeMap){
|
|
93
|
-
if (queryTypeMap[queryType]?.includes(pluginKind)) {
|
|
94
|
-
return queryType;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
throw new Error(`Unable to determine the query type: ${pluginKind}`);
|
|
98
|
-
}, [
|
|
99
|
-
queryTypeMap,
|
|
100
|
-
isTimeSeriesQueryLoading,
|
|
101
|
-
isTraceQueryPluginLoading,
|
|
102
|
-
isProfileQueryPluginLoading,
|
|
103
|
-
isLogQueryPluginLoading
|
|
104
|
-
]);
|
|
105
|
-
return getQueryType;
|
|
106
|
-
}
|
|
107
25
|
|
|
108
26
|
//# sourceMappingURL=model.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/model.ts"],"sourcesContent":["// Copyright 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 {
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/model.ts"],"sourcesContent":["// Copyright 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 { QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/spec';\nimport { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { ReactNode } from 'react';\n\nexport type QueryOptions = Record<string, unknown>;\nexport interface DataQueriesProviderProps<Kind = unknown, PluginSpec = UnknownSpec> {\n definitions: Array<QueryDefinition<Kind, PluginSpec>>;\n children?: ReactNode;\n options?: QueryOptions;\n queryOptions?: Omit<QueryObserverOptions, 'queryKey'>;\n}\n\nexport interface DataQueriesContextType {\n queryDefinitions: QueryDefinition[];\n queryResults: QueryData[];\n refetchAll: () => void;\n isFetching: boolean;\n isLoading: boolean;\n errors: unknown[];\n}\n\nexport interface UseDataQueryResults<T> extends Omit<DataQueriesContextType, 'queryResults'> {\n queryResults: Array<QueryData<T>>;\n}\n\nexport type QueryData<T = QueryDataType> = {\n data?: T;\n definition: QueryDefinition;\n error: Error;\n isFetching: boolean;\n isLoading: boolean;\n refetch?: () => void;\n};\n\nexport function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]): QueryData[] {\n return results.map(({ data, isFetching, isLoading, refetch, error }, i) => {\n return {\n definition: definitions[i],\n data,\n isFetching,\n isLoading,\n refetch,\n error,\n } as QueryData;\n });\n}\n"],"names":["transformQueryResults","results","definitions","map","data","isFetching","isLoading","refetch","error","i","definition"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAoCjC,OAAO,SAASA,sBAAsBC,OAAyB,EAAEC,WAA8B;IAC7F,OAAOD,QAAQE,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,KAAK,EAAE,EAAEC;QACnE,OAAO;YACLC,YAAYR,WAAW,CAACO,EAAE;YAC1BL;YACAC;YACAC;YACAC;YACAC;QACF;IACF;AACF"}
|