From 6bde42b95e97fc9ee01551a1a17d37f57c386fbf Mon Sep 17 00:00:00 2001 From: Julia Bardi <90178898+juliaElastic@users.noreply.github.com> Date: Fri, 31 Oct 2025 16:02:21 +0100 Subject: [PATCH] [Fleet] create test data stream data before test (#241410) ## Summary Closes https://github.com/elastic/kibana/issues/230292 It seems some other tests are impacting the agent data status test. Added test logs docs so the incoming data status is always true instead of being flaky. ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [ ] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... (cherry picked from commit b99823fe806b8aba7f3511e0a644a7511a589ef6) --- .../apis/agents/status.ts | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/x-pack/solutions/security/test/fleet_api_integration/apis/agents/status.ts b/x-pack/solutions/security/test/fleet_api_integration/apis/agents/status.ts index 0ebf7e855106b..c232e33274850 100644 --- a/x-pack/solutions/security/test/fleet_api_integration/apis/agents/status.ts +++ b/x-pack/solutions/security/test/fleet_api_integration/apis/agents/status.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; - +import { v4 as uuidv4 } from 'uuid'; import { AGENTS_INDEX } from '@kbn/fleet-plugin/common'; import type { FtrProviderContext } from '../../../api_integration/ftr_provider_context'; import { testUsers } from '../test_users'; @@ -355,6 +355,39 @@ export default function ({ getService }: FtrProviderContext) { .send({ force: true }) .expect(200); + await es.create({ + refresh: 'wait_for', + index: 'logs-system.system-default', + id: uuidv4(), + body: { + agent: { + id: 'agent1', + }, + '@timestamp': new Date().toISOString(), + data_stream: { + dataset: 'system.system', + namespace: 'default', + type: 'logs', + }, + }, + }); + await es.create({ + refresh: 'wait_for', + index: 'logs-system.system-default', + id: uuidv4(), + body: { + agent: { + id: 'agent2', + }, + '@timestamp': new Date().toISOString(), + data_stream: { + dataset: 'system.system', + namespace: 'default', + type: 'logs', + }, + }, + }); + const { body: apiResponse1 } = await supertest .get(`/api/fleet/agent_status/data?agentsIds=agent1&agentsIds=agent2`) .expect(200); @@ -364,13 +397,27 @@ export default function ({ getService }: FtrProviderContext) { ) .expect(200); expect(apiResponse1).to.eql({ - items: [{ agent1: { data: false } }, { agent2: { data: false } }], + items: [{ agent1: { data: true } }, { agent2: { data: true } }], dataPreview: [], }); expect(apiResponse2).to.eql({ - items: [{ agent1: { data: false } }, { agent2: { data: false } }], + items: [{ agent1: { data: true } }, { agent2: { data: true } }], dataPreview: [], }); + + // clean up test data + await es.deleteByQuery({ + index: 'logs-system.system-default', + query: { + bool: { + filter: { + terms: { + 'agent.id': ['agent1', 'agent2'], + }, + }, + }, + }, + }); }); }); }