Skip to content

Commit

Permalink
[ES body removal] @elastic/stack-monitoring (elastic#204865)
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo authored Jan 22, 2025
1 parent a878c98 commit ca26eaa
Show file tree
Hide file tree
Showing 27 changed files with 308 additions and 336 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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',
},
size: 1,
sort: [
{
timestamp: {
order: 'desc',
unmapped_type: 'long',
},
],
query: {
bool: {
must: [
{
term: {
type: {
value: 'cluster_stats',
},
},
],
query: {
bool: {
must: [
{
term: {
type: {
value: 'cluster_stats',
},
},
{
term: {
cluster_uuid: {
value: clusterUuid,
},
},
{
term: {
cluster_uuid: {
value: clusterUuid,
},
},
{
range: {
timestamp: {
gte: 'now-1h',
},
},
{
range: {
timestamp: {
gte: 'now-1h',
},
},
],
},
},
aggs: {
indices: {
terms: {
field: '_index',
size: 2,
},
],
},
},
aggs: {
indices: {
terms: {
field: '_index',
size: 2,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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',
},
},
],
},
},
],
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -44,48 +44,46 @@ 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,
},
},
{
term: {
cluster_uuid: {
value: clusterUuid,
},
},
{
range: {
timestamp: {
gte: 'now-1h',
},
},
{
range: {
timestamp: {
gte: 'now-1h',
},
},
...filters,
],
},
},
aggs: {
uuids: {
terms: {
field: uuidPath,
size,
},
aggs: {
indices: {
terms: {
field: '_index',
size: 2,
},
...filters,
],
},
},
aggs: {
uuids: {
terms: {
field: uuidPath,
size,
},
aggs: {
indices: {
terms: {
field: '_index',
size: 2,
},
},
},
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 { elasticsearchServiceMock } from '@kbn/core/server/mocks';
import { fetchAvailableCcs } from './fetch_available_ccs';

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

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 { RequestHandlerContext } from '@kbn/core/server';
import { prefixIndexPatternWithCcs } from '../../../../../../common/ccs_utils';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Loading

0 comments on commit ca26eaa

Please sign in to comment.