Skip to content

Commit

Permalink
Merge branch 'main' into acceleration-table-tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Li <[email protected]>
  • Loading branch information
sejli authored Mar 14, 2024
2 parents 56c851f + 8874c8c commit fe92fdc
Show file tree
Hide file tree
Showing 41 changed files with 2,763 additions and 714 deletions.
2 changes: 1 addition & 1 deletion common/constants/data_connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const OPENSEARCH_S3_DOCUMENTATION_URL =
'https://opensearch.org/docs/latest/dashboards/management/S3-data-source/';

export const OPENSEARCH_ACC_DOCUMENTATION_URL =
'https://opensearch.org/docs/latest/data-acceleration/index';
'https://opensearch.org/docs/latest/dashboards/management/accelerate-external-data/';
export const QUERY_RESTRICTED = 'query-restricted';
export const QUERY_ALL = 'query-all';

Expand Down
2 changes: 1 addition & 1 deletion common/constants/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ export const TYPE_TAB_MAPPING = {
};

export const DEFAULT_EMPTY_EXPLORER_FIELDS = [
{ name: 'timestamp', type: 'timestamp' },
// timestamp field will be a default but is added after finding what it is
{ name: '_source', type: 'string' },
];

Expand Down
2 changes: 2 additions & 0 deletions common/constants/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,5 @@ export const DIRECT_DUMMY_QUERY = 'select 1';
export const DEFAULT_START_TIME = 'now-15m';
export const QUERY_ASSIST_START_TIME = 'now-40y';
export const QUERY_ASSIST_END_TIME = 'now';

export const TIMESTAMP_DATETIME_TYPES = ['date', 'date_nanos'];
17 changes: 11 additions & 6 deletions common/types/data_connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ export interface CachedColumn {

export interface CachedTable {
name: string;
columns: CachedColumn[];
columns?: CachedColumn[];
}

export interface CachedDatabase {
name: string;
tables: CachedTable[];
lastUpdated: string; // Assuming date string in UTC format
lastUpdated: string; // date string in UTC format
status: CachedDataSourceStatus;
}

export interface CachedDataSource {
name: string;
lastUpdated: string; // Assuming date string in UTC format
lastUpdated: string; // date string in UTC format
status: CachedDataSourceStatus;
databases: CachedDatabase[];
}
Expand All @@ -115,13 +115,18 @@ export interface CachedAccelerations {
status: string;
}

export interface AccelerationsCacheData {
version: string;
export interface CachedAcclerationByDataSource {
name: string;
accelerations: CachedAccelerations[];
lastUpdated: string; // Assuming date string in UTC format
lastUpdated: string; // date string in UTC format
status: CachedDataSourceStatus;
}

export interface AccelerationsCacheData {
version: string;
dataSources: CachedAcclerationByDataSource[];
}

export interface PollingSuccessResult {
schema: Array<{ name: string; type: string }>;
datarows: Array<Array<string | number | boolean>>;
Expand Down
58 changes: 54 additions & 4 deletions public/components/common/search/direct_search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,25 @@ import {
EuiPopoverFooter,
EuiToolTip,
} from '@elastic/eui';
import { isEqual } from 'lodash';
import { isEmpty, isEqual } from 'lodash';
import React, { useEffect, useState } from 'react';
import { batch, useDispatch, useSelector } from 'react-redux';
import { ASYNC_POLLING_INTERVAL, QUERY_LANGUAGE } from '../../../../common/constants/data_sources';
import { APP_ANALYTICS_TAB_ID_REGEX, RAW_QUERY } from '../../../../common/constants/explorer';
import { PPL_NEWLINE_REGEX, PPL_SPAN_REGEX } from '../../../../common/constants/shared';
import { DirectQueryLoadingStatus, DirectQueryRequest } from '../../../../common/types/explorer';
import {
APP_ANALYTICS_TAB_ID_REGEX,
RAW_QUERY,
SELECTED_TIMESTAMP,
} from '../../../../common/constants/explorer';
import {
PPL_NEWLINE_REGEX,
PPL_SPAN_REGEX,
TIMESTAMP_DATETIME_TYPES,
} from '../../../../common/constants/shared';
import {
DirectQueryLoadingStatus,
DirectQueryRequest,
IDefaultTimestampState,
} from '../../../../common/types/explorer';
import { uiSettingsService } from '../../../../common/utils';
import { getAsyncSessionId, setAsyncSessionId } from '../../../../common/utils/query_session_utils';
import { get as getObjValue } from '../../../../common/utils/shared';
Expand All @@ -42,6 +54,7 @@ import { formatError } from '../../event_analytics/utils';
import { usePolling } from '../../hooks/use_polling';
import { PPLReferenceFlyout } from '../helpers';
import { Autocomplete } from './autocomplete';
import { i18n } from '@osd/i18n';
export interface IQueryBarProps {
query: string;
tempQuery: string;
Expand Down Expand Up @@ -250,6 +263,33 @@ export const DirectSearch = (props: any) => {
});
};

const getDirectQueryTimestamp = (schema: Array<{ name: string; type: string }>) => {
const timestamp: IDefaultTimestampState = {
hasSchemaConflict: false, // schema conflict bool used for OS index w/ different mappings, not needed here
default_timestamp: '',
message: i18n.translate(`discover.events.directQuery.noTimeStampFoundMessage`, {
defaultMessage: 'Index does not contain a valid time field.',
}),
};

for (let i = 0; i < schema.length; i++) {
const fieldMapping = schema[i];
if (!isEmpty(fieldMapping)) {
const fieldName = fieldMapping.name;
const fieldType = fieldMapping.type;
const isValidTimeType = TIMESTAMP_DATETIME_TYPES.some((dateTimeType) =>
isEqual(fieldType, dateTimeType)
);
if (isValidTimeType && isEmpty(timestamp.default_timestamp)) {
timestamp.default_timestamp = fieldName;
timestamp.message = '';
break;
}
}
}
return timestamp;
};

useEffect(() => {
// cancel direct query
if (!pollingResult) return;
Expand All @@ -258,6 +298,16 @@ export const DirectSearch = (props: any) => {

if (status === DirectQueryLoadingStatus.SUCCESS || datarows) {
stopPollingWithStatus(status);
// find the timestamp from results
const derivedTimestamp = getDirectQueryTimestamp(pollingResult.schema);
dispatch(
changeQuery({
tabId,
query: {
[SELECTED_TIMESTAMP]: derivedTimestamp.default_timestamp,
},
})
);
// update page with data
dispatchOnGettingHis(pollingResult, '');
} else if (status === DirectQueryLoadingStatus.FAILED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { act } from '@testing-library/react';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { act } from '@testing-library/react';
import React from 'react';
import ReactDOM from 'react-dom';
import { coreRefs } from '../../../../../public/framework/core_refs';
import {
describePrometheusDataConnection,
describeS3Dataconnection,
} from '../../../../../test/datasources';
import { DataConnection } from '../manage/data_connection';
import ReactDOM from 'react-dom';
import { coreRefs } from '../../../../../public/framework/core_refs';

jest.mock('../../../../plugin', () => ({
getRenderAccelerationDetailsFlyout: jest.fn(() =>
jest.fn().mockImplementation(() => console.log('Acceleration Details Flyout Rendered'))
),
getRenderAssociatedObjectsDetailsFlyout: jest.fn(() =>
jest.fn().mockImplementation(() => console.log('Associated Objects Details Flyout Rendered'))
),
getRenderAccelerationDetailsFlyout: jest.fn(),
getRenderAssociatedObjectsDetailsFlyout: jest.fn(),
getRenderCreateAccelerationFlyout: jest.fn(),
}));

jest.mock('../../../../../public/framework/core_refs', () => ({
Expand Down
Loading

0 comments on commit fe92fdc

Please sign in to comment.