Skip to content

Commit 1d53ea8

Browse files
Update / Add tests for exclude event data
1 parent c5411ef commit 1d53ea8

File tree

4 files changed

+132
-23
lines changed

4 files changed

+132
-23
lines changed

x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_request_diagnostics_modal/index.test.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe('AgentRequestDiagnosticsModal', () => {
5858

5959
expect(mockSendPostRequestDiagnostics).toHaveBeenCalledWith('agent1', {
6060
additional_metrics: ['CPU'],
61+
exclude_events_log: true,
6162
});
6263
});
6364

@@ -70,6 +71,23 @@ describe('AgentRequestDiagnosticsModal', () => {
7071

7172
expect(mockSendPostRequestDiagnostics).toHaveBeenCalledWith('agent1', {
7273
additional_metrics: [],
74+
exclude_events_log: true,
75+
});
76+
});
77+
78+
it('should have Exclude Events Log set to false when checkbox is checked', async () => {
79+
const { utils } = render();
80+
81+
act(() => {
82+
fireEvent.click(utils.getByTestId('includeEventsLogCheckbox'));
83+
});
84+
act(() => {
85+
fireEvent.click(utils.getByTestId('confirmModalConfirmButton'));
86+
});
87+
88+
expect(mockSendPostRequestDiagnostics).toHaveBeenCalledWith('agent1', {
89+
additional_metrics: [],
90+
exclude_events_log: false,
7391
});
7492
});
7593

@@ -86,6 +104,7 @@ describe('AgentRequestDiagnosticsModal', () => {
86104
expect(mockSendPostBulkRequestDiagnostics).toHaveBeenCalledWith({
87105
additional_metrics: ['CPU'],
88106
agents: ['agent1', 'agent2'],
107+
exclude_events_log: true,
89108
});
90109
});
91110

@@ -98,9 +117,25 @@ describe('AgentRequestDiagnosticsModal', () => {
98117

99118
expect(mockSendPostBulkRequestDiagnostics).toHaveBeenCalledWith({
100119
additional_metrics: [],
120+
exclude_events_log: true,
101121
agents: ['agent1', 'agent2'],
102122
});
103123
});
104124

105-
// TODO Create test
125+
it('should have Exclude Events Log set to false when checkbox is checked within bulk action', async () => {
126+
const { utils } = render({ agents: [{ id: 'agent1' }, { id: 'agent2' }], agentCount: 2 });
127+
128+
act(() => {
129+
fireEvent.click(utils.getByTestId('includeEventsLogCheckbox'));
130+
});
131+
act(() => {
132+
fireEvent.click(utils.getByTestId('confirmModalConfirmButton'));
133+
});
134+
135+
expect(mockSendPostBulkRequestDiagnostics).toHaveBeenCalledWith({
136+
additional_metrics: [],
137+
exclude_events_log: false,
138+
agents: ['agent1', 'agent2'],
139+
});
140+
});
106141
});

x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_request_diagnostics_modal/index.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,20 @@ export const AgentRequestDiagnosticsModal: React.FunctionComponent<Props> = ({
133133
defaultMessage="Diagnostics files are stored in Elasticsearch, and as such can incur storage costs. By default, files are periodically deleted via an ILM policy."
134134
/>
135135
</p>
136-
<p>
137-
<EuiCheckbox
138-
id="cpuMetricsCheckbox"
139-
data-test-subj="cpuMetricsCheckbox"
140-
label="Collect additional CPU metrics"
141-
checked={cpuMetricsEnabled}
142-
onChange={() => setCPUMetricsEnabled(!cpuMetricsEnabled)}
143-
/>
144-
</p>
145-
<p>
146-
<EuiCheckbox
147-
id="includeEventsLogCheckbox"
148-
data-test-subj="includeEventsLogCheckbox"
149-
label="Include Events Logs (might contain sensible information)"
150-
checked={includeEventsLogEnabled}
151-
onChange={() => setIncludeEventsLog(!includeEventsLogEnabled)}
152-
/>
153-
</p>
136+
<EuiCheckbox
137+
id="cpuMetricsCheckbox"
138+
data-test-subj="cpuMetricsCheckbox"
139+
label="Collect additional CPU metrics"
140+
checked={cpuMetricsEnabled}
141+
onChange={() => setCPUMetricsEnabled(!cpuMetricsEnabled)}
142+
/>
143+
<EuiCheckbox
144+
id="includeEventsLogCheckbox"
145+
data-test-subj="includeEventsLogCheckbox"
146+
label="Include Events Logs (might contain sensible information)"
147+
checked={includeEventsLogEnabled}
148+
onChange={() => setIncludeEventsLog(!includeEventsLogEnabled)}
149+
/>
154150
</EuiConfirmModal>
155151
);
156152
};

x-pack/plugins/fleet/server/routes/agent/request_diagnostics_handler.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('request diagnostics handler', () => {
3636
let mockRequest: KibanaRequest<
3737
{ agentId: string },
3838
undefined,
39-
{ additional_metrics: RequestDiagnosticsAdditionalMetrics[] },
39+
{ additional_metrics: RequestDiagnosticsAdditionalMetrics[]; exclude_events_log?: boolean },
4040
any
4141
>;
4242

@@ -59,7 +59,7 @@ describe('request diagnostics handler', () => {
5959
} as unknown as RequestHandlerContext;
6060
mockRequest = httpServerMock.createKibanaRequest({
6161
params: { agentId: 'agent1' },
62-
body: { additional_metrics: ['CPU'] },
62+
body: { additional_metrics: ['CPU'], exclude_events_log: false },
6363
});
6464
});
6565

x-pack/test/fleet_api_integration/apis/agents/request_diagnostics.ts

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,85 @@ export default function (providerContext: FtrProviderContext) {
162162
const action: any = actionsRes.hits.hits[0]._source;
163163
expect(action.data.additional_metrics).contain('CPU');
164164
});
165+
166+
it('should create action with exclude_events_log when api contains exclude_events_log option', async () => {
167+
await supertest
168+
.post(`/api/fleet/agents/agent1/request_diagnostics`)
169+
.set('kbn-xsrf', 'xxx')
170+
.send({
171+
exclude_events_log: false,
172+
})
173+
.expect(200);
174+
const actionsRes = await es.search({
175+
index: '.fleet-actions',
176+
body: {
177+
sort: [{ '@timestamp': { order: 'desc' } }],
178+
},
179+
});
180+
const action: any = actionsRes.hits.hits[0]._source;
181+
expect(action.data.exclude_events_log).equal(false);
182+
});
183+
184+
it('/agents/bulk_request_diagnostics should add exclude_events_log option to action doc', async () => {
185+
await supertestWithoutAuth
186+
.post(`/api/fleet/agents/bulk_request_diagnostics`)
187+
.set('kbn-xsrf', 'xxx')
188+
.auth(testUsers.fleet_agents_read_only.username, testUsers.fleet_agents_read_only.password)
189+
.send({
190+
agents: ['agent2', 'agent3'],
191+
exclude_events_log: true,
192+
});
193+
194+
const actionsRes = await es.search({
195+
index: '.fleet-actions',
196+
body: {
197+
sort: [{ '@timestamp': { order: 'desc' } }],
198+
},
199+
});
200+
const action: any = actionsRes.hits.hits[0]._source;
201+
expect(action.data.exclude_events_log).equal(true);
202+
});
203+
204+
it('should create action with exclude_events_log when api contains exclude_events_log and collect CPU option', async () => {
205+
await supertest
206+
.post(`/api/fleet/agents/agent1/request_diagnostics`)
207+
.set('kbn-xsrf', 'xxx')
208+
.send({
209+
additional_metrics: ['CPU'],
210+
exclude_events_log: false,
211+
})
212+
.expect(200);
213+
const actionsRes = await es.search({
214+
index: '.fleet-actions',
215+
body: {
216+
sort: [{ '@timestamp': { order: 'desc' } }],
217+
},
218+
});
219+
const action: any = actionsRes.hits.hits[0]._source;
220+
expect(action.data.exclude_events_log).equal(false);
221+
expect(action.data.additional_metrics).contain('CPU');
222+
});
223+
224+
it('/agents/bulk_request_diagnostics should add exclude_events_log and collect CPU option to action doc', async () => {
225+
await supertestWithoutAuth
226+
.post(`/api/fleet/agents/bulk_request_diagnostics`)
227+
.set('kbn-xsrf', 'xxx')
228+
.auth(testUsers.fleet_agents_read_only.username, testUsers.fleet_agents_read_only.password)
229+
.send({
230+
agents: ['agent2', 'agent3'],
231+
additional_metrics: ['CPU'],
232+
exclude_events_log: true,
233+
});
234+
235+
const actionsRes = await es.search({
236+
index: '.fleet-actions',
237+
body: {
238+
sort: [{ '@timestamp': { order: 'desc' } }],
239+
},
240+
});
241+
const action: any = actionsRes.hits.hits[0]._source;
242+
expect(action.data.exclude_events_log).equal(true);
243+
expect(action.data.additional_metrics).contain('CPU');
244+
});
165245
});
166246
}
167-
168-
// TODO Add test

0 commit comments

Comments
 (0)