Skip to content

Commit fb1ca61

Browse files
authored
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.
1 parent 20e8381 commit fb1ca61

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { getNodes } from './get_nodes';
9+
import { STANDALONE_CLUSTER_CLUSTER_UUID } from '../../../common/constants';
10+
import { LegacyRequest } from '../../types';
11+
12+
jest.mock('../../static_globals', () => ({
13+
Globals: {
14+
app: {
15+
config: {
16+
ui: {
17+
ccs: { enabled: true },
18+
},
19+
},
20+
},
21+
},
22+
}));
23+
24+
describe('getNodes', () => {
25+
it('ensures collapse key is present query responses', async () => {
26+
const configs: { [key: string]: number } = { 'monitoring.ui.max_bucket_size': 10000 };
27+
const config = {
28+
get: jest.fn().mockImplementation((key: string) => configs[key]),
29+
};
30+
31+
const response = {};
32+
const callWithRequest = jest.fn().mockResolvedValue(response);
33+
34+
const req = {
35+
server: {
36+
config() {
37+
return config;
38+
},
39+
plugins: {
40+
elasticsearch: {
41+
getCluster: () => ({
42+
callWithRequest,
43+
}),
44+
},
45+
},
46+
},
47+
payload: {
48+
// borrowed from detail_drawer.test.js
49+
timeRange: {
50+
min: 1516131138639,
51+
max: 1516135440463,
52+
},
53+
},
54+
} as unknown as LegacyRequest;
55+
56+
await getNodes(req, {
57+
clusterUuid: STANDALONE_CLUSTER_CLUSTER_UUID,
58+
});
59+
60+
expect(callWithRequest.mock.calls.length).toBe(1);
61+
expect(callWithRequest.mock.calls[0].length).toBe(3);
62+
63+
const filters = callWithRequest.mock.calls[0][2].body.query.bool.filter;
64+
expect(filters).toContainEqual(
65+
expect.objectContaining({
66+
exists: {
67+
field: 'logstash_stats.logstash.uuid',
68+
},
69+
})
70+
);
71+
});
72+
});

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ export async function getNodes(req: LegacyRequest, { clusterUuid }: { clusterUui
8181
const start = moment.utc(req.payload.timeRange.min).valueOf();
8282
const end = moment.utc(req.payload.timeRange.max).valueOf();
8383

84+
const filters = [{ exists: { field: 'logstash_stats.logstash.uuid' } }];
85+
8486
const params = {
8587
index: indexPatterns,
8688
size: config.get('monitoring.ui.max_bucket_size'), // FIXME
@@ -90,6 +92,7 @@ export async function getNodes(req: LegacyRequest, { clusterUuid }: { clusterUui
9092
type,
9193
dsDataset: `${moduleType}.${dataset}`,
9294
metricset: dataset,
95+
filters,
9396
start,
9497
end,
9598
clusterUuid,

0 commit comments

Comments
 (0)