Skip to content

Commit

Permalink
events timeline improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
benakansara committed Oct 21, 2024
1 parent fb33997 commit e1d9dfe
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export const investigationKeys = {
userProfiles: (profileIds: Set<string>) =>
[...investigationKeys.all, 'userProfiles', ...profileIds] as const,
tags: () => [...investigationKeys.all, 'tags'] as const,
events: (rangeFrom?: string, rangeTo?: string) =>
[...investigationKeys.all, 'events', rangeFrom, rangeTo] as const,
events: (rangeFrom?: string, rangeTo?: string, filter?: string) =>
[...investigationKeys.all, 'events', rangeFrom, rangeTo, filter] as const,
stats: () => [...investigationKeys.all, 'stats'] as const,
lists: () => [...investigationKeys.all, 'list'] as const,
list: (params: { page: number; perPage: number; search?: string; filter?: string }) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ export interface Response {
export function useFetchEvents({
rangeFrom,
rangeTo,
filter,
}: {
rangeFrom?: string;
rangeTo?: string;
filter?: string;
}): Response {
const {
core: {
Expand All @@ -35,12 +37,13 @@ export function useFetchEvents({
} = useKibana();

const { isInitialLoading, isLoading, isError, isSuccess, isRefetching, data } = useQuery({
queryKey: investigationKeys.events(rangeFrom, rangeTo),
queryKey: investigationKeys.events(rangeFrom, rangeTo, filter),
queryFn: async ({ signal }) => {
return await http.get<GetEventsResponse>(`/api/observability/events`, {
query: {
rangeFrom,
rangeTo,
filter,
},
version: '2023-10-31',
signal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { Chart, Axis, AreaSeries, Position, ScaleType, Settings } from '@elastic
import { useActiveCursor } from '@kbn/charts-plugin/public';
import { EuiSkeletonText } from '@elastic/eui';
import { getBrushData } from '@kbn/observability-utils/chart/utils';
import { Group } from '@kbn/observability-alerting-rule-utils';
import { ALERT_GROUP } from '@kbn/rule-data-utils';
import { AnnotationEvent } from './annotation_event';
import { TIME_LINE_THEME } from './timeline_theme';
import { useFetchEvents } from '../../../../hooks/use_fetch_events';
Expand All @@ -24,10 +26,20 @@ export const EventsTimeLine = () => {
const baseTheme = dependencies.start.charts.theme.useChartsBaseTheme();

const { globalParams, updateInvestigationParams } = useInvestigation();
const { alert } = useInvestigation();

const groups = useMemo(
() =>
(alert?.[ALERT_GROUP] as unknown as Group[])
?.map(({ field }) => `"${field}":"${alert?.[field]}"`)
.join(','),
[alert]
);

const { data: events, isLoading } = useFetchEvents({
rangeFrom: globalParams.timeRange.from,
rangeTo: globalParams.timeRange.to,
filter: `{${groups}}`,
});

const chartRef = useRef(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export async function getAlertEvents(
id: _source[ALERT_UUID],
title: `${_source[ALERT_RULE_CATEGORY]} breached`,
description: _source[ALERT_REASON],
timestamp: new Date(_source['@timestamp']).getTime(),
timestamp: new Date(_source[ALERT_START] as string).getTime(),
eventType: 'alert',
alertStatus: _source[ALERT_STATUS],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ const genLensEqForCustomThresholdRule = (criterion: MetricExpression) => {

criterion.metrics.forEach((metric: CustomThresholdExpressionMetric) => {
const metricFilter = metric.filter ? `kql='${metric.filter}'` : '';
metricNameResolver[metric.name] = `${
AggMappingForLens[metric.aggType] ? AggMappingForLens[metric.aggType] : metric.aggType
}(${metric.field ? metric.field : metricFilter})`;
if (metric.aggType === 'rate') {
metricNameResolver[metric.name] = `counter_rate(max(${
metric.field ? metric.field : metricFilter
}))`;
} else {
metricNameResolver[metric.name] = `${
AggMappingForLens[metric.aggType] ? AggMappingForLens[metric.aggType] : metric.aggType
}(${metric.field ? metric.field : metricFilter})`;
}
});

let equation = criterion.equation
Expand Down

0 comments on commit e1d9dfe

Please sign in to comment.