From f530e85dbb45dfd9846009d69444e2cbf38f21d2 Mon Sep 17 00:00:00 2001 From: Bharat Pasupula <123897612+bhapas@users.noreply.github.com> Date: Tue, 10 Dec 2024 07:32:22 +0100 Subject: [PATCH] [Automatic Import] Use datastream description in readme (#203236) ## Release note Use provided data stream description in generated README ## Summary Closes [#201294](https://github.com/elastic/kibana/issues/201294) This PR fixes use of `datastream description` that the user entered in the input field. ![image](https://github.com/user-attachments/assets/b093c978-2102-4bdc-824e-d60aa3fd908b) --- .../build_integration.test.ts | 39 +++++++++++-------- .../integration_builder/build_integration.ts | 2 +- .../integration_builder/readme_files.test.ts | 8 ++-- .../integration_builder/readme_files.ts | 32 +++++++++++---- .../server/templates/build_readme.md.njk | 8 ++-- .../server/templates/description_readme.njk | 7 +++- .../server/templates/package_readme.md.njk | 8 ++-- 7 files changed, 65 insertions(+), 39 deletions(-) diff --git a/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.test.ts b/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.test.ts index d7ce89e2e8f63..eaa50e87d41b4 100644 --- a/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.test.ts +++ b/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.test.ts @@ -209,24 +209,29 @@ describe('buildPackage', () => { await buildPackage(testIntegration); - expect(createReadme).toHaveBeenCalledWith(integrationPath, testIntegration.name, [ - { - datastream: firstDatastreamName, - fields: [ - { name: 'name a', description: 'description 1', type: 'type 1' }, + expect(createReadme).toHaveBeenCalledWith( + integrationPath, + testIntegration.name, + testIntegration.dataStreams, + [ + { + datastream: firstDatastreamName, + fields: [ + { name: 'name a', description: 'description 1', type: 'type 1' }, - { name: 'name b', description: 'description 1', type: 'type 1' }, - ], - }, - { - datastream: secondDatastreamName, - fields: [ - { name: 'name c', description: 'description 2', type: 'type 2' }, - { name: 'name d', description: 'description 2', type: 'type 2' }, - { name: 'name e', description: 'description 3', type: 'type 3' }, - ], - }, - ]); + { name: 'name b', description: 'description 1', type: 'type 1' }, + ], + }, + { + datastream: secondDatastreamName, + fields: [ + { name: 'name c', description: 'description 2', type: 'type 2' }, + { name: 'name d', description: 'description 2', type: 'type 2' }, + { name: 'name e', description: 'description 3', type: 'type 3' }, + ], + }, + ] + ); }); }); diff --git a/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.ts b/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.ts index bf2e9b6b9d5a7..785c11125afd9 100644 --- a/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.ts +++ b/x-pack/plugins/integration_assistant/server/integration_builder/build_integration.ts @@ -59,7 +59,7 @@ export async function buildPackage(integration: Integration): Promise { }; }); - createReadme(packageDir, integration.name, fieldsPerDatastream); + createReadme(packageDir, integration.name, integration.dataStreams, fieldsPerDatastream); const zipBuffer = await createZipArchive(workingDir, packageDirectoryName); removeDirSync(workingDir); diff --git a/x-pack/plugins/integration_assistant/server/integration_builder/readme_files.test.ts b/x-pack/plugins/integration_assistant/server/integration_builder/readme_files.test.ts index ae9080fff8a74..2cb350458378e 100644 --- a/x-pack/plugins/integration_assistant/server/integration_builder/readme_files.test.ts +++ b/x-pack/plugins/integration_assistant/server/integration_builder/readme_files.test.ts @@ -59,7 +59,7 @@ describe('createReadme', () => { }, ]; - createReadme(integrationPath, testIntegration.name, fields); + createReadme(integrationPath, testIntegration.name, testIntegration.dataStreams, fields); expect(createSync).toHaveBeenCalledWith( `${integrationPath}/_dev/build/docs/README.md`, @@ -103,7 +103,7 @@ describe('createReadme', () => { }, ]; - createReadme(integrationPath, testIntegration.name, fields); + createReadme(integrationPath, testIntegration.name, testIntegration.dataStreams, fields); const firstDatastreamFieldsDisplayed = ` | Field | Description | Type | @@ -139,7 +139,7 @@ describe('createReadme', () => { }, ]; - createReadme(integrationPath, testIntegration.name, fields); + createReadme(integrationPath, testIntegration.name, testIntegration.dataStreams, fields); expect(createSync).toHaveBeenCalledWith( `${integrationPath}/_dev/build/docs/README.md`, @@ -165,7 +165,7 @@ describe('createReadme', () => { }, ]; - createReadme(integrationPath, testIntegration.name, fields); + createReadme(integrationPath, testIntegration.name, testIntegration.dataStreams, fields); const firstDatastreamFieldsDisplayed = ` | Field | Description | Type | diff --git a/x-pack/plugins/integration_assistant/server/integration_builder/readme_files.ts b/x-pack/plugins/integration_assistant/server/integration_builder/readme_files.ts index 5467a1549cea2..9b2b38c171d0d 100644 --- a/x-pack/plugins/integration_assistant/server/integration_builder/readme_files.ts +++ b/x-pack/plugins/integration_assistant/server/integration_builder/readme_files.ts @@ -8,29 +8,46 @@ import { Environment, FileSystemLoader } from 'nunjucks'; import { join as joinPath } from 'path'; +import { DataStream } from '../../common'; import { createSync, ensureDirSync } from '../util'; -export function createReadme(packageDir: string, integrationName: string, fields: object[]) { - createPackageReadme(packageDir, integrationName, fields); - createBuildReadme(packageDir, integrationName, fields); +export function createReadme( + packageDir: string, + integrationName: string, + datastreams: DataStream[], + fields: object[] +) { + createPackageReadme(packageDir, integrationName, datastreams, fields); + createBuildReadme(packageDir, integrationName, datastreams, fields); } -function createPackageReadme(packageDir: string, integrationName: string, fields: object[]) { +function createPackageReadme( + packageDir: string, + integrationName: string, + datastreams: DataStream[], + fields: object[] +) { const dirPath = joinPath(packageDir, 'docs/'); // The readme nunjucks template files should be named in the format `somename_readme.md.njk` and not just `readme.md.njk` // since any file with `readme.*` pattern is skipped in build process in buildkite. - createReadmeFile(dirPath, 'package_readme.md.njk', integrationName, fields); + createReadmeFile(dirPath, 'package_readme.md.njk', integrationName, datastreams, fields); } -function createBuildReadme(packageDir: string, integrationName: string, fields: object[]) { +function createBuildReadme( + packageDir: string, + integrationName: string, + datastreams: DataStream[], + fields: object[] +) { const dirPath = joinPath(packageDir, '_dev/build/docs/'); - createReadmeFile(dirPath, 'build_readme.md.njk', integrationName, fields); + createReadmeFile(dirPath, 'build_readme.md.njk', integrationName, datastreams, fields); } function createReadmeFile( targetDir: string, templateName: string, integrationName: string, + datastreams: DataStream[], fields: object[] ) { ensureDirSync(targetDir); @@ -44,6 +61,7 @@ function createReadmeFile( const renderedTemplate = template.render({ package_name: integrationName, + datastreams, fields, }); diff --git a/x-pack/plugins/integration_assistant/server/templates/build_readme.md.njk b/x-pack/plugins/integration_assistant/server/templates/build_readme.md.njk index 1b58e55aebd37..92b03575b10fb 100644 --- a/x-pack/plugins/integration_assistant/server/templates/build_readme.md.njk +++ b/x-pack/plugins/integration_assistant/server/templates/build_readme.md.njk @@ -1,8 +1,8 @@ {% include "./description_readme.njk" %} -{% for data_stream in fields %} -### {{ data_stream.datastream }} - -Insert a description of the datastream here. +{% for datastream in datastreams %} +### {{ datastream.title }} +{{ datastream.description }}{% endfor %} +{% for data_stream in fields %} {% raw %}{{fields {% endraw %}"{{ data_stream.datastream }}"{% raw %}}}{% endraw %} {% endfor %} \ No newline at end of file diff --git a/x-pack/plugins/integration_assistant/server/templates/description_readme.njk b/x-pack/plugins/integration_assistant/server/templates/description_readme.njk index 91c1bf6f1b40c..9fe32dccb2b2b 100644 --- a/x-pack/plugins/integration_assistant/server/templates/description_readme.njk +++ b/x-pack/plugins/integration_assistant/server/templates/description_readme.njk @@ -7,8 +7,11 @@ Check the [overview guidelines](https://www.elastic.co/guide/en/integrations-dev ## Datastreams -Provide a high-level overview of the kind of data that is collected by the integration. -Check the [datastreams guidelines](https://www.elastic.co/guide/en/integrations-developer/current/documentation-guidelines.html#idg-docs-guidelines-datastreams) for more information. +{% for datastream in datastreams %} +### {{ datastream.title }} + +{{ datastream.description }} +{% endfor %} ## Requirements diff --git a/x-pack/plugins/integration_assistant/server/templates/package_readme.md.njk b/x-pack/plugins/integration_assistant/server/templates/package_readme.md.njk index bd56aba5ac1e5..3131822e3f2ee 100644 --- a/x-pack/plugins/integration_assistant/server/templates/package_readme.md.njk +++ b/x-pack/plugins/integration_assistant/server/templates/package_readme.md.njk @@ -1,15 +1,15 @@ {% include "./description_readme.njk" %} -{% for data_stream in fields %} -### {{ data_stream.datastream }} +{% for datastream in datastreams %} +### {{ datastream.title }} -Insert a description of the datastream here. +{{ datastream.description }}{% endfor %} **ECS Field Reference** Please refer to the following [document](https://www.elastic.co/guide/en/ecs/current/ecs-field-reference.html) for detailed information on ECS fields. **Exported fields** - +{% for data_stream in fields %} | Field | Description | Type | |---|---|---| {% for field in data_stream.fields %}| {{ field.name }} | {{ field.description | default('') | replace('\n', ' ') | trim }} | {{ field.type }} |