Skip to content

Commit

Permalink
[Logs UI] Support partitioned log rate results in API (elastic#46751)
Browse files Browse the repository at this point in the history
* Add partitioning to log rate results API
  • Loading branch information
weltenwort authored and Kerry350 committed Oct 3, 2019
1 parent 8d2bc28 commit c73a911
Show file tree
Hide file tree
Showing 17 changed files with 1,023 additions and 547 deletions.
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>
<EuiFlexItem grow={false}>
<EuiSuperDatePicker
start={selectedTimeRange.startTime}
end={selectedTimeRange.endTime}
Expand Down
Loading

0 comments on commit c73a911

Please sign in to comment.