@grafana/scenes 1.2.0 → 1.3.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/CHANGELOG.md +23 -3
- package/dist/esm/components/NestedScene.js +31 -68
- package/dist/esm/components/NestedScene.js.map +1 -1
- package/dist/esm/components/VizPanel/VizPanel.js +12 -3
- package/dist/esm/components/VizPanel/VizPanel.js.map +1 -1
- package/dist/esm/components/layout/grid/SceneGridRow.js +5 -4
- package/dist/esm/components/layout/grid/SceneGridRow.js.map +1 -1
- package/dist/esm/core/SceneDataNode.js +8 -0
- package/dist/esm/core/SceneDataNode.js.map +1 -1
- package/dist/esm/core/sceneGraph/index.js +2 -1
- package/dist/esm/core/sceneGraph/index.js.map +1 -1
- package/dist/esm/core/sceneGraph/sceneGraph.js +25 -1
- package/dist/esm/core/sceneGraph/sceneGraph.js.map +1 -1
- package/dist/esm/core/types.js.map +1 -1
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/querying/SceneDataLayers.js +21 -0
- package/dist/esm/querying/SceneDataLayers.js.map +1 -0
- package/dist/esm/querying/SceneDataTransformer.js +13 -2
- package/dist/esm/querying/SceneDataTransformer.js.map +1 -1
- package/dist/esm/querying/SceneQueryRunner.js +70 -3
- package/dist/esm/querying/SceneQueryRunner.js.map +1 -1
- package/dist/esm/querying/layers/SceneDataLayerBase.js +80 -0
- package/dist/esm/querying/layers/SceneDataLayerBase.js.map +1 -0
- package/dist/esm/querying/layers/SceneDataLayerControls.js +66 -0
- package/dist/esm/querying/layers/SceneDataLayerControls.js.map +1 -0
- package/dist/esm/querying/layers/annotations/AnnotationsDataLayer.js +109 -0
- package/dist/esm/querying/layers/annotations/AnnotationsDataLayer.js.map +1 -0
- package/dist/esm/querying/layers/annotations/filterAnnotationsOperator.js +86 -0
- package/dist/esm/querying/layers/annotations/filterAnnotationsOperator.js.map +1 -0
- package/dist/esm/querying/layers/annotations/standardAnnotationQuery.js +94 -0
- package/dist/esm/querying/layers/annotations/standardAnnotationQuery.js.map +1 -0
- package/dist/esm/querying/layers/annotations/standardAnnotationsSupport.js +211 -0
- package/dist/esm/querying/layers/annotations/standardAnnotationsSupport.js.map +1 -0
- package/dist/esm/querying/layers/annotations/utils.js +58 -0
- package/dist/esm/querying/layers/annotations/utils.js.map +1 -0
- package/dist/esm/querying/layers/index.js +2 -0
- package/dist/esm/querying/layers/index.js.map +1 -0
- package/dist/esm/utils/ControlsLabel.js +43 -0
- package/dist/esm/utils/ControlsLabel.js.map +1 -0
- package/dist/esm/variables/components/VariableValueSelectors.js +13 -49
- package/dist/esm/variables/components/VariableValueSelectors.js.map +1 -1
- package/dist/index.d.ts +127 -10
- package/dist/index.js +2502 -1742
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { DataTopic, arrayToDataFrame } from '@grafana/data';
|
|
2
|
+
import { from, mergeMap, map, merge, mergeAll, reduce } from 'rxjs';
|
|
3
|
+
import { emptyPanelData } from '../../../core/SceneDataNode.js';
|
|
4
|
+
import { sceneGraph } from '../../../core/sceneGraph/index.js';
|
|
5
|
+
import { getDataSource } from '../../../utils/getDataSource.js';
|
|
6
|
+
import { SceneDataLayerBase } from '../SceneDataLayerBase.js';
|
|
7
|
+
import { executeAnnotationQuery } from './standardAnnotationQuery.js';
|
|
8
|
+
import { postProcessQueryResult } from './utils.js';
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __defProps = Object.defineProperties;
|
|
12
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
13
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
14
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
16
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
|
+
var __spreadValues = (a, b) => {
|
|
18
|
+
for (var prop in b || (b = {}))
|
|
19
|
+
if (__hasOwnProp.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
if (__getOwnPropSymbols)
|
|
22
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
23
|
+
if (__propIsEnum.call(b, prop))
|
|
24
|
+
__defNormalProp(a, prop, b[prop]);
|
|
25
|
+
}
|
|
26
|
+
return a;
|
|
27
|
+
};
|
|
28
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
29
|
+
class AnnotationsDataLayer extends SceneDataLayerBase {
|
|
30
|
+
constructor(initialState) {
|
|
31
|
+
super(__spreadValues({
|
|
32
|
+
isEnabled: true
|
|
33
|
+
}, initialState));
|
|
34
|
+
this.topic = DataTopic.Annotations;
|
|
35
|
+
}
|
|
36
|
+
onEnable() {
|
|
37
|
+
const timeRange = sceneGraph.getTimeRange(this);
|
|
38
|
+
this._timeRangeSub = timeRange.subscribeToState(() => {
|
|
39
|
+
this.runWithTimeRange(timeRange);
|
|
40
|
+
});
|
|
41
|
+
this.runLayer();
|
|
42
|
+
}
|
|
43
|
+
onDisable() {
|
|
44
|
+
var _a;
|
|
45
|
+
(_a = this._timeRangeSub) == null ? void 0 : _a.unsubscribe();
|
|
46
|
+
}
|
|
47
|
+
onActivate() {
|
|
48
|
+
const deactivationHandle = super.onActivate();
|
|
49
|
+
if (this.shouldRunQueriesOnActivate()) {
|
|
50
|
+
this.runLayer();
|
|
51
|
+
}
|
|
52
|
+
return () => {
|
|
53
|
+
deactivationHandle();
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
runLayer() {
|
|
57
|
+
const timeRange = sceneGraph.getTimeRange(this);
|
|
58
|
+
this.runWithTimeRange(timeRange);
|
|
59
|
+
}
|
|
60
|
+
async runWithTimeRange(timeRange) {
|
|
61
|
+
const { queries } = this.state;
|
|
62
|
+
if (this.querySub) {
|
|
63
|
+
this.querySub.unsubscribe();
|
|
64
|
+
}
|
|
65
|
+
if (!(queries == null ? void 0 : queries.length)) {
|
|
66
|
+
this.onDataReceived([]);
|
|
67
|
+
}
|
|
68
|
+
const observables = queries.filter((q) => q.enable).map((query) => {
|
|
69
|
+
return from(getDataSource(query.datasource || void 0, {})).pipe(
|
|
70
|
+
mergeMap((ds) => {
|
|
71
|
+
return executeAnnotationQuery(ds, timeRange, query);
|
|
72
|
+
}),
|
|
73
|
+
map((events) => {
|
|
74
|
+
return postProcessQueryResult(query, events || []);
|
|
75
|
+
})
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
this.querySub = merge(observables).pipe(
|
|
79
|
+
mergeAll(),
|
|
80
|
+
reduce((acc, value) => {
|
|
81
|
+
acc = acc.concat(value);
|
|
82
|
+
return acc;
|
|
83
|
+
})
|
|
84
|
+
).subscribe((result) => {
|
|
85
|
+
this.onDataReceived(result);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
onDataReceived(result) {
|
|
89
|
+
const stateUpdate = __spreadValues({}, emptyPanelData);
|
|
90
|
+
const df = arrayToDataFrame(result);
|
|
91
|
+
df.meta = __spreadProps(__spreadValues({}, df.meta), {
|
|
92
|
+
dataTopic: DataTopic.Annotations
|
|
93
|
+
});
|
|
94
|
+
stateUpdate.annotations = [df];
|
|
95
|
+
this.publishResults(stateUpdate, DataTopic.Annotations);
|
|
96
|
+
this.setState({
|
|
97
|
+
data: stateUpdate
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
shouldRunQueriesOnActivate() {
|
|
101
|
+
if (this.state.data) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { AnnotationsDataLayer };
|
|
109
|
+
//# sourceMappingURL=AnnotationsDataLayer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnnotationsDataLayer.js","sources":["../../../../../src/querying/layers/annotations/AnnotationsDataLayer.ts"],"sourcesContent":["import { AnnotationEvent, arrayToDataFrame, DataTopic, PanelData, AnnotationQuery } from '@grafana/data';\nimport { from, map, merge, mergeAll, mergeMap, reduce, Unsubscribable } from 'rxjs';\nimport { emptyPanelData } from '../../../core/SceneDataNode';\nimport { sceneGraph } from '../../../core/sceneGraph';\nimport { SceneDataLayerProvider, SceneTimeRangeLike, SceneDataLayerProviderState } from '../../../core/types';\nimport { getDataSource } from '../../../utils/getDataSource';\nimport { SceneDataLayerBase } from '../SceneDataLayerBase';\nimport { executeAnnotationQuery } from './standardAnnotationQuery';\nimport { postProcessQueryResult } from './utils';\n\ninterface AnnotationsDataLayerState extends SceneDataLayerProviderState {\n data?: PanelData;\n queries: AnnotationQuery[];\n}\n\nexport class AnnotationsDataLayer\n extends SceneDataLayerBase<AnnotationsDataLayerState>\n implements SceneDataLayerProvider\n{\n private _timeRangeSub: Unsubscribable | undefined;\n public topic = DataTopic.Annotations;\n\n public constructor(initialState: AnnotationsDataLayerState) {\n super({\n isEnabled: true,\n ...initialState,\n });\n }\n\n public onEnable(): void {\n const timeRange = sceneGraph.getTimeRange(this);\n\n this._timeRangeSub = timeRange.subscribeToState(() => {\n this.runWithTimeRange(timeRange);\n });\n\n this.runLayer();\n }\n\n public onDisable(): void {\n this._timeRangeSub?.unsubscribe();\n }\n\n protected onActivate() {\n const deactivationHandle = super.onActivate();\n\n if (this.shouldRunQueriesOnActivate()) {\n this.runLayer();\n }\n\n return () => {\n deactivationHandle();\n };\n }\n\n public runLayer() {\n const timeRange = sceneGraph.getTimeRange(this);\n this.runWithTimeRange(timeRange);\n }\n\n private async runWithTimeRange(timeRange: SceneTimeRangeLike) {\n const { queries } = this.state;\n\n if (this.querySub) {\n this.querySub.unsubscribe();\n }\n\n // Simple path when no queries exist\n if (!queries?.length) {\n this.onDataReceived([]);\n }\n\n const observables = queries\n // get enabled queries\n .filter((q) => q.enable)\n // execute queries & collect results\n .map((query) => {\n // TODO pass scopedVars\n return from(getDataSource(query.datasource || undefined, {})).pipe(\n mergeMap((ds) => {\n // TODO: There is a lot of AnnotationEvents[] -> DataFrame -> AnnotationEvents[] conversion going on here\n // This needs to be refactored an possibly optimized to use DataFrame only.\n // Seems like this is done to allow mappings to be applied by the data source using processEvents method.\n return executeAnnotationQuery(ds, timeRange, query);\n }),\n\n map((events) => {\n // Feels like this should be done in annotation processing, not as a separate step.\n return postProcessQueryResult(query, events || []);\n })\n );\n });\n\n this.querySub = merge(observables)\n .pipe(\n mergeAll(),\n // Combine all annotation results into a single array\n reduce((acc: AnnotationEvent[], value: AnnotationEvent[]) => {\n acc = acc.concat(value);\n return acc;\n })\n )\n .subscribe((result) => {\n this.onDataReceived(result);\n });\n }\n\n private onDataReceived(result: AnnotationEvent[]) {\n // This is only faking panel data\n const stateUpdate = { ...emptyPanelData };\n const df = arrayToDataFrame(result);\n df.meta = {\n ...df.meta,\n dataTopic: DataTopic.Annotations,\n };\n\n stateUpdate.annotations = [df];\n\n this.publishResults(stateUpdate, DataTopic.Annotations);\n\n this.setState({\n data: stateUpdate,\n });\n }\n\n private shouldRunQueriesOnActivate() {\n if (this.state.data) {\n return false;\n }\n\n return true;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeO,MAAM,6BACH,kBAEV,CAAA;AAAA,EAIS,YAAY,YAAyC,EAAA;AAC1D,IAAM,KAAA,CAAA,cAAA,CAAA;AAAA,MACJ,SAAW,EAAA,IAAA;AAAA,KAAA,EACR,YACJ,CAAA,CAAA,CAAA;AANH,IAAA,IAAA,CAAO,QAAQ,SAAU,CAAA,WAAA,CAAA;AAAA,GAOzB;AAAA,EAEO,QAAiB,GAAA;AACtB,IAAM,MAAA,SAAA,GAAY,UAAW,CAAA,YAAA,CAAa,IAAI,CAAA,CAAA;AAE9C,IAAK,IAAA,CAAA,aAAA,GAAgB,SAAU,CAAA,gBAAA,CAAiB,MAAM;AACpD,M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A;AAAA,MACZ,IAAM,EAAA,WAAA;AAAA,KACP,CAAA,CAAA;AAAA,GACH;AAAA,EAEQ,0BAA6B,GAAA;AACnC,IAAI,IAAA,IAAA,CAAK,MAAM,IAAM,EAAA;AACnB,MAAO,OAAA,KAAA,CAAA;AAAA,KACT;AAEA,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACF;;;;"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { map } from 'rxjs';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
const filterAnnotationsOperator = (filters) => (ctx) => (source) => {
|
|
23
|
+
return source.pipe(
|
|
24
|
+
map((data) => {
|
|
25
|
+
var _a;
|
|
26
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
const rows = /* @__PURE__ */ new Set();
|
|
30
|
+
for (const frame of data) {
|
|
31
|
+
for (let index = 0; index < frame.length; index++) {
|
|
32
|
+
if (rows.has(index)) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
let matching = true;
|
|
36
|
+
const panelIdField = frame.fields.find((f) => f.name === "panelId");
|
|
37
|
+
const sourceField = frame.fields.find((f) => f.name === "source");
|
|
38
|
+
if (sourceField) {
|
|
39
|
+
if (panelIdField && sourceField.values[index].type === "dashboard") {
|
|
40
|
+
matching = panelIdField.values[index] === filters.panelId;
|
|
41
|
+
}
|
|
42
|
+
const sourceFilter = sourceField.values[index].filter;
|
|
43
|
+
if (sourceFilter) {
|
|
44
|
+
const includes = ((_a = sourceFilter.ids) != null ? _a : []).includes(filters.panelId);
|
|
45
|
+
if (sourceFilter.exclude) {
|
|
46
|
+
if (includes) {
|
|
47
|
+
matching = false;
|
|
48
|
+
}
|
|
49
|
+
} else if (!includes) {
|
|
50
|
+
matching = false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (matching) {
|
|
55
|
+
rows.add(index);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const processed = [];
|
|
60
|
+
const frameLength = rows.size;
|
|
61
|
+
for (const frame of data) {
|
|
62
|
+
const fields = [];
|
|
63
|
+
for (const field of frame.fields) {
|
|
64
|
+
const buffer = [];
|
|
65
|
+
for (let index = 0; index < frame.length; index++) {
|
|
66
|
+
if (rows.has(index)) {
|
|
67
|
+
buffer.push(field.values[index]);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
fields.push(__spreadProps(__spreadValues({}, field), {
|
|
72
|
+
values: buffer
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
processed.push(__spreadProps(__spreadValues({}, frame), {
|
|
76
|
+
fields,
|
|
77
|
+
length: frameLength
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
return processed;
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export { filterAnnotationsOperator };
|
|
86
|
+
//# sourceMappingURL=filterAnnotationsOperator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterAnnotationsOperator.js","sources":["../../../../../src/querying/layers/annotations/filterAnnotationsOperator.ts"],"sourcesContent":["import { CustomTransformOperator, DataFrame, Field } from '@grafana/data';\nimport { map } from 'rxjs';\nimport { DataLayerFilter } from '../../../core/types';\n\n// Provided SceneDataLayerProviderResult is an array of DataFrames.\nexport const filterAnnotationsOperator: (filters: DataLayerFilter) => CustomTransformOperator =\n (filters) => (ctx) => (source) => {\n return source.pipe(\n map((data) => {\n if (!Array.isArray(data) || data.length === 0) {\n return data;\n }\n\n const rows = new Set<number>();\n\n for (const frame of data) {\n for (let index = 0; index < frame.length; index++) {\n if (rows.has(index)) {\n continue;\n }\n let matching = true;\n\n // Let's call those standard fields that annotations data frame has.\n // panelId is a standard field, but it's not always present. It's added to annotations that were added to a particular panel.\n const panelIdField = frame.fields.find((f) => f.name === 'panelId');\n // Source field contains annotation definition, with type and filters included.\n const sourceField = frame.fields.find((f) => f.name === 'source');\n\n if (sourceField) {\n // Here we are filtering Grafana annotations that were added to a particular panel.\n if (panelIdField && sourceField.values[index].type === 'dashboard') {\n matching = panelIdField.values[index] === filters.panelId;\n }\n\n const sourceFilter = sourceField.values[index].filter;\n\n // Here we are filtering based on annotation filter definition.\n // Those fitlers are: Show annotation in selected panels, Exclude annotation from selected panels.\n if (sourceFilter) {\n const includes = (sourceFilter.ids ?? []).includes(filters.panelId);\n if (sourceFilter.exclude) {\n if (includes) {\n matching = false;\n }\n } else if (!includes) {\n matching = false;\n }\n }\n }\n\n if (matching) {\n rows.add(index);\n }\n }\n }\n\n const processed: DataFrame[] = [];\n const frameLength = rows.size;\n\n for (const frame of data) {\n const fields: Field[] = [];\n\n for (const field of frame.fields) {\n const buffer = [];\n\n for (let index = 0; index < frame.length; index++) {\n if (rows.has(index)) {\n buffer.push(field.values[index]);\n continue;\n }\n }\n\n fields.push({\n ...field,\n values: buffer,\n });\n }\n\n processed.push({\n ...frame,\n fields: fields,\n length: frameLength,\n });\n }\n\n return processed;\n })\n );\n };\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAKO,MAAM,4BACX,CAAC,OAAA,KAAY,CAAC,GAAA,KAAQ,CAAC,MAAW,KAAA;AAChC,EAAA,OAAO,MAAO,CAAA,IAAA;AAAA,IACZ,GAAA,CAAI,CAAC,IAAS,KAAA;AARpB,MAAA,IAAA,EAAA,CAAA;AASQ,MAAA,IAAI,CAAC,KAAM,CAAA,OAAA,CAAQ,IAAI,CAAK,IAAA,IAAA,CAAK,WAAW,CAAG,EAAA;AAC7C,QAAO,OAAA,IAAA,CAAA;AAAA,OACT;AAEA,MAAM,MAAA,IAAA,uBAAW,GAAY,EAAA,CAAA;AAE7B,MAAA,KAAA,MAAW,SAAS,IAAM,EAAA;AACxB,QAAA,KAAA,IAAS,KAAQ,GAAA,CAAA,EAAG,KAAQ,GAAA,KAAA,CAAM,QAAQ,KAAS,EAAA,EAAA;AACjD,UAAI,IAAA,IAAA,CAAK,GAAI,CAAA,KAAK,CAAG,EAAA;AACnB,YAAA,SAAA;AAAA,WACF;AACA,UAAA,IAAI,QAAW,GAAA,IAAA,CAAA;AAIf,UAAM,MAAA,YAAA,GAAe,MAAM,MAAO,CAAA,IAAA,CAAK,CAAC,CAAM,KAAA,CAAA,CAAE,SAAS,SAAS,CAAA,CAAA;AAElE,UAAM,MAAA,WAAA,GAAc,MAAM,MAAO,CAAA,IAAA,CAAK,CAAC,CAAM,KAAA,CAAA,CAAE,SAAS,QAAQ,CAAA,CAAA;AAEhE,UAAA,IAAI,WAAa,EAAA;AAEf,YAAA,IAAI,YAAgB,IAAA,WAAA,CAAY,MAAO,CAAA,KAAA,CAAA,CAAO,SAAS,WAAa,EAAA;AAClE,cAAW,QAAA,GAAA,YAAA,CAAa,MA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AAK,iCACP,KADO,CAAA,EAAA;AAAA,YAEV,MAAQ,EAAA,MAAA;AAAA,WACT,CAAA,CAAA,CAAA;AAAA,SACH;AAEA,QAAU,SAAA,CAAA,IAAA,CAAK,iCACV,KADU,CAAA,EAAA;AAAA,UAEb,MAAA;AAAA,UACA,MAAQ,EAAA,WAAA;AAAA,SACT,CAAA,CAAA,CAAA;AAAA,OACH;AAEA,MAAO,OAAA,SAAA,CAAA;AAAA,KACR,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { from, of } from 'rxjs';
|
|
2
|
+
import { map, mergeMap } from 'rxjs/operators';
|
|
3
|
+
import { rangeUtil, CoreApp, DataTopic } from '@grafana/data';
|
|
4
|
+
import { getRunRequest } from '@grafana/runtime';
|
|
5
|
+
import { shouldUseLegacyRunner, standardAnnotationSupport } from './standardAnnotationsSupport.js';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defProps = Object.defineProperties;
|
|
9
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
let counter = 100;
|
|
27
|
+
function getNextRequestId() {
|
|
28
|
+
return "AQ" + counter++;
|
|
29
|
+
}
|
|
30
|
+
function executeAnnotationQuery(datasource, timeRange, query) {
|
|
31
|
+
var _a;
|
|
32
|
+
if (datasource.annotationQuery && shouldUseLegacyRunner(datasource)) {
|
|
33
|
+
console.warn("Using deprecated annotationQuery method, please upgrade your datasource");
|
|
34
|
+
return from(
|
|
35
|
+
datasource.annotationQuery({
|
|
36
|
+
range: timeRange.state.value,
|
|
37
|
+
rangeRaw: timeRange.state.value.raw,
|
|
38
|
+
annotation: query,
|
|
39
|
+
dashboard: {}
|
|
40
|
+
})
|
|
41
|
+
).pipe(map((events) => events));
|
|
42
|
+
}
|
|
43
|
+
const processor = __spreadValues(__spreadValues({}, standardAnnotationSupport), datasource.annotations);
|
|
44
|
+
const annotationWithDefaults = __spreadValues(__spreadValues({}, (_a = processor.getDefaultQuery) == null ? void 0 : _a.call(processor)), query);
|
|
45
|
+
const annotation = processor.prepareAnnotation(annotationWithDefaults);
|
|
46
|
+
if (!annotation) {
|
|
47
|
+
return of([]);
|
|
48
|
+
}
|
|
49
|
+
const processedQuery = processor.prepareQuery(annotation);
|
|
50
|
+
if (!processedQuery) {
|
|
51
|
+
return of([]);
|
|
52
|
+
}
|
|
53
|
+
const maxDataPoints = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
|
|
54
|
+
const interval = rangeUtil.calculateInterval(timeRange.state.value, maxDataPoints, datasource.interval);
|
|
55
|
+
const scopedVars = {
|
|
56
|
+
__interval: { text: interval.interval, value: interval.interval },
|
|
57
|
+
__interval_ms: { text: interval.intervalMs.toString(), value: interval.intervalMs },
|
|
58
|
+
__annotation: { text: annotation.name, value: annotation }
|
|
59
|
+
};
|
|
60
|
+
const queryRequest = __spreadProps(__spreadValues({
|
|
61
|
+
startTime: Date.now(),
|
|
62
|
+
requestId: getNextRequestId(),
|
|
63
|
+
range: timeRange.state.value,
|
|
64
|
+
maxDataPoints,
|
|
65
|
+
scopedVars
|
|
66
|
+
}, interval), {
|
|
67
|
+
app: CoreApp.Dashboard,
|
|
68
|
+
timezone: timeRange.getTimeZone(),
|
|
69
|
+
targets: [
|
|
70
|
+
__spreadProps(__spreadValues({}, processedQuery), {
|
|
71
|
+
refId: "Anno"
|
|
72
|
+
})
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
const runRequest = getRunRequest();
|
|
76
|
+
return runRequest(datasource, queryRequest).pipe(
|
|
77
|
+
mergeMap((panelData) => {
|
|
78
|
+
const data = (panelData == null ? void 0 : panelData.series.length) ? panelData.series : panelData.annotations;
|
|
79
|
+
if (!(data == null ? void 0 : data.length)) {
|
|
80
|
+
return of([]);
|
|
81
|
+
}
|
|
82
|
+
data.forEach((frame) => {
|
|
83
|
+
var _a2;
|
|
84
|
+
if (!((_a2 = frame.meta) == null ? void 0 : _a2.dataTopic)) {
|
|
85
|
+
frame.meta = __spreadProps(__spreadValues({}, frame.meta || {}), { dataTopic: DataTopic.Annotations });
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return processor.processEvents(annotation, data).pipe(map((events) => events != null ? events : []));
|
|
89
|
+
})
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { executeAnnotationQuery };
|
|
94
|
+
//# sourceMappingURL=standardAnnotationQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standardAnnotationQuery.js","sources":["../../../../../src/querying/layers/annotations/standardAnnotationQuery.ts"],"sourcesContent":["import { from, Observable, of } from 'rxjs';\nimport { map, mergeMap } from 'rxjs/operators';\n\nimport {\n AnnotationEvent,\n AnnotationQuery,\n CoreApp,\n DataQueryRequest,\n DataSourceApi,\n DataTopic,\n PanelModel,\n rangeUtil,\n ScopedVars,\n} from '@grafana/data';\n\nimport { getRunRequest } from '@grafana/runtime';\nimport { shouldUseLegacyRunner, standardAnnotationSupport } from './standardAnnotationsSupport';\nimport { Dashboard } from '@grafana/schema';\nimport { SceneTimeRangeLike } from '../../../core/types';\nlet counter = 100;\nfunction getNextRequestId() {\n return 'AQ' + counter++;\n}\n\nexport interface AnnotationQueryOptions {\n dashboard: Dashboard;\n panel: PanelModel;\n}\n\nexport function executeAnnotationQuery(\n datasource: DataSourceApi,\n timeRange: SceneTimeRangeLike,\n query: AnnotationQuery\n): Observable<AnnotationEvent[]> {\n // Check if we should use the old annotationQuery method\n if (datasource.annotationQuery && shouldUseLegacyRunner(datasource)) {\n console.warn('Using deprecated annotationQuery method, please upgrade your datasource');\n return from(\n datasource.annotationQuery({\n range: timeRange.state.value,\n rangeRaw: timeRange.state.value.raw,\n annotation: query,\n dashboard: {},\n })\n ).pipe(map((events) => events));\n }\n\n // Standard API for annotations support. Spread in datasource annotations support overrides\n const processor = {\n ...standardAnnotationSupport,\n ...datasource.annotations,\n };\n\n const annotationWithDefaults = {\n // Default query provided by a data source\n ...processor.getDefaultQuery?.(),\n ...query,\n };\n\n // Data source query migrations\n const annotation = processor.prepareAnnotation!(annotationWithDefaults);\n if (!annotation) {\n return of([]);\n }\n\n const processedQuery = processor.prepareQuery!(annotation);\n if (!processedQuery) {\n return of([]);\n }\n\n // No more points than pixels\n const maxDataPoints = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;\n\n // Add interval to annotation queries\n const interval = rangeUtil.calculateInterval(timeRange.state.value, maxDataPoints, datasource.interval);\n\n const scopedVars: ScopedVars = {\n __interval: { text: interval.interval, value: interval.interval },\n __interval_ms: { text: interval.intervalMs.toString(), value: interval.intervalMs },\n __annotation: { text: annotation.name, value: annotation },\n };\n\n const queryRequest: DataQueryRequest = {\n startTime: Date.now(),\n requestId: getNextRequestId(),\n range: timeRange.state.value,\n maxDataPoints,\n scopedVars,\n ...interval,\n app: CoreApp.Dashboard,\n timezone: timeRange.getTimeZone(),\n targets: [\n {\n ...processedQuery,\n refId: 'Anno',\n },\n ],\n // TODO\n //publicDashboardAccessToken: options.dashboard.meta.publicDashboardAccessToken,\n };\n\n const runRequest = getRunRequest();\n\n return runRequest(datasource, queryRequest).pipe(\n mergeMap((panelData) => {\n // Some annotations set the topic already\n const data = panelData?.series.length ? panelData.series : panelData.annotations;\n if (!data?.length) {\n return of([]);\n }\n\n // Add data topic to each frame\n data.forEach((frame) => {\n // If data topic has not been provided by the data source, make sure it's set correctly\n if (!frame.meta?.dataTopic) {\n frame.meta = { ...(frame.meta || {}), dataTopic: DataTopic.Annotations };\n }\n });\n\n return processor.processEvents!(annotation, data).pipe(map((events) => events ?? []));\n })\n );\n}\n"],"names":["_a"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,IAAI,OAAU,GAAA,GAAA,CAAA;AACd,SAAS,gBAAmB,GAAA;AAC1B,EAAA,OAAO,IAAO,GAAA,OAAA,EAAA,CAAA;AAChB,CAAA;AAOgB,SAAA,sBAAA,CACd,UACA,EAAA,SAAA,EACA,KAC+B,EAAA;AAjCjC,EAAA,IAAA,EAAA,CAAA;AAmCE,EAAA,IAAI,UAAW,CAAA,eAAA,IAAmB,qBAAsB,CAAA,UAAU,CAAG,EAAA;AACnE,IAAA,OAAA,CAAQ,KAAK,yEAAyE,CAAA,CAAA;AACtF,IAAO,OAAA,IAAA;AAAA,MACL,WAAW,eAAgB,CAAA;AAAA,QACzB,KAAA,EAAO,UAAU,KAAM,CAAA,KAAA;AAAA,QACvB,QAAA,EAAU,SAAU,CAAA,KAAA,CAAM,KAAM,CAAA,GAAA;AAAA,QAChC,UAAY,EAAA,KAAA;AAAA,QACZ,WAAW,EAAC;AAAA,OACb,CAAA;AAAA,MACD,IAAK,CAAA,GAAA,CAAI,CAAC,MAAA,KAAW,MAAM,CAAC,CAAA,CAAA;AAAA,GAChC;AAGA,EAAM,MAAA,SAAA,GAAY,cACb,CAAA,cAAA,CAAA,EAAA,EAAA,yBAAA,CAAA,EACA,UAAW,CAAA,WAAA,CAAA,C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AI,CAAA,CAAC,MAAW,KAAA,MAAA,IAAA,IAAA,GAAA,MAAA,GAAU,EAAE,CAAC,CAAA,CAAA;AAAA,KACrF,CAAA;AAAA,GACH,CAAA;AACF;;;;"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { isString } from 'lodash';
|
|
2
|
+
import { of } from 'rxjs';
|
|
3
|
+
import { map, mergeMap } from 'rxjs/operators';
|
|
4
|
+
import { FieldType, getFieldDisplayName, AnnotationEventFieldSource, standardTransformers } from '@grafana/data';
|
|
5
|
+
import { config } from '@grafana/runtime';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defProps = Object.defineProperties;
|
|
9
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
var __objRest = (source, exclude) => {
|
|
27
|
+
var target = {};
|
|
28
|
+
for (var prop in source)
|
|
29
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
30
|
+
target[prop] = source[prop];
|
|
31
|
+
if (source != null && __getOwnPropSymbols)
|
|
32
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
33
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
34
|
+
target[prop] = source[prop];
|
|
35
|
+
}
|
|
36
|
+
return target;
|
|
37
|
+
};
|
|
38
|
+
const standardAnnotationSupport = {
|
|
39
|
+
prepareAnnotation: (json) => {
|
|
40
|
+
if (isString(json == null ? void 0 : json.query)) {
|
|
41
|
+
const _a = json, { query } = _a, rest = __objRest(_a, ["query"]);
|
|
42
|
+
return __spreadProps(__spreadValues({}, rest), {
|
|
43
|
+
target: {
|
|
44
|
+
refId: "annotation_query",
|
|
45
|
+
query
|
|
46
|
+
},
|
|
47
|
+
mappings: {}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return json;
|
|
51
|
+
},
|
|
52
|
+
prepareQuery: (anno) => anno.target,
|
|
53
|
+
processEvents: (anno, data) => {
|
|
54
|
+
return getAnnotationsFromData(data, anno.mappings);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
function singleFrameFromPanelData() {
|
|
58
|
+
return (source) => source.pipe(
|
|
59
|
+
mergeMap((data) => {
|
|
60
|
+
if (!(data == null ? void 0 : data.length)) {
|
|
61
|
+
return of(void 0);
|
|
62
|
+
}
|
|
63
|
+
if (data.length === 1) {
|
|
64
|
+
return of(data[0]);
|
|
65
|
+
}
|
|
66
|
+
const ctx = {
|
|
67
|
+
interpolate: (v) => v
|
|
68
|
+
};
|
|
69
|
+
return of(data).pipe(
|
|
70
|
+
standardTransformers.mergeTransformer.operator({}, ctx),
|
|
71
|
+
map((d) => d[0])
|
|
72
|
+
);
|
|
73
|
+
})
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
const annotationEventNames = [
|
|
77
|
+
{
|
|
78
|
+
key: "time",
|
|
79
|
+
field: (frame) => frame.fields.find((f) => f.type === FieldType.time),
|
|
80
|
+
placeholder: "time, or the first time field"
|
|
81
|
+
},
|
|
82
|
+
{ key: "timeEnd", help: "When this field is defined, the annotation will be treated as a range" },
|
|
83
|
+
{
|
|
84
|
+
key: "title"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
key: "text",
|
|
88
|
+
field: (frame) => frame.fields.find((f) => f.type === FieldType.string),
|
|
89
|
+
placeholder: "text, or the first text field"
|
|
90
|
+
},
|
|
91
|
+
{ key: "tags", split: ",", help: "The results will be split on comma (,)" },
|
|
92
|
+
{
|
|
93
|
+
key: "id"
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
const publicDashboardEventNames = [
|
|
97
|
+
{
|
|
98
|
+
key: "color"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
key: "isRegion"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
key: "source"
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
const alertEventAndAnnotationFields = [
|
|
108
|
+
...config.isPublicDashboardView ? publicDashboardEventNames : [],
|
|
109
|
+
...annotationEventNames,
|
|
110
|
+
{ key: "userId" },
|
|
111
|
+
{ key: "login" },
|
|
112
|
+
{ key: "email" },
|
|
113
|
+
{ key: "prevState" },
|
|
114
|
+
{ key: "newState" },
|
|
115
|
+
{ key: "data" },
|
|
116
|
+
{ key: "panelId" },
|
|
117
|
+
{ key: "alertId" },
|
|
118
|
+
{ key: "dashboardId" },
|
|
119
|
+
{ key: "dashboardUID" }
|
|
120
|
+
];
|
|
121
|
+
function getAnnotationsFromData(data, options) {
|
|
122
|
+
return of(data).pipe(
|
|
123
|
+
singleFrameFromPanelData(),
|
|
124
|
+
map((frame) => {
|
|
125
|
+
if (!(frame == null ? void 0 : frame.length)) {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
let hasTime = false;
|
|
129
|
+
let hasText = false;
|
|
130
|
+
const byName = {};
|
|
131
|
+
for (const f of frame.fields) {
|
|
132
|
+
const name = getFieldDisplayName(f, frame);
|
|
133
|
+
byName[name.toLowerCase()] = f;
|
|
134
|
+
}
|
|
135
|
+
if (!options) {
|
|
136
|
+
options = {};
|
|
137
|
+
}
|
|
138
|
+
const fields = [];
|
|
139
|
+
for (const evts of alertEventAndAnnotationFields) {
|
|
140
|
+
const opt = options[evts.key] || {};
|
|
141
|
+
if (opt.source === AnnotationEventFieldSource.Skip) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const setter = { key: evts.key, split: evts.split };
|
|
145
|
+
if (opt.source === AnnotationEventFieldSource.Text) {
|
|
146
|
+
setter.text = opt.value;
|
|
147
|
+
} else {
|
|
148
|
+
const lower = (opt.value || evts.key).toLowerCase();
|
|
149
|
+
setter.field = byName[lower];
|
|
150
|
+
if (!setter.field && evts.field) {
|
|
151
|
+
setter.field = evts.field(frame);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (setter.field || setter.text) {
|
|
155
|
+
fields.push(setter);
|
|
156
|
+
if (setter.key === "time") {
|
|
157
|
+
hasTime = true;
|
|
158
|
+
} else if (setter.key === "text") {
|
|
159
|
+
hasText = true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!hasTime || !hasText) {
|
|
164
|
+
console.error("Cannot process annotation fields. No time or text present.");
|
|
165
|
+
return [];
|
|
166
|
+
}
|
|
167
|
+
const events = [];
|
|
168
|
+
for (let i = 0; i < frame.length; i++) {
|
|
169
|
+
const anno = {
|
|
170
|
+
type: "default",
|
|
171
|
+
color: "red"
|
|
172
|
+
};
|
|
173
|
+
for (const f of fields) {
|
|
174
|
+
let v = void 0;
|
|
175
|
+
if (f.text) {
|
|
176
|
+
v = f.text;
|
|
177
|
+
} else if (f.field) {
|
|
178
|
+
v = f.field.values.get(i);
|
|
179
|
+
if (v !== void 0 && f.regex) {
|
|
180
|
+
const match = f.regex.exec(v);
|
|
181
|
+
if (match) {
|
|
182
|
+
v = match[1] ? match[1] : match[0];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (v !== null && v !== void 0) {
|
|
187
|
+
if (f.split && typeof v === "string") {
|
|
188
|
+
v = v.split(",");
|
|
189
|
+
}
|
|
190
|
+
anno[f.key] = v;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
events.push(anno);
|
|
194
|
+
}
|
|
195
|
+
return events;
|
|
196
|
+
})
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
const legacyRunner = [
|
|
200
|
+
"prometheus",
|
|
201
|
+
"loki",
|
|
202
|
+
"elasticsearch",
|
|
203
|
+
"grafana-opensearch-datasource"
|
|
204
|
+
];
|
|
205
|
+
function shouldUseLegacyRunner(datasource) {
|
|
206
|
+
const { type } = datasource;
|
|
207
|
+
return !datasource.annotations || legacyRunner.includes(type);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export { annotationEventNames, getAnnotationsFromData, publicDashboardEventNames, shouldUseLegacyRunner, singleFrameFromPanelData, standardAnnotationSupport };
|
|
211
|
+
//# sourceMappingURL=standardAnnotationsSupport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standardAnnotationsSupport.js","sources":["../../../../../src/querying/layers/annotations/standardAnnotationsSupport.ts"],"sourcesContent":["import { isString } from 'lodash';\nimport { Observable, of, OperatorFunction } from 'rxjs';\nimport { map, mergeMap } from 'rxjs/operators';\n\nimport {\n AnnotationEvent,\n AnnotationEventFieldSource,\n AnnotationEventMappings,\n AnnotationQuery,\n AnnotationSupport,\n DataFrame,\n DataSourceApi,\n DataTransformContext,\n Field,\n FieldType,\n getFieldDisplayName,\n KeyValue,\n standardTransformers,\n} from '@grafana/data';\nimport { config } from '@grafana/runtime';\n\nexport const standardAnnotationSupport: AnnotationSupport = {\n /**\n * Assume the stored value is standard model.\n */\n prepareAnnotation: (json: any) => {\n if (isString(json?.query)) {\n const { query, ...rest } = json;\n return {\n ...rest,\n target: {\n refId: 'annotation_query',\n query,\n },\n mappings: {},\n };\n }\n return json as AnnotationQuery;\n },\n\n /**\n * Default will just return target from the annotation.\n */\n prepareQuery: (anno: AnnotationQuery) => anno.target,\n\n /**\n * Provides default processing from dataFrame to annotation events.\n */\n processEvents: (anno: AnnotationQuery, data: DataFrame[]) => {\n return getAnnotationsFromData(data, anno.mappings);\n },\n};\n\n/**\n * Flatten all frames into a single frame with mergeTransformer.\n */\n\nexport function singleFrameFromPanelData(): OperatorFunction<DataFrame[], DataFrame | undefined> {\n return (source) =>\n source.pipe(\n mergeMap((data) => {\n if (!data?.length) {\n return of(undefined);\n }\n\n if (data.length === 1) {\n return of(data[0]);\n }\n\n const ctx: DataTransformContext = {\n interpolate: (v: string) => v,\n };\n\n return of(data).pipe(\n standardTransformers.mergeTransformer.operator({}, ctx),\n map((d) => d[0])\n );\n })\n );\n}\n\ninterface AnnotationEventFieldSetter {\n key: keyof AnnotationEvent;\n field?: Field;\n text?: string;\n regex?: RegExp;\n split?: string; // for tags\n}\n\nexport interface AnnotationFieldInfo {\n key: keyof AnnotationEvent;\n\n split?: string;\n field?: (frame: DataFrame) => Field | undefined;\n placeholder?: string;\n help?: string;\n}\n\n// These fields get added to the standard UI\nexport const annotationEventNames: AnnotationFieldInfo[] = [\n {\n key: 'time',\n field: (frame: DataFrame) => frame.fields.find((f) => f.type === FieldType.time),\n placeholder: 'time, or the first time field',\n },\n { key: 'timeEnd', help: 'When this field is defined, the annotation will be treated as a range' },\n {\n key: 'title',\n },\n {\n key: 'text',\n field: (frame: DataFrame) => frame.fields.find((f) => f.type === FieldType.string),\n placeholder: 'text, or the first text field',\n },\n { key: 'tags', split: ',', help: 'The results will be split on comma (,)' },\n {\n key: 'id',\n },\n];\n\nexport const publicDashboardEventNames: AnnotationFieldInfo[] = [\n {\n key: 'color',\n },\n {\n key: 'isRegion',\n },\n {\n key: 'source',\n },\n];\n\n// Given legacy infrastructure, alert events are passed though the same annotation\n// pipeline, but include fields that should not be exposed generally\nconst alertEventAndAnnotationFields: AnnotationFieldInfo[] = [\n ...(config.isPublicDashboardView ? publicDashboardEventNames : []),\n ...annotationEventNames,\n { key: 'userId' },\n { key: 'login' },\n { key: 'email' },\n { key: 'prevState' },\n { key: 'newState' },\n { key: 'data' as any },\n { key: 'panelId' },\n { key: 'alertId' },\n { key: 'dashboardId' },\n { key: 'dashboardUID' },\n];\n\nexport function getAnnotationsFromData(\n data: DataFrame[],\n options?: AnnotationEventMappings\n): Observable<AnnotationEvent[]> {\n return of(data).pipe(\n singleFrameFromPanelData(),\n map((frame) => {\n if (!frame?.length) {\n return [];\n }\n\n let hasTime = false;\n let hasText = false;\n const byName: KeyValue<Field> = {};\n\n for (const f of frame.fields) {\n const name = getFieldDisplayName(f, frame);\n byName[name.toLowerCase()] = f;\n }\n\n if (!options) {\n options = {};\n }\n\n const fields: AnnotationEventFieldSetter[] = [];\n\n for (const evts of alertEventAndAnnotationFields) {\n const opt = options[evts.key] || {}; //AnnotationEventFieldMapping\n\n if (opt.source === AnnotationEventFieldSource.Skip) {\n continue;\n }\n\n const setter: AnnotationEventFieldSetter = { key: evts.key, split: evts.split };\n\n if (opt.source === AnnotationEventFieldSource.Text) {\n setter.text = opt.value;\n } else {\n const lower = (opt.value || evts.key).toLowerCase();\n setter.field = byName[lower];\n\n if (!setter.field && evts.field) {\n setter.field = evts.field(frame);\n }\n }\n\n if (setter.field || setter.text) {\n fields.push(setter);\n if (setter.key === 'time') {\n hasTime = true;\n } else if (setter.key === 'text') {\n hasText = true;\n }\n }\n }\n\n if (!hasTime || !hasText) {\n console.error('Cannot process annotation fields. No time or text present.');\n return [];\n }\n\n // Add each value to the string\n const events: AnnotationEvent[] = [];\n\n for (let i = 0; i < frame.length; i++) {\n const anno: AnnotationEvent = {\n type: 'default',\n color: 'red',\n };\n\n for (const f of fields) {\n let v: any = undefined;\n\n if (f.text) {\n v = f.text; // TODO support templates!\n } else if (f.field) {\n v = f.field.values.get(i);\n if (v !== undefined && f.regex) {\n const match = f.regex.exec(v);\n if (match) {\n v = match[1] ? match[1] : match[0];\n }\n }\n }\n\n if (v !== null && v !== undefined) {\n if (f.split && typeof v === 'string') {\n v = v.split(',');\n }\n (anno as any)[f.key] = v;\n }\n }\n\n events.push(anno);\n }\n return events;\n })\n );\n}\n\n// These opt outs are here only for quicker and easier migration to react based annotations editors and because\n// annotation support API needs some work to support less \"standard\" editors like prometheus and here it is not\n// polluting public API.\n\nconst legacyRunner = [\n 'prometheus',\n 'loki',\n 'elasticsearch',\n 'grafana-opensearch-datasource', // external\n];\n\n/**\n * Use legacy runner. Used only as an escape hatch for easier transition to React based annotation editor.\n */\nexport function shouldUseLegacyRunner(datasource: DataSourceApi): boolean {\n const { type } = datasource;\n return !datasource.annotations || legacyRunner.includes(type);\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBO,MAAM,yBAA+C,GAAA;AAAA,EAI1D,iBAAA,EAAmB,CAAC,IAAc,KAAA;AAChC,IAAI,IAAA,QAAA,CAAS,IAAM,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,IAAA,CAAA,KAAK,CAAG,EAAA;AACzB,MAAA,MAA2B,WAAnB,EA3Bd,KAAA,EAAA,GA2BiC,EAAT,EAAA,IAAA,GAAA,SAAA,CAAS,IAAT,CAAV,OAAA,CAAA,CAAA,CAAA;AACR,MAAA,OAAO,iCACF,IADE,CAAA,EAAA;AAAA,QAEL,MAAQ,EAAA;AAAA,UACN,KAAO,EAAA,kBAAA;AAAA,UACP,KAAA;AAAA,SACF;AAAA,QACA,UAAU,EAAC;AAAA,OACb,CAAA,CAAA;AAAA,KACF;AACA,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AAAA,EAKA,YAAA,EAAc,CAAC,IAAA,KAA0B,IAAK,CAAA,MAAA;AAAA,EAK9C,aAAA,EAAe,CAAC,IAAA,EAAuB,IAAsB,KAAA;AAC3D,IAAO,OAAA,sBAAA,CAAuB,IAAM,EAAA,IAAA,CAAK,QAAQ,CAAA,CAAA;AAAA,GACnD;AAC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CAAA,GAAK,KAAM,CAAA,CAAA,CAAA,GAAK,KAAM,CAAA,CAAA,CAAA,CAAA;AAAA,eAClC;AAAA,aACF;AAAA,WACF;AAEA,UAAI,IAAA,CAAA,KAAM,IAAQ,IAAA,CAAA,KAAM,KAAW,CAAA,EAAA;AACjC,YAAA,IAAI,CAAE,CAAA,KAAA,IAAS,OAAO,CAAA,KAAM,QAAU,EAAA;AACpC,cAAI,CAAA,GAAA,CAAA,CAAE,MAAM,GAAG,CAAA,CAAA;AAAA,aACjB;AACA,YAAC,IAAA,CAAa,EAAE,GAAO,CAAA,GAAA,CAAA,CAAA;AAAA,WACzB;AAAA,SACF;AAEA,QAAA,MAAA,CAAO,KAAK,IAAI,CAAA,CAAA;AAAA,OAClB;AACA,MAAO,OAAA,MAAA,CAAA;AAAA,KACR,CAAA;AAAA,GACH,CAAA;AACF,CAAA;AAMA,MAAM,YAAe,GAAA;AAAA,EACnB,YAAA;AAAA,EACA,MAAA;AAAA,EACA,eAAA;AAAA,EACA,+BAAA;AACF,CAAA,CAAA;AAKO,SAAS,sBAAsB,UAAoC,EAAA;AACxE,EAAM,MAAA,EAAE,MAAS,GAAA,UAAA,CAAA;AACjB,EAAA,OAAO,CAAC,UAAA,CAAW,WAAe,IAAA,YAAA,CAAa,SAAS,IAAI,CAAA,CAAA;AAC9D;;;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { config } from '@grafana/runtime';
|
|
2
|
+
import { cloneDeep } from 'lodash';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
function postProcessQueryResult(annotation, results) {
|
|
21
|
+
if (annotation.snapshotData) {
|
|
22
|
+
annotation = cloneDeep(annotation);
|
|
23
|
+
delete annotation.snapshotData;
|
|
24
|
+
}
|
|
25
|
+
const processed = results.map((item) => {
|
|
26
|
+
var _a;
|
|
27
|
+
const processedItem = __spreadValues({}, item);
|
|
28
|
+
processedItem.source = annotation;
|
|
29
|
+
processedItem.color = config.theme2.visualization.getColorByName(annotation.iconColor);
|
|
30
|
+
processedItem.type = annotation.name;
|
|
31
|
+
processedItem.isRegion = Boolean(processedItem.timeEnd && processedItem.time !== processedItem.timeEnd);
|
|
32
|
+
switch ((_a = processedItem.newState) == null ? void 0 : _a.toLowerCase()) {
|
|
33
|
+
case "pending":
|
|
34
|
+
processedItem.color = "yellow";
|
|
35
|
+
break;
|
|
36
|
+
case "alerting":
|
|
37
|
+
processedItem.color = "red";
|
|
38
|
+
break;
|
|
39
|
+
case "ok":
|
|
40
|
+
processedItem.color = "green";
|
|
41
|
+
break;
|
|
42
|
+
case "normal":
|
|
43
|
+
processedItem.color = "green";
|
|
44
|
+
break;
|
|
45
|
+
case "no_data":
|
|
46
|
+
processedItem.color = "gray";
|
|
47
|
+
break;
|
|
48
|
+
case "nodata":
|
|
49
|
+
processedItem.color = "gray";
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
return processedItem;
|
|
53
|
+
});
|
|
54
|
+
return processed;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { postProcessQueryResult };
|
|
58
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../../src/querying/layers/annotations/utils.ts"],"sourcesContent":["// These opt outs are here only for quicker and easier migration to react based annotations editors and because\n// annotation support API needs some work to support less \"standard\" editors like prometheus and here it is not\n// polluting public API.\n\nimport { AnnotationEvent, AnnotationQuery, DataSourceApi } from '@grafana/data';\nimport { config } from '@grafana/runtime';\nimport { cloneDeep } from 'lodash';\n\nconst legacyRunner = [\n 'prometheus',\n 'loki',\n 'elasticsearch',\n 'grafana-opensearch-datasource', // external\n];\n\n/**\n * Use legacy runner. Used only as an escape hatch for easier transition to React based annotation editor.\n */\nexport function shouldUseLegacyRunner(datasource: DataSourceApi): boolean {\n const { type } = datasource;\n return !datasource.annotations || legacyRunner.includes(type);\n}\n\nexport function postProcessQueryResult(annotation: AnnotationQuery, results: AnnotationEvent[]): AnnotationEvent[] {\n // if annotation has snapshotData\n // make clone and remove it\n if (annotation.snapshotData) {\n annotation = cloneDeep(annotation);\n delete annotation.snapshotData;\n }\n\n //\n const processed = results.map((item) => {\n const processedItem = { ...item };\n\n processedItem.source = annotation;\n processedItem.color = config.theme2.visualization.getColorByName(annotation.iconColor);\n processedItem.type = annotation.name;\n processedItem.isRegion = Boolean(processedItem.timeEnd && processedItem.time !== processedItem.timeEnd);\n\n switch (processedItem.newState?.toLowerCase()) {\n case 'pending':\n processedItem.color = 'yellow';\n break;\n case 'alerting':\n processedItem.color = 'red';\n break;\n case 'ok':\n processedItem.color = 'green';\n break;\n case 'normal': // ngalert (\"normal\" instead of \"ok\")\n processedItem.color = 'green';\n break;\n case 'no_data':\n processedItem.color = 'gray';\n break;\n case 'nodata': // ngalert\n processedItem.color = 'gray';\n break;\n }\n\n return processedItem;\n });\n\n return processed;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAuBgB,SAAA,sBAAA,CAAuB,YAA6B,OAA+C,EAAA;AAGjH,EAAA,IAAI,WAAW,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