Add export ingest-pipelines command#2574
Conversation
| return cobraext.NewCommand(cmd, cobraext.ContextPackage) | ||
| } | ||
|
|
||
| func exportDashboardsCmd(cmd *cobra.Command, args []string) error { |
There was a problem hiding this comment.
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.
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.
This file was extracted from cmd/export.go
jsoriano
left a comment
There was a problem hiding this comment.
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.
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.
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.
Yep, this is fine by now, but creating a shared package sounds good too, as you prefer.
jsoriano
left a comment
There was a problem hiding this comment.
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.
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.
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