Skip to content

Commit a836fc7

Browse files
mengweiericjoshuali925
authored andcommitted
Refactor Saved objects and add visualization embeddable (opensearch-project#341)
Signed-off-by: Eric Wei <menwe@amazon.com> Signed-off-by: Joshua Li <joshuali925@gmail.com> Signed-off-by: Peter Fitzgibbons <pjfitz@amazon.com> Signed-off-by: Shenoy Pratik <sgguruda@amazon.com> Signed-off-by: Derek Ho <dxho@amazon.com> Co-authored-by: Joshua Li <joshuali925@gmail.com> Co-authored-by: Peter Fitzgibbons <peter.fitzgibbons@gmail.com> Co-authored-by: Peter Fitzgibbons <pjfitz@amazon.com> Co-authored-by: Shenoy Pratik <sgguruda@amazon.com> Co-authored-by: Derek Ho <dxho@amazon.com> (cherry picked from commit 583010d)
1 parent 0453fa7 commit a836fc7

File tree

109 files changed

+6800
-1467
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+6800
-1467
lines changed

common/constants/explorer.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55

66
import { htmlIdGenerator } from '@elastic/eui';
7-
import { VIS_CHART_TYPES } from './shared';
87
import { ThresholdUnitType } from '../../public/components/event_analytics/explorer/visualizations/config_panel/config_panes/config_controls/config_thresholds';
8+
import { VIS_CHART_TYPES } from './shared';
99

1010
export const EVENT_ANALYTICS_DOCUMENTATION_URL =
1111
'https://opensearch.org/docs/latest/observability-plugin/event-analytics/';
@@ -31,6 +31,11 @@ export const TAB_EVENT_ID_TXT_PFX = 'main-content-events-';
3131
export const TAB_CHART_ID_TXT_PFX = 'main-content-vis-';
3232
export const TAB_EVENT_ID = 'main-content-events';
3333
export const TAB_CHART_ID = 'main-content-vis';
34+
export const CREATE_TAB_PARAM_KEY = 'create';
35+
export const CREATE_TAB_PARAM = {
36+
[TAB_EVENT_ID]: 'events',
37+
[TAB_CHART_ID]: 'visualizations',
38+
} as const;
3439
export const HAS_SAVED_TIMESTAMP = 'hasSavedTimestamp';
3540
export const FILTER_OPTIONS = ['Visualization', 'Query', 'Metric'];
3641
export const SAVED_QUERY = 'savedQuery';
@@ -309,3 +314,8 @@ export const sampleLogPatternData = {
309314
"Mozilla/5.0 (X11; Linux x86_64; rv:6.0a1) Gecko/20110421 Firefox/6.0a1"',
310315
anomalyCount: 0,
311316
};
317+
318+
export const TYPE_TAB_MAPPING = {
319+
[SAVED_QUERY]: TAB_EVENT_ID,
320+
[SAVED_VISUALIZATION]: TAB_CHART_ID,
321+
};

common/types/explorer.ts

+10-19
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@ import SavedObjects from '../../public/services/saved_objects/event_analytics/sa
3333
import TimestampUtils from '../../public/services/timestamp/timestamp';
3434
import PPLService from '../../public/services/requests/ppl';
3535
import DSLService from '../../public/services/requests/dsl';
36-
import { SavedObjectsStart } from '../../../../src/core/public/saved_objects';
36+
import {
37+
SavedObjectAttributes,
38+
SavedObjectsStart,
39+
} from '../../../../src/core/public/saved_objects';
40+
3741
export interface IQueryTab {
3842
id: string;
3943
name: React.ReactNode | string;
4044
content: React.ReactNode;
4145
}
4246

43-
export interface IField {
47+
export interface IField extends SavedObjectAttributes {
4448
name: string;
4549
type: string;
4650
label?: string;
@@ -151,33 +155,20 @@ export interface SavedQuery {
151155
selected_timestamp: IField;
152156
}
153157

154-
export interface SavedVisualization {
158+
export interface SavedVisualization extends SavedObjectAttributes {
155159
description: string;
156160
name: string;
157161
query: string;
158162
selected_date_range: { start: string; end: string; text: string };
159163
selected_fields: { text: string; tokens: [] };
160164
selected_timestamp: IField;
161165
type: string;
166+
sub_type?: 'metric' | 'visualization'; // exists if sub type is metric
167+
user_configs?: string;
168+
units_of_measure?: string;
162169
application_id?: string;
163170
}
164171

165-
export interface SavedQueryRes {
166-
createdTimeMs: number;
167-
lastUpdatedTimeMs: number;
168-
objectId: string;
169-
savedQuery: SavedQuery;
170-
tenant: string;
171-
}
172-
173-
export interface SavedVizRes {
174-
createdTimeMs: number;
175-
lastUpdatedTimeMs: number;
176-
objectId: string;
177-
savedVisualization: SavedVisualization;
178-
tenant: string;
179-
}
180-
181172
export interface ExplorerDataType {
182173
jsonData: object[];
183174
jsonDataAll: object[];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { SavedObjectAttributes } from '../../../../src/core/types';
7+
import { SavedVisualization } from './explorer';
8+
9+
export const VISUALIZATION_SAVED_OBJECT = 'observability-visualization';
10+
export const OBSERVABILTY_SAVED_OBJECTS = [VISUALIZATION_SAVED_OBJECT] as const;
11+
export const SAVED_OBJECT_VERSION = 1;
12+
13+
export interface VisualizationSavedObjectAttributes extends SavedObjectAttributes {
14+
title: string;
15+
description: string;
16+
version: number;
17+
createdTimeMs: number;
18+
savedVisualization: SavedVisualization;
19+
}

common/utils/core_services.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import {
7+
HttpStart,
8+
IUiSettingsClient,
9+
NotificationsStart,
10+
SavedObjectsClientContract,
11+
ToastInput,
12+
} from '../../../../src/core/public';
13+
import { createGetterSetter } from '../../../../src/plugins/opensearch_dashboards_utils/common';
14+
import PPLService from '../../public/services/requests/ppl';
15+
import { QueryManager } from '../query_manager';
16+
17+
let uiSettings: IUiSettingsClient;
18+
let notifications: NotificationsStart;
19+
20+
export const uiSettingsService = {
21+
init: (client: IUiSettingsClient, notificationsStart: NotificationsStart) => {
22+
uiSettings = client;
23+
notifications = notificationsStart;
24+
},
25+
get: (key: string, defaultOverride?: any) => {
26+
return uiSettings?.get(key, defaultOverride) || '';
27+
},
28+
set: (key: string, value: any) => {
29+
return uiSettings?.set(key, value) || Promise.reject('uiSettings client not initialized.');
30+
},
31+
addToast: (toast: ToastInput) => {
32+
return notifications.toasts.add(toast);
33+
},
34+
};
35+
36+
export const [getPPLService, setPPLService] = createGetterSetter<PPLService>('PPLService');
37+
export const [getOSDHttp, setOSDHttp] = createGetterSetter<HttpStart>('http');
38+
export const [getOSDSavedObjectsClient, setOSDSavedObjectsClient] = createGetterSetter<
39+
SavedObjectsClientContract
40+
>('SavedObjectsClient');
41+
export const [getQueryManager, setQueryManager] = createGetterSetter<QueryManager>('QueryManager');

common/utils/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export {
1010
composeFinalQuery,
1111
removeBacktick,
1212
} from './query_utils';
13-
export { uiSettingsService } from './settings_service';
13+
14+
export * from './core_services';

common/utils/query_utils.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
PPL_INDEX_INSERT_POINT_REGEX,
1414
PPL_INDEX_REGEX,
1515
PPL_NEWLINE_REGEX,
16-
PPL_STATS_REGEX,
1716
} from '../../common/constants/shared';
1817

1918
/**
@@ -42,6 +41,7 @@ export const preprocessQuery = ({
4241
selectedPatternField,
4342
patternRegex,
4443
filteredPattern,
44+
whereClause,
4545
}: {
4646
rawQuery: string;
4747
startTime: string;
@@ -51,6 +51,7 @@ export const preprocessQuery = ({
5151
selectedPatternField?: string;
5252
patternRegex?: string;
5353
filteredPattern?: string;
54+
whereClause?: string;
5455
}) => {
5556
let finalQuery = '';
5657

@@ -65,7 +66,13 @@ export const preprocessQuery = ({
6566

6667
finalQuery = `${tokens![1]}=${
6768
tokens![2]
68-
} | where ${timeField} >= '${start}' and ${timeField} <= '${end}'${tokens![3]}`;
69+
} | where ${timeField} >= '${start}' and ${timeField} <= '${end}'`;
70+
71+
if (whereClause) {
72+
finalQuery += ` AND ${whereClause}`;
73+
}
74+
75+
finalQuery += tokens![3];
6976

7077
if (isLiveQuery) {
7178
finalQuery = finalQuery + ` | sort - ${timeField}`;

common/utils/settings_service.ts

-25
This file was deleted.

opensearch_dashboards.json

+6-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
"ui": true,
77
"requiredPlugins": [
88
"charts",
9+
"dashboard",
910
"data",
1011
"embeddable",
1112
"inspector",
12-
"urlForwarding",
1313
"navigation",
14+
"opensearchDashboardsReact",
15+
"opensearchDashboardsUtils",
16+
"savedObjects",
1417
"uiActions",
15-
"dashboard",
16-
"visualizations",
17-
"opensearchDashboardsReact"
18+
"urlForwarding",
19+
"visualizations"
1820
]
1921
}

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
"ag-grid-react": "^27.3.0",
2222
"antlr4": "4.8.0",
2323
"antlr4ts": "^0.5.0-alpha.4",
24+
"performance-now": "^2.1.0",
2425
"plotly.js-dist": "^2.2.0",
2526
"postinstall": "^0.7.4",
2627
"react-graph-vis": "^1.0.5",
2728
"react-paginate": "^8.1.3",
2829
"react-plotly.js": "^2.5.1",
29-
"redux-persist": "^6.0.0",
30-
"performance-now": "^2.1.0"
30+
"redux-persist": "^6.0.0"
3131
},
3232
"devDependencies": {
3333
"@cypress/skip-test": "^2.6.1",
@@ -37,7 +37,8 @@
3737
"antlr4ts-cli": "^0.5.0-alpha.4",
3838
"cypress": "^6.0.0",
3939
"eslint": "^6.8.0",
40-
"jest-dom": "^4.0.0"
40+
"jest-dom": "^4.0.0",
41+
"ts-jest": "^29.1.0"
4142
},
4243
"resolutions": {
4344
"react-syntax-highlighter": "^15.4.3",

0 commit comments

Comments
 (0)