From 958186aff6b8f6a7edb9e03a28d80fd9eb27e6cc Mon Sep 17 00:00:00 2001 From: Peter Fitzgibbons Date: Mon, 18 Dec 2023 12:35:27 -0800 Subject: [PATCH] Metrics Explorer updated with PromQL (#1303) * Metrics Explorer updated with PromQL including query for Prometheus Metrics and updated Export Panel --------- Signed-off-by: Peter Fitzgibbons (cherry picked from commit d16f2b2edfe0085295ac237bbfc9905c55210839) Signed-off-by: Peter Fitzgibbons --- .../__tests__/visualization_helpers.test.tsx | 24 + common/utils/visualization_helpers.ts | 19 + .../__snapshots__/search.test.tsx.snap | 910 ++++++++++++++++++ .../common/search/__tests__/search.test.tsx | 27 + .../slices/__tests__/metric_slice.test.tsx | 207 ++++ .../metrics/sidebar/metrics_edit_inline.tsx | 78 ++ .../metrics_export.test.tsx.snap | 125 +++ .../__tests__/metrics_export.test.tsx | 188 ++++ .../metrics/top_menu/metrics_export.tsx | 394 ++++++++ test/metrics_constants.ts | 394 ++++++++ 10 files changed, 2366 insertions(+) create mode 100644 common/utils/__tests__/visualization_helpers.test.tsx create mode 100644 common/utils/visualization_helpers.ts create mode 100644 public/components/common/search/__tests__/__snapshots__/search.test.tsx.snap create mode 100644 public/components/common/search/__tests__/search.test.tsx create mode 100644 public/components/metrics/redux/slices/__tests__/metric_slice.test.tsx create mode 100644 public/components/metrics/sidebar/metrics_edit_inline.tsx create mode 100644 public/components/metrics/top_menu/__tests__/__snapshots__/metrics_export.test.tsx.snap create mode 100644 public/components/metrics/top_menu/__tests__/metrics_export.test.tsx create mode 100644 public/components/metrics/top_menu/metrics_export.tsx create mode 100644 test/metrics_constants.ts diff --git a/common/utils/__tests__/visualization_helpers.test.tsx b/common/utils/__tests__/visualization_helpers.test.tsx new file mode 100644 index 0000000000..6c7f9f8577 --- /dev/null +++ b/common/utils/__tests__/visualization_helpers.test.tsx @@ -0,0 +1,24 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { getUserConfigFrom } from '../visualization_helpers'; + +describe('Utils helper functions', () => { + describe('getUserConfigFrom', () => { + it('should return empty object from empty input', () => { + expect(getUserConfigFrom(undefined)).toEqual({}); + expect(getUserConfigFrom('')).toEqual({}); + expect(getUserConfigFrom({})).toEqual({}); + }); + it('should get object from user_configs json', () => { + const container = { user_configs: '{ "key": "value" }' }; + expect(getUserConfigFrom(container)).toEqual({ key: 'value' }); + }); + it('should get object from userConfigs', () => { + const container = { userConfigs: '{ "key": "value" }' }; + expect(getUserConfigFrom(container)).toEqual({ key: 'value' }); + }); + }); +}); diff --git a/common/utils/visualization_helpers.ts b/common/utils/visualization_helpers.ts new file mode 100644 index 0000000000..8a93cd7af3 --- /dev/null +++ b/common/utils/visualization_helpers.ts @@ -0,0 +1,19 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { isEmpty, isString } from 'lodash'; + +/* The file contains helper functions for visualizaitons operations + * getUserConfigFrom - returns input objects' user_configs or userConfigs, JSON parsed if necessary + */ + +export const getUserConfigFrom = (container: unknown): object => { + const config = container?.user_configs || container?.userConfigs || {}; + + if (isEmpty(config)) return {}; + + if (isString(config)) return JSON.parse(config); + else return {}; +}; diff --git a/public/components/common/search/__tests__/__snapshots__/search.test.tsx.snap b/public/components/common/search/__tests__/__snapshots__/search.test.tsx.snap new file mode 100644 index 0000000000..b8a95255af --- /dev/null +++ b/public/components/common/search/__tests__/__snapshots__/search.test.tsx.snap @@ -0,0 +1,910 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Explorer Search component renders basic component 1`] = ` + + +
+ +
+ +
+ + PPL + + } + closePopover={[Function]} + display="inlineBlock" + hasArrow={true} + id="smallContextMenuExample" + isOpen={false} + ownFocus={true} + panelPaddingSize="none" + > +
+
+ + + + + +
+
+
+
+
+ +
+ +
+ + +