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

[ES body removal] @elastic/obs-ux-logs-team #204863

Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
* 2.0.
*/

import { QueryDslBoolQuery } from '@elastic/elasticsearch/lib/api/types';
import type { ElasticsearchClient } from '@kbn/core/server';
import type {
AggregationsCompositeAggregation,
QueryDslBoolQuery,
} from '@elastic/elasticsearch/lib/api/types';
import { DataStreamDocsStat } from '../../../common/api_types';
import { createDatasetQualityESClient } from '../../utils';
import { rangeQuery } from '../../utils/queries';
Expand All @@ -32,7 +35,9 @@ export async function getAggregatedDatasetPaginatedResults(options: {

const datasetQualityESClient = createDatasetQualityESClient(esClient);

const aggs = (afterKey?: Dataset) => ({
const aggs = (
afterKey?: Dataset
): { datasets: { composite: AggregationsCompositeAggregation } } => ({
datasets: {
composite: {
...(afterKey ? { after: afterKey } : {}),
Expand Down Expand Up @@ -65,6 +70,7 @@ export async function getAggregatedDatasetPaginatedResults(options: {

const currResults =
response.aggregations?.datasets.buckets.map((bucket) => ({
// @ts-expect-error types above don't infer these bucket.key types
dataset: `${bucket.key.type}-${bucket.key.dataset}-${bucket.key.namespace}`,
count: bucket.doc_count,
})) ?? [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function getDegradedFieldValues({
],
});

const values = extractAndDeduplicateValues(response.hits.hits, degradedField);
const values = extractAndDeduplicateValues(response.hits.hits as SearchHit[], degradedField);

return {
field: degradedField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
*/

import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import type {
AggregationsDateHistogramAggregation,
AggregationsMaxAggregation,
AggregationsTermsAggregation,
} from '@elastic/elasticsearch/lib/api/types';
import { DegradedFieldResponse } from '../../../../common/api_types';
import { MAX_DEGRADED_FIELDS } from '../../../../common/constants';
import { INDEX, TIMESTAMP, _IGNORED } from '../../../../common/es_fields';
Expand All @@ -31,7 +36,16 @@ export async function getDegradedFields({

const mustQuery = [...existsQuery(_IGNORED)];

const aggs = {
const aggs: {
degradedFields: {
terms: AggregationsTermsAggregation;
aggs: {
lastOccurrence: { max: AggregationsMaxAggregation };
index: { terms: AggregationsTermsAggregation };
timeSeries: { date_histogram: AggregationsDateHistogramAggregation };
};
};
} = {
degradedFields: {
terms: {
size: MAX_DEGRADED_FIELDS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { DataView, DataViewsContract, FieldSpec } from '@kbn/data-views-plugin/common';
import { LogSourcesService } from '@kbn/logs-data-access-plugin/common/services/log_sources_service/types';
import { TIEBREAKER_FIELD, TIMESTAMP_FIELD } from '../constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import * as rt from 'io-ts';
import {
logEntryAfterCursorRT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { JsonArray, JsonValue } from '@kbn/utility-types';
import { RouteMethod } from '@kbn/core/server';
import { VersionedRouteConfig } from '@kbn/core-http-server';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { TransportRequestParams } from '@elastic/elasticsearch';
import { CoreSetup, IRouter, RouteMethod } from '@kbn/core/server';
import { UI_SETTINGS } from '@kbn/data-plugin/server';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { JsonObject } from '@kbn/utility-types';
import { LogColumn, LogEntry, LogEntryCursor } from '../../../../common/log_entry';
import {
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 type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';

import { commonSearchSuccessResponseFieldsRT } from '../../../../utils/elasticsearch_runtime_types';

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

import { errors, TransportResult } from '@elastic/elasticsearch';
import { AsyncSearchSubmitResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { AsyncSearchSubmitResponse } from '@elastic/elasticsearch/lib/api/types';
import {
elasticsearchServiceMock,
httpServerMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import * as rt from 'io-ts';
import {
LogEntryAfterCursor,
Expand Down Expand Up @@ -39,26 +39,24 @@ export const createGetLogEntriesQuery = (
return {
index: logEntriesIndex,
allow_no_indices: true,
body: {
size,
track_scores: false,
track_total_hits: false,
query: {
bool: {
filter: [
...(query ? [query] : []),
...(highlightQuery ? [highlightQuery] : []),
...createTimeRangeFilterClauses(startTimestamp, endTimestamp, timestampField),
],
},
size,
track_scores: false,
track_total_hits: false,
query: {
bool: {
filter: [
...(query ? [query] : []),
...(highlightQuery ? [highlightQuery] : []),
...createTimeRangeFilterClauses(startTimestamp, endTimestamp, timestampField),
],
},
fields,
runtime_mappings: runtimeMappings,
_source: false,
...createSortClause(sortDirection, timestampField, tiebreakerField),
...createSearchAfterClause(cursor),
...createHighlightClause(highlightQuery, fields),
},
fields,
runtime_mappings: runtimeMappings,
_source: false,
...createSortClause(sortDirection, timestampField, tiebreakerField),
...createSearchAfterClause(cursor),
...createHighlightClause(highlightQuery, fields),
};
};

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

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import * as rt from 'io-ts';
import { jsonArrayRT } from '../../../../common/typed_json';
import {
Expand All @@ -21,30 +21,28 @@ export const createGetLogEntryQuery = (
runtimeMappings?: estypes.MappingRuntimeFields
): estypes.AsyncSearchSubmitRequest => ({
index: logEntryIndex,
body: {
size: 1,
terminate_after: 1,
track_scores: false,
track_total_hits: false,
query: {
ids: {
values: [logEntryId],
},
size: 1,
terminate_after: 1,
track_scores: false,
track_total_hits: false,
query: {
ids: {
values: [logEntryId],
},
fields: ['*'],
runtime_mappings: runtimeMappings,
sort: [
{
[timestampField]: {
order: 'desc',
format: 'strict_date_optional_time_nanos',
numeric_type: 'date_nanos',
},
},
{ [tiebreakerField]: 'desc' },
],
_source: false,
},
fields: ['*'],
runtime_mappings: runtimeMappings,
sort: [
{
[timestampField]: {
order: 'desc',
format: 'strict_date_optional_time_nanos',
numeric_type: 'date_nanos',
},
},
{ [tiebreakerField]: 'desc' },
],
_source: false,
});

export const logEntryHitRT = rt.intersection([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import {
logEntryAfterCursorRT,
logEntryBeforeCursorRT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { HttpHandler } from '@kbn/core/public';
import { decodeOrThrow } from '@kbn/io-ts-utils';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { HttpHandler } from '@kbn/core/public';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';

import { decodeOrThrow } from '@kbn/io-ts-utils';
import type { ValidationIndicesFieldSpecification } from '../../../../../common/http_api';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { HttpHandler } from '@kbn/core/public';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { IdFormat, JobType } from '../../../../common/http_api/latest';
import type {
ValidateLogEntryDatasetsResponsePayload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { i18n } from '@kbn/i18n';
import type { HttpHandler } from '@kbn/core/public';
import type { IdFormat } from '../../../../../../common/http_api/latest';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import createContainer from 'constate';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { useMemo } from 'react';
import type { IdFormat } from '../../../../../../common/http_api/latest';
import { useLogAnalysisModule } from '../../log_analysis_module';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { HttpHandler } from '@kbn/core/public';
import type { IdFormat } from '../../../../../../common/http_api/latest';
import type { DatasetFilter, LogEntryRateJobType } from '../../../../../../common/log_analysis';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import createContainer from 'constate';
import { useMemo } from 'react';
import type { IdFormat } from '../../../../../../common/http_api/latest';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { PersistedLogViewReference, ResolvedLogView } from '@kbn/logs-shared-plugin/common';
import { decodeOrThrow } from '@kbn/io-ts-utils';
import type { IdFormat, IdFormatByJobType } from '../../../common/http_api/latest';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { ElasticsearchClient } from '@kbn/core/server';
import type {
LogEntryContext,
Expand Down
Loading