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

[Monitoring] Fix issue with loading logstash node page under standalone cluster #93617

Merged
Merged
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 @@ -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