-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[scout] migrate FTR logstash api tests #262953
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
Merged
dmlemeshko
merged 13 commits into
elastic:main
from
dmlemeshko:scout/migrate-logstash-api-tests
Apr 18, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0b6b454
[logstash] migrate api tests to scout
dmlemeshko 1fb17b6
fix ts errors
dmlemeshko f0ea26d
fix review comments
dmlemeshko a9414a2
Changes from node scripts/regenerate_moon_projects.js --update
kibanamachine d6c4e79
Merge branch 'main' into scout/migrate-logstash-api-tests
dmlemeshko 423d643
add apiServices.logstash helper
dmlemeshko 352019e
Merge branch 'main' into scout/migrate-logstash-api-tests
dmlemeshko 96629f7
Merge branch 'main' into scout/migrate-logstash-api-tests
dmlemeshko d310af0
Merge branch 'main' into scout/migrate-logstash-api-tests
dmlemeshko 7edad9c
Merge branch 'main' into scout/migrate-logstash-api-tests
dmlemeshko f0ad78d
Merge branch 'main' into scout/migrate-logstash-api-tests
dmlemeshko 3d85880
reuse helpers
dmlemeshko 3dc810f
Merge branch 'main' into scout/migrate-logstash-api-tests
dmlemeshko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ plugins: | |
| - infra | ||
| - intercepts | ||
| - lens | ||
| - logstash | ||
| - maps | ||
| - navigation | ||
| - observability | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
x-pack/platform/plugins/private/logstash/test/scout/api/fixtures/constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * 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 type { ElasticsearchRoleDescriptor } from '@kbn/scout'; | ||
|
|
||
| export const API_PATHS = { | ||
| CLUSTER: 'api/logstash/cluster', | ||
| PIPELINE: (id: string) => `api/logstash/pipeline/${id}`, | ||
| PIPELINES: 'api/logstash/pipelines', | ||
| PIPELINES_DELETE: 'api/logstash/pipelines/delete', | ||
| }; | ||
|
|
||
| export const COMMON_HEADERS = { | ||
| 'kbn-xsrf': 'scout', | ||
| 'x-elastic-internal-origin': 'kibana', | ||
| }; | ||
|
|
||
| export const PIPELINE_IDS = { | ||
| TWEETS_AND_BEATS: 'tweets_and_beats', | ||
| FAST_GENERATOR: 'fast_generator', | ||
| /** Unique IDs for the bulk-delete test */ | ||
| BULK_DELETE_1: 'scout_bulk_delete_1', | ||
| BULK_DELETE_2: 'scout_bulk_delete_2', | ||
| }; | ||
|
|
||
| /** Expected response body for GET /api/logstash/pipeline/tweets_and_beats */ | ||
| export const EXPECTED_TWEETS_AND_BEATS_PIPELINE = { | ||
| id: 'tweets_and_beats', | ||
| description: 'ingest tweets and beats', | ||
| username: 'elastic', | ||
| pipeline: | ||
| 'input {\n twitter {\n consumer_key => "enter_your_consumer_key_here"\n consumer_secret => "enter_your_secret_here"\n keywords => ["cloud"]\n oauth_token => "enter_your_access_token_here"\n oauth_token_secret => "enter_your_access_token_secret_here"\n }\n beats {\n port => "5043"\n }\n}\noutput {\n elasticsearch {\n hosts => ["IP Address 1:port1", "IP Address 2:port2", "IP Address 3"]\n }\n}', | ||
| settings: {}, | ||
| }; | ||
|
|
||
| /** Minimum ES privileges required to manage Logstash pipelines */ | ||
| export const LOGSTASH_MANAGER_ROLE: ElasticsearchRoleDescriptor = { | ||
| cluster: ['manage_logstash_pipelines'], | ||
| }; | ||
|
|
||
| /** Minimum ES privileges required to call GET /api/logstash/cluster (proxies ES info()) */ | ||
| export const LOGSTASH_CLUSTER_ROLE: ElasticsearchRoleDescriptor = { | ||
| cluster: ['monitor'], | ||
| }; | ||
28 changes: 28 additions & 0 deletions
28
x-pack/platform/plugins/private/logstash/test/scout/api/fixtures/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /* | ||
| * 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 { apiTest as base } from '@kbn/scout'; | ||
| import { getLogstashApiService, type LogstashApiService } from '../services/logstash_api_service'; | ||
|
|
||
| // Augment the shared ApiServicesFixture interface so that apiServices.logstash is typed | ||
| // everywhere inside this plugin's Scout tests. | ||
| declare module '@kbn/scout' { | ||
| interface ApiServicesFixture { | ||
| logstash: LogstashApiService; | ||
| } | ||
| } | ||
|
|
||
| export const apiTest = base.extend<{}, { apiServices: import('@kbn/scout').ApiServicesFixture }>({ | ||
| apiServices: [ | ||
| async ({ apiServices, esClient, log }, use) => { | ||
| await use(Object.assign(apiServices, { logstash: getLogstashApiService({ esClient, log }) })); | ||
| }, | ||
| { scope: 'worker' }, | ||
| ], | ||
| }); | ||
|
|
||
| export * as testData from './constants'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
x-pack/platform/plugins/private/logstash/test/scout/api/services/logstash_api_service.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * 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 type { ScoutLogger } from '@kbn/scout'; | ||
| import type { Client } from '@elastic/elasticsearch'; | ||
|
|
||
| export interface LogstashApiService { | ||
| /** | ||
| * Creates one or more minimal Logstash pipelines by ID via the ES Logstash Pipeline Management API. | ||
| */ | ||
| createPipelines: (...ids: string[]) => Promise<void>; | ||
| /** | ||
| * Deletes one or more Logstash pipelines by ID using the ES Logstash Pipeline Management API. | ||
| * Silently ignores 404s so it is safe to call in afterAll even when setup failed partway through. | ||
| */ | ||
| deletePipelines: (...ids: string[]) => Promise<void>; | ||
| } | ||
|
|
||
| // ES accepts an empty settings object at runtime; the TS type is overly strict | ||
| type PipelineSettings = import('@elastic/elasticsearch').estypes.LogstashPipelineSettings; | ||
| const EMPTY_PIPELINE_SETTINGS = {} as unknown as PipelineSettings; | ||
|
|
||
| export const getLogstashApiService = ({ | ||
| log, | ||
| esClient, | ||
| }: { | ||
| log: ScoutLogger; | ||
| esClient: Client; | ||
| }): LogstashApiService => { | ||
| return { | ||
| createPipelines: async (...ids: string[]) => { | ||
| for (const id of ids) { | ||
| log.debug(`[logstash] Creating pipeline '${id}'`); | ||
| await esClient.logstash.putPipeline({ | ||
| id, | ||
| pipeline: { | ||
| description: `pipeline ${id}`, | ||
| last_modified: new Date().toISOString(), | ||
| pipeline: '# empty', | ||
| pipeline_metadata: { type: 'logstash_pipeline', version: '1' }, | ||
| pipeline_settings: EMPTY_PIPELINE_SETTINGS, | ||
| username: 'elastic', | ||
| }, | ||
| }); | ||
| } | ||
| }, | ||
|
|
||
| deletePipelines: async (...ids: string[]) => { | ||
| for (const id of ids) { | ||
| log.debug(`[logstash] Deleting pipeline '${id}'`); | ||
| await esClient.logstash.deletePipeline({ id }).catch((err) => { | ||
| if (err?.statusCode !== 404) { | ||
| log.warning(`[logstash] Failed to delete pipeline '${id}': ${err?.message}`); | ||
| } | ||
| }); | ||
| } | ||
| }, | ||
| }; | ||
|
macroscopeapp[bot] marked this conversation as resolved.
|
||
| }; | ||
36 changes: 36 additions & 0 deletions
36
x-pack/platform/plugins/private/logstash/test/scout/api/tests/cluster.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * 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 type { RoleApiCredentials } from '@kbn/scout'; | ||
| import { tags } from '@kbn/scout'; | ||
| import { expect } from '@kbn/scout/api'; | ||
| import { apiTest, testData } from '../fixtures'; | ||
|
|
||
| // The route calls client.asCurrentUser.info() which requires the ES `monitor` cluster privilege. | ||
| // The built-in `viewer` Kibana role has no ES cluster privileges and produces a non-403 error | ||
| // that bypasses the route's catch block, resulting in a 500. A custom role with `monitor` is | ||
| // the minimum required privilege. | ||
| apiTest.describe('GET /api/logstash/cluster', { tag: tags.stateful.classic }, () => { | ||
| let credentials: RoleApiCredentials; | ||
|
|
||
| apiTest.beforeAll(async ({ requestAuth }) => { | ||
| credentials = await requestAuth.getApiKeyForCustomRole(testData.LOGSTASH_CLUSTER_ROLE); | ||
| }); | ||
|
|
||
| apiTest('should return the ES cluster info', async ({ apiClient, esClient }) => { | ||
| const response = await apiClient.get(testData.API_PATHS.CLUSTER, { | ||
| headers: { ...testData.COMMON_HEADERS, ...credentials.apiKeyHeader }, | ||
| responseType: 'json', | ||
| }); | ||
|
|
||
| expect(response).toHaveStatusCode(200); | ||
| expect(response.body.cluster).toBeDefined(); | ||
|
|
||
| const esInfo = await esClient.info(); | ||
| expect(response.body.cluster.uuid).toBe(esInfo.cluster_uuid); | ||
| }); | ||
| }); |
109 changes: 109 additions & 0 deletions
109
x-pack/platform/plugins/private/logstash/test/scout/api/tests/pipeline.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * 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 type { RoleApiCredentials } from '@kbn/scout'; | ||
| import { tags } from '@kbn/scout'; | ||
| import { expect } from '@kbn/scout/api'; | ||
| import { apiTest, testData } from '../fixtures'; | ||
|
|
||
| apiTest.describe('/api/logstash/pipeline/{id}', { tag: tags.stateful.classic }, () => { | ||
| let credentials: RoleApiCredentials; | ||
|
|
||
| apiTest.beforeAll(async ({ requestAuth, esClient }) => { | ||
| credentials = await requestAuth.getApiKeyForCustomRole(testData.LOGSTASH_MANAGER_ROLE); | ||
|
|
||
| await esClient.logstash.putPipeline({ | ||
| id: testData.PIPELINE_IDS.TWEETS_AND_BEATS, | ||
| pipeline: { | ||
| description: testData.EXPECTED_TWEETS_AND_BEATS_PIPELINE.description, | ||
| last_modified: '2017-08-02T18:59:07.724Z', | ||
| pipeline: testData.EXPECTED_TWEETS_AND_BEATS_PIPELINE.pipeline, | ||
| pipeline_metadata: { type: 'logstash_pipeline', version: '1' }, | ||
| // ES accepts an empty settings object at runtime; the TS type is overly strict | ||
| pipeline_settings: | ||
| {} as unknown as import('@elastic/elasticsearch').estypes.LogstashPipelineSettings, | ||
| username: testData.EXPECTED_TWEETS_AND_BEATS_PIPELINE.username, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| apiTest.afterAll(async ({ apiServices }) => { | ||
| await apiServices.logstash.deletePipelines( | ||
| testData.PIPELINE_IDS.TWEETS_AND_BEATS, | ||
| testData.PIPELINE_IDS.FAST_GENERATOR | ||
| ); | ||
| }); | ||
|
|
||
| apiTest('GET should return the specified pipeline', async ({ apiClient }) => { | ||
| const response = await apiClient.get( | ||
| testData.API_PATHS.PIPELINE(testData.PIPELINE_IDS.TWEETS_AND_BEATS), | ||
| { | ||
| headers: { ...testData.COMMON_HEADERS, ...credentials.apiKeyHeader }, | ||
| responseType: 'json', | ||
| } | ||
| ); | ||
|
|
||
| expect(response).toHaveStatusCode(200); | ||
| expect(response.body).toStrictEqual(testData.EXPECTED_TWEETS_AND_BEATS_PIPELINE); | ||
| }); | ||
|
|
||
| apiTest('GET should return 404 for a non-existing pipeline', async ({ apiClient }) => { | ||
| const response = await apiClient.get(testData.API_PATHS.PIPELINE('non_existing_pipeline'), { | ||
| headers: { ...testData.COMMON_HEADERS, ...credentials.apiKeyHeader }, | ||
| responseType: 'json', | ||
| }); | ||
|
|
||
| expect(response).toHaveStatusCode(404); | ||
| }); | ||
|
|
||
| apiTest( | ||
| 'PUT should create the specified pipeline and DELETE should remove it', | ||
| async ({ apiClient }) => { | ||
| const createResponse = await apiClient.put( | ||
| testData.API_PATHS.PIPELINE(testData.PIPELINE_IDS.FAST_GENERATOR), | ||
| { | ||
| headers: { ...testData.COMMON_HEADERS, ...credentials.apiKeyHeader }, | ||
| body: { | ||
| description: 'foobar baz', | ||
| pipeline: 'input { generator {} }\n\n output { stdout {} }', | ||
| }, | ||
| responseType: 'json', | ||
| } | ||
| ); | ||
| expect(createResponse).toHaveStatusCode(204); | ||
|
|
||
| const loadResponse = await apiClient.get( | ||
| testData.API_PATHS.PIPELINE(testData.PIPELINE_IDS.FAST_GENERATOR), | ||
| { | ||
| headers: { ...testData.COMMON_HEADERS, ...credentials.apiKeyHeader }, | ||
| responseType: 'json', | ||
| } | ||
| ); | ||
| expect(loadResponse).toHaveStatusCode(200); | ||
| expect(loadResponse.body.id).toBe(testData.PIPELINE_IDS.FAST_GENERATOR); | ||
| expect(loadResponse.body.description).toBe('foobar baz'); | ||
| expect(loadResponse.body.pipeline).toBe('input { generator {} }\n\n output { stdout {} }'); | ||
|
|
||
| const deleteResponse = await apiClient.delete( | ||
| testData.API_PATHS.PIPELINE(testData.PIPELINE_IDS.FAST_GENERATOR), | ||
| { | ||
| headers: { ...testData.COMMON_HEADERS, ...credentials.apiKeyHeader }, | ||
| } | ||
| ); | ||
| expect(deleteResponse).toHaveStatusCode(204); | ||
|
|
||
| const afterDeleteResponse = await apiClient.get( | ||
| testData.API_PATHS.PIPELINE(testData.PIPELINE_IDS.FAST_GENERATOR), | ||
| { | ||
| headers: { ...testData.COMMON_HEADERS, ...credentials.apiKeyHeader }, | ||
| responseType: 'json', | ||
| } | ||
| ); | ||
| expect(afterDeleteResponse).toHaveStatusCode(404); | ||
| } | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great change actually that aligns with the docs! Thank you.