Skip to content

Commit

Permalink
Changed Explorer Data Grid useage of timestamp (opensearch-project#1479
Browse files Browse the repository at this point in the history
…) (opensearch-project#1520)

* add support to use timestamp from set default

* update data grid test and snap

* direct query now sets default timestamp using same logic

* small linting complaints

* appeasing lint pt2

* implement i18n for column names

* using timestamp prop

* add test with different user timestamp

* remove console log

* direct search to use i18n translate

---------

(cherry picked from commit d17cad3)

Signed-off-by: Paul Sebastian <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
(cherry picked from commit 3fc3b25)
  • Loading branch information
opensearch-trigger-bot[bot] authored and A9 Swift Project User committed Apr 7, 2024
1 parent 3ef1fd9 commit b77cec2
Show file tree
Hide file tree
Showing 7 changed files with 690 additions and 38 deletions.
4 changes: 2 additions & 2 deletions auto_sync_commit_metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"last_github_commit": "04e824dbe1775f94e51ed9424cfe6da4fd564a99",
"last_gitfarm_commit": "fdabb9a2046a73d918f8acfc003779d0cf809f0f"
"last_github_commit": "3fc3b2537803f5833eaabc7fe876f7cc18967674",
"last_gitfarm_commit": "6faa35fb7832356d64e46d5fcb89c47d306e7981"
}
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 @@ -263,3 +263,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'];
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
Loading

0 comments on commit b77cec2

Please sign in to comment.