[ES body removal] @elastic/stack-monitoring (#204865)

This commit is contained in:
Alejandro Fernández Haro 2025-01-22 09:25:21 +01:00 committed by GitHub
parent a878c98ecc
commit ca26eaa718
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 320 additions and 348 deletions

View file

@ -7,7 +7,7 @@
import { ElasticsearchClient } from '@kbn/core/server';
import { get } from 'lodash';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { StackProductUsage } from '../types';
interface ESIndicesBucket {
@ -37,49 +37,47 @@ export async function fetchESUsage(
'hits.hits._source.cluster_stats.nodes.count.total',
'aggregations.indices.buckets',
],
body: {
size: 1,
sort: [
{
timestamp: {
order: 'desc',
unmapped_type: 'long',
},
},
],
query: {
bool: {
must: [
{
term: {
type: {
value: 'cluster_stats',
},
},
},
{
term: {
cluster_uuid: {
value: clusterUuid,
},
},
},
{
range: {
timestamp: {
gte: 'now-1h',
},
},
},
],
size: 1,
sort: [
{
timestamp: {
order: 'desc',
unmapped_type: 'long',
},
},
aggs: {
indices: {
terms: {
field: '_index',
size: 2,
],
query: {
bool: {
must: [
{
term: {
type: {
value: 'cluster_stats',
},
},
},
{
term: {
cluster_uuid: {
value: clusterUuid,
},
},
},
{
range: {
timestamp: {
gte: 'now-1h',
},
},
},
],
},
},
aggs: {
indices: {
terms: {
field: '_index',
size: 2,
},
},
},

View file

@ -7,7 +7,7 @@
import { get } from 'lodash';
import { ElasticsearchClient } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { INDEX_PATTERN_ELASTICSEARCH } from '../../../../common/constants';
import { getCcsIndexPattern } from '../../../lib/alerts/get_ccs_index_pattern';
@ -23,35 +23,33 @@ export async function fetchLicenseType(
const params: estypes.SearchRequest = {
index,
filter_path: ['hits.hits._source.license'],
body: {
size: 1,
sort: [
{
timestamp: {
order: 'desc',
unmapped_type: 'long',
size: 1,
sort: [
{
timestamp: {
order: 'desc',
unmapped_type: 'long',
},
},
],
query: {
bool: {
must: [
{
term: {
cluster_uuid: {
value: clusterUuid,
},
},
},
},
],
query: {
bool: {
must: [
{
term: {
cluster_uuid: {
value: clusterUuid,
},
{
term: {
type: {
value: 'cluster_stats',
},
},
{
term: {
type: {
value: 'cluster_stats',
},
},
},
],
},
},
],
},
},
};

View file

@ -54,10 +54,10 @@ describe('fetchStackProductUsage', () => {
]
);
const params = searchMock.mock.calls[0][0];
expect(params.body.query.bool.must[0].term.type.value).toBe('kibana_stats');
expect(params.body.query.bool.must[1].term.cluster_uuid.value).toBe(clusterUuid);
expect(params.body.query.bool.must[2].range.timestamp.gte).toBe('now-1h');
expect(params.body.query.bool.must[3].term.type.value).toBe('foo');
expect(params.query.bool.must[0].term.type.value).toBe('kibana_stats');
expect(params.query.bool.must[1].term.cluster_uuid.value).toBe(clusterUuid);
expect(params.query.bool.must[2].range.timestamp.gte).toBe('now-1h');
expect(params.query.bool.must[3].term.type.value).toBe('foo');
});
it('should get the usage data', async () => {

View file

@ -7,7 +7,7 @@
import { get } from 'lodash';
import { ElasticsearchClient } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { MonitoringConfig } from '../../../config';
import { StackProductUsage } from '../types';
@ -44,50 +44,48 @@ export async function fetchStackProductUsage(
index,
ignore_unavailable: true,
filter_path: ['aggregations.uuids.buckets'],
body: {
size: 0,
query: {
bool: {
must: [
{
term: {
type: {
value: type,
},
size: 0,
query: {
bool: {
must: [
{
term: {
type: {
value: type,
},
},
{
term: {
cluster_uuid: {
value: clusterUuid,
},
},
},
{
range: {
timestamp: {
gte: 'now-1h',
},
},
},
...filters,
],
},
},
aggs: {
uuids: {
terms: {
field: uuidPath,
size,
},
aggs: {
indices: {
terms: {
field: '_index',
size: 2,
{
term: {
cluster_uuid: {
value: clusterUuid,
},
},
},
{
range: {
timestamp: {
gte: 'now-1h',
},
},
},
...filters,
],
},
},
aggs: {
uuids: {
terms: {
field: uuidPath,
size,
},
aggs: {
indices: {
terms: {
field: '_index',
size: 2,
},
},
},
},
},

View file

@ -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 { elasticsearchServiceMock } from '@kbn/core/server/mocks';
import { fetchAvailableCcs } from './fetch_available_ccs';

View file

@ -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 { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { fetchClusterHealth } from './fetch_cluster_health';

View file

@ -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 { elasticsearchServiceMock } from '@kbn/core/server/mocks';
import { fetchClusters } from './fetch_clusters';

View file

@ -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 { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { fetchCpuUsageNodeStats } from './fetch_cpu_usage_node_stats';

View file

@ -7,7 +7,7 @@
import { elasticsearchServiceMock } from '@kbn/core/server/mocks';
import { fetchElasticsearchVersions } from './fetch_elasticsearch_versions';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
jest.mock('../../static_globals', () => ({
Globals: {

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { ClusterGetSettingsResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { ClusterGetSettingsResponse } from '@elastic/elasticsearch/lib/api/types';
import { checkClusterSettings } from '.';
import { LegacyRequest } from '../../types';

View file

@ -6,7 +6,7 @@
*/
import { get } from 'lodash';
import { ClusterGetSettingsResponse } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { ClusterGetSettingsResponse } from '@elastic/elasticsearch/lib/api/types';
import { findReason } from './find_reason';
import { ClusterSettingsReasonResponse, LegacyRequest } from '../../types';

View file

@ -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 { RequestHandlerContext } from '@kbn/core/server';
import { prefixIndexPatternWithCcs } from '../../../../../../common/ccs_utils';
import {

View file

@ -6,7 +6,7 @@
*/
import { CoreSetup, ElasticsearchClient, Logger, PluginInitializerContext } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { MonitoringConfig } from './config';
import { PluginsSetup } from './types';
import { mbSafeQuery } from './lib/mb_safe_query';

View file

@ -37,7 +37,7 @@ describe('Get Beats Stats', () => {
searchMock.returns(Promise.resolve({}));
await fetchBeatsStats(callCluster, clusterUuids, start, end, {} as any);
const { args } = searchMock.firstCall;
const [{ body }] = args;
const [body] = args;
expect(body.from).toEqual(0);
expect(body.size).toEqual(10000);
@ -47,7 +47,7 @@ describe('Get Beats Stats', () => {
searchMock.returns(Promise.resolve({}));
await fetchBeatsStats(callCluster, clusterUuids, start, end, { page: 1 } as any);
const { args } = searchMock.firstCall;
const [{ body }] = args;
const [body] = args;
expect(body.from).toEqual(10000);
expect(body.size).toEqual(10000);
@ -57,7 +57,7 @@ describe('Get Beats Stats', () => {
searchMock.returns(Promise.resolve({}));
await fetchBeatsStats(callCluster, clusterUuids, start, end, { page: 2 } as any);
const { args } = searchMock.firstCall;
const [{ body }] = args;
const [body] = args;
expect(body.from).toEqual(20000);
expect(body.size).toEqual(10000);

View file

@ -7,7 +7,7 @@
import { get } from 'lodash';
import { ElasticsearchClient } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { createQuery } from './create_query';
import { INDEX_PATTERN_BEATS } from '../../common/constants';
@ -340,25 +340,23 @@ async function fetchBeatsByType(
'hits.hits._source.beats_state.state',
'hits.hits._source.beats_state.beat.type',
],
body: {
query: createQuery({
start,
end,
filters: [
{ terms: { cluster_uuid: clusterUuids } },
{
bool: {
must_not: { term: { [`${type}.beat.type`]: 'apm-server' } },
must: { term: { type } },
},
query: createQuery({
start,
end,
filters: [
{ terms: { cluster_uuid: clusterUuids } },
{
bool: {
must_not: { term: { [`${type}.beat.type`]: 'apm-server' } },
must: { term: { type } },
},
],
}) as estypes.QueryDslQueryContainer,
from: page * HITS_SIZE,
collapse: { field: `${type}.beat.uuid` },
sort: [{ [`${type}.timestamp`]: { order: 'desc', unmapped_type: 'long' } }],
size: HITS_SIZE,
},
},
],
}) as estypes.QueryDslQueryContainer,
from: page * HITS_SIZE,
collapse: { field: `${type}.beat.uuid` },
sort: [{ [`${type}.timestamp`]: { order: 'desc', unmapped_type: 'long' } }],
size: HITS_SIZE,
};
const results = await callCluster.search<BeatsStats>(params);

View file

@ -8,7 +8,7 @@
import { get } from 'lodash';
import moment from 'moment';
import { ElasticsearchClient } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { createQuery } from './create_query';
import {
INDEX_PATTERN_ELASTICSEARCH,
@ -43,29 +43,27 @@ export async function fetchClusterUuids(
index: INDEX_PATTERN_ELASTICSEARCH,
ignore_unavailable: true,
filter_path: 'aggregations.cluster_uuids.buckets.key',
body: {
size: 0,
query: createQuery({
start,
end,
filters: [
{
bool: {
should: [
{ term: { type: 'cluster_stats' } },
{ term: { 'metricset.name': 'cluster_stats' } },
],
},
},
],
}) as estypes.QueryDslQueryContainer,
aggs: {
cluster_uuids: {
terms: {
field: 'cluster_uuid',
size: maxBucketSize,
size: 0,
query: createQuery({
start,
end,
filters: [
{
bool: {
should: [
{ term: { type: 'cluster_stats' } },
{ term: { 'metricset.name': 'cluster_stats' } },
],
},
},
],
}) as estypes.QueryDslQueryContainer,
aggs: {
cluster_uuids: {
terms: {
field: 'cluster_uuid',
size: maxBucketSize,
},
},
},
};

View file

@ -6,7 +6,7 @@
*/
import { ElasticsearchClient } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import moment from 'moment';
import { INDEX_PATTERN_ELASTICSEARCH } from '../../common/constants';
@ -66,39 +66,37 @@ export async function fetchElasticsearchStats(
'hits.hits._source.stack_stats',
'hits.hits._source.elasticsearch',
],
body: {
size: maxBucketSize,
query: {
bool: {
filter: [
/*
* Note: Unlike most places, we don't care about the old _type: cluster_stats because it would NOT
* have the license in it (that used to be in the .monitoring-data-2 index in cluster_info)
*/
{
bool: {
should: [
{ term: { type: 'cluster_stats' } },
{ term: { 'metricset.name': 'cluster_stats' } },
],
size: maxBucketSize,
query: {
bool: {
filter: [
/*
* Note: Unlike most places, we don't care about the old _type: cluster_stats because it would NOT
* have the license in it (that used to be in the .monitoring-data-2 index in cluster_info)
*/
{
bool: {
should: [
{ term: { type: 'cluster_stats' } },
{ term: { 'metricset.name': 'cluster_stats' } },
],
},
},
{ terms: { cluster_uuid: clusterUuids } },
{
range: {
timestamp: {
format: 'epoch_millis',
gte: moment.utc(start).valueOf(),
lte: moment.utc(end).valueOf(),
},
},
{ terms: { cluster_uuid: clusterUuids } },
{
range: {
timestamp: {
format: 'epoch_millis',
gte: moment.utc(start).valueOf(),
lte: moment.utc(end).valueOf(),
},
},
},
],
},
},
],
},
collapse: { field: 'cluster_uuid' },
sort: { timestamp: { order: 'desc', unmapped_type: 'long' } },
},
collapse: { field: 'cluster_uuid' },
sort: { timestamp: { order: 'desc', unmapped_type: 'long' } },
};
return await callCluster.search<ESClusterStats>(params);

View file

@ -7,7 +7,7 @@
import { get } from 'lodash';
import { ElasticsearchClient } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { createQuery } from './create_query';
import {
INDEX_PATTERN_KIBANA,
@ -317,20 +317,18 @@ export async function fetchHighLevelStats<
`hits.hits._source.${product}_stats.cloud.region`,
`hits.hits._source.${product}_stats.cloud.zone`,
],
body: {
size: maxBucketSize,
query: createQuery({
start,
end,
type: `${product}_stats`,
filters,
}) as estypes.QueryDslQueryContainer,
collapse: {
// a more ideal field would be the concatenation of the uuid + transport address for duped UUIDs (copied installations)
field: `${product}_stats.${product}.uuid`,
},
sort: [{ timestamp: { order: 'desc', unmapped_type: 'long' } }],
size: maxBucketSize,
query: createQuery({
start,
end,
type: `${product}_stats`,
filters,
}) as estypes.QueryDslQueryContainer,
collapse: {
// a more ideal field would be the concatenation of the uuid + transport address for duped UUIDs (copied installations)
field: `${product}_stats.${product}.uuid`,
},
sort: [{ timestamp: { order: 'desc', unmapped_type: 'long' } }],
};
const response = await callCluster.search<T>(params, {

View file

@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import {
getUsageStats,
combineStats,

View file

@ -7,7 +7,7 @@
import moment from 'moment';
import { isEmpty } from 'lodash';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { ElasticsearchClient } from '@kbn/core/server';
import { KIBANA_SYSTEM_ID, TELEMETRY_COLLECTION_INTERVAL } from '../../common/constants';
import {

View file

@ -6,7 +6,7 @@
*/
import { ElasticsearchClient } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import type { LicenseGetLicenseInformation } from '@elastic/elasticsearch/lib/api/types';
import { INDEX_PATTERN_ELASTICSEARCH, USAGE_FETCH_INTERVAL } from '../../common/constants';
@ -42,32 +42,30 @@ export async function fetchLicenses(
index: INDEX_PATTERN_ELASTICSEARCH,
ignore_unavailable: true,
filter_path: ['hits.hits._source.cluster_uuid', 'hits.hits._source.license'],
body: {
size: maxBucketSize,
query: {
bool: {
filter: [
/*
* Note: Unlike most places, we don't care about the old _type: cluster_stats because it would NOT
* have the license in it (that used to be in the .monitoring-data-2 index in cluster_info)
*/
{ term: { type: 'cluster_stats' } },
{ terms: { cluster_uuid: clusterUuids } },
{
range: {
timestamp: {
format: 'epoch_millis',
gte: timestamp - USAGE_FETCH_INTERVAL,
lte: timestamp,
},
size: maxBucketSize,
query: {
bool: {
filter: [
/*
* Note: Unlike most places, we don't care about the old _type: cluster_stats because it would NOT
* have the license in it (that used to be in the .monitoring-data-2 index in cluster_info)
*/
{ term: { type: 'cluster_stats' } },
{ terms: { cluster_uuid: clusterUuids } },
{
range: {
timestamp: {
format: 'epoch_millis',
gte: timestamp - USAGE_FETCH_INTERVAL,
lte: timestamp,
},
},
],
},
},
],
},
collapse: { field: 'cluster_uuid' },
sort: { timestamp: { order: 'desc', unmapped_type: 'long' } },
},
collapse: { field: 'cluster_uuid' },
sort: { timestamp: { order: 'desc', unmapped_type: 'long' } },
};
return await callCluster.search<ESClusterStatsWithLicense>(params);

View file

@ -82,7 +82,7 @@ describe('LogstashAgentMonitoring', () => {
{} as any
);
const { args } = searchMock.firstCall;
const [{ body }] = args;
const [body] = args;
expect(body.from).toEqual(0);
expect(body.size).toEqual(10000);
@ -125,7 +125,7 @@ describe('LogstashAgentMonitoring', () => {
{} as any
);
const { args } = searchMock.firstCall;
const [{ body }] = args;
const [body] = args;
expect(body.query).toEqual(expected);
});
});

View file

@ -6,7 +6,7 @@
*/
import { ElasticsearchClient } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import moment from 'moment';
import { createQuery } from './create_query';
import { mapToList } from './get_high_level_stats';
@ -201,32 +201,30 @@ export class LogstashAgentMonitoring implements LogstashMonitoring {
index: INDEX_PATTERN_LOGSTASH_METRICS_NODE,
ignore_unavailable: true,
filter_path: filterPath,
body: {
query: createQuery({
filters: [
{
bool: {
should: [{ term: { 'data_stream.dataset': 'logstash.node' } }],
query: createQuery({
filters: [
{
bool: {
should: [{ term: { 'data_stream.dataset': 'logstash.node' } }],
},
},
{
range: {
'@timestamp': {
format: 'epoch_millis',
gte: moment.utc(start).valueOf(),
lte: moment.utc(end).valueOf(),
},
},
{
range: {
'@timestamp': {
format: 'epoch_millis',
gte: moment.utc(start).valueOf(),
lte: moment.utc(end).valueOf(),
},
},
},
],
}) as estypes.QueryDslQueryContainer,
collapse: {
field: 'host.id',
},
sort: [{ '@timestamp': { order: 'desc', unmapped_type: 'long' } }],
from: page * HITS_SIZE,
size: HITS_SIZE,
},
],
}) as estypes.QueryDslQueryContainer,
collapse: {
field: 'host.id',
},
sort: [{ '@timestamp': { order: 'desc', unmapped_type: 'long' } }],
from: page * HITS_SIZE,
size: HITS_SIZE,
};
const results = await callCluster.search<LogstashStats>(params, {
@ -284,14 +282,12 @@ export class LogstashAgentMonitoring implements LogstashMonitoring {
index: INDEX_PATTERN_LOGSTASH_METRICS_PLUGINS,
ignore_unavailable: true,
filter_path: ['hits.hits._source.logstash.pipeline'],
body: {
query: createQuery({
filters,
}) as estypes.QueryDslQueryContainer,
collapse: { field: `logstash.pipeline.plugin.${pluginType}.id` },
sort: [{ '@timestamp': { order: 'desc', unmapped_type: 'long' } }],
size: HITS_SIZE,
},
query: createQuery({
filters,
}) as estypes.QueryDslQueryContainer,
collapse: { field: `logstash.pipeline.plugin.${pluginType}.id` },
sort: [{ '@timestamp': { order: 'desc', unmapped_type: 'long' } }],
size: HITS_SIZE,
};
const results = await callCluster.search<LogstashState>(params, {

View file

@ -100,7 +100,7 @@ describe('LogstashMetricbeatMonitoring', () => {
{} as any
);
const { args } = searchMock.firstCall;
const [{ body }] = args;
const [body] = args;
expect(body.from).toEqual(0);
expect(body.size).toEqual(10000);
@ -137,7 +137,7 @@ describe('LogstashMetricbeatMonitoring', () => {
{} as any
);
const { args } = searchMock.firstCall;
const [{ body }] = args;
const [body] = args;
expect(body.query).toEqual(expected);
});
});

View file

@ -6,7 +6,7 @@
*/
import { ElasticsearchClient } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { createQuery } from './create_query';
import { mapToList } from './get_high_level_stats';
import { incrementByKey } from './get_high_level_stats';
@ -271,28 +271,26 @@ export class LogstashMetricbeatMonitoring implements LogstashMonitoring {
index: this.indexPattern.stats,
ignore_unavailable: true,
filter_path: filterPath,
body: {
query: createQuery({
start,
end,
filters: [
{
bool: {
should: [
{ term: { 'metricset.name': 'node_stats' } },
{ term: { 'data_stream.dataset': 'logstash.stack_monitoring.node_stats' } },
],
},
query: createQuery({
start,
end,
filters: [
{
bool: {
should: [
{ term: { 'metricset.name': 'node_stats' } },
{ term: { 'data_stream.dataset': 'logstash.stack_monitoring.node_stats' } },
],
},
],
}) as estypes.QueryDslQueryContainer,
collapse: {
field: 'logstash.node.stats.logstash.uuid',
},
sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }],
from: page * HITS_SIZE,
size: HITS_SIZE,
},
],
}) as estypes.QueryDslQueryContainer,
collapse: {
field: 'logstash.node.stats.logstash.uuid',
},
sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }],
from: page * HITS_SIZE,
size: HITS_SIZE,
};
const results = await callCluster.search<LogstashStats>(params, {
@ -335,28 +333,26 @@ export class LogstashMetricbeatMonitoring implements LogstashMonitoring {
index: this.indexPattern.state,
ignore_unavailable: true,
filter_path: filterPath,
body: {
query: createQuery({
// metricbeat occasionally sends state metrics
// so, not using start and end periods as we need node state info to fill plugin usages
filters: [
{ terms: { 'logstash.node.state.pipeline.ephemeral_id': ephemeralIds } },
{
bool: {
should: [
{ term: { 'metricset.name': 'node' } },
{ term: { 'data_stream.dataset': 'logstash.stack_monitoring.node' } },
],
},
query: createQuery({
// metricbeat occasionally sends state metrics
// so, not using start and end periods as we need node state info to fill plugin usages
filters: [
{ terms: { 'logstash.node.state.pipeline.ephemeral_id': ephemeralIds } },
{
bool: {
should: [
{ term: { 'metricset.name': 'node' } },
{ term: { 'data_stream.dataset': 'logstash.stack_monitoring.node' } },
],
},
],
}) as estypes.QueryDslQueryContainer,
collapse: {
field: 'logstash.node.state.pipeline.ephemeral_id',
},
sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }],
size: ephemeralIds.length,
},
],
}) as estypes.QueryDslQueryContainer,
collapse: {
field: 'logstash.node.state.pipeline.ephemeral_id',
},
sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }],
size: ephemeralIds.length,
};
const results = await callCluster.search<LogstashState>(params, {

View file

@ -87,7 +87,7 @@ describe('LogstashSelfMonitoring', () => {
{} as any
);
const { args } = searchMock.firstCall;
const [{ body }] = args;
const [body] = args;
expect(body.from).toEqual(0);
expect(body.size).toEqual(10000);
@ -130,7 +130,7 @@ describe('LogstashSelfMonitoring', () => {
{} as any
);
const { args } = searchMock.firstCall;
const [{ body }] = args;
const [body] = args;
expect(body.query).toEqual(expected);
});
});

View file

@ -6,7 +6,7 @@
*/
import { ElasticsearchClient } from '@kbn/core/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type * as estypes from '@elastic/elasticsearch/lib/api/types';
import { createQuery } from './create_query';
import { mapToList } from './get_high_level_stats';
import { incrementByKey } from './get_high_level_stats';
@ -257,26 +257,24 @@ export class LogstashSelfMonitoring implements LogstashMonitoring {
index: INDEX_PATTERN_LOGSTASH_MONITORING,
ignore_unavailable: true,
filter_path: filterPath,
body: {
query: createQuery({
start,
end,
filters: [
{ term: { cluster_uuid: clusterUuid } },
{
bool: {
should: [{ term: { type: 'logstash_stats' } }],
},
query: createQuery({
start,
end,
filters: [
{ term: { cluster_uuid: clusterUuid } },
{
bool: {
should: [{ term: { type: 'logstash_stats' } }],
},
],
}) as estypes.QueryDslQueryContainer,
from: page * HITS_SIZE,
collapse: {
field: 'logstash_stats.logstash.uuid',
},
sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }],
size: HITS_SIZE,
},
],
}) as estypes.QueryDslQueryContainer,
from: page * HITS_SIZE,
collapse: {
field: 'logstash_stats.logstash.uuid',
},
sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }],
size: HITS_SIZE,
};
const results = await callCluster.search<LogstashStats>(params, {
@ -321,25 +319,23 @@ export class LogstashSelfMonitoring implements LogstashMonitoring {
index: INDEX_PATTERN_LOGSTASH_MONITORING,
ignore_unavailable: true,
filter_path: filterPath,
body: {
query: createQuery({
start,
end,
filters: [
{ terms: { 'logstash_state.pipeline.ephemeral_id': ephemeralIds } },
{
bool: {
should: [{ term: { type: 'logstash_state' } }],
},
query: createQuery({
start,
end,
filters: [
{ terms: { 'logstash_state.pipeline.ephemeral_id': ephemeralIds } },
{
bool: {
should: [{ term: { type: 'logstash_state' } }],
},
],
}) as estypes.QueryDslQueryContainer,
collapse: {
field: 'logstash_state.pipeline.ephemeral_id',
},
sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }],
size: ephemeralIds.length,
},
],
}) as estypes.QueryDslQueryContainer,
collapse: {
field: 'logstash_state.pipeline.ephemeral_id',
},
sort: [{ ['timestamp']: { order: 'desc', unmapped_type: 'long' } }],
size: ephemeralIds.length,
};
const results = await callCluster.search<LogstashState>(params, {