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

[Logs UI] Support partitioned log rate results in API #46751

Merged
Merged
Show file tree
Hide file tree
Changes from 11 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@

import * as rt from 'io-ts';

import {
badRequestErrorRT,
conflictErrorRT,
forbiddenErrorRT,
metricStatisticsRT,
timeRangeRT,
} from '../../shared';
import { badRequestErrorRT, conflictErrorRT, forbiddenErrorRT, timeRangeRT } from '../../shared';

export const LOG_ANALYSIS_GET_LOG_ENTRY_RATE_PATH =
'/api/infra/log_analysis/results/log_entry_rate';
Expand Down Expand Up @@ -43,12 +37,15 @@ export const logEntryRateAnomaly = rt.type({
typicalLogEntryRate: rt.number,
});

export const logEntryRateHistogramBucket = rt.type({
export const logEntryRateDataSetRT = rt.type({
analysisBucketCount: rt.number,
anomalies: rt.array(logEntryRateAnomaly),
duration: rt.number,
logEntryRateStats: metricStatisticsRT,
modelLowerBoundStats: metricStatisticsRT,
modelUpperBoundStats: metricStatisticsRT,
averageActualLogEntryRate: rt.number,
dataSetId: rt.string,
});

export const logEntryRateHistogramBucket = rt.type({
dataSets: rt.array(logEntryRateDataSetRT),
startTime: rt.number,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { fold } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { identity } from 'fp-ts/lib/function';
import { kfetch } from 'ui/kfetch';

import {
getLogEntryRateRequestPayloadRT,
getLogEntryRateSuccessReponsePayloadRT,
LOG_ANALYSIS_GET_LOG_ENTRY_RATE_PATH,
} from '../../../../../common/http_api/log_analysis';
import { createPlainError, throwErrors } from '../../../../../common/runtime_types';

export const callGetLogEntryRateAPI = async (
sourceId: string,
startTime: number,
endTime: number,
bucketDuration: number
) => {
const response = await kfetch({
method: 'POST',
pathname: LOG_ANALYSIS_GET_LOG_ENTRY_RATE_PATH,
body: JSON.stringify(
getLogEntryRateRequestPayloadRT.encode({
data: {
sourceId,
timeRange: {
startTime,
endTime,
},
bucketDuration,
},
})
),
});
return pipe(
getLogEntryRateSuccessReponsePayloadRT.decode(response),
fold(throwErrors(createPlainError), identity)
);
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@
*/

import { useMemo, useState } from 'react';
import { kfetch } from 'ui/kfetch';

import { fold } from 'fp-ts/lib/Either';
import { pipe } from 'fp-ts/lib/pipeable';
import { identity } from 'fp-ts/lib/function';
import {
getLogEntryRateRequestPayloadRT,
getLogEntryRateSuccessReponsePayloadRT,
GetLogEntryRateSuccessResponsePayload,
LOG_ANALYSIS_GET_LOG_ENTRY_RATE_PATH,
} from '../../../../common/http_api/log_analysis';
import { createPlainError, throwErrors } from '../../../../common/runtime_types';
import { GetLogEntryRateSuccessResponsePayload } from '../../../../common/http_api/log_analysis';
import { useTrackedPromise } from '../../../utils/use_tracked_promise';
import { callGetLogEntryRateAPI } from './api/get_log_entry_rate';

type LogEntryRateResults = GetLogEntryRateSuccessResponsePayload['data'];

Expand All @@ -38,30 +29,10 @@ export const useLogEntryRate = ({
{
cancelPreviousOn: 'resolution',
createPromise: async () => {
return await kfetch({
method: 'POST',
pathname: LOG_ANALYSIS_GET_LOG_ENTRY_RATE_PATH,
body: JSON.stringify(
getLogEntryRateRequestPayloadRT.encode({
data: {
sourceId,
timeRange: {
startTime,
endTime,
},
bucketDuration,
},
})
),
});
return await callGetLogEntryRateAPI(sourceId, startTime, endTime, bucketDuration);
},
onResolve: response => {
const { data } = pipe(
getLogEntryRateSuccessReponsePayloadRT.decode(response),
fold(throwErrors(createPlainError), identity)
);

setLogEntryRate(data);
setLogEntryRate(response.data);
},
},
[sourceId, startTime, endTime, bucketDuration]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import datemath from '@elastic/datemath';
import {
EuiBadge,
EuiFlexGroup,
EuiFlexItem,
EuiPage,
Expand All @@ -17,7 +16,6 @@ import {
EuiSuperDatePicker,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import moment from 'moment';
import React, { useCallback, useMemo, useState } from 'react';

Expand Down Expand Up @@ -122,21 +120,6 @@ export const AnalysisResultsContent = ({
[setAutoRefresh]
);

const anomaliesDetected = useMemo(() => {
if (!logEntryRate) {
return null;
} else {
if (logEntryRate.histogramBuckets && logEntryRate.histogramBuckets.length) {
return logEntryRate.histogramBuckets.reduce(
(acc, bucket) => acc + bucket.anomalies.length,
0
);
} else {
return null;
}
}
}, [logEntryRate]);

return (
<>
{isLoading && !logEntryRate ? (
Expand All @@ -150,29 +133,8 @@ export const AnalysisResultsContent = ({
<EuiPage>
<EuiPanel paddingSize="l">
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem grow={7}>
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={false}>
{anomaliesDetected !== null ? (
<span>
<FormattedMessage
id="xpack.infra.logs.analysis.anomaliesDetectedText"
defaultMessage="Detected {formattedNumber} {number, plural, one {anomaly} other {anomalies}}"
values={{
formattedNumber: (
<EuiBadge color={anomaliesDetected === 0 ? 'default' : 'warning'}>
{anomaliesDetected}
</EuiBadge>
),
number: anomaliesDetected,
}}
/>
</span>
) : null}
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexItem></EuiFlexItem>
Kerry350 marked this conversation as resolved.
Show resolved Hide resolved
<EuiFlexItem grow={false}>
<EuiSuperDatePicker
start={selectedTimeRange.startTime}
end={selectedTimeRange.endTime}
Expand Down
Loading