Skip to content
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

Check and generate multiple readme files in one package #282

Merged
merged 23 commits into from
Mar 23, 2021
Merged

Check and generate multiple readme files in one package #282

merged 23 commits into from
Mar 23, 2021

Conversation

kaiyan-sheng
Copy link
Contributor

@kaiyan-sheng kaiyan-sheng commented Mar 9, 2021

With the new package-spec update with input groups, we start to allow multiple readme files .md under _dev/build/docs and docs. This PR is to add the check and generate multiple readme files when running elastic-package build and elastic-package lint.

elastic-package lint when billing.md and cloudtrail.md are missing

elastic-package has been installed.
Lint the package
billing.md is outdated. Rebuild the package with 'elastic-package build'
cloudtrail.md is outdated. Rebuild the package with 'elastic-package build'
Error: checking readme files are up-to-date failed: check readme files are up-to-date failed

elastic-package build output

kaiyansheng@KaiyanMacBookPro:~/go/src/github.com/elastic/elastic-package/test/packages/aws (additional_readmes)$ elastic-package build
Build the package
README.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/README.md
billing.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/billing.md
cloudtrail.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/cloudtrail.md
cloudwatch.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/cloudwatch.md
dynamodb.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/dynamodb.md
ebs.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/ebs.md
ec2.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/ec2.md
elb.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/elb.md
lambda.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/lambda.md
natgateway.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/natgateway.md
rds.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/rds.md
s3.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/s3.md
sns.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/sns.md
sqs.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/sqs.md
transitgateway.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/transitgateway.md
usage.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/usage.md
vpcflow.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/vpcflow.md
vpn.md file rendered: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/vpn.md
Package built: /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
Done

elastic-package lint when there is no file missing

kaiyansheng@KaiyanMacBookPro:~/go/src/github.com/elastic/elastic-package/test/packages/aws (additional_readmes)$ elastic-package lint
Lint the package
Done

@kaiyan-sheng kaiyan-sheng self-assigned this Mar 9, 2021
@kaiyan-sheng kaiyan-sheng added the Team:Integrations Label for the Integrations team label Mar 9, 2021
@kaiyan-sheng kaiyan-sheng requested a review from mtojek March 9, 2021 14:24
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 9, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #282 updated

  • Start Time: 2021-03-23T03:48:33.517+0000

  • Duration: 21 min 32 sec

  • Commit: 17506c5

Test stats 🧪

Test Results
Failed 0
Passed 316
Skipped 1
Total 317

Trends 🧪

Image of Build Times

Image of Tests

@mtojek mtojek requested a review from ycombinator March 9, 2021 14:42
Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the command output should be adjusted:

Build the package
README.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/README.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
billing.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/billing.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
cloudtrail.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/cloudtrail.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
cloudwatch.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/cloudwatch.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
dynamodb.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/dynamodb.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
ebs.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/ebs.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
ec2.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/ec2.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
elb.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/elb.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
lambda.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/lambda.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
natgateway.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/natgateway.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
rds.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/rds.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
s3.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/s3.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
sns.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/sns.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
sqs.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/sqs.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
transitgateway.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/transitgateway.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
usage.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/usage.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
vpcflow.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/vpcflow.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999
vpn.md file rendered: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/test/packages/aws/docs/vpn.md
Package built: /Users/marcin.tojek/go/src/github.com/elastic/elastic-package/build/integrations/aws/999.999.999

We don't have to notify the developer multiple times that the package has been built :)

cmd/build.go Outdated Show resolved Hide resolved
cmd/lint.go Outdated Show resolved Hide resolved
internal/docs/readme.go Outdated Show resolved Hide resolved
cmd/build.go Outdated Show resolved Hide resolved
cmd/build.go Outdated Show resolved Hide resolved
cmd/lint.go Outdated Show resolved Hide resolved
internal/docs/readme.go Outdated Show resolved Hide resolved
internal/docs/readme.go Show resolved Hide resolved
@kaiyan-sheng
Copy link
Contributor Author

@mtojek @ycombinator The current CI failure is caused by:

kaiyansheng@KaiyanMacBookPro:~/go/src/github.com/elastic/elastic-package/test/packages/kubernetes (additional_readmes)$ elastic-package lint
Lint the package
Error: can't check if readme files are up-to-date: failed to return a list of directory entries from /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/kubernetes: open /Users/kaiyansheng/go/src/github.com/elastic/elastic-package/test/packages/kubernetes/_dev/build/docs: no such file or directory

I see in several test packages, we have docs/README.md but the package itself doesn't have _dev/build/docs/README.md. I think _dev/build/docs/README.md is required to create the actual docs/README.md right?

@mtojek
Copy link
Contributor

mtojek commented Mar 15, 2021

I see in several test packages, we have docs/README.md but the package itself doesn't have _dev/build/docs/README.md. I think _dev/build/docs/README.md is required to create the actual docs/README.md right?

Actually it is the other way round. The doc template can be used to generate the README file, but it's not a hard requirement. Please take a look at the log integration: https://github.com/elastic/integrations/tree/master/packages/log (it's exactly this use case).

@kaiyan-sheng
Copy link
Contributor Author

Actually it is the other way round. The doc template can be used to generate the README file, but it's not a hard requirement. Please take a look at the log integration: https://github.com/elastic/integrations/tree/master/packages/log (it's exactly this use case).

Thanks! OK it's fixed now I believe. This PR is ready for another review :) Thank you @mtojek and @ycombinator !

cmd/build.go Outdated
cmd.Printf("%s file rendered: %s\n", docs.ReadmeFile, target)

for _, target := range targets {
if target != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the case that the target is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be empty when README file is static and can't be generated from the template file. This came from generateReadme(fileName, packageRoot) function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see! It might be cleaner to skip this file on the lower layer (in the docs.UpdateReadmes()), so "" (empty string) won't leak here.

cmd/lint.go Outdated Show resolved Hide resolved
cmd/lint.go Outdated Show resolved Hide resolved
internal/docs/readme.go Outdated Show resolved Hide resolved
internal/docs/readme.go Outdated Show resolved Hide resolved
internal/docs/readme.go Outdated Show resolved Hide resolved
internal/docs/readme.go Outdated Show resolved Hide resolved
internal/docs/readme.go Show resolved Hide resolved
@mtojek mtojek requested a review from ycombinator March 15, 2021 15:27
cmd/lint.go Outdated
outdatedStr := ""
errStr := ""
for _, f := range readmeFiles {
if !f.UpToDate {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to capture all outdated file names here to display in the error message. It's not pretty again. Is there a better way to do so?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other comment I suggested to return an error if something bad happens.

You can check if docs.AreReadmesUpToDate() returned an error and any readmeFiles. If so, you can print the error and conditionally iterate over readmeFiles. No need to concatenate single error message. You can return a generic error and use cmd.Printf to iterate over problematic files. We used to mix cmd.Printf and errrors.Wrap for such cases, you can take a look at cmd/build.go and internal/builder/packages.go.

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're close to the final form. Thanks for all adjustments!

internal/docs/readme.go Outdated Show resolved Hide resolved
internal/docs/readme.go Show resolved Hide resolved
cmd/lint.go Outdated
outdatedStr := ""
errStr := ""
for _, f := range readmeFiles {
if !f.UpToDate {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other comment I suggested to return an error if something bad happens.

You can check if docs.AreReadmesUpToDate() returned an error and any readmeFiles. If so, you can print the error and conditionally iterate over readmeFiles. No need to concatenate single error message. You can return a generic error and use cmd.Printf to iterate over problematic files. We used to mix cmd.Printf and errrors.Wrap for such cases, you can take a look at cmd/build.go and internal/builder/packages.go.

internal/docs/readme.go Show resolved Hide resolved
cmd/build.go Outdated
cmd.Printf("%s file rendered: %s\n", docs.ReadmeFile, target)

for _, target := range targets {
if target != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see! It might be cleaner to skip this file on the lower layer (in the docs.UpdateReadmes()), so "" (empty string) won't leak here.

Copy link
Contributor

@ycombinator ycombinator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending the ongoing changes from @mtojek's review, this PR LGTM.

@kaiyan-sheng
Copy link
Contributor Author

@mtojek cmd.Printf is exactly what I was looking for! Thank you!!

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of nit-picks and you're good to go :)

Regarding the issue reported by CI:

test case failed: one or more problems with fields found in documents: [0] unexpected pipeline error: field [json] not present as part of path [json]

... I fixed it in the integrations repo: elastic/integrations#791 . Most likely you need to sync it here.

internal/docs/readme.go Outdated Show resolved Hide resolved
internal/docs/readme.go Outdated Show resolved Hide resolved
internal/docs/readme.go Outdated Show resolved Hide resolved
Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! Ship it :) (just wait for the green status)

Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaiyan-sheng could you please describe/justify the fix you applied to the PR to make it green? I'm curious what exactly was the root cause :)

@@ -487,6 +487,7 @@ func createPackageDatastream(
// Add package-level vars
pkgVars := kibana.Vars{}
input := pkg.PolicyTemplates[0].FindInputByType(streamInput)
input.Vars = append(input.Vars, pkg.Vars...)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ycombinator could you please verify this fix? I'm not quite sure about implications.

Copy link
Contributor

@ycombinator ycombinator Mar 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of this change is that all the package-level vars, defined in the package's manifest.yml file, are being copied into to each input's vars list.

From a system test definition perspective, this means that the top-level vars in the system test definition file could be used to override not just input vars but now also the package vars. So I think this change makes sense.

The only thing I would change is move this line inside the if input != nil check below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! Thanks @ycombinator for the review!!

@@ -487,6 +487,7 @@ func createPackageDatastream(
// Add package-level vars
pkgVars := kibana.Vars{}
input := pkg.PolicyTemplates[0].FindInputByType(streamInput)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something we'll have to look to support multiple policy templates.

@kaiyan-sheng
Copy link
Contributor Author

@kaiyan-sheng could you please describe/justify the fix you applied to the PR to make it green? I'm curious what exactly was the root cause :)

Thanks for the review! This new AWS package manifest.yml file added all AWS credential variables under vars at the package level, which is the same level as policy templates. The current code doesn't read these package level variables so they are not passed into the agent policy. This last commit is to collect the package level variables and combine them with the input level variables under the policy template so these variables can be added into the agent policy:

inputs:
  - id: f45e9a6b-0fcf-4022-aa24-a3b43e1fdab1
    name: aws-ec2_metrics
    revision: 1
    type: aws/metrics
    use_output: default
    meta:
      package:
        name: aws
        version: 999.999.999
    data_stream:
      namespace: ep
    streams:
      - id: aws/metrics-aws.ec2_metrics-f45e9a6b-0fcf-4022-aa24-a3b43e1fdab1
        data_stream:
          dataset: aws.ec2_metrics
          type: metrics
        metricsets:
          - ec2
        period: 60s
        access_key_id: abcd
        secret_access_key: abcd
        session_token: >-
          abcd
        tags_filter:
          - key: Name
            value: elastic-package-test-78669

@kaiyan-sheng kaiyan-sheng merged commit 96ac7e9 into elastic:master Mar 23, 2021
@kaiyan-sheng kaiyan-sheng deleted the additional_readmes branch March 23, 2021 05:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants