Skip to content

Conversation

mrodm
Copy link
Contributor

@mrodm mrodm commented Oct 2, 2025

Fixes elastic/package-spec#833

This PR adds support to set automatically the pipeline name used in transforms adding the current package version as a prefix.

In order to achieve that elasticsearch/transform/*/transform.yml is managed by elastic-package as a template file (Golang html template). And it is allowed to use a function in the template named IngestPipelineName that adds the current version of the package to the pipeline.

Example:

dest:
  index: "logs-ti_anomali_latest.threatstream-2"
  pipeline: '{{ IngestPipelineName "transform" }}'
  aliases:
    - alias: "logs-ti_anomali_latest.threatstream"
      move_on_creation: true

This rendering of the template happens at different stages to ensure always is performed:

  • Building package: elastic-package build
  • Installing package: elastic-package install
  • System tests: elastic-package test system

Author's checklist

How to test this PR locally

elastic-package stack up -v -d
package_path="test/packages/parallel/ti_anomali_template"

# Build and check that pipeline has been replaced
elastic-package -C "${package_path}" build -v
grep -A 5 "dest:"  build/packages/ti_anomali_template/1.22.1/elasticsearch/transform/latest_ioc/transform.yml 
# Expected output:
# dest:
#   index: "logs-ti_anomali_latest.threatstream-2"
#   pipeline: '1.22.1-transform'
#   aliases:
#     - alias: "logs-ti_anomali_latest.threatstream"
#       move_on_creation: true


# Install package
elastic-package -C "${package_path}" install -v

# check in Kibana that the transform has been installed with the right pipeline
curl -k -s -u elastic:changeme 'https://localhost:9200/_transform/logs-ti_anomali_template.latest_ioc-default-0.3.0' | jq -r '.transforms[] | .dest'
# Expected output:
# {
#   "index": "logs-ti_anomali_latest.threatstream-2",
#   "aliases": [
#     {
#       "alias": "logs-ti_anomali_latest.threatstream",
#       "move_on_creation": true
#     }
#   ],
#   "pipeline": "1.22.1-transform"
# }

# Running system tests for this package should work successfully
# Transform should be detected and validated
elastic-package -C "${package_path}" test system -v

elastic-package stack down -v

mrodm added 2 commits October 2, 2025 12:26
Allow to set an IngestPipelineName function in these templates in order
to set the right ingest template filename. This filename must contain as
a prefix the package version (from the manifest).
@mrodm mrodm self-assigned this Oct 2, 2025
@mrodm
Copy link
Contributor Author

mrodm commented Oct 2, 2025

/test

6 similar comments
@mrodm
Copy link
Contributor Author

mrodm commented Oct 2, 2025

/test

@mrodm
Copy link
Contributor Author

mrodm commented Oct 2, 2025

/test

@mrodm
Copy link
Contributor Author

mrodm commented Oct 2, 2025

/test

@mrodm
Copy link
Contributor Author

mrodm commented Oct 2, 2025

/test

@mrodm
Copy link
Contributor Author

mrodm commented Oct 3, 2025

/test

@mrodm
Copy link
Contributor Author

mrodm commented Oct 3, 2025

/test

@mrodm mrodm marked this pull request as ready for review October 3, 2025 11:46
@mrodm mrodm requested a review from a team October 6, 2025 08:42
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.

LGTM, some nitpicking and wondering if we should use text/template instead of html/template.

"encoding/json"
"errors"
"fmt"
"html/template"
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason to use html/template instead of text/template? The html one escapes some characters for safe HTML rendering, but we probably don't want or need this here.

Suggested change
"html/template"
"text/template"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No specific reason, I'll test with text/template 👍


t := template.New(filepath.Base(transformPath))
t, err = t.Funcs(template.FuncMap{
"IngestPipelineName": func(pipelineName string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit. Looking to examples in the doc I think we should use lower case for functions.

Suggested change
"IngestPipelineName": func(pipelineName string) (string, error) {
"ingestPipelineName": func(pipelineName string) (string, error) {

Comment on lines 469 to 472
_, err = os.Stat(filepath.Join(packageRootPath, "elasticsearch", "ingest_pipeline", pipelineFileName))
if err != nil {
return nil, TransformDefinition{}, fmt.Errorf("destination ingest pipeline file %s not found: %w", pipelineFileName, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Did you test with integrations? Maybe some package fails with this 😬 Though if it does we should fix the package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing to build locally all packages in the integrations repository, there is one package that sets as dest.pipeline the ingest pipeline from the data stream:

dest:
  index: "aws_billing.cur-v1"
  pipeline: "metrics-aws_billing.cur-0.1.0-pipeline_extract_metadata"
  aliases:
    - alias: "aws_billing.cur_latest"
      move_on_creation: true

That fails with the current validation 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That package (aws_billing) is failing this validation because of:

  1. It's using a pipeline from a data stream
  2. It set an old version in the destination pipeline, it should be 0.2.0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That pipeline from cur data stream looks like it is not used:
https://github.com/elastic/integrations/blob/34df8c08914a678dc3310bd000e7908a1af42ef6/packages/aws_billing/data_stream/cur/elasticsearch/ingest_pipeline/pipeline_extract_metadata.yml

At least from the default pipeline there is no pipeline processor to trigger that other pipeline:
https://github.com/elastic/integrations/blob/34df8c08914a678dc3310bd000e7908a1af42ef6/packages/aws_billing/data_stream/cur/elasticsearch/ingest_pipeline/default.yml

Here I've added the support to detect if the ingest pipeline exists on any data stream:
4f2756e

Probably, it could be moved the pipeline in that package to be on the elasticsearch folder in the root, but in any case it could be interesting to keep the support to check if pipelines are located in data streams.

WDYT ?

@mrodm
Copy link
Contributor Author

mrodm commented Oct 7, 2025

test integrations

@elastic-vault-github-plugin-prod

Created or updated PR in integrations repository to test this version. Check elastic/integrations#15594

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @mrodm

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.

[Change Proposal] Add support for ingest pipelines in transforms
3 participants