[8.0] Ensure logstash getNodes always contains a uuid (#124201) (#124319)

* Ensure logstash getNodes always contains a uuid (#124201)

This is less of an issue on main since we've stopped querying `metricbeat-*` but might become important when we start doing agent testing (`metrics-*`).

On 8.0 it's easy to have error documents land in `metricbeat-*` for standalone logstash and break the UI.

(cherry picked from commit fb1ca61db5)

# Conflicts:
#	x-pack/plugins/monitoring/server/lib/logstash/get_nodes.ts

* No global stubs required in 8.0 branch
This commit is contained in:
Mat Schaffer 2022-02-02 18:09:55 +09:00 committed by GitHub
parent 04eaaf3c33
commit 2f9491207f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 63 additions and 0 deletions

View file

@ -0,0 +1,60 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { getNodes } from './get_nodes';
import { INDEX_PATTERN_LOGSTASH, STANDALONE_CLUSTER_CLUSTER_UUID } from '../../../common/constants';
import { LegacyRequest } from '../../types';
describe('getNodes', () => {
it('ensures collapse key is present query responses', async () => {
const configs: { [key: string]: number } = { 'monitoring.ui.max_bucket_size': 10000 };
const config = {
get: jest.fn().mockImplementation((key: string) => configs[key]),
};
const response = {};
const callWithRequest = jest.fn().mockResolvedValue(response);
const req = {
server: {
config() {
return config;
},
plugins: {
elasticsearch: {
getCluster: () => ({
callWithRequest,
}),
},
},
},
payload: {
// borrowed from detail_drawer.test.js
timeRange: {
min: 1516131138639,
max: 1516135440463,
},
},
} as unknown as LegacyRequest;
await getNodes(req, INDEX_PATTERN_LOGSTASH, {
clusterUuid: STANDALONE_CLUSTER_CLUSTER_UUID,
});
expect(callWithRequest.mock.calls.length).toBe(1);
expect(callWithRequest.mock.calls[0].length).toBe(3);
const filters = callWithRequest.mock.calls[0][2].body.query.bool.filter;
expect(filters).toContainEqual(
expect.objectContaining({
exists: {
field: 'logstash_stats.logstash.uuid',
},
})
);
});
});

View file

@ -75,12 +75,15 @@ export async function getNodes(
const start = moment.utc(req.payload.timeRange.min).valueOf();
const end = moment.utc(req.payload.timeRange.max).valueOf();
const filters = [{ exists: { field: 'logstash_stats.logstash.uuid' } }];
const params = {
index: lsIndexPattern,
size: config.get('monitoring.ui.max_bucket_size'), // FIXME
ignore_unavailable: true,
body: {
query: createQuery({
filters,
start,
end,
clusterUuid,