Skip to content

Commit

Permalink
Fix issue with loading logstash node page under standalone cluster (#…
Browse files Browse the repository at this point in the history
…93617)

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
chrisronline and kibanamachine authored Mar 9, 2021
1 parent cceed8d commit 7d237b8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
);
});
});
13 changes: 9 additions & 4 deletions x-pack/plugins/monitoring/server/lib/logstash/get_node_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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' },
Expand Down

0 comments on commit 7d237b8

Please sign in to comment.