@perses-dev/plugin-system 0.51.0-beta.1 → 0.51.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/DatasourceSelect.js +155 -71
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +91 -1
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +11 -7
- package/dist/cjs/constants/user-interface-text.js +3 -1
- package/dist/cjs/remote/PluginRuntime.js +168 -162
- package/dist/cjs/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +13 -0
- package/dist/cjs/runtime/time-series-queries.js +3 -13
- package/dist/cjs/runtime/trace-queries.js +46 -16
- package/dist/cjs/runtime/utils.js +39 -0
- package/dist/components/DatasourceSelect.d.ts +8 -3
- package/dist/components/DatasourceSelect.d.ts.map +1 -1
- package/dist/components/DatasourceSelect.js +148 -72
- package/dist/components/DatasourceSelect.js.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.d.ts +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +2 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +94 -2
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +11 -7
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/constants/user-interface-text.d.ts +2 -0
- package/dist/constants/user-interface-text.d.ts.map +1 -1
- package/dist/constants/user-interface-text.js +3 -1
- package/dist/constants/user-interface-text.js.map +1 -1
- package/dist/model/trace-queries.d.ts +13 -1
- package/dist/model/trace-queries.d.ts.map +1 -1
- package/dist/model/trace-queries.js.map +1 -1
- package/dist/remote/PluginRuntime.d.ts +0 -1
- package/dist/remote/PluginRuntime.d.ts.map +1 -1
- package/dist/remote/PluginRuntime.js +169 -160
- package/dist/remote/PluginRuntime.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts +7 -0
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js +13 -0
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.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.map +1 -1
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +1 -11
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/trace-queries.d.ts.map +1 -1
- package/dist/runtime/trace-queries.js +47 -17
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/runtime/utils.d.ts +7 -0
- package/dist/runtime/utils.d.ts.map +1 -0
- package/dist/runtime/utils.js +25 -0
- package/dist/runtime/utils.js.map +1 -0
- package/package.json +3 -3
|
@@ -24,9 +24,6 @@ _export(exports, {
|
|
|
24
24
|
loadPlugin: function() {
|
|
25
25
|
return loadPlugin;
|
|
26
26
|
},
|
|
27
|
-
pluginRuntime: function() {
|
|
28
|
-
return pluginRuntime;
|
|
29
|
-
},
|
|
30
27
|
usePluginRuntime: function() {
|
|
31
28
|
return usePluginRuntime;
|
|
32
29
|
}
|
|
@@ -35,8 +32,8 @@ const _runtime = require("@module-federation/enhanced/runtime");
|
|
|
35
32
|
const _reactquery = /*#__PURE__*/ _interop_require_wildcard(require("@tanstack/react-query"));
|
|
36
33
|
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
|
|
37
34
|
const _reactdom = /*#__PURE__*/ _interop_require_default(require("react-dom"));
|
|
38
|
-
const _reactrouterdom = /*#__PURE__*/ _interop_require_wildcard(require("react-router-dom"));
|
|
39
35
|
const _reacthookform = /*#__PURE__*/ _interop_require_wildcard(require("react-hook-form"));
|
|
36
|
+
const _reactrouterdom = /*#__PURE__*/ _interop_require_wildcard(require("react-router-dom"));
|
|
40
37
|
function _interop_require_default(obj) {
|
|
41
38
|
return obj && obj.__esModule ? obj : {
|
|
42
39
|
default: obj
|
|
@@ -83,166 +80,175 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
83
80
|
}
|
|
84
81
|
return newObj;
|
|
85
82
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
83
|
+
let instance = null;
|
|
84
|
+
const getPluginRuntime = ()=>{
|
|
85
|
+
if (instance === null) {
|
|
86
|
+
const pluginRuntime = (0, _runtime.init)({
|
|
87
|
+
name: '@perses/perses-ui-host',
|
|
88
|
+
remotes: [],
|
|
89
|
+
shared: {
|
|
90
|
+
react: {
|
|
91
|
+
version: _react.default.version,
|
|
92
|
+
lib: ()=>_react.default,
|
|
93
|
+
shareConfig: {
|
|
94
|
+
singleton: true,
|
|
95
|
+
requiredVersion: `^${_react.default.version}`
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
'react-dom': {
|
|
99
|
+
version: '18.3.1',
|
|
100
|
+
lib: ()=>_reactdom.default,
|
|
101
|
+
shareConfig: {
|
|
102
|
+
singleton: true,
|
|
103
|
+
requiredVersion: `^18.3.1`
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
'react-router-dom': {
|
|
107
|
+
version: '6.26.0',
|
|
108
|
+
lib: ()=>_reactrouterdom,
|
|
109
|
+
shareConfig: {
|
|
110
|
+
singleton: true,
|
|
111
|
+
requiredVersion: '^6.26.0'
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
'@tanstack/react-query': {
|
|
115
|
+
version: '5.64.2',
|
|
116
|
+
lib: ()=>_reactquery,
|
|
117
|
+
shareConfig: {
|
|
118
|
+
singleton: true,
|
|
119
|
+
requiredVersion: '^5.64.2'
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
'react-hook-form': {
|
|
123
|
+
version: '7.52.2',
|
|
124
|
+
lib: ()=>_reacthookform,
|
|
125
|
+
shareConfig: {
|
|
126
|
+
singleton: true,
|
|
127
|
+
requiredVersion: '^7.52.2'
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
echarts: {
|
|
131
|
+
version: '5.5.0',
|
|
132
|
+
lib: ()=>require('echarts'),
|
|
133
|
+
shareConfig: {
|
|
134
|
+
singleton: true,
|
|
135
|
+
requiredVersion: '^5.5.0'
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
'@perses-dev/components': {
|
|
139
|
+
version: '0.51.0-beta.0',
|
|
140
|
+
lib: ()=>require('@perses-dev/components'),
|
|
141
|
+
shareConfig: {
|
|
142
|
+
singleton: true,
|
|
143
|
+
requiredVersion: '^0.51.0-beta.0'
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
'@perses-dev/plugin-system': {
|
|
147
|
+
version: '0.51.0-beta.0',
|
|
148
|
+
lib: ()=>require('@perses-dev/plugin-system'),
|
|
149
|
+
shareConfig: {
|
|
150
|
+
singleton: true,
|
|
151
|
+
requiredVersion: '^0.51.0-beta.0'
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
'@perses-dev/explore': {
|
|
155
|
+
version: '0.51.0-beta.0',
|
|
156
|
+
lib: ()=>require('@perses-dev/explore'),
|
|
157
|
+
shareConfig: {
|
|
158
|
+
singleton: true,
|
|
159
|
+
requiredVersion: '^0.51.0-beta.0'
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
'@perses-dev/dashboards': {
|
|
163
|
+
version: '0.51.0-beta.0',
|
|
164
|
+
lib: ()=>require('@perses-dev/dashboards'),
|
|
165
|
+
shareConfig: {
|
|
166
|
+
singleton: true,
|
|
167
|
+
requiredVersion: '^0.51.0-beta.0'
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
// Below are the shared modules that are used by the plugins, this can be part of the SDK
|
|
171
|
+
'date-fns': {
|
|
172
|
+
version: '4.1.0',
|
|
173
|
+
lib: ()=>require('date-fns'),
|
|
174
|
+
shareConfig: {
|
|
175
|
+
singleton: true,
|
|
176
|
+
requiredVersion: '^4.1.0'
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
'date-fns-tz': {
|
|
180
|
+
version: '3.2.0',
|
|
181
|
+
lib: ()=>require('date-fns-tz'),
|
|
182
|
+
shareConfig: {
|
|
183
|
+
singleton: true,
|
|
184
|
+
requiredVersion: '^3.2.0'
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
lodash: {
|
|
188
|
+
version: '4.17.21',
|
|
189
|
+
lib: ()=>require('lodash'),
|
|
190
|
+
shareConfig: {
|
|
191
|
+
singleton: true,
|
|
192
|
+
requiredVersion: '^4.17.21'
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
'@emotion/react': {
|
|
196
|
+
version: '11.11.3',
|
|
197
|
+
lib: ()=>require('@emotion/react'),
|
|
198
|
+
shareConfig: {
|
|
199
|
+
singleton: true,
|
|
200
|
+
requiredVersion: '^11.11.3'
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
'@emotion/styled': {
|
|
204
|
+
version: '11.11.0',
|
|
205
|
+
lib: ()=>require('@emotion/styled'),
|
|
206
|
+
shareConfig: {
|
|
207
|
+
singleton: true,
|
|
208
|
+
requiredVersion: '^11.11.0'
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
'@hookform/resolvers/zod': {
|
|
212
|
+
version: '3.3.4',
|
|
213
|
+
lib: ()=>require('@hookform/resolvers/zod'),
|
|
214
|
+
shareConfig: {
|
|
215
|
+
singleton: true,
|
|
216
|
+
requiredVersion: '^3.3.4'
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
'use-resize-observer': {
|
|
220
|
+
version: '9.1.0',
|
|
221
|
+
lib: ()=>require('use-resize-observer'),
|
|
222
|
+
shareConfig: {
|
|
223
|
+
singleton: true,
|
|
224
|
+
requiredVersion: '^9.1.0'
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
'mdi-material-ui': {
|
|
228
|
+
version: '7.4.0',
|
|
229
|
+
lib: ()=>require('mdi-material-ui'),
|
|
230
|
+
shareConfig: {
|
|
231
|
+
singleton: true,
|
|
232
|
+
requiredVersion: '^7.4.0'
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
immer: {
|
|
236
|
+
version: '10.1.1',
|
|
237
|
+
lib: ()=>require('immer'),
|
|
238
|
+
shareConfig: {
|
|
239
|
+
singleton: true,
|
|
240
|
+
requiredVersion: '^10.1.1'
|
|
241
|
+
}
|
|
242
|
+
}
|
|
168
243
|
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
version: '4.1.0',
|
|
173
|
-
lib: ()=>require('date-fns'),
|
|
174
|
-
shareConfig: {
|
|
175
|
-
singleton: true,
|
|
176
|
-
requiredVersion: '^4.1.0'
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
'date-fns-tz': {
|
|
180
|
-
version: '3.2.0',
|
|
181
|
-
lib: ()=>require('date-fns-tz'),
|
|
182
|
-
shareConfig: {
|
|
183
|
-
singleton: true,
|
|
184
|
-
requiredVersion: '^3.2.0'
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
lodash: {
|
|
188
|
-
version: '4.17.21',
|
|
189
|
-
lib: ()=>require('lodash'),
|
|
190
|
-
shareConfig: {
|
|
191
|
-
singleton: true,
|
|
192
|
-
requiredVersion: '^4.17.21'
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
'@emotion/react': {
|
|
196
|
-
version: '11.11.3',
|
|
197
|
-
lib: ()=>require('@emotion/react'),
|
|
198
|
-
shareConfig: {
|
|
199
|
-
singleton: true,
|
|
200
|
-
requiredVersion: '^11.11.3'
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
'@emotion/styled': {
|
|
204
|
-
version: '11.11.0',
|
|
205
|
-
lib: ()=>require('@emotion/styled'),
|
|
206
|
-
shareConfig: {
|
|
207
|
-
singleton: true,
|
|
208
|
-
requiredVersion: '^11.11.0'
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
'@hookform/resolvers/zod': {
|
|
212
|
-
version: '3.3.4',
|
|
213
|
-
lib: ()=>require('@hookform/resolvers/zod'),
|
|
214
|
-
shareConfig: {
|
|
215
|
-
singleton: true,
|
|
216
|
-
requiredVersion: '^3.3.4'
|
|
217
|
-
}
|
|
218
|
-
},
|
|
219
|
-
'use-resize-observer': {
|
|
220
|
-
version: '9.1.0',
|
|
221
|
-
lib: ()=>require('use-resize-observer'),
|
|
222
|
-
shareConfig: {
|
|
223
|
-
singleton: true,
|
|
224
|
-
requiredVersion: '^9.1.0'
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
'mdi-material-ui': {
|
|
228
|
-
version: '7.4.0',
|
|
229
|
-
lib: ()=>require('mdi-material-ui'),
|
|
230
|
-
shareConfig: {
|
|
231
|
-
singleton: true,
|
|
232
|
-
requiredVersion: '^7.4.0'
|
|
233
|
-
}
|
|
234
|
-
},
|
|
235
|
-
immer: {
|
|
236
|
-
version: '10.1.1',
|
|
237
|
-
lib: ()=>require('immer'),
|
|
238
|
-
shareConfig: {
|
|
239
|
-
singleton: true,
|
|
240
|
-
requiredVersion: '^10.1.1'
|
|
241
|
-
}
|
|
242
|
-
}
|
|
244
|
+
});
|
|
245
|
+
instance = pluginRuntime;
|
|
246
|
+
return instance;
|
|
243
247
|
}
|
|
244
|
-
|
|
248
|
+
return instance;
|
|
249
|
+
};
|
|
245
250
|
const registerRemote = (name, baseURL)=>{
|
|
251
|
+
const pluginRuntime = getPluginRuntime();
|
|
246
252
|
const existingRemote = pluginRuntime.options.remotes.find((remote)=>remote.name === name);
|
|
247
253
|
if (!existingRemote) {
|
|
248
254
|
const remoteEntryURL = baseURL ? `${baseURL}/${name}/mf-manifest.json` : `/plugins/${name}/mf-manifest.json`;
|
|
@@ -261,7 +267,7 @@ const loadPlugin = async (moduleName, pluginName, baseURL)=>{
|
|
|
261
267
|
};
|
|
262
268
|
function usePluginRuntime({ plugin }) {
|
|
263
269
|
return {
|
|
264
|
-
pluginRuntime,
|
|
270
|
+
pluginRuntime: getPluginRuntime(),
|
|
265
271
|
loadPlugin: ()=>loadPlugin(plugin.moduleName, plugin.name, plugin.baseURL)
|
|
266
272
|
};
|
|
267
273
|
}
|
|
@@ -30,6 +30,9 @@ _export(exports, {
|
|
|
30
30
|
useShowCustomTimeRangeSetting: function() {
|
|
31
31
|
return useShowCustomTimeRangeSetting;
|
|
32
32
|
},
|
|
33
|
+
useShowZoomRangeSetting: function() {
|
|
34
|
+
return useShowZoomRangeSetting;
|
|
35
|
+
},
|
|
33
36
|
useTimeRangeOptionsSetting: function() {
|
|
34
37
|
return useTimeRangeOptionsSetting;
|
|
35
38
|
},
|
|
@@ -56,6 +59,7 @@ const DEFAULT_OPTIONS = [
|
|
|
56
59
|
];
|
|
57
60
|
const defaultTimeRangeSettings = {
|
|
58
61
|
showCustom: true,
|
|
62
|
+
showZoomButtons: true,
|
|
59
63
|
options: DEFAULT_OPTIONS.map((duration)=>(0, _components.buildRelativeTimeOption)(duration))
|
|
60
64
|
};
|
|
61
65
|
const TimeRangeSettingsContext = /*#__PURE__*/ (0, _react.createContext)(defaultTimeRangeSettings);
|
|
@@ -76,6 +80,13 @@ function useShowCustomTimeRangeSetting(override) {
|
|
|
76
80
|
}
|
|
77
81
|
return showCustomTimeRange;
|
|
78
82
|
}
|
|
83
|
+
function useShowZoomRangeSetting(override) {
|
|
84
|
+
const showZoomTimeRange = useTimeRangeSettings().showZoomButtons;
|
|
85
|
+
if (override !== undefined) {
|
|
86
|
+
return override;
|
|
87
|
+
}
|
|
88
|
+
return showZoomTimeRange;
|
|
89
|
+
}
|
|
79
90
|
function useTimeRangeOptionsSetting(override) {
|
|
80
91
|
const showCustomTimeRange = useTimeRangeSettings().options;
|
|
81
92
|
if (override !== undefined) {
|
|
@@ -87,10 +98,12 @@ function TimeRangeSettingsProvider(props) {
|
|
|
87
98
|
const ctx = (0, _react.useMemo)(()=>{
|
|
88
99
|
return {
|
|
89
100
|
showCustom: props.showCustom === undefined ? defaultTimeRangeSettings.showCustom : props.showCustom,
|
|
101
|
+
showZoomButtons: props.showZoomButtons === undefined ? defaultTimeRangeSettings.showZoomButtons : props.showZoomButtons,
|
|
90
102
|
options: props.options === undefined ? defaultTimeRangeSettings.options : props.options
|
|
91
103
|
};
|
|
92
104
|
}, [
|
|
93
105
|
props.showCustom,
|
|
106
|
+
props.showZoomButtons,
|
|
94
107
|
props.options
|
|
95
108
|
]);
|
|
96
109
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(TimeRangeSettingsContext.Provider, {
|
|
@@ -42,25 +42,15 @@ const _variables = require("./variables");
|
|
|
42
42
|
const _TimeRangeProvider = require("./TimeRangeProvider");
|
|
43
43
|
const _datasources = require("./datasources");
|
|
44
44
|
const _pluginregistry = require("./plugin-registry");
|
|
45
|
+
const _utils = require("./utils");
|
|
45
46
|
const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';
|
|
46
|
-
/**
|
|
47
|
-
* Returns a serialized string of the current state of variable values.
|
|
48
|
-
*/ function getVariableValuesKey(v) {
|
|
49
|
-
return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
|
|
50
|
-
}
|
|
51
|
-
function filterVariableStateMap(v, names) {
|
|
52
|
-
if (!names) {
|
|
53
|
-
return v;
|
|
54
|
-
}
|
|
55
|
-
return Object.fromEntries(Object.entries(v).filter(([name])=>names.includes(name)));
|
|
56
|
-
}
|
|
57
47
|
function getQueryOptions({ plugin, definition, context }) {
|
|
58
48
|
const { timeRange, datasourceStore, suggestedStepMs, mode, variableState, refreshKey } = context;
|
|
59
49
|
const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};
|
|
60
50
|
const variableDependencies = dependencies?.variables;
|
|
61
51
|
// Determine queryKey
|
|
62
|
-
const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);
|
|
63
|
-
const variablesValueKey = getVariableValuesKey(filteredVariabledState);
|
|
52
|
+
const filteredVariabledState = (0, _utils.filterVariableStateMap)(variableState, variableDependencies);
|
|
53
|
+
const variablesValueKey = (0, _utils.getVariableValuesKey)(filteredVariabledState);
|
|
64
54
|
const queryKey = [
|
|
65
55
|
definition,
|
|
66
56
|
timeRange,
|
|
@@ -36,6 +36,8 @@ const _reactquery = require("@tanstack/react-query");
|
|
|
36
36
|
const _datasources = require("./datasources");
|
|
37
37
|
const _pluginregistry = require("./plugin-registry");
|
|
38
38
|
const _TimeRangeProvider = require("./TimeRangeProvider");
|
|
39
|
+
const _variables = require("./variables");
|
|
40
|
+
const _utils = require("./utils");
|
|
39
41
|
const TRACE_QUERY_KEY = 'TraceQuery';
|
|
40
42
|
function getUnixTimeRange(timeRange) {
|
|
41
43
|
const { start, end } = timeRange;
|
|
@@ -46,34 +48,62 @@ function getUnixTimeRange(timeRange) {
|
|
|
46
48
|
}
|
|
47
49
|
function useTraceQueries(definitions) {
|
|
48
50
|
const { getPlugin } = (0, _pluginregistry.usePluginRegistry)();
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
absoluteTimeRange
|
|
54
|
-
};
|
|
51
|
+
const context = useTraceQueryContext();
|
|
52
|
+
const pluginLoaderResponse = (0, _pluginregistry.usePlugins)('TraceQuery', definitions.map((d)=>({
|
|
53
|
+
kind: d.spec.plugin.kind
|
|
54
|
+
})));
|
|
55
55
|
// useQueries() handles data fetching from query plugins (e.g. traceQL queries, promQL queries)
|
|
56
56
|
// https://tanstack.com/query/v4/docs/react/reference/useQuery
|
|
57
57
|
return (0, _reactquery.useQueries)({
|
|
58
|
-
queries: definitions.map((definition)=>{
|
|
59
|
-
const
|
|
58
|
+
queries: definitions.map((definition, idx)=>{
|
|
59
|
+
const plugin = pluginLoaderResponse[idx]?.data;
|
|
60
|
+
const { queryEnabled, queryKey } = getQueryOptions({
|
|
61
|
+
context,
|
|
60
62
|
definition,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
]; // `queryKey` watches and reruns `queryFn` if keys in the array change
|
|
63
|
+
plugin
|
|
64
|
+
});
|
|
64
65
|
const traceQueryKind = definition?.spec?.plugin?.kind;
|
|
65
66
|
return {
|
|
67
|
+
enabled: queryEnabled,
|
|
66
68
|
queryKey: queryKey,
|
|
67
69
|
queryFn: async ()=>{
|
|
68
70
|
const plugin = await getPlugin(TRACE_QUERY_KEY, traceQueryKind);
|
|
69
71
|
const data = await plugin.getTraceData(definition.spec.plugin.spec, context);
|
|
70
72
|
return data;
|
|
71
|
-
}
|
|
72
|
-
// The data returned by getTraceData() contains circular dependencies (a span has a reference to the parent span, and the parent span has an array of child spans)
|
|
73
|
-
// Therefore structuralSharing must be turned off, otherwise the query is stuck in the 'fetching' state on re-fetch.
|
|
74
|
-
// Ref: https://github.com/TanStack/query/issues/6954#issuecomment-1962321426
|
|
75
|
-
structuralSharing: false
|
|
73
|
+
}
|
|
76
74
|
};
|
|
77
75
|
})
|
|
78
76
|
});
|
|
79
77
|
}
|
|
78
|
+
function getQueryOptions({ plugin, definition, context }) {
|
|
79
|
+
const { datasourceStore, variableState, absoluteTimeRange } = context;
|
|
80
|
+
const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};
|
|
81
|
+
const variableDependencies = dependencies?.variables;
|
|
82
|
+
const filteredVariabledState = (0, _utils.filterVariableStateMap)(variableState, variableDependencies);
|
|
83
|
+
const variablesValueKey = (0, _utils.getVariableValuesKey)(filteredVariabledState);
|
|
84
|
+
const queryKey = [
|
|
85
|
+
definition,
|
|
86
|
+
datasourceStore,
|
|
87
|
+
absoluteTimeRange,
|
|
88
|
+
variablesValueKey
|
|
89
|
+
];
|
|
90
|
+
let waitToLoad = false;
|
|
91
|
+
if (variableDependencies) {
|
|
92
|
+
waitToLoad = variableDependencies.some((v)=>variableState[v]?.loading);
|
|
93
|
+
}
|
|
94
|
+
const queryEnabled = plugin !== undefined && !waitToLoad;
|
|
95
|
+
return {
|
|
96
|
+
queryKey,
|
|
97
|
+
queryEnabled
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function useTraceQueryContext() {
|
|
101
|
+
const { absoluteTimeRange } = (0, _TimeRangeProvider.useTimeRange)();
|
|
102
|
+
const variableState = (0, _variables.useAllVariableValues)();
|
|
103
|
+
const datasourceStore = (0, _datasources.useDatasourceStore)();
|
|
104
|
+
return {
|
|
105
|
+
variableState,
|
|
106
|
+
datasourceStore,
|
|
107
|
+
absoluteTimeRange
|
|
108
|
+
};
|
|
109
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: all[name]
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
filterVariableStateMap: function() {
|
|
25
|
+
return filterVariableStateMap;
|
|
26
|
+
},
|
|
27
|
+
getVariableValuesKey: function() {
|
|
28
|
+
return getVariableValuesKey;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
function filterVariableStateMap(v, names) {
|
|
32
|
+
if (!names) {
|
|
33
|
+
return v;
|
|
34
|
+
}
|
|
35
|
+
return Object.fromEntries(Object.entries(v).filter(([name])=>names.includes(name)));
|
|
36
|
+
}
|
|
37
|
+
function getVariableValuesKey(v) {
|
|
38
|
+
return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
|
|
39
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { OutlinedSelectProps, BaseSelectProps } from '@mui/material';
|
|
2
|
-
import { DatasourceSelector } from '@perses-dev/core';
|
|
2
|
+
import { DatasourceSelector, VariableName } from '@perses-dev/core';
|
|
3
3
|
import { ReactElement } from 'react';
|
|
4
|
+
import { DatasourceSelectItemGroup, VariableStateMap } from '../runtime';
|
|
4
5
|
type OmittedMuiProps = 'children' | 'value' | 'onChange';
|
|
6
|
+
export type DatasourceSelectValue<T = DatasourceSelector> = T | VariableName;
|
|
5
7
|
export interface DatasourceSelectProps extends Omit<OutlinedSelectProps & BaseSelectProps<string>, OmittedMuiProps> {
|
|
6
|
-
value:
|
|
7
|
-
onChange: (next:
|
|
8
|
+
value: DatasourceSelectValue;
|
|
9
|
+
onChange: (next: DatasourceSelectValue) => void;
|
|
8
10
|
datasourcePluginKind: string;
|
|
9
11
|
project?: string;
|
|
10
12
|
}
|
|
@@ -18,5 +20,8 @@ export declare function DatasourceName(props: {
|
|
|
18
20
|
overridden?: boolean;
|
|
19
21
|
overriding?: boolean;
|
|
20
22
|
}): ReactElement;
|
|
23
|
+
export declare function isVariableDatasource(value: DatasourceSelectValue | undefined): value is VariableName;
|
|
24
|
+
export declare const datasourceSelectValueToSelector: (value: DatasourceSelectValue | undefined, variables: VariableStateMap, datasourceSelectItemGroups: DatasourceSelectItemGroup[] | undefined) => DatasourceSelector | undefined;
|
|
25
|
+
export declare const useDatasourceSelectValueToSelector: (value: DatasourceSelectValue, datasourcePluginKind: string) => DatasourceSelector;
|
|
21
26
|
export {};
|
|
22
27
|
//# sourceMappingURL=DatasourceSelect.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatasourceSelect.d.ts","sourceRoot":"","sources":["../../src/components/DatasourceSelect.tsx"],"names":[],"mappings":"AAcA,OAAO,
|
|
1
|
+
{"version":3,"file":"DatasourceSelect.d.ts","sourceRoot":"","sources":["../../src/components/DatasourceSelect.tsx"],"names":[],"mappings":"AAcA,OAAO,EAML,mBAAmB,EACnB,eAAe,EAGhB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAC9C,OAAO,EAEL,yBAAyB,EAIzB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAOpB,KAAK,eAAe,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAWzD,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,kBAAkB,IAAI,CAAC,GAAG,YAAY,CAAC;AAE7E,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,mBAAmB,GAAG,eAAe,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;IACjH,KAAK,EAAE,qBAAqB,CAAC;IAC7B,QAAQ,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAChD,oBAAoB,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,YAAY,CAiH3E;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,YAAY,CAahH;AAuCD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,qBAAqB,GAAG,SAAS,GAAG,KAAK,IAAI,YAAY,CAEpG;AAED,eAAO,MAAM,+BAA+B,UACnC,qBAAqB,GAAG,SAAS,aAC7B,gBAAgB,8BACC,yBAAyB,EAAE,GAAG,SAAS,KAClE,kBAAkB,GAAG,SA4BvB,CAAC;AAEF,eAAO,MAAM,kCAAkC,UACtC,qBAAqB,wBACN,MAAM,KAC3B,kBAQF,CAAC"}
|