-
Notifications
You must be signed in to change notification settings - Fork 124
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
Add export ingest-pipelines command #2574
Conversation
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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?
⏳ Build in-progress, with failures
Failed CI StepsHistory
|
return writeAssignments | ||
} | ||
|
||
func countFiles(t *testing.T, dir string) (count int) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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.
Resolves: #1722
elastic-package export ingest-pipelines