Skip to content

Commit

Permalink
Add Correct Erroring in Event Analytics (opensearch-project#248)
Browse files Browse the repository at this point in the history
* Add check for properties

Signed-off-by: Eugene Lee <[email protected]>

* Change logic order to support switching between match and other where fields

Signed-off-by: Eugene Lee <[email protected]>

* Autocomplete for data values

Signed-off-by: Eugene Lee <[email protected]>

* Fetch data values earlier and save them

Signed-off-by: Eugene Lee <[email protected]>

* Update to current status

Signed-off-by: Eugene Lee <[email protected]>

* Fetch dataValues for match early

Signed-off-by: Eugene Lee <[email protected]>

* Try addError

Signed-off-by: Eugene Lee <[email protected]>

* Fix error messaging on Event Explorer

Signed-off-by: Eugene Lee <[email protected]>

* Remove fielddata

Signed-off-by: Eugene Lee <[email protected]>

* Assign string to fields with fields property

Signed-off-by: Eugene Lee <[email protected]>

* Remove possible double toast and add console log back in

Signed-off-by: Eugene Lee <[email protected]>
  • Loading branch information
eugenesk24 authored and joshuali925 committed Nov 17, 2021
1 parent a8e62bc commit ae3236f
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 39 deletions.
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 @@ -265,8 +264,8 @@ 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].properties) {
fieldsFromBackend.push({ label: element, type: 'string' })
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 {
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 {
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

0 comments on commit ae3236f

Please sign in to comment.