Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix Application Analytics timestamp query error #513

Merged
merged 3 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
getIndexPatternFromRawQuery,
preprocessQuery,
buildQuery,
buildRawQuery,
composeFinalQuery,
removeBacktick,
} from './query_utils';
Expand Down
7 changes: 7 additions & 0 deletions common/utils/query_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ export const buildQuery = (baseQuery: string, currQuery: string) => {
return fullQuery;
};

export const buildRawQuery = (query: any, appBaseQuery: string) => {
const rawQueryStr = (query.rawQuery as string).includes(appBaseQuery)
? query.rawQuery
: buildQuery(appBaseQuery, query.rawQuery);
return rawQueryStr;
};

export const composeFinalQuery = (
curQuery: string,
startingTime: string,
Expand Down
3 changes: 0 additions & 3 deletions public/components/event_analytics/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,6 @@ export const Explorer = ({

const fetchData = async (startingTime?: string, endingTime?: string) => {
const curQuery: IQuery = queryRef.current!;
const rawQueryStr = (curQuery![RAW_QUERY] as string).includes(appBaseQuery)
? curQuery![RAW_QUERY]
: buildQuery(appBasedRef.current, curQuery![RAW_QUERY]);
new PPLDataFetcher(
{ ...curQuery },
{ batch, dispatch, changeQuery, changeVizConfig },
Expand Down
29 changes: 20 additions & 9 deletions public/services/data_fetchers/ppl/ppl_data_fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { isEmpty } from 'lodash';
import { IDefaultTimestampState, IQuery } from '../../../../common/types/explorer';
import { IDataFetcher } from '../fetch_interface';
import { DataFetcherBase } from '../fetcher_base';
import { composeFinalQuery, getIndexPatternFromRawQuery } from '../../../../common/utils';
import {
buildRawQuery,
composeFinalQuery,
getIndexPatternFromRawQuery,
} from '../../../../common/utils';
import {
FILTERED_PATTERN,
PATTERNS_REGEX,
Expand All @@ -31,8 +35,6 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {
protected readonly notifications
) {
super();
// index/index patterns for this search
this.queryIndex = this.getIndex(this.searchParams.query.rawQuery);
}

async setTimestamp(index: string) {
Expand Down Expand Up @@ -65,6 +67,10 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {

if (isEmpty(query)) return;

this.queryIndex = this.getIndex(buildRawQuery(query, appBaseQuery));

if (this.queryIndex === '') return; // Returns if page is refreshed

const {
tabId,
findAutoInterval,
Expand All @@ -77,7 +83,7 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {
} = this.searchContext;
const { dispatch, changeQuery } = this.storeContext;

await this.processTimestamp(query);
await this.processTimestamp(query, appBaseQuery);
if (isEmpty(this.timestamp)) return;

const curStartTime = startingTime || this.query[SELECTED_DATE_RANGE][0];
Expand All @@ -97,7 +103,7 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {
);

// update UI with new query state
await this.updateQueryState(this.query[RAW_QUERY], finalQuery, this.timestamp);
await this.updateQueryState(this.query[RAW_QUERY], finalQuery, this.timestamp, appBaseQuery);
// calculate proper time interval for count distribution
if (!selectedInterval.current || selectedInterval.current.text === 'Auto') {
findAutoInterval(curStartTime, curEndTime);
Expand Down Expand Up @@ -152,8 +158,8 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {
}
}

async processTimestamp(query: IQuery) {
if (query[SELECTED_TIMESTAMP]) {
async processTimestamp(query: IQuery, appBaseQuery: string) {
if (query[SELECTED_TIMESTAMP] && appBaseQuery === '') {
this.timestamp = query[SELECTED_TIMESTAMP];
} else {
await this.setTimestamp(this.queryIndex);
Expand All @@ -169,7 +175,12 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {
return await timestampUtils.getTimestamp(indexPattern);
}

async updateQueryState(rawQuery: string, finalQuery: string, curTimestamp: string) {
async updateQueryState(
rawQuery: string,
finalQuery: string,
curTimestamp: string,
appBaseQuery: string
) {
const { batch, dispatch, changeQuery, changeVizConfig } = this.storeContext;
const { query } = this.searchParams;
const {
Expand All @@ -186,7 +197,7 @@ export class PPLDataFetcher extends DataFetcherBase implements IDataFetcher {
tabId,
query: {
finalQuery,
[RAW_QUERY]: query.rawQuery,
[RAW_QUERY]: buildRawQuery(query, appBaseQuery),
[SELECTED_TIMESTAMP]: curTimestamp,
},
})
Expand Down