Skip to content

Commit 3433c92

Browse files
Ensure constants and utils are under common (#88)
Signed-off-by: Chenyang Ji <[email protected]> (cherry picked from commit e5c5d4b) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent c62743f commit 3433c92

File tree

17 files changed

+130
-80
lines changed

17 files changed

+130
-80
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: 'Install Query Insights Dashboards with Plugin via Binary'
2+
3+
on: [push, pull_request]
4+
env:
5+
OPENSEARCH_VERSION: '2.19.0'
6+
CI: 1
7+
# avoid warnings like "tput: No value for $TERM and no -T specified"
8+
TERM: xterm
9+
OPENSEARCH_INITIAL_ADMIN_PASSWORD: myStrongPassword123!
10+
11+
jobs:
12+
verify-binary-installation:
13+
name: Run binary installation
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [ubuntu-latest]
18+
# TODO: add windows support when OSD core is stable on windows
19+
runs-on: ${{ matrix.os }}
20+
steps:
21+
- name: Checkout Branch
22+
uses: actions/checkout@v3
23+
24+
- name: Set env
25+
run: |
26+
opensearch_version=$(node -p "require('./package.json').opensearchDashboards.version")
27+
plugin_version=$(node -p "require('./package.json').version")
28+
echo "OPENSEARCH_VERSION=$opensearch_version" >> $GITHUB_ENV
29+
echo "PLUGIN_VERSION=$plugin_version" >> $GITHUB_ENV
30+
shell: bash
31+
32+
- name: Run OpenSearch
33+
uses: derek-ho/start-opensearch@v6
34+
with:
35+
opensearch-version: ${{ env.OPENSEARCH_VERSION }}
36+
security-enabled: false
37+
38+
- name: Run Dashboard
39+
id: setup-dashboards
40+
uses: derek-ho/setup-opensearch-dashboards@v1
41+
with:
42+
plugin_name: query-insights-dashboards
43+
built_plugin_name: queryInsightsDashboards
44+
install_zip: true
45+
46+
- name: Start the binary
47+
run: |
48+
nohup ./bin/opensearch-dashboards &
49+
working-directory: ${{ steps.setup-dashboards.outputs.dashboards-binary-directory }}
50+
shell: bash
51+
52+
- name: Health check
53+
run: |
54+
timeout 300 bash -c 'while [[ "$(curl -u admin:${{ env.OPENSEARCH_INITIAL_ADMIN_PASSWORD }} -k http://localhost:5601/api/status | jq -r '.status.overall.state')" != "green" ]]; do sleep 5; done'
55+
shell: bash

common/constants.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,54 @@ export const GROUP_BY = 'Group by';
1818
export const AVERAGE_LATENCY = 'Average Latency';
1919
export const AVERAGE_CPU_TIME = 'Average CPU Time';
2020
export const AVERAGE_MEMORY_USAGE = 'Average Memory Usage';
21+
/*
22+
* Copyright OpenSearch Contributors
23+
* SPDX-License-Identifier: Apache-2.0
24+
*/
25+
export const MetricType = {
26+
LATENCY: 'latency',
27+
CPU: 'cpu',
28+
MEMORY: 'memory',
29+
};
30+
export const METRIC_TYPES_TEXT = [
31+
{ value: MetricType.LATENCY, text: 'Latency' },
32+
{ value: MetricType.CPU, text: 'CPU' },
33+
{ value: MetricType.MEMORY, text: 'Memory' },
34+
];
35+
export const TIME_UNITS_TEXT = [
36+
{ value: 'MINUTES', text: 'Minute(s)' },
37+
{ value: 'HOURS', text: 'Hour(s)' },
38+
];
39+
export const MINUTES_OPTIONS = [
40+
{ value: '1', text: '1' },
41+
{ value: '5', text: '5' },
42+
{ value: '10', text: '10' },
43+
{ value: '30', text: '30' },
44+
];
45+
export const GROUP_BY_OPTIONS = [
46+
{ value: 'none', text: 'None' },
47+
{ value: 'similarity', text: 'Similarity' },
48+
];
49+
export const TIME_UNIT = {
50+
MINUTES: 'MINUTES',
51+
HOURS: 'HOURS',
52+
};
53+
export const TIME_UNIT_ABBREVIATION = {
54+
MINUTES: 'm',
55+
HOURS: 'h',
56+
};
57+
export const EXPORTER_TYPE = {
58+
localIndex: 'local_index',
59+
none: 'none',
60+
};
61+
export const EXPORTER_TYPES_LIST = [
62+
{ value: EXPORTER_TYPE.localIndex, text: 'Local Index' },
63+
{ value: EXPORTER_TYPE.none, text: 'None' },
64+
];
65+
export const DEFAULT_METRIC_ENABLED = true;
66+
export const DEFAULT_TOP_N_SIZE = '10';
67+
export const DEFAULT_WINDOW_SIZE = '5';
68+
export const DEFAULT_TIME_UNIT = TIME_UNIT.MINUTES;
69+
export const DEFAULT_GROUP_BY = 'none';
70+
export const DEFAULT_EXPORTER_TYPE = EXPORTER_TYPE.localIndex;
71+
export const DEFAULT_DELETE_AFTER_DAYS = '7';
File renamed without changes.

public/pages/Utils/MetricUtils.ts renamed to common/utils/MetricUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { DEFAULT_TIME_UNIT, DEFAULT_WINDOW_SIZE, TIME_UNIT_ABBREVIATION } from './Constants';
7-
import { MetricSettingsResponse } from '../../../types/types';
6+
import { DEFAULT_TIME_UNIT, DEFAULT_WINDOW_SIZE, TIME_UNIT_ABBREVIATION } from '../constants';
7+
import { MetricSettingsResponse } from '../../types/types';
88

99
export function calculateMetric(
1010
value?: number,

public/pages/Utils/QueryUtils.ts renamed to common/utils/QueryUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { SearchQueryRecord } from '../../../types/types';
6+
import { SearchQueryRecord } from '../../types/types';
77

88
// Utility function to fetch query by id and time range
99
export const retrieveQueryById = async (

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"version": "2.19.0.0",
44
"description": "OpenSearch Dashboards plugin for Query Insights",
55
"main": "index.js",
6+
"opensearchDashboards": {
7+
"version": "2.19.0",
8+
"templateVersion": "2.19.0"
9+
},
610
"license": "Apache-2.0",
711
"homepage": "https://github.com/opensearch-project/query-insights-dashboards",
812
"config": {
@@ -65,4 +69,4 @@
6569
"node_modules/*",
6670
"target/*"
6771
]
68-
}
72+
}

public/pages/Configuration/Configuration.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
GROUP_BY_OPTIONS,
4040
EXPORTER_TYPES_LIST,
4141
EXPORTER_TYPE,
42-
} from '../Utils/Constants';
42+
} from '../../../common/constants';
4343
import { QueryInsightsDataSourceMenu } from '../../components/DataSourcePicker';
4444
import { QueryInsightsDashboardsPluginStartDependencies } from '../../types';
4545

public/pages/QueryDetails/Components/QuerySummary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
TIMESTAMP,
1717
TOTAL_SHARDS,
1818
} from '../../../../common/constants';
19-
import { calculateMetric } from '../../Utils/MetricUtils';
19+
import { calculateMetric } from '../../../../common/utils/MetricUtils';
2020

2121
// Panel component for displaying query detail values
2222
const PanelItem = ({ label, value }: { label: string; value: string | number }) => (

public/pages/QueryDetails/QueryDetails.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import '@testing-library/jest-dom';
1212
import plotly from 'plotly.js-dist';
1313
import { MemoryRouter, Route } from 'react-router-dom';
1414
import hash from 'object-hash';
15-
import { retrieveQueryById } from '../Utils/QueryUtils';
15+
import { retrieveQueryById } from '../../../common/utils/QueryUtils';
1616
import { DataSourceContext } from '../TopNQueries/TopNQueries';
1717

1818
jest.mock('plotly.js-dist', () => ({
1919
newPlot: jest.fn(),
2020
}));
2121

22-
jest.mock('../Utils/QueryUtils', () => ({
22+
jest.mock('../../../common/utils/QueryUtils', () => ({
2323
retrieveQueryById: jest.fn(),
2424
}));
2525

public/pages/QueryDetails/QueryDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { DataSourceContext, QUERY_INSIGHTS } from '../TopNQueries/TopNQueries';
2626
import { SearchQueryRecord } from '../../../types/types';
2727
import { PageHeader } from '../../components/PageHeader';
2828
import { QueryInsightsDashboardsPluginStartDependencies } from '../../types';
29-
import { retrieveQueryById } from '../Utils/QueryUtils';
29+
import { retrieveQueryById } from '../../../common/utils/QueryUtils';
3030
import { QueryInsightsDataSourceMenu } from '../../components/DataSourcePicker';
3131

3232
import { getDataSourceFromUrl } from '../../utils/datasource-utils';

public/pages/QueryGroupDetails/Components/QueryGroupAggregateSummary.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
GROUP_BY,
1313
ID,
1414
} from '../../../../common/constants';
15-
import { calculateMetric } from '../../Utils/MetricUtils';
15+
import { calculateMetric } from '../../../../common/utils/MetricUtils';
1616

1717
// Panel component for displaying query group detail values
1818
const PanelItem = ({ label, value }: { label: string; value: string | number }) => (

public/pages/QueryGroupDetails/QueryGroupDetails.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { CoreStart } from 'opensearch-dashboards/public';
1010
import React from 'react';
1111
import { mockQueries } from '../../../test/mocks/mockQueries';
1212
import '@testing-library/jest-dom/extend-expect';
13-
import { retrieveQueryById } from '../Utils/QueryUtils';
13+
import { retrieveQueryById } from '../../../common/utils/QueryUtils';
1414
import { DataSourceContext } from '../TopNQueries/TopNQueries';
1515

1616
jest.mock('object-hash', () => jest.fn(() => '8c1e50c035663459d567fa11d8eb494d'));
@@ -21,7 +21,7 @@ jest.mock('plotly.js-dist', () => ({
2121
relayout: jest.fn(),
2222
}));
2323

24-
jest.mock('../Utils/QueryUtils', () => ({
24+
jest.mock('../../../common/utils/QueryUtils', () => ({
2525
retrieveQueryById: jest.fn(),
2626
}));
2727

public/pages/QueryGroupDetails/QueryGroupDetails.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { QueryGroupSampleQuerySummary } from './Components/QueryGroupSampleQuery
2929
import { QueryInsightsDashboardsPluginStartDependencies } from '../../types';
3030
import { PageHeader } from '../../components/PageHeader';
3131
import { SearchQueryRecord } from '../../../types/types';
32-
import { retrieveQueryById } from '../Utils/QueryUtils';
32+
import { retrieveQueryById } from '../../../common/utils/QueryUtils';
3333
import { QueryInsightsDataSourceMenu } from '../../components/DataSourcePicker';
3434
import { getDataSourceFromUrl } from '../../utils/datasource-utils';
3535

public/pages/QueryInsights/QueryInsights.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import {
2323
TOTAL_SHARDS,
2424
TYPE,
2525
} from '../../../common/constants';
26-
import { calculateMetric } from '../Utils/MetricUtils';
27-
import { parseDateString } from '../Utils/DateUtils';
26+
import { calculateMetric } from '../../../common/utils/MetricUtils';
27+
import { parseDateString } from '../../../common/utils/DateUtils';
2828
import { QueryInsightsDataSourceMenu } from '../../components/DataSourcePicker';
2929
import { QueryInsightsDashboardsPluginStartDependencies } from '../../types';
3030

public/pages/TopNQueries/TopNQueries.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ import {
2424
DEFAULT_TIME_UNIT,
2525
DEFAULT_TOP_N_SIZE,
2626
DEFAULT_WINDOW_SIZE,
27+
EXPORTER_TYPE,
2728
MetricType,
28-
} from '../Utils/Constants';
29+
} from '../../../common/constants';
2930

30-
import { parseDateString } from '../Utils/DateUtils';
31+
import { parseDateString } from '../../../common/utils/DateUtils';
3132
import {
3233
getMergedMetricSettings,
3334
getMergedStringSettings,
3435
getTimeAndUnitFromString,
35-
} from '../Utils/MetricUtils';
36+
} from '../../../common/utils/MetricUtils';
3637
import { getDataSourceFromUrl } from '../../utils/datasource-utils';
37-
import { EXPORTER_TYPE } from '../Utils/Constants';
3838

3939
export const QUERY_INSIGHTS = '/queryInsights';
4040
export const CONFIGURATION = '/configuration';

public/pages/Utils/Constants.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

server/routes/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { schema } from '@osd/config-schema';
77
import { IRouter } from '../../../../src/core/server';
8-
import { EXPORTER_TYPE } from '../../public/pages/Utils/Constants';
8+
import { EXPORTER_TYPE } from '../../common/constants';
99

1010
export function defineRoutes(router: IRouter, dataSourceEnabled: boolean) {
1111
router.get(

0 commit comments

Comments
 (0)