Skip to content

Commit b23d50b

Browse files
committed
Refactoring: make ingest pipeline name method of DataStreamManifest
1 parent 6588f87 commit b23d50b

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

internal/packages/assets.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package packages

internal/packages/packages.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const (
2020

2121
// DataStreamManifestFile is the name of the data stream's manifest file.
2222
DataStreamManifestFile = "manifest.yml"
23+
24+
defaultPipelineName = "default"
2325
)
2426

2527
// VarValue represents a variable value as defined in a package or data stream
@@ -182,6 +184,13 @@ func ReadDataStreamManifest(path string) (*DataStreamManifest, error) {
182184
return &m, nil
183185
}
184186

187+
func (dsm *DataStreamManifest) GetPipelineNameOrDefault() string {
188+
if dsm.Elasticsearch != nil && dsm.Elasticsearch.IngestPipeline != nil && dsm.Elasticsearch.IngestPipeline.Name != "" {
189+
return dsm.Elasticsearch.IngestPipeline.Name
190+
}
191+
return defaultPipelineName
192+
}
193+
185194
// FindInputByType returns the input for the provided type.
186195
func (pt *PolicyTemplate) FindInputByType(inputType string) *Input {
187196
for _, input := range pt.Inputs {

internal/testrunner/runners/pipeline/ingest_pipeline.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import (
2323
"github.com/elastic/elastic-package/internal/packages"
2424
)
2525

26-
const defaultPipelineName = "default"
27-
2826
var ingestPipelineTag = regexp.MustCompile("{{\\s*IngestPipeline.+}}")
2927

3028
type pipelineResource struct {
@@ -57,7 +55,7 @@ func installIngestPipelines(esClient *elasticsearch.Client, dataStreamPath strin
5755

5856
nonce := time.Now().UnixNano()
5957

60-
mainPipeline := getWithPipelineNameWithNonce(getPipelineNameOrDefault(dataStreamManifest), nonce)
58+
mainPipeline := getWithPipelineNameWithNonce(dataStreamManifest.GetPipelineNameOrDefault(), nonce)
6159
pipelines, err := loadIngestPipelineFiles(dataStreamPath, nonce)
6260
if err != nil {
6361
return "", nil, errors.Wrap(err, "loading ingest pipeline files failed")
@@ -75,13 +73,6 @@ func installIngestPipelines(esClient *elasticsearch.Client, dataStreamPath strin
7573
return mainPipeline, jsonPipelines, nil
7674
}
7775

78-
func getPipelineNameOrDefault(dsm *packages.DataStreamManifest) string {
79-
if dsm.Elasticsearch != nil && dsm.Elasticsearch.IngestPipeline != nil && dsm.Elasticsearch.IngestPipeline.Name != "" {
80-
return dsm.Elasticsearch.IngestPipeline.Name
81-
}
82-
return defaultPipelineName
83-
}
84-
8576
func loadIngestPipelineFiles(dataStreamPath string, nonce int64) ([]pipelineResource, error) {
8677
elasticsearchPath := filepath.Join(dataStreamPath, "elasticsearch", "ingest_pipeline")
8778
fis, err := ioutil.ReadDir(elasticsearchPath)

0 commit comments

Comments
 (0)