@perses-dev/plugin-system 0.53.1 → 0.54.0-beta.1
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/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/TimeRangeControls/TimeRangeControls.js +2 -2
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +2 -3
- package/dist/cjs/context/ValidationProvider.js +5 -4
- package/dist/cjs/model/calculations.js +178 -0
- package/dist/cjs/model/index.js +3 -0
- package/dist/cjs/model/legend.js +6 -5
- package/dist/cjs/model/log-volume-utils.js +124 -0
- package/dist/cjs/model/time-series-queries.js +10 -0
- package/dist/cjs/remote/PluginRuntime.js +11 -10
- package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +6 -6
- package/dist/cjs/runtime/TimeRangeProvider/query-params.js +7 -7
- package/dist/cjs/runtime/TimeRangeProvider/refresh-interval.js +2 -2
- package/dist/cjs/test/utils.js +2 -2
- package/dist/cjs/utils/index.js +0 -1
- 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 +1 -1
- package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +2 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +1 -2
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
- package/dist/components/DatasourceSelect/DatasourceSelect.d.ts +1 -1
- package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +1 -2
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.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 +2 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -2
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
- package/dist/components/Variables/variable-model.d.ts +1 -1
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/context/ValidationProvider.d.ts +2 -1
- package/dist/context/ValidationProvider.d.ts.map +1 -1
- package/dist/context/ValidationProvider.js +3 -2
- package/dist/context/ValidationProvider.js.map +1 -1
- 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/datasource.d.ts +8 -1
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js +1 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/explore.d.ts +1 -1
- package/dist/model/explore.js.map +1 -1
- package/dist/model/index.d.ts +3 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +3 -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/log-volume-utils.d.ts +6 -0
- package/dist/model/log-volume-utils.d.ts.map +1 -0
- package/dist/model/log-volume-utils.js +119 -0
- package/dist/model/log-volume-utils.js.map +1 -0
- package/dist/model/panels.d.ts +1 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/plugin-base.d.ts +1 -1
- package/dist/model/plugin-base.js.map +1 -1
- package/dist/model/plugins.d.ts +1 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/model/profile-queries.d.ts +1 -1
- package/dist/model/profile-queries.js.map +1 -1
- 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 +1 -1
- package/dist/model/trace-queries.js.map +1 -1
- package/dist/model/variables.d.ts +1 -1
- package/dist/model/variables.js.map +1 -1
- package/dist/remote/PluginRuntime.d.ts.map +1 -1
- package/dist/remote/PluginRuntime.js +11 -10
- package/dist/remote/PluginRuntime.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts +1 -1
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeSettingsProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.d.ts +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.js +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts +1 -1
- package/dist/runtime/TimeRangeProvider/refresh-interval.js +1 -1
- package/dist/runtime/TimeRangeProvider/refresh-interval.js.map +1 -1
- package/dist/runtime/UsageMetricsProvider.d.ts +1 -1
- package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -1
- package/dist/runtime/UsageMetricsProvider.js +1 -1
- package/dist/runtime/UsageMetricsProvider.js.map +1 -1
- package/dist/runtime/builtin-variables.d.ts +1 -1
- package/dist/runtime/builtin-variables.js.map +1 -1
- package/dist/runtime/datasources.d.ts +1 -1
- package/dist/runtime/datasources.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.d.ts +1 -1
- package/dist/runtime/log-queries.js.map +1 -1
- package/dist/runtime/plugin-registry.d.ts +1 -1
- package/dist/runtime/plugin-registry.js.map +1 -1
- package/dist/runtime/profile-queries.d.ts +1 -1
- package/dist/runtime/profile-queries.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts +1 -1
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/trace-queries.d.ts +1 -1
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/test/mock-data.d.ts +1 -1
- package/dist/test/mock-data.js.map +1 -1
- package/dist/test/utils.d.ts.map +1 -1
- package/dist/test/utils.js +1 -1
- package/dist/test/utils.js.map +1 -1
- 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 +8 -5
- package/dist/cjs/utils/action.js +0 -43
- package/dist/utils/action.d.ts +0 -4
- package/dist/utils/action.d.ts.map +0 -1
- package/dist/utils/action.js +0 -27
- package/dist/utils/action.js.map +0 -1
|
@@ -22,8 +22,8 @@ Object.defineProperty(exports, "CalculationSelector", {
|
|
|
22
22
|
});
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
24
|
const _components = require("@perses-dev/components");
|
|
25
|
-
const
|
|
26
|
-
const CALC_OPTIONS = Object.entries(
|
|
25
|
+
const _model = require("../../model");
|
|
26
|
+
const CALC_OPTIONS = Object.entries(_model.CALCULATIONS_CONFIG).map(([id, config])=>{
|
|
27
27
|
return {
|
|
28
28
|
id: id,
|
|
29
29
|
...config
|
|
@@ -33,7 +33,7 @@ function CalculationSelector({ value, onChange }) {
|
|
|
33
33
|
const handleCalculationChange = (_, newValue)=>{
|
|
34
34
|
onChange(newValue.id);
|
|
35
35
|
};
|
|
36
|
-
const calcConfig =
|
|
36
|
+
const calcConfig = _model.CALCULATIONS_CONFIG[value];
|
|
37
37
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
|
|
38
38
|
label: "Calculation",
|
|
39
39
|
control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.SettingsAutocomplete, {
|
|
@@ -27,13 +27,12 @@ const _components = require("@perses-dev/components");
|
|
|
27
27
|
const _react = require("react");
|
|
28
28
|
const _reacthookform = require("react-hook-form");
|
|
29
29
|
const _context = require("../../context");
|
|
30
|
-
const _utils = require("../../utils");
|
|
31
30
|
const _PluginEditor = require("../PluginEditor");
|
|
32
31
|
function DatasourceEditorForm(props) {
|
|
33
32
|
const { initialDatasourceDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete } = props;
|
|
34
33
|
const [isDiscardDialogOpened, setDiscardDialogOpened] = (0, _react.useState)(false);
|
|
35
|
-
const titleAction = (0,
|
|
36
|
-
const submitText = (0,
|
|
34
|
+
const titleAction = (0, _components.getTitleAction)(action, isDraft);
|
|
35
|
+
const submitText = (0, _components.getSubmitText)(action, isDraft);
|
|
37
36
|
const { datasourceEditorSchema } = (0, _context.useValidationSchemas)();
|
|
38
37
|
const form = (0, _reacthookform.useForm)({
|
|
39
38
|
resolver: (0, _zod.zodResolver)(datasourceEditorSchema),
|
|
@@ -22,7 +22,6 @@ Object.defineProperty(exports, "LegendOptionsEditor", {
|
|
|
22
22
|
});
|
|
23
23
|
const _jsxruntime = require("react/jsx-runtime");
|
|
24
24
|
const _material = require("@mui/material");
|
|
25
|
-
const _core = require("@perses-dev/core");
|
|
26
25
|
const _components = require("@perses-dev/components");
|
|
27
26
|
const _react = require("react");
|
|
28
27
|
const _model = require("../../model");
|
|
@@ -42,7 +41,7 @@ function LegendOptionsEditor({ value, onChange, showValuesEditor = true, calcula
|
|
|
42
41
|
const handleLegendShowChange = (_, checked)=>{
|
|
43
42
|
// legend is hidden when legend obj is undefined
|
|
44
43
|
const legendValue = checked === true ? {
|
|
45
|
-
position:
|
|
44
|
+
position: _components.DEFAULT_LEGEND.position
|
|
46
45
|
} : undefined;
|
|
47
46
|
onChange(legendValue);
|
|
48
47
|
};
|
|
@@ -69,10 +68,10 @@ function LegendOptionsEditor({ value, onChange, showValuesEditor = true, calcula
|
|
|
69
68
|
});
|
|
70
69
|
};
|
|
71
70
|
const isValidLegend = (0, _model.validateLegendSpec)(value);
|
|
72
|
-
const currentPosition = (0,
|
|
71
|
+
const currentPosition = (0, _components.getLegendPosition)(value?.position);
|
|
73
72
|
const legendPositionConfig = _model.LEGEND_POSITIONS_CONFIG[currentPosition];
|
|
74
|
-
const currentMode = (0,
|
|
75
|
-
const currentSize = (0,
|
|
73
|
+
const currentMode = (0, _components.getLegendMode)(value?.mode);
|
|
74
|
+
const currentSize = (0, _components.getLegendSize)(value?.size);
|
|
76
75
|
const legendSizeConfig = _model.LEGEND_SIZE_CONFIG[currentSize];
|
|
77
76
|
const legendValuesConfig = (0, _react.useMemo)(()=>{
|
|
78
77
|
const currentValues = value?.values;
|
|
@@ -34,7 +34,7 @@ const _PlusCircleOutline = /*#__PURE__*/ _interop_require_default(require("mdi-m
|
|
|
34
34
|
const _MinusCircleOutline = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/MinusCircleOutline"));
|
|
35
35
|
const _material = require("@mui/material");
|
|
36
36
|
const _components = require("@perses-dev/components");
|
|
37
|
-
const
|
|
37
|
+
const _spec = require("@perses-dev/spec");
|
|
38
38
|
const _react = require("react");
|
|
39
39
|
const _constants = require("../../constants");
|
|
40
40
|
const _runtime = require("../../runtime");
|
|
@@ -100,7 +100,7 @@ function TimeRangeControls({ heightPx, showTimeRangeSelector = true, showRefresh
|
|
|
100
100
|
setRefreshInterval
|
|
101
101
|
]);
|
|
102
102
|
const fromDurationToMillis = (strDuration)=>{
|
|
103
|
-
const duration = (0,
|
|
103
|
+
const duration = (0, _spec.parseDurationString)(strDuration);
|
|
104
104
|
const millis = // eslint-disable-next-line prettier/prettier
|
|
105
105
|
((duration.seconds ?? 0) + (duration.minutes ?? 0) * 60 + (duration.hours ?? 0) * 3600 + (duration.days ?? 0) * 86400 + (duration.weeks ?? 0) * 7 * 86400 + (duration.months ?? 0) * 30.436875 * 86400 + // avg month duration is ok for zoom purposes
|
|
106
106
|
(duration.years ?? 0) * 365.2425 * 86400) * // avg year duration is ok for zoom purposes
|
|
@@ -27,7 +27,6 @@ const _components = require("@perses-dev/components");
|
|
|
27
27
|
const _reacthookform = require("react-hook-form");
|
|
28
28
|
const _zod = require("@hookform/resolvers/zod");
|
|
29
29
|
const _reactquery = require("@tanstack/react-query");
|
|
30
|
-
const _utils = require("../../../utils");
|
|
31
30
|
const _PluginEditor = require("../../PluginEditor");
|
|
32
31
|
const _context = require("../../../context");
|
|
33
32
|
const _variablemodel = require("../variable-model");
|
|
@@ -395,8 +394,8 @@ function ListVariableEditorForm({ action, control }) {
|
|
|
395
394
|
}
|
|
396
395
|
function VariableEditorForm({ initialVariableDefinition, action, isDraft, isReadonly, onActionChange, onSave, onClose, onDelete }) {
|
|
397
396
|
const [isDiscardDialogOpened, setDiscardDialogOpened] = (0, _react.useState)(false);
|
|
398
|
-
const titleAction = (0,
|
|
399
|
-
const submitText = (0,
|
|
397
|
+
const titleAction = (0, _components.getTitleAction)(action, isDraft);
|
|
398
|
+
const submitText = (0, _components.getSubmitText)(action, isDraft);
|
|
400
399
|
const { variableEditorSchema } = (0, _context.useValidationSchemas)();
|
|
401
400
|
const form = (0, _reacthookform.useForm)({
|
|
402
401
|
resolver: (0, _zod.zodResolver)(variableEditorSchema),
|
|
@@ -33,6 +33,7 @@ _export(exports, {
|
|
|
33
33
|
});
|
|
34
34
|
const _jsxruntime = require("react/jsx-runtime");
|
|
35
35
|
const _react = require("react");
|
|
36
|
+
const _spec = require("@perses-dev/spec");
|
|
36
37
|
const _core = require("@perses-dev/core");
|
|
37
38
|
const ValidationSchemasContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
|
|
38
39
|
function useValidationSchemas() {
|
|
@@ -44,16 +45,16 @@ function useValidationSchemas() {
|
|
|
44
45
|
}
|
|
45
46
|
function ValidationProvider({ children }) {
|
|
46
47
|
const [datasourceEditorSchema, setDatasourceEditorSchema] = (0, _react.useState)(_core.datasourceDefinitionSchema);
|
|
47
|
-
const [panelEditorSchema, setPanelEditorSchema] = (0, _react.useState)(
|
|
48
|
-
const [variableEditorSchema, setVariableEditorSchema] = (0, _react.useState)(
|
|
48
|
+
const [panelEditorSchema, setPanelEditorSchema] = (0, _react.useState)(_spec.panelEditorSchema); // TODO I don't get why this does not compile
|
|
49
|
+
const [variableEditorSchema, setVariableEditorSchema] = (0, _react.useState)(_spec.variableDefinitionSchema);
|
|
49
50
|
function setDatasourceEditorSchemaPlugin(pluginSchema) {
|
|
50
51
|
setDatasourceEditorSchema((0, _core.buildDatasourceDefinitionSchema)(pluginSchema));
|
|
51
52
|
}
|
|
52
53
|
function setPanelEditorSchemaPlugin(pluginSchema) {
|
|
53
|
-
setPanelEditorSchema((0,
|
|
54
|
+
setPanelEditorSchema((0, _spec.buildPanelEditorSchema)(pluginSchema));
|
|
54
55
|
}
|
|
55
56
|
function setVariableEditorSchemaPlugin(pluginSchema) {
|
|
56
|
-
setVariableEditorSchema((0,
|
|
57
|
+
setVariableEditorSchema((0, _spec.buildVariableDefinitionSchema)(pluginSchema));
|
|
57
58
|
}
|
|
58
59
|
return /*#__PURE__*/ (0, _jsxruntime.jsx)(ValidationSchemasContext.Provider, {
|
|
59
60
|
value: {
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
function _export(target, all) {
|
|
18
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_export(exports, {
|
|
24
|
+
get CALCULATIONS_CONFIG () {
|
|
25
|
+
return CALCULATIONS_CONFIG;
|
|
26
|
+
},
|
|
27
|
+
get CalculationsMap () {
|
|
28
|
+
return CalculationsMap;
|
|
29
|
+
},
|
|
30
|
+
get DEFAULT_CALCULATION () {
|
|
31
|
+
return DEFAULT_CALCULATION;
|
|
32
|
+
},
|
|
33
|
+
get getCalculation () {
|
|
34
|
+
return getCalculation;
|
|
35
|
+
},
|
|
36
|
+
get getCalculations () {
|
|
37
|
+
return getCalculations;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const DEFAULT_CALCULATION = 'last'; // aligned with cue
|
|
41
|
+
const CalculationsMap = {
|
|
42
|
+
first: first,
|
|
43
|
+
last: last,
|
|
44
|
+
'first-number': firstNumber,
|
|
45
|
+
'last-number': lastNumber,
|
|
46
|
+
mean: mean,
|
|
47
|
+
sum: sum,
|
|
48
|
+
min: min,
|
|
49
|
+
max: max
|
|
50
|
+
};
|
|
51
|
+
const CALCULATIONS_CONFIG = {
|
|
52
|
+
first: {
|
|
53
|
+
label: 'First',
|
|
54
|
+
description: 'First value'
|
|
55
|
+
},
|
|
56
|
+
last: {
|
|
57
|
+
label: 'Last',
|
|
58
|
+
description: 'Last value'
|
|
59
|
+
},
|
|
60
|
+
'first-number': {
|
|
61
|
+
label: 'First *',
|
|
62
|
+
description: 'First numeric value'
|
|
63
|
+
},
|
|
64
|
+
'last-number': {
|
|
65
|
+
label: 'Last *',
|
|
66
|
+
description: 'Last numeric value'
|
|
67
|
+
},
|
|
68
|
+
mean: {
|
|
69
|
+
label: 'Avg',
|
|
70
|
+
description: 'Average value excluding nulls'
|
|
71
|
+
},
|
|
72
|
+
sum: {
|
|
73
|
+
label: 'Sum',
|
|
74
|
+
description: 'The sum of all values'
|
|
75
|
+
},
|
|
76
|
+
min: {
|
|
77
|
+
label: 'Min',
|
|
78
|
+
description: 'Minimum value'
|
|
79
|
+
},
|
|
80
|
+
max: {
|
|
81
|
+
label: 'Max',
|
|
82
|
+
description: 'Maximum value'
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
function getCalculations(values, includeCalculations) {
|
|
86
|
+
const calculations = includeCalculations.reduce((initResult, calculation)=>{
|
|
87
|
+
initResult[calculation] = undefined;
|
|
88
|
+
return initResult;
|
|
89
|
+
}, {});
|
|
90
|
+
// We save these values as separate values instead of directly setting them
|
|
91
|
+
// in the calculations because they are needed by multiple calculations.
|
|
92
|
+
let nonNullCount = 0;
|
|
93
|
+
let sum = 0;
|
|
94
|
+
// We use this large function capable of performing one or more calculations
|
|
95
|
+
// in a single iteration of the data to minimize the performance impact of
|
|
96
|
+
// generating multiple calculations for large timeseries values. This is
|
|
97
|
+
// less optimized for certain single calculations when done in isolation (e.g.
|
|
98
|
+
// `last`), but will be more performant in the more expensive cases where
|
|
99
|
+
// multiple values are being used (e.g. table legend).
|
|
100
|
+
values.forEach((tuple, i)=>{
|
|
101
|
+
const value = tuple[1];
|
|
102
|
+
if (i === 0 && 'first' in calculations) {
|
|
103
|
+
calculations.first = value;
|
|
104
|
+
}
|
|
105
|
+
if (i === values.length - 1 && 'last' in calculations) {
|
|
106
|
+
calculations.last = value;
|
|
107
|
+
}
|
|
108
|
+
// Handling specific to non-null values.
|
|
109
|
+
if (typeof value === 'number') {
|
|
110
|
+
nonNullCount += 1;
|
|
111
|
+
sum += value;
|
|
112
|
+
if ('first-number' in calculations && calculations['first-number'] === undefined) {
|
|
113
|
+
// Save the first number we see.
|
|
114
|
+
calculations['first-number'] = value;
|
|
115
|
+
}
|
|
116
|
+
if ('last-number' in calculations) {
|
|
117
|
+
// Keep setting the numbers we see, which will eventually be set to the
|
|
118
|
+
// last number when finished iterating.
|
|
119
|
+
calculations['last-number'] = value;
|
|
120
|
+
}
|
|
121
|
+
if ('min' in calculations) {
|
|
122
|
+
if (typeof calculations.min !== 'number') {
|
|
123
|
+
// Init the first time we see a number
|
|
124
|
+
calculations.min = value;
|
|
125
|
+
} else {
|
|
126
|
+
// Use lowest value once initialized
|
|
127
|
+
calculations.min = Math.min(calculations.min, value);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if ('max' in calculations) {
|
|
131
|
+
if (typeof calculations.max !== 'number') {
|
|
132
|
+
// Init the first time we see a number
|
|
133
|
+
calculations.max = value;
|
|
134
|
+
} else {
|
|
135
|
+
// Use highest value once initialized
|
|
136
|
+
calculations.max = Math.max(calculations.max, value);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
// Set calculations that require iterating over all values.
|
|
142
|
+
if (nonNullCount > 0 && 'sum' in calculations) {
|
|
143
|
+
calculations.sum = sum;
|
|
144
|
+
}
|
|
145
|
+
if (nonNullCount > 0 && 'mean' in calculations) {
|
|
146
|
+
calculations.mean = sum / nonNullCount;
|
|
147
|
+
}
|
|
148
|
+
return calculations;
|
|
149
|
+
}
|
|
150
|
+
function getCalculation(values, calculation) {
|
|
151
|
+
return getCalculations(values, [
|
|
152
|
+
calculation
|
|
153
|
+
])[calculation];
|
|
154
|
+
}
|
|
155
|
+
function first(values) {
|
|
156
|
+
return getCalculation(values, 'first');
|
|
157
|
+
}
|
|
158
|
+
function last(values) {
|
|
159
|
+
return getCalculation(values, 'last');
|
|
160
|
+
}
|
|
161
|
+
function firstNumber(values) {
|
|
162
|
+
return getCalculation(values, 'first-number');
|
|
163
|
+
}
|
|
164
|
+
function lastNumber(values) {
|
|
165
|
+
return getCalculation(values, 'last-number');
|
|
166
|
+
}
|
|
167
|
+
function mean(values) {
|
|
168
|
+
return getCalculation(values, 'mean');
|
|
169
|
+
}
|
|
170
|
+
function sum(values) {
|
|
171
|
+
return getCalculation(values, 'sum');
|
|
172
|
+
}
|
|
173
|
+
function min(values) {
|
|
174
|
+
return getCalculation(values, 'min');
|
|
175
|
+
}
|
|
176
|
+
function max(values) {
|
|
177
|
+
return getCalculation(values, 'max');
|
|
178
|
+
}
|
package/dist/cjs/model/index.js
CHANGED
|
@@ -16,6 +16,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
16
16
|
});
|
|
17
17
|
_export_star(require("./datasource"), exports);
|
|
18
18
|
_export_star(require("./legend"), exports);
|
|
19
|
+
_export_star(require("./log-queries"), exports);
|
|
20
|
+
_export_star(require("./log-volume-utils"), exports);
|
|
19
21
|
_export_star(require("./panels"), exports);
|
|
20
22
|
_export_star(require("./plugins"), exports);
|
|
21
23
|
_export_star(require("./plugin-base"), exports);
|
|
@@ -24,6 +26,7 @@ _export_star(require("./time-series-queries"), exports);
|
|
|
24
26
|
_export_star(require("./trace-queries"), exports);
|
|
25
27
|
_export_star(require("./profile-queries"), exports);
|
|
26
28
|
_export_star(require("./variables"), exports);
|
|
29
|
+
_export_star(require("./calculations"), exports);
|
|
27
30
|
function _export_star(from, to) {
|
|
28
31
|
Object.keys(from).forEach(function(k) {
|
|
29
32
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
package/dist/cjs/model/legend.js
CHANGED
|
@@ -43,7 +43,8 @@ _export(exports, {
|
|
|
43
43
|
return validateLegendSpec;
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
-
const
|
|
46
|
+
const _components = require("@perses-dev/components");
|
|
47
|
+
const _calculations = require("./calculations");
|
|
47
48
|
const legendValues = [
|
|
48
49
|
'mean',
|
|
49
50
|
'first',
|
|
@@ -89,7 +90,7 @@ const LEGEND_SIZE_CONFIG = {
|
|
|
89
90
|
}
|
|
90
91
|
};
|
|
91
92
|
const LEGEND_VALUE_CONFIG = legendValues.reduce((config, value)=>{
|
|
92
|
-
config[value] =
|
|
93
|
+
config[value] = _calculations.CALCULATIONS_CONFIG[value];
|
|
93
94
|
return config;
|
|
94
95
|
}, {});
|
|
95
96
|
function validateLegendSpec(legend) {
|
|
@@ -97,13 +98,13 @@ function validateLegendSpec(legend) {
|
|
|
97
98
|
// undefined is valid since this is how legend is hidden by default
|
|
98
99
|
return true;
|
|
99
100
|
}
|
|
100
|
-
if (!(0,
|
|
101
|
+
if (!(0, _components.isValidLegendPosition)(legend.position)) {
|
|
101
102
|
return false;
|
|
102
103
|
}
|
|
103
|
-
if (legend.mode && !(0,
|
|
104
|
+
if (legend.mode && !(0, _components.isValidLegendMode)(legend.mode)) {
|
|
104
105
|
return false;
|
|
105
106
|
}
|
|
106
|
-
if (legend.size && !(0,
|
|
107
|
+
if (legend.size && !(0, _components.isValidLegendSize)(legend.size)) {
|
|
107
108
|
return false;
|
|
108
109
|
}
|
|
109
110
|
return true;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
// Target number of bars for log volume histogram
|
|
14
|
+
"use strict";
|
|
15
|
+
Object.defineProperty(exports, "__esModule", {
|
|
16
|
+
value: true
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "calculateVolumeInterval", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function() {
|
|
21
|
+
return calculateVolumeInterval;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const TARGET_HISTOGRAM_BARS = 40;
|
|
25
|
+
// Standard intervals for histogram calculations (in milliseconds)
|
|
26
|
+
const STANDARD_INTERVALS = [
|
|
27
|
+
{
|
|
28
|
+
ms: 1000,
|
|
29
|
+
label: '1s'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
ms: 2000,
|
|
33
|
+
label: '2s'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
ms: 5000,
|
|
37
|
+
label: '5s'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
ms: 10000,
|
|
41
|
+
label: '10s'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
ms: 15000,
|
|
45
|
+
label: '15s'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
ms: 30000,
|
|
49
|
+
label: '30s'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
ms: 60000,
|
|
53
|
+
label: '1m'
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
ms: 120000,
|
|
57
|
+
label: '2m'
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
ms: 300000,
|
|
61
|
+
label: '5m'
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
ms: 600000,
|
|
65
|
+
label: '10m'
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
ms: 900000,
|
|
69
|
+
label: '15m'
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
ms: 1800000,
|
|
73
|
+
label: '30m'
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
ms: 3600000,
|
|
77
|
+
label: '1h'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
ms: 7200000,
|
|
81
|
+
label: '2h'
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
ms: 21600000,
|
|
85
|
+
label: '6h'
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
ms: 43200000,
|
|
89
|
+
label: '12h'
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
ms: 86400000,
|
|
93
|
+
label: '1d'
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
ms: 604800000,
|
|
97
|
+
label: '7d'
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
ms: 2592000000,
|
|
101
|
+
label: '30d'
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
function calculateVolumeInterval(timeRangeMs) {
|
|
105
|
+
// Prefer smallest interval that produces 20-100 bars (optimal range)
|
|
106
|
+
for (const interval of STANDARD_INTERVALS){
|
|
107
|
+
const barCount = timeRangeMs / interval.ms;
|
|
108
|
+
if (barCount >= 20 && barCount <= 100) {
|
|
109
|
+
return interval.label;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Fallback: find closest to target if no interval fits optimal range
|
|
113
|
+
let bestInterval = STANDARD_INTERVALS[STANDARD_INTERVALS.length - 1];
|
|
114
|
+
let bestDistance = Infinity;
|
|
115
|
+
for (const interval of STANDARD_INTERVALS){
|
|
116
|
+
const barCount = timeRangeMs / interval.ms;
|
|
117
|
+
const distance = Math.abs(barCount - TARGET_HISTOGRAM_BARS);
|
|
118
|
+
if (distance < bestDistance) {
|
|
119
|
+
bestDistance = distance;
|
|
120
|
+
bestInterval = interval;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return bestInterval.label;
|
|
124
|
+
}
|
|
@@ -14,3 +14,13 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
+
Object.defineProperty(exports, "isTimeSeriesValueTuple", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return isTimeSeriesValueTuple;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
function isTimeSeriesValueTuple(data) {
|
|
24
|
+
if (data.length !== 2) return false;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
@@ -147,44 +147,45 @@ const getPluginRuntime = ()=>{
|
|
|
147
147
|
requiredVersion: '^5.5.0'
|
|
148
148
|
}
|
|
149
149
|
},
|
|
150
|
+
// TODO should we add @perses-dev/spec here ?
|
|
150
151
|
'@perses-dev/core': {
|
|
151
|
-
version: '0.53.
|
|
152
|
+
version: '0.53.1',
|
|
152
153
|
lib: ()=>require('@perses-dev/core'),
|
|
153
154
|
shareConfig: {
|
|
154
155
|
singleton: true,
|
|
155
|
-
requiredVersion: '^0.53.
|
|
156
|
+
requiredVersion: '^0.53.1'
|
|
156
157
|
}
|
|
157
158
|
},
|
|
158
159
|
'@perses-dev/components': {
|
|
159
|
-
version: '0.53.
|
|
160
|
+
version: '0.53.1',
|
|
160
161
|
lib: ()=>require('@perses-dev/components'),
|
|
161
162
|
shareConfig: {
|
|
162
163
|
singleton: true,
|
|
163
|
-
requiredVersion: '^0.53.
|
|
164
|
+
requiredVersion: '^0.53.1'
|
|
164
165
|
}
|
|
165
166
|
},
|
|
166
167
|
'@perses-dev/plugin-system': {
|
|
167
|
-
version: '0.53.
|
|
168
|
+
version: '0.53.1',
|
|
168
169
|
lib: ()=>require('@perses-dev/plugin-system'),
|
|
169
170
|
shareConfig: {
|
|
170
171
|
singleton: true,
|
|
171
|
-
requiredVersion: '^0.53.
|
|
172
|
+
requiredVersion: '^0.53.1'
|
|
172
173
|
}
|
|
173
174
|
},
|
|
174
175
|
'@perses-dev/explore': {
|
|
175
|
-
version: '0.53.
|
|
176
|
+
version: '0.53.1',
|
|
176
177
|
lib: ()=>require('@perses-dev/explore'),
|
|
177
178
|
shareConfig: {
|
|
178
179
|
singleton: true,
|
|
179
|
-
requiredVersion: '
|
|
180
|
+
requiredVersion: '^0.53.1'
|
|
180
181
|
}
|
|
181
182
|
},
|
|
182
183
|
'@perses-dev/dashboards': {
|
|
183
|
-
version: '0.53.
|
|
184
|
+
version: '0.53.1',
|
|
184
185
|
lib: ()=>require('@perses-dev/dashboards'),
|
|
185
186
|
shareConfig: {
|
|
186
187
|
singleton: true,
|
|
187
|
-
requiredVersion: '
|
|
188
|
+
requiredVersion: '^0.53.1'
|
|
188
189
|
}
|
|
189
190
|
},
|
|
190
191
|
// Below are the shared modules that are used by the plugins, this can be part of the SDK
|
|
@@ -39,7 +39,7 @@ _export(exports, {
|
|
|
39
39
|
});
|
|
40
40
|
const _jsxruntime = require("react/jsx-runtime");
|
|
41
41
|
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
42
|
-
const
|
|
42
|
+
const _spec = require("@perses-dev/spec");
|
|
43
43
|
const _reactquery = require("@tanstack/react-query");
|
|
44
44
|
const _refreshinterval = require("./refresh-interval");
|
|
45
45
|
function _getRequireWildcardCache(nodeInterop) {
|
|
@@ -97,21 +97,21 @@ function useTimeRange() {
|
|
|
97
97
|
function useSuggestedStepMs(width) {
|
|
98
98
|
const { absoluteTimeRange } = useTimeRange();
|
|
99
99
|
if (width === undefined) return 0;
|
|
100
|
-
return (0,
|
|
100
|
+
return (0, _spec.getSuggestedStepMs)(absoluteTimeRange, width);
|
|
101
101
|
}
|
|
102
102
|
function TimeRangeProvider(props) {
|
|
103
103
|
const { timeRange, refreshInterval, children, setTimeRange, setRefreshInterval } = props;
|
|
104
104
|
const queryClient = (0, _reactquery.useQueryClient)();
|
|
105
|
-
const [absoluteTimeRange, setAbsoluteTimeRange] = (0, _react.useState)((0,
|
|
105
|
+
const [absoluteTimeRange, setAbsoluteTimeRange] = (0, _react.useState)((0, _spec.isRelativeTimeRange)(timeRange) ? (0, _spec.toAbsoluteTimeRange)(timeRange) : timeRange);
|
|
106
106
|
const handleSetTimeRange = (0, _react.useCallback)((value)=>{
|
|
107
107
|
setTimeRange(value);
|
|
108
|
-
setAbsoluteTimeRange((0,
|
|
108
|
+
setAbsoluteTimeRange((0, _spec.isRelativeTimeRange)(value) ? (0, _spec.toAbsoluteTimeRange)(value) : value);
|
|
109
109
|
}, [
|
|
110
110
|
setTimeRange
|
|
111
111
|
]);
|
|
112
112
|
// Refresh is called when clicking on the refresh button, it refreshes all queries including variables
|
|
113
113
|
const refresh = (0, _react.useCallback)(()=>{
|
|
114
|
-
setAbsoluteTimeRange((0,
|
|
114
|
+
setAbsoluteTimeRange((0, _spec.isRelativeTimeRange)(timeRange) ? (0, _spec.toAbsoluteTimeRange)(timeRange) : timeRange);
|
|
115
115
|
queryClient.invalidateQueries({
|
|
116
116
|
queryKey: [
|
|
117
117
|
'query'
|
|
@@ -138,7 +138,7 @@ function TimeRangeProvider(props) {
|
|
|
138
138
|
]);
|
|
139
139
|
// Auto refresh is only refreshing queries of panels
|
|
140
140
|
const autoRefresh = (0, _react.useCallback)(()=>{
|
|
141
|
-
setAbsoluteTimeRange((0,
|
|
141
|
+
setAbsoluteTimeRange((0, _spec.isRelativeTimeRange)(timeRange) ? (0, _spec.toAbsoluteTimeRange)(timeRange) : timeRange);
|
|
142
142
|
queryClient.invalidateQueries({
|
|
143
143
|
queryKey: [
|
|
144
144
|
'query'
|
|
@@ -58,7 +58,7 @@ _export(exports, {
|
|
|
58
58
|
const _react = require("react");
|
|
59
59
|
const _usequeryparams = require("use-query-params");
|
|
60
60
|
const _datefns = require("date-fns");
|
|
61
|
-
const
|
|
61
|
+
const _spec = require("@perses-dev/spec");
|
|
62
62
|
/* Interprets an encoded string and returns either the string or null/undefined if not available */ function getEncodedValue(input, allowEmptyString) {
|
|
63
63
|
// '' or []
|
|
64
64
|
if (!input || input.length === 0 && (!allowEmptyString || allowEmptyString && input !== '')) {
|
|
@@ -78,7 +78,7 @@ function encodeTimeRangeValue(timeOptionValue) {
|
|
|
78
78
|
return timeOptionValue;
|
|
79
79
|
}
|
|
80
80
|
if (typeof timeOptionValue === 'string') {
|
|
81
|
-
if ((0,
|
|
81
|
+
if ((0, _spec.isDurationString)(timeOptionValue)) {
|
|
82
82
|
return timeOptionValue;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -87,7 +87,7 @@ function encodeTimeRangeValue(timeOptionValue) {
|
|
|
87
87
|
function decodeTimeRangeValue(input) {
|
|
88
88
|
const paramString = getEncodedValue(input);
|
|
89
89
|
if (!paramString) return null;
|
|
90
|
-
return (0,
|
|
90
|
+
return (0, _spec.isDurationString)(paramString) ? paramString : new Date(Number(paramString));
|
|
91
91
|
}
|
|
92
92
|
const TimeRangeParam = {
|
|
93
93
|
encode: encodeTimeRangeValue,
|
|
@@ -121,7 +121,7 @@ function useInitialTimeRange(dashboardDuration) {
|
|
|
121
121
|
return initialTimeRange;
|
|
122
122
|
}
|
|
123
123
|
const startStr = start.toString();
|
|
124
|
-
if ((0,
|
|
124
|
+
if ((0, _spec.isDurationString)(startStr)) {
|
|
125
125
|
initialTimeRange = {
|
|
126
126
|
pastDuration: startStr
|
|
127
127
|
};
|
|
@@ -148,7 +148,7 @@ function useTimeRangeParams(initialTimeRange) {
|
|
|
148
148
|
(0, _react.useEffect)(()=>{
|
|
149
149
|
// when dashboard loaded with no params, default to dashboard duration
|
|
150
150
|
if (!paramsLoaded && !start) {
|
|
151
|
-
if ((0,
|
|
151
|
+
if ((0, _spec.isRelativeTimeRange)(initialTimeRange)) {
|
|
152
152
|
setQuery({
|
|
153
153
|
start: initialTimeRange.pastDuration,
|
|
154
154
|
end: undefined
|
|
@@ -163,7 +163,7 @@ function useTimeRangeParams(initialTimeRange) {
|
|
|
163
163
|
setQuery
|
|
164
164
|
]);
|
|
165
165
|
const setTimeRange = (0, _react.useCallback)((value)=>{
|
|
166
|
-
if ((0,
|
|
166
|
+
if ((0, _spec.isRelativeTimeRange)(value)) {
|
|
167
167
|
setQuery({
|
|
168
168
|
start: value.pastDuration,
|
|
169
169
|
end: undefined
|
|
@@ -190,7 +190,7 @@ function useInitialRefreshInterval(dashboardDuration) {
|
|
|
190
190
|
return initialTimeRange;
|
|
191
191
|
}
|
|
192
192
|
const startStr = refresh.toString();
|
|
193
|
-
if ((0,
|
|
193
|
+
if ((0, _spec.isDurationString)(startStr)) {
|
|
194
194
|
initialTimeRange = startStr;
|
|
195
195
|
}
|
|
196
196
|
return initialTimeRange;
|