Skip to content

Commit

Permalink
showing last reported time
Browse files Browse the repository at this point in the history
  • Loading branch information
juliaElastic committed Nov 30, 2023
1 parent 57fa51e commit 1e0f352
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/rest_spec/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ export interface PostLogstashApiKeyResponse {
export interface GetOutputHealthResponse {
state: string;
message: string;
timestamp: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import { EuiBadge, EuiCallOut } from '@elastic/eui';
import { EuiBadge, EuiCallOut, EuiToolTip } from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { FormattedMessage, FormattedRelative } from '@kbn/i18n-react';
import React, { useEffect, useState } from 'react';
import { useQuery } from '@tanstack/react-query';

Expand Down Expand Up @@ -92,9 +92,30 @@ export const OutputHealth: React.FunctionComponent<Props> = ({ output, showBadge
),
};

return outputHealth?.state
? showBadge
? OutputStatusBadge[outputHealth.state] || null
: EditOutputStatus[outputHealth.state] || null
: null;
const msLastTimestamp = new Date(outputHealth?.timestamp || 0).getTime();
const lastTimestampText = msLastTimestamp ? (
<>
<FormattedMessage
id="xpack.fleet.outputHealth.timestampTooltipText"
defaultMessage="Last reported {timestamp}"
values={{
timestamp: <FormattedRelative value={msLastTimestamp} />,
}}
/>
</>
) : null;

const outputBadge = (outputHealth?.state && OutputStatusBadge[outputHealth?.state]) || null;

return showBadge ? (
lastTimestampText && outputHealth?.state ? (
<EuiToolTip position="top" content={lastTimestampText}>
<>{outputBadge} </>
</EuiToolTip>
) : (
outputBadge
)
) : (
(outputHealth?.state && EditOutputStatus[outputHealth.state]) || null
);
};
3 changes: 3 additions & 0 deletions x-pack/plugins/fleet/server/services/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -965,19 +965,22 @@ class OutputService {
return {
state: 'UNKOWN',
message: '',
timestamp: '',
};
}
const latestHit = response.hits.hits[0]._source as any;
return {
state: latestHit.state,
message: latestHit.message ?? '',
timestamp: latestHit['@timestamp'],
};
}
}

interface OutputHealth {
state: string;
message: string;
timestamp: string;
}

export const outputService = new OutputService();

0 comments on commit 1e0f352

Please sign in to comment.