Skip to content

Add export ingest-pipelines command #2574

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 24 commits into from
May 16, 2025

Conversation

MichelLosier
Copy link
Contributor

@MichelLosier MichelLosier commented May 6, 2025

Resolves: #1722

  • Adds ingest pipeline export from elasticsearch to a package with the command elastic-package export ingest-pipelines
  • User is prompted with a multi-selection of pipelines to export
    • References to pipelines in a pipeline processor definitions will also be pulled automatically
  • User is prompted to select an existing data stream in the package, or the package root as destinations to export to.
    • Dependent pipeline references are not prompted for, they'll be written to the same destination as selected for the parent.
  • Pipelines are written to yaml files unchanged

Screenshot 2025-05-09 at 12 01 29 PM
Screenshot 2025-05-09 at 12 02 27 PM

cmd.PersistentFlags().StringP(cobraext.ProfileFlagName, "p", "", fmt.Sprintf(cobraext.ProfileFlagDescription, install.ProfileNameEnvVar))

return cobraext.NewCommand(cmd, cobraext.ContextPackage)
}

func exportDashboardsCmd(cmd *cobra.Command, args []string) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moves export dashboards functionality into own file now that we are adding support for ingest-pipelines

)

// IngestPipeline contains the information needed to export an ingest pipeline.
type IngestPipeline struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of this functionality was moved to the internal/elasticsearch package since it shares a lot of retrieval needs with the new export functionality

@@ -0,0 +1,122 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file was extracted from cmd/export.go

@MichelLosier MichelLosier marked this pull request as ready for review May 9, 2025 19:09
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! This is looking quite good, and works well. Added some comments.


type PipelineWriteAssignments map[string]PipelineWriteLocation

func IngestPipelines(ctx context.Context, api *elasticsearch.API, writeAssignments PipelineWriteAssignments) error {
Copy link
Member

Choose a reason for hiding this comment

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

Could we have a test case for this?

@elasticmachine
Copy link
Collaborator

⏳ Build in-progress, with failures

Failed CI Steps

History

return writeAssignments
}

func countFiles(t *testing.T, dir string) (count int) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair bit of testing utils borrowed from the dump package tests. I didn't come across an existing package where shared testing utils might have a home, but since this is the only place this code is repeated, I figured this is fine for now. Otherwise, I could create an internal/testutils package if we expect to see more of this type of testing pattern of comparing file output from the CLI.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, this is fine by now, but creating a shared package sounds good too, as you prefer.

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.

Nice, thanks for adding the test cases!

return writeAssignments
}

func countFiles(t *testing.T, dir string) (count int) {
Copy link
Member

Choose a reason for hiding this comment

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

Yep, this is fine by now, but creating a shared package sounds good too, as you prefer.

Comment on lines +103 to +108
var documentBytes bytes.Buffer
// requirement: https://github.com/elastic/package-spec/pull/54
documentBytes.WriteString("---\n")
yamlEncoder := yaml.NewEncoder(&documentBytes)
yamlEncoder.SetIndent(2)
err = yamlEncoder.Encode(jsonPipeline)
Copy link
Member

Choose a reason for hiding this comment

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

Btw, we have a formatter package with shared formatters for JSON and YAML. They do basically what we are doing here, with the exception of filtering out fields.

Maybe we can add a method FormatWithFilter(content []byte, filter func(map[string]any))

But current approach is fine too, so as you prefer.

@MichelLosier MichelLosier merged commit b7f6a7c into elastic:main May 16, 2025
3 checks passed
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.

[Feature] elastic-package export pipelines
3 participants