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

[EDR Workflows][Osquery] Fix last results pack value #192678

Merged
merged 3 commits into from
Sep 17, 2024
Merged
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
40 changes: 19 additions & 21 deletions x-pack/plugins/osquery/public/packs/pack_queries_status_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const ViewResultsInLensActionComponent: React.FC<ViewResultsInDiscoverActionProp
const { data: logsDataView } = useLogsDataView({ skip: !actionId, checkOnly: true });

const handleClick = useCallback(
(event: any) => {
(event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();

if (logsDataView?.id) {
Expand Down Expand Up @@ -372,33 +372,31 @@ const ScheduledQueryLastResults: React.FC<ScheduledQueryLastResultsProps> = ({
interval,
});

const timestamp = useMemo(() => {
const dateTime = lastResultsData?.['@timestamp'];
if (!dateTime) return undefined;

return Array.isArray(dateTime) ? dateTime[0] : dateTime;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was reported that this issue is a regression. As a result, I’ve accounted for the possibility that some stack versions might return the search aggregation as a string rather than an array of strings.

}, [lastResultsData]);

if (isLoading) {
return <EuiLoadingSpinner />;
}

if (!lastResultsData) {
return <>{'-'}</>;
}

return (
<EuiFlexGroup gutterSize="s" alignItems="center">
<EuiFlexItem grow={4}>
{lastResultsData?.['@timestamp'] ? (
{timestamp ? (
<EuiToolTip
content={
<>
<FormattedDate
value={lastResultsData['@timestamp']}
year="numeric"
month="short"
day="2-digit"
/>{' '}
<FormattedTime value={lastResultsData['@timestamp']} timeZoneName="short" />
<FormattedDate value={timestamp} year="numeric" month="short" day="2-digit" />{' '}
<FormattedTime value={timestamp} timeZoneName="short" />
</>
}
>
<div data-test-subj="last-results-date">
<FormattedRelative value={lastResultsData['@timestamp']} />
<FormattedRelative value={timestamp} />
</div>
</EuiToolTip>
) : (
Expand Down Expand Up @@ -584,7 +582,7 @@ const PackQueriesStatusTableComponent: React.FC<PackQueriesStatusTableProps> = (
Record<string, ReturnType<typeof ScheduledQueryExpandedContent>>
>({});

const renderQueryColumn = useCallback((query: string, item: any) => {
const renderQueryColumn = useCallback((query: string, item: PackQueryFormData) => {
const singleLine = removeMultilines(query);
const content = singleLine.length > 55 ? `${singleLine.substring(0, 55)}...` : singleLine;

Expand Down Expand Up @@ -618,7 +616,7 @@ const PackQueriesStatusTableComponent: React.FC<PackQueriesStatusTableProps> = (
);

const renderLastResultsColumn = useCallback(
(item: any) => (
(item: PackQueryFormData) => (
<ScheduledQueryLastResults
actionId={getPackActionId(item.id, packName)}
interval={item.interval}
Expand All @@ -627,19 +625,19 @@ const PackQueriesStatusTableComponent: React.FC<PackQueriesStatusTableProps> = (
[packName]
);
const renderDocsColumn = useCallback(
(item: any) => (
(item: PackQueryFormData) => (
<DocsColumnResults actionId={getPackActionId(item.id, packName)} interval={item.interval} />
),
[packName]
);
const renderAgentsColumn = useCallback(
(item: any) => (
(item: PackQueryFormData) => (
<AgentsColumnResults actionId={getPackActionId(item.id, packName)} interval={item.interval} />
),
[packName]
);
const renderErrorsColumn = useCallback(
(item: any) => (
(item: PackQueryFormData) => (
<ErrorsColumnResults
queryId={item.id}
interval={item.interval}
Expand All @@ -652,12 +650,12 @@ const PackQueriesStatusTableComponent: React.FC<PackQueriesStatusTableProps> = (
);

const renderDiscoverResultsAction = useCallback(
(item: any) => <PackViewInDiscoverAction item={item} packName={packName} />,
(item: PackQueryFormData) => <PackViewInDiscoverAction item={item} packName={packName} />,
[packName]
);

const renderLensResultsAction = useCallback(
(item: any) => <PackViewInLensAction item={item} packName={packName} />,
(item: PackQueryFormData) => <PackViewInLensAction item={item} packName={packName} />,
[packName]
);

Expand Down