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

Add correct erroring in Event Analytics #248

Merged
merged 16 commits into from
Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 15 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
22 changes: 21 additions & 1 deletion dashboards-observability/common/types/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import {
SELECTED_TIMESTAMP,
SELECTED_DATE_RANGE
} from '../constants/explorer';
import { HttpStart } from '../../../../src/core/public';
import { HttpStart, NotificationsStart } from '../../../../src/core/public';
import SavedObjects from '../../public/services/saved_objects/event_analytics/saved_objects';
import TimestampUtils from '../../public/services/timestamp/timestamp';
import PPLService from '../../public/services/requests/ppl';
import DSLService from '../../public/services/requests/dsl';
import { History } from 'history';

export interface IQueryTab {
id: string;
Expand Down Expand Up @@ -69,6 +70,8 @@ export interface ILogExplorerProps {
dslService: DSLService;
savedObjects: SavedObjects;
http: HttpStart;
history: History;
notifications: NotificationsStart;
timestampUtils: TimestampUtils;
setToast: (
title: string,
Expand All @@ -78,4 +81,21 @@ export interface ILogExplorerProps {
) => void;
savedObjectId: string;
getExistingEmptyTab: (params: EmptyTabParams) => string;
}

export interface IExplorerProps {
pplService: PPLService;
dslService: DSLService;
tabId: string;
savedObjects: SavedObjects;
timestampUtils: TimestampUtils;
history: History;
notifications: NotificationsStart;
savedObjectId: string;
setToast: (
title: string,
color?: string,
text?: React.ReactChild | undefined,
side?: string | undefined
) => void;
}
1 change: 1 addition & 0 deletions dashboards-observability/public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const App = ({
savedObjects={savedObjects}
timestampUtils={timestampUtils}
http={http}
notifications={notifications}
{...props}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import './search.scss';
import $ from 'jquery';
import React, {
useEffect,
useMemo,
useState
} from 'react';
Expand Down Expand Up @@ -150,14 +149,6 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
return [{ label: str + '|', input: str, suggestion: '|', itemName: '|' }].filter(
({ label }) => label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(label.toLowerCase())
);
} else if (inMatch && fieldList.includes(splittedModel[splittedModel.length - 2])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to line 212

inMatch = true;
currField = splittedModel[splittedModel.length - 2];
currFieldType = fieldsFromBackend.find((field) => field.label === currField)?.type || '';
await getDataValues(currIndex, currField, currFieldType, dslService)
return [{ label: str + ',', input: str, suggestion: ',', itemName: ','}].filter(
({ suggestion }) => suggestion.startsWith(prefix) && prefix !== suggestion
);
} else if (splittedModel[splittedModel.length - 2] === 'stats') {
nextStats = splittedModel.length;
return fillSuggestions(str, prefix, statsCommands);
Expand Down Expand Up @@ -218,6 +209,14 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
currFieldType = fieldsFromBackend.find((field: {label: string, type: string}) => field.label === currField)?.type || '';
await getDataValues(currIndex, currField, currFieldType, dslService);
return fullSuggestions.filter((suggestion: { label: string }) => suggestion.label.toLowerCase().startsWith(lowerPrefix) && lowerPrefix.localeCompare(suggestion.label.toLowerCase()));
} else if (inMatch && fieldList.includes(splittedModel[splittedModel.length - 2])) {
inMatch = true;
currField = splittedModel[splittedModel.length - 2];
currFieldType = fieldsFromBackend.find((field) => field.label === currField)?.type || '';
await getDataValues(currIndex, currField, currFieldType, dslService);
return [{ label: str + ',', input: str, suggestion: ',', itemName: ','}].filter(
({ suggestion }) => suggestion.startsWith(prefix) && prefix !== suggestion
);
} else if (nextWhere === splittedModel.length - 2) {
return fillSuggestions(
str,
Expand Down Expand Up @@ -265,7 +264,9 @@ const getFields = async (dslService: DSLService) => {
const res = await dslService.fetchFields(currIndex);
fieldsFromBackend.length = 0;
for (const element in res?.[currIndex].mappings.properties) {
if (res?.[currIndex].mappings.properties[element].type === 'keyword') {
if (res?.[currIndex].mappings.properties[element].properties || res?.[currIndex].mappings.properties[element].fields) {
fieldsFromBackend.push({ label: element, type: 'string' });
} else if (res?.[currIndex].mappings.properties[element].type === 'keyword') {
fieldsFromBackend.push({ label: element, type: 'string' });
} else {
fieldsFromBackend.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export const getDataValueQuery = (index: string, field: string) => {
'aggs': {
'top_tags': {
'terms': {
'field': field
'field': field,
}
}
}
}
return query;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const EventAnalytics = ({
savedObjects,
timestampUtils,
http,
notifications,
...props
}: any) => {
const history = useHistory();
Expand Down Expand Up @@ -82,6 +83,7 @@ export const EventAnalytics = ({
chrome={chrome}
getExistingEmptyTab={getExistingEmptyTab}
history={history}
notifications={notifications}
/>
);
}}
Expand Down
81 changes: 49 additions & 32 deletions dashboards-observability/public/components/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ import { selectFields, updateFields, sortFields } from './slices/field_slice';
import { updateTabName } from './slices/query_tab_slice';
import { selectCountDistribution } from './slices/count_distribution_slice';
import { selectExplorerVisualization } from './slices/visualization_slice';
import PPLService from '../../services/requests/ppl';
import DSLService from '../../services/requests/dsl';
import SavedObjects from '../../services/saved_objects/event_analytics/saved_objects';
import TimestampUtils from 'public/services/timestamp/timestamp';
import { IExplorerProps } from '../../../common/types/explorer';

const TAB_EVENT_ID = 'main-content-events';
const TAB_CHART_ID = 'main-content-vis';
Expand All @@ -66,20 +63,6 @@ const TYPE_TAB_MAPPING = {
[SAVED_VISUALIZATION]: TAB_CHART_ID
};

interface IExplorerProps {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to explorer.ts

pplService: PPLService;
dslService: DSLService;
tabId: string;
savedObjects: SavedObjects;
timestampUtils: TimestampUtils;
setToast: (
title: string,
color?: string,
text?: React.ReactChild | undefined,
side?: string | undefined
) => void;
}

export const Explorer = ({
pplService,
dslService,
Expand All @@ -88,6 +71,7 @@ export const Explorer = ({
timestampUtils,
setToast,
history,
notifications,
savedObjectId
}: IExplorerProps) => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -127,7 +111,7 @@ export const Explorer = ({
const [tempQuery, setTempQuery] = useState(query[RAW_QUERY]);

const queryRef = useRef();
const selectedPanelNameRef = useRef();
const selectedPanelNameRef = useRef('');
const explorerFieldsRef = useRef();
queryRef.current = query;
selectedPanelNameRef.current = selectedPanelName;
Expand Down Expand Up @@ -171,6 +155,23 @@ export const Explorer = ({
});
};

const formatError = (name: string, message: string, details: string) => {
return {
name: name,
message: message,
body: {
attributes: {
error: {
caused_by: {
type: '',
reason: details
}
}
}
}
}
}

const getSavedDataById = async (objectId: string) => {
// load saved query/visualization if object id exists
await savedObjects.fetchSavedObjects({
Expand Down Expand Up @@ -220,7 +221,9 @@ export const Explorer = ({

})
.catch((error) => {
setToast(`Cannot get saved data for object id: ${objectId}, error: ${error.message}`, 'danger');
notifications.toasts.addError(error, {
title: `Cannot get saved data for object id: ${objectId}`
});
});
};

Expand Down Expand Up @@ -286,10 +289,10 @@ export const Explorer = ({
} else {
findAutoInterval(curQuery![SELECTED_DATE_RANGE][0], curQuery![SELECTED_DATE_RANGE][1])
getEvents(undefined, (error) => {
setToast(
`Error fetching events: ${error?.body?.message || 'see console error for more details.'}`,
'danger'
);
const formattedError = formatError(error.name, error.message, error.body.message);
notifications.toasts.addError(formattedError, {
title: 'Error fetching events'
});
});
getCountVisualizations(minInterval);
}
Expand Down Expand Up @@ -423,8 +426,10 @@ export const Explorer = ({
setToast(`Timestamp has been overridden successfully.`, 'success');
return res;
})
.catch((error: any) => {
setToast(`Cannot override timestamp, error: ${error.message}`, 'danger');
.catch((error: any) => {
notifications.toasts.addError(error, {
title: 'Cannot override timestamp'
});
})
.finally(() => {
setIsOverridingTimestamp(false);
Expand All @@ -438,7 +443,9 @@ export const Explorer = ({
return res;
})
.catch((error: any) => {
setToast(`Cannot override timestamp, error: ${error.message}`, 'danger');
notifications.toasts.addError(error, {
title: 'Cannot override timestamp'
});
})
.finally(() => {
setIsOverridingTimestamp(false);
Expand Down Expand Up @@ -698,7 +705,9 @@ export const Explorer = ({
return res;
})
.catch((error: any) => {
setToast(`Cannot update query '${selectedPanelNameRef.current}', error: ${error.message}`, 'danger');
notifications.toasts.addError(error, {
title: `Cannot update query '${selectedPanelNameRef.current}'`
});
});
} else {
// create new saved query
Expand All @@ -725,7 +734,9 @@ export const Explorer = ({
if (error?.body?.statusCode === 403) {
showPermissionErrorToast();
} else {
setToast(`Cannot save query '${selectedPanelNameRef.current}', error: ${error.message}`, 'danger');
notifications.toasts.addError(error ,{
title: `Cannot save query '${selectedPanelNameRef.current}'`
});
}
});
}
Expand Down Expand Up @@ -753,7 +764,9 @@ export const Explorer = ({
return res;
})
.catch((error: any) => {
setToast(`Cannot update Visualization '${selectedPanelNameRef.current}', error: ${error.message}`, 'danger');
notifications.toasts.addError(error, {
title: `Cannot update Visualization '${selectedPanelNameRef.current}'`
});
});
} else {
// create new saved visualization
Expand Down Expand Up @@ -783,7 +796,9 @@ export const Explorer = ({
setToast(`New visualization '${selectedPanelNameRef.current}' has been successfully saved.`, 'success');
})
.catch((error: any) => {
setToast(`Cannot save Visualization '${selectedPanelNameRef.current}', error: ${error.message}`, 'danger');
notifications.toasts.addError(error, {
title: `Cannot save Visualization '${selectedPanelNameRef.current}'`
});
});
}
if (!has(savingVisRes, 'objectId')) return;
Expand All @@ -797,7 +812,9 @@ export const Explorer = ({
setToast(`Visualization '${selectedPanelNameRef.current}' has been successfully saved to operation panels.`, 'success');
})
.catch((error: any) => {
setToast(`Cannot add Visualization '${selectedPanelNameRef.current}' to operation panels, error: ${error.message}`, 'danger');
notifications.toasts.addError(error, {
title: `Cannot add Visualization '${selectedPanelNameRef.current}' to operation panels`
});
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const LogExplorer = ({
setToast,
savedObjectId,
getExistingEmptyTab,
history
history,
notifications,
}: ILogExplorerProps) => {

const dispatch = useDispatch();
Expand Down Expand Up @@ -181,6 +182,7 @@ export const LogExplorer = ({
timestampUtils={ timestampUtils }
setToast={ setToast }
history={history}
notifications={notifications}
savedObjectId={savedObjectId}
tabCreatedTypes={tabCreatedTypes}
/>
Expand Down