diff --git a/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.test.js b/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.test.js index 62cca4c06de8..e34defc43afc 100644 --- a/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.test.js +++ b/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.test.js @@ -6,7 +6,9 @@ */ import moment from 'moment'; -import { handleResponse } from './get_node_info'; +import { STANDALONE_CLUSTER_CLUSTER_UUID } from '../../../common/constants'; +import { handleResponse, getNodeInfo } from './get_node_info'; +import { standaloneClusterFilter } from '../standalone_clusters/standalone_cluster_query_filter'; describe('get_logstash_info', () => { // TODO: test was not running before and is not up to date @@ -147,4 +149,29 @@ describe('get_logstash_info', () => { }, }); }); + + it('works with standalone cluster', async () => { + const callWithRequest = jest.fn().mockReturnValue({ + then: jest.fn(), + }); + const req = { + server: { + plugins: { + elasticsearch: { + getCluster: () => ({ + callWithRequest, + }), + }, + }, + }, + }; + await getNodeInfo(req, '.monitoring-logstash-*', { + clusterUuid: STANDALONE_CLUSTER_CLUSTER_UUID, + }); + expect(callWithRequest.mock.calls.length).toBe(1); + expect(callWithRequest.mock.calls[0].length).toBe(3); + expect(callWithRequest.mock.calls[0][2].body.query.bool.filter[0]).toBe( + standaloneClusterFilter + ); + }); }); diff --git a/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.ts b/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.ts index 87f91c2fcefe..60d4da6c8335 100644 --- a/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.ts +++ b/x-pack/plugins/monitoring/server/lib/logstash/get_node_info.ts @@ -12,6 +12,9 @@ import { checkParam } from '../error_missing_required'; import { calculateAvailability } from '../calculate_availability'; import { LegacyRequest } from '../../types'; import { ElasticsearchResponse } from '../../../common/types/es'; +import { STANDALONE_CLUSTER_CLUSTER_UUID } from '../../../common/constants'; +// @ts-ignore +import { standaloneClusterFilter } from '../standalone_clusters/standalone_cluster_query_filter'; export function handleResponse(resp: ElasticsearchResponse) { const source = resp.hits?.hits[0]?._source?.logstash_stats; @@ -32,6 +35,11 @@ export function getNodeInfo( { clusterUuid, logstashUuid }: { clusterUuid: string; logstashUuid: string } ) { checkParam(lsIndexPattern, 'lsIndexPattern in getNodeInfo'); + const isStandaloneCluster = clusterUuid === STANDALONE_CLUSTER_CLUSTER_UUID; + + const clusterFilter = isStandaloneCluster + ? standaloneClusterFilter + : { term: { cluster_uuid: clusterUuid } }; const params = { index: lsIndexPattern, @@ -48,10 +56,7 @@ export function getNodeInfo( body: { query: { bool: { - filter: [ - { term: { cluster_uuid: clusterUuid } }, - { term: { 'logstash_stats.logstash.uuid': logstashUuid } }, - ], + filter: [clusterFilter, { term: { 'logstash_stats.logstash.uuid': logstashUuid } }], }, }, collapse: { field: 'logstash_stats.logstash.uuid' },