Skip to content

Commit

Permalink
[Logs UI] Versioning for Logs related APIs (#158710)
Browse files Browse the repository at this point in the history
## 📓  Summary

Closes #157324 
Closes #159275 
Closes #159303 

This work converts the APIs related to the Logs UI feature into
versioned APIs using the new [Kibana versioned
router](https://docs.elastic.dev/kibana-dev-docs/versioning-http-apis#4-adhere-to-the-http-versioning-specification).

The converted APIs are the following, where each endpoint now is set to
version `1`:
-
[log_views](https://github.com/elastic/kibana/tree/main/x-pack/plugins/infra/server/routes/log_views)
-
[log_entries](https://github.com/elastic/kibana/tree/main/x-pack/plugins/infra/server/routes/log_entries)
-
[log_analysis](https://github.com/elastic/kibana/tree/main/x-pack/plugins/infra/server/routes/log_analysis)
-
[log_alerts](https://github.com/elastic/kibana/tree/main/x-pack/plugins/infra/server/routes/log_alerts)

The PR also includes moving the interfaces and runtime types relatives
to each endpoint's group into the recommended practices for [versioning
interfaces](https://docs.elastic.dev/kibana-dev-docs/versioning-interfaces).

## 🧪 Testing

- Navigate to the Logs UI settings page and verify the log view is
correctly retrieved and can be successfully updated.
- Navigate to the Logs stream page and verify the stream entries are
retrieved and rendered.
- Navigate to the Anomalies and Categories pages page and verify the
anomalies entries are retrieved and rendered correctly.
- Create a Log threshold alert and verify the chart preview data are
correctly retrieved and shown.

---------

Co-authored-by: Marco Antonio Ghiani <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
3 people authored Jun 8, 2023
1 parent 4f67843 commit e3fddf3
Show file tree
Hide file tree
Showing 70 changed files with 987 additions and 844 deletions.
8 changes: 5 additions & 3 deletions x-pack/plugins/infra/common/http_api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
* 2.0.
*/

export * from './log_analysis';
export * from './metadata_api';
export * from './log_entries';
export * from './metrics_explorer';
export * from './metrics_api';
export * from './log_alerts';
export * from './snapshot_api';
export * from './host_details';
export * from './infra';
Expand All @@ -20,4 +17,9 @@ export * from './infra';
*/
export * from './latest';
export * as inventoryViewsV1 from './inventory_views/v1';
export * as logAlertsV1 from './log_alerts/v1';
export * as logAnalysisResultsV1 from './log_analysis/results/v1';
export * as logAnalysisValidationV1 from './log_analysis/validation/v1';
export * as logEntriesV1 from './log_entries/v1';
export * as logViewsV1 from './log_views/v1';
export * as metricsExplorerViewsV1 from './metrics_explorer_views/v1';
5 changes: 5 additions & 0 deletions x-pack/plugins/infra/common/http_api/latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@
*/

export * from './inventory_views/v1';
export * from './log_alerts/v1';
export * from './log_analysis/results/v1';
export * from './log_analysis/validation/v1';
export * from './log_entries/v1';
export * from './log_views/v1';
export * from './metrics_explorer_views/v1';
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
timeUnitRT,
timeSizeRT,
groupByRT,
} from '../../alerting/logs/log_threshold/types';
import { persistedLogViewReferenceRT } from '../../log_views';
} from '../../../alerting/logs/log_threshold/types';
import { persistedLogViewReferenceRT } from '../../../log_views';

export const LOG_ALERTS_CHART_PREVIEW_DATA_PATH = '/api/infra/log_alerts/chart_preview_data';

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

import * as rt from 'io-ts';

import { persistedLogViewReferenceRT } from '../../../log_views';
import { timeRangeRT, routeTimingMetadataRT } from '../../shared';
import { persistedLogViewReferenceRT } from '../../../../log_views';
import { timeRangeRT, routeTimingMetadataRT } from '../../../shared';
import {
logEntryAnomalyRT,
logEntryAnomalyDatasetsRT,
anomaliesSortRT,
paginationRT,
paginationCursorRT,
} from '../../../log_analysis';
} from '../../../../log_analysis';

export const LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_PATH =
'/api/infra/log_analysis/results/log_entry_anomalies';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/

import * as rt from 'io-ts';
import { persistedLogViewReferenceRT } from '../../../log_views';
import { persistedLogViewReferenceRT } from '../../../../log_views';

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

export const LOG_ANALYSIS_GET_LOG_ENTRY_ANOMALIES_DATASETS_PATH =
'/api/infra/log_analysis/results/log_entry_anomalies_datasets';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

import * as rt from 'io-ts';

import { persistedLogViewReferenceRT } from '../../../log_views';
import { persistedLogViewReferenceRT } from '../../../../log_views';
import {
badRequestErrorRT,
forbiddenErrorRT,
timeRangeRT,
routeTimingMetadataRT,
} from '../../shared';
} from '../../../shared';

import { logEntryCategoryRT, categoriesSortRT } from '../../../log_analysis';
import { logEntryCategoryRT, categoriesSortRT } from '../../../../log_analysis';

export const LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORIES_PATH =
'/api/infra/log_analysis/results/log_entry_categories';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
forbiddenErrorRT,
timeRangeRT,
routeTimingMetadataRT,
} from '../../shared';
import { persistedLogViewReferenceRT } from '../../../log_views';
} from '../../../shared';
import { persistedLogViewReferenceRT } from '../../../../log_views';
export const LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_DATASETS_PATH =
'/api/infra/log_analysis/results/log_entry_category_datasets';

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

import * as rt from 'io-ts';

import { timeRangeRT, routeTimingMetadataRT } from '../../shared';
import { timeRangeRT, routeTimingMetadataRT } from '../../../shared';

export const LOG_ANALYSIS_GET_LATEST_LOG_ENTRY_CATEGORY_DATASETS_STATS_PATH =
'/api/infra/log_analysis/results/latest_log_entry_category_datasets_stats';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import * as rt from 'io-ts';

import { persistedLogViewReferenceRT } from '../../../log_views';
import { persistedLogViewReferenceRT } from '../../../../log_views';
import {
badRequestErrorRT,
forbiddenErrorRT,
timeRangeRT,
routeTimingMetadataRT,
} from '../../shared';
import { logEntryContextRT } from '../../../log_entry';
} from '../../../shared';
import { logEntryContextRT } from '../../../../log_entry';

export const LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORY_EXAMPLES_PATH =
'/api/infra/log_analysis/results/log_entry_category_examples';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/

import * as rt from 'io-ts';
import { persistedLogViewReferenceRT } from '../../../log_views';
import { logEntryExampleRT } from '../../../log_analysis';
import { persistedLogViewReferenceRT } from '../../../../log_views';
import { logEntryExampleRT } from '../../../../log_analysis';
import {
badRequestErrorRT,
forbiddenErrorRT,
timeRangeRT,
routeTimingMetadataRT,
} from '../../shared';
} from '../../../shared';

export const LOG_ANALYSIS_GET_LOG_ENTRY_RATE_EXAMPLES_PATH =
'/api/infra/log_analysis/results/log_entry_examples';
Expand Down Expand Up @@ -48,7 +48,7 @@ export type GetLogEntryExamplesRequestPayload = rt.TypeOf<
* response
*/

export const getLogEntryExamplesSuccessReponsePayloadRT = rt.intersection([
export const getLogEntryExamplesSuccessResponsePayloadRT = rt.intersection([
rt.type({
data: rt.type({
examples: rt.array(logEntryExampleRT),
Expand All @@ -60,11 +60,11 @@ export const getLogEntryExamplesSuccessReponsePayloadRT = rt.intersection([
]);

export type GetLogEntryExamplesSuccessReponsePayload = rt.TypeOf<
typeof getLogEntryExamplesSuccessReponsePayloadRT
typeof getLogEntryExamplesSuccessResponsePayloadRT
>;

export const getLogEntryExamplesResponsePayloadRT = rt.union([
getLogEntryExamplesSuccessReponsePayloadRT,
getLogEntryExamplesSuccessResponsePayloadRT,
badRequestErrorRT,
forbiddenErrorRT,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import * as rt from 'io-ts';
import { mappingRuntimeFieldRT } from '../../shared/es_request';
import { mappingRuntimeFieldRT } from '../../../shared/es_request';

export const LOG_ANALYSIS_VALIDATE_INDICES_PATH =
'/api/infra/log_analysis/validation/log_entry_rate_indices';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import * as rt from 'io-ts';
import { logEntryCursorRT, logEntryRT } from '../../log_entry';
import { logViewColumnConfigurationRT } from '../../log_views';
import { logViewReferenceRT } from '../../log_views';
import { logEntryCursorRT, logEntryRT } from '../../../log_entry';
import { logViewColumnConfigurationRT } from '../../../log_views';
import { logViewReferenceRT } from '../../../log_views';

export const LOG_ENTRIES_HIGHLIGHTS_PATH = '/api/log_entries/highlights';

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

import * as rt from 'io-ts';
import { logViewReferenceRT } from '../../log_views';
import { logViewReferenceRT } from '../../../log_views';

export const LOG_ENTRIES_SUMMARY_PATH = '/api/log_entries/summary';

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

import * as rt from 'io-ts';
import { logEntryCursorRT } from '../../log_entry';
import { logEntryCursorRT } from '../../../log_entry';
import { logEntriesSummaryRequestRT, logEntriesSummaryBucketRT } from './summary';

export const LOG_ENTRIES_SUMMARY_HIGHLIGHTS_PATH = '/api/log_entries/summary_highlights';
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/infra/common/http_api/log_views/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@
*/

export { getLogViewUrl, LOG_VIEW_URL } from './common';
export * from './get_log_view';
export * from './put_log_view';
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
*/

import * as rt from 'io-ts';
import { logViewRT } from '../../log_views';
import { logViewRT } from '../../../log_views';

export const getLogViewRequestParamsRT = rt.type({
// the id of the log view
logViewId: rt.string,
});

export type GetLogViewRequestParams = rt.TypeOf<typeof getLogViewRequestParamsRT>;

export const getLogViewResponsePayloadRT = rt.type({
data: logViewRT,
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* 2.0.
*/

export * from './results';
export * from './validation';
export * from './get_log_view';
export * from './put_log_view';
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import * as rt from 'io-ts';
import { logViewAttributesRT, logViewRT } from '../../log_views';
import { logViewAttributesRT, logViewRT } from '../../../log_views';

export const putLogViewRequestParamsRT = rt.type({
logViewId: rt.string,
Expand All @@ -15,6 +15,7 @@ export const putLogViewRequestParamsRT = rt.type({
export const putLogViewRequestPayloadRT = rt.type({
attributes: rt.partial(logViewAttributesRT.type.props),
});

export type PutLogViewRequestPayload = rt.TypeOf<typeof putLogViewRequestPayloadRT>;

export const putLogViewResponsePayloadRT = rt.type({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { Color, colorTransformer } from '../../../../../common/color_palette';
import {
GetLogAlertsChartPreviewDataAlertParamsSubset,
getLogAlertsChartPreviewDataAlertParamsSubsetRT,
} from '../../../../../common/http_api/log_alerts';
} from '../../../../../common/http_api';
import { useChartPreviewData } from './hooks/use_chart_preview_data';
import { decodeOrThrow } from '../../../../../common/runtime_types';
import { useKibanaTimeZoneSetting } from '../../../../hooks/use_kibana_time_zone_setting';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
* 2.0.
*/

import { useState, useMemo } from 'react';
import { HttpHandler } from '@kbn/core/public';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { useMemo, useState } from 'react';
import { isRatioRule } from '../../../../../../common/alerting/logs/log_threshold';
import { PersistedLogViewReference } from '../../../../../../common/log_views';
import { ExecutionTimeRange } from '../../../../../types';
import { useTrackedPromise } from '../../../../../utils/use_tracked_promise';
import {
GetLogAlertsChartPreviewDataAlertParamsSubset,
getLogAlertsChartPreviewDataRequestPayloadRT,
GetLogAlertsChartPreviewDataSuccessResponsePayload,
getLogAlertsChartPreviewDataSuccessResponsePayloadRT,
getLogAlertsChartPreviewDataRequestPayloadRT,
LOG_ALERTS_CHART_PREVIEW_DATA_PATH,
} from '../../../../../../common/http_api';
import { PersistedLogViewReference } from '../../../../../../common/log_views';
import { decodeOrThrow } from '../../../../../../common/runtime_types';
import { GetLogAlertsChartPreviewDataAlertParamsSubset } from '../../../../../../common/http_api/log_alerts';
import { ExecutionTimeRange } from '../../../../../types';
import { useTrackedPromise } from '../../../../../utils/use_tracked_promise';

interface Options {
logViewReference: PersistedLogViewReference;
Expand Down Expand Up @@ -147,6 +147,7 @@ export const callGetChartPreviewDataAPI = async (
},
})
),
version: '1',
});

return decodeOrThrow(getLogAlertsChartPreviewDataSuccessResponsePayloadRT)(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
ISearchOptions,
} from '@kbn/data-plugin/public';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { getLogViewResponsePayloadRT } from '../../../common/http_api/log_views';
import { getLogViewResponsePayloadRT } from '../../../common/http_api';
import { defaultLogViewAttributes } from '../../../common/log_views';
import {
LogEntriesSearchResponsePayload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const callGetLatestCategoriesDatasetsStatsAPI = async (
},
})
),
version: '1',
});

return decodeOrThrow(getLatestLogEntryCategoryDatasetsStatsSuccessResponsePayloadRT)(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const callValidateDatasetsAPI = async (requestArgs: RequestArgs, fetch: H
},
})
),
version: '1',
});

return decodeOrThrow(validateLogEntryDatasetsResponsePayloadRT)(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const callValidateIndicesAPI = async (requestArgs: RequestArgs, fetch: Ht
// @ts-expect-error TODO: fix after elasticsearch-js bump
validationIndicesRequestPayloadRT.encode({ data: { indices, fields, runtimeMappings } })
),
version: '1',
});

return decodeOrThrow(validationIndicesResponsePayloadRT)(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import {
ValidateLogEntryDatasetsResponsePayload,
ValidationIndicesResponsePayload,
} from '../../../../common/http_api/log_analysis';
} from '../../../../common/http_api';
import { DatasetFilter } from '../../../../common/log_analysis';
import { DeleteJobsResponsePayload } from './api/ml_cleanup';
import { FetchJobStatusResponsePayload } from './api/ml_get_jobs_summary_api';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const fetchLogEntriesHighlights = async (
const response = await fetch(LOG_ENTRIES_HIGHLIGHTS_PATH, {
method: 'POST',
body: JSON.stringify(logEntriesHighlightsRequestRT.encode(requestArgs)),
version: '1',
});

return decodeOrThrow(logEntriesHighlightsResponseRT)(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const fetchLogSummaryHighlights = async (
const response = await fetch(LOG_ENTRIES_SUMMARY_HIGHLIGHTS_PATH, {
method: 'POST',
body: JSON.stringify(logEntriesSummaryHighlightsRequestRT.encode(requestArgs)),
version: '1',
});

return decodeOrThrow(logEntriesSummaryHighlightsResponseRT)(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const fetchLogSummary = async (
const response = await fetch(LOG_ENTRIES_SUMMARY_PATH, {
method: 'POST',
body: JSON.stringify(logEntriesSummaryRequestRT.encode(requestArgs)),
version: '1',
});

return decodeOrThrow(logEntriesSummaryResponseRT)(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { HttpHandler } from '@kbn/core/public';
import {
ValidateLogEntryDatasetsResponsePayload,
ValidationIndicesResponsePayload,
} from '../../../common/http_api/log_analysis';
} from '../../../common/http_api';
import { DeleteJobsResponsePayload } from './api/ml_cleanup';
import { FetchJobStatusResponsePayload } from './api/ml_get_jobs_summary_api';
import { GetMlModuleResponsePayload } from './api/ml_get_module';
Expand Down
Loading

0 comments on commit e3fddf3

Please sign in to comment.