Skip to content

Support routing_rules.yml and ingest pipeline test for reroute processor #1372

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
merged 12 commits into from
Aug 7, 2023

Conversation

kaiyan-sheng
Copy link
Contributor

@kaiyan-sheng kaiyan-sheng commented Jul 26, 2023

What does this PR do?

This PR does two things:

  1. Support routing_rules.yml file when running pipeline test using command elastic-package test pipeline -d <datastream> --generate -v.

routing_rules.yml now can be read and take into account when running the test pipeline command. The file is read as yml and convert into reroute processors. Then these reroute processors are attached under the processors section from the ingest pipeline.

For example:

- source_dataset: awsfirehose.log
  rules:
    - target_dataset: aws.cloudtrail
      if: ctx['aws.cloudwatch.log_stream'].contains('CloudTrail')
      namespace:
        - "{{labels.data_stream.namespace}}"
        - default

routing_rules.yml looks like the example above will be translated into:

- reroute:
      tag: awsfirehose.log
      if: ctx['aws.cloudwatch.log_stream'].contains('CloudTrail')
      dataset: aws.cloudtrail
      namespace: ["{{labels.data_stream.namespace}}", default]
  1. Support ingest pipeline test for reroute processors when they are added under elasticsearch/ingest_pipeline directly.
  • This PR added the index name for testing based on the dataset so we don't see error like this:
[0] unexpected pipeline error: invalid data stream name: [_index]; must follow naming scheme <type>-<dataset>-<namespace>
  • When checking the value for data_stream.dataset, it's read from the reroute processors for the new target dataset. Because reroute processor will change the value of this field.

How to test this PR locally

I've been testing this PR locally with elastic/integrations#7146. After make build elastic package locally, I ran elastic-package test pipeline -d log --generate -v and under integrations/packages/awsfirehose/data_stream/log/_dev/test/pipeline/test-cloudtrail.json-expected.json, you can see the data_stream.dataset value changed to aws.cloudtrail and data_stream.namespace changed to default. These are the two fields I defined under reroute processor:

  - reroute:
      if: ctx['aws.cloudwatch.log_stream'].contains('CloudTrail')
      dataset: aws.cloudtrail
      namespace: default

Same thing works for defining it under routing_rules.yml

- source_dataset: awsfirehose.log
  rules:
    - target_dataset: aws.cloudtrail
      if: ctx['aws.cloudwatch.log_stream'].contains('CloudTrail')
      namespace:
        - "{{labels.data_stream.namespace}}"
        - default

@kaiyan-sheng kaiyan-sheng self-assigned this Jul 26, 2023
@kaiyan-sheng kaiyan-sheng requested review from mrodm and jsoriano July 26, 2023 23:17
@jsoriano
Copy link
Member

This PR is to support ingest pipeline test for reroute processor.

Hey @kaiyan-sheng,

This PR adds support to test the reroute processors defined on ingest pipelines, right? But the recommended way to add routing rules is to use the routing_rules.yml file (as defined in elastic/package-spec#514).

I think that appart of these changes, for pipeline tests, we would need to make elastic-package to install the routing rules in a way that they apply when using the simulate API.

It would be also great to add a test package here.

@jsoriano
Copy link
Member

Also, by reading the routing_rules.yml file, tests might know on what datasets data stream to look for the data.

@felixbarny
Copy link
Member

This PR adds support to test the reroute processors defined on ingest pipelines, right? But the recommended way to add routing rules is to use the routing_rules.yml file (as defined in elastic/package-spec#514).

The routing rules in routing_rules.yml will be translated into reroute processors that are added in the package's pipeline. So in theory, they should be tested by test pipeline command. If not, that's an issue we should fix.

@jsoriano
Copy link
Member

This PR adds support to test the reroute processors defined on ingest pipelines, right? But the recommended way to add routing rules is to use the routing_rules.yml file (as defined in elastic/package-spec#514).

The routing rules in routing_rules.yml will be translated into reroute processors that are added in the package's pipeline. So in theory, they should be tested by test pipeline command. If not, that's an issue we should fix.

Yes, they are translated to reroute processors when installed through Fleet, but I think that currently elastic-package test pipelines only installs the pipelines, it doesn't install the package, so it is probably not installing the routing rules. We should probably change this.

@kaiyan-sheng
Copy link
Contributor Author

@jsoriano Yep it only looks for the yml files under elasticsearch/ingest_pipeline for pipelines right now. Can I keep this PR for only supporting ingest pipelines for reroute processors and then have a separate PR for supporting routing_rules.yml?

@zmoog
Copy link
Contributor

zmoog commented Jul 27, 2023

More than happy to help with adding support for the routing-rules.yml to the pipeline testing; I also need this for the Kubernetes integration. I'm available for both implementation and review.

@kaiyan-sheng kaiyan-sheng changed the title Support ingest pipeline test for reroute processor Support routing_rules.yml and ingest pipeline test for reroute processor Jul 31, 2023
Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Thanks for adding tests! It looks like expectation files need to be regenerated.

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Thanks!

@kaiyan-sheng kaiyan-sheng requested a review from zmoog August 4, 2023 22:26
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @kaiyan-sheng

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants