Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions internal/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type DataStreamManifest struct {
Title string `config:"title" json:"title" yaml:"title"`
Type string `config:"type" json:"type" yaml:"type"`
Dataset string `config:"dataset" json:"dataset" yaml:"dataset"`
Hidden bool `config:"hidden" json:"hidden" yaml:"hidden"`
Release string `config:"release" json:"release" yaml:"release"`
Elasticsearch *struct {
IngestPipeline *struct {
Expand Down Expand Up @@ -241,12 +242,21 @@ func (dsm *DataStreamManifest) GetPipelineNameOrDefault() string {

// IndexTemplateName returns the name of the Elasticsearch index template that would be installed
// for this data stream.
// The template name starts with dot "." if the datastream is hidden which is consistent with kibana implementation
// https://github.com/elastic/kibana/blob/3955d0dc819fec03f68cd1d931f64da8472e34b2/x-pack/plugins/fleet/server/services/epm/elasticsearch/index.ts#L14
func (dsm *DataStreamManifest) IndexTemplateName(pkgName string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

As this isn't a standard, straightforward logic, would you mind adding some unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if dsm.Dataset == "" {
return fmt.Sprintf("%s-%s.%s", dsm.Type, pkgName, dsm.Name)
return fmt.Sprintf("%s%s-%s.%s", dsm.indexTemplateNamePrefix(), dsm.Type, pkgName, dsm.Name)
}

return fmt.Sprintf("%s-%s", dsm.Type, dsm.Dataset)
return fmt.Sprintf("%s%s-%s", dsm.indexTemplateNamePrefix(), dsm.Type, dsm.Dataset)
}

func (dsm *DataStreamManifest) indexTemplateNamePrefix() string {
if dsm.Hidden {
return "."
}
return ""
}

// FindInputByType returns the input for the provided type.
Expand Down
19 changes: 19 additions & 0 deletions internal/packages/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ func TestDataStreamManifest_IndexTemplateName(t *testing.T) {
"pkg",
dataStreamTypeLogs + "-pkg.foo",
},
"no_dataset_hidden": {
DataStreamManifest{
Name: "foo",
Type: dataStreamTypeLogs,
Hidden: true,
},
"pkg",
"." + dataStreamTypeLogs + "-pkg.foo",
},
"with_dataset": {
DataStreamManifest{
Name: "foo",
Expand All @@ -66,6 +75,16 @@ func TestDataStreamManifest_IndexTemplateName(t *testing.T) {
"pkg",
dataStreamTypeLogs + "-custom",
},
"with_dataset_hidden": {
DataStreamManifest{
Name: "foo",
Type: dataStreamTypeLogs,
Dataset: "custom",
Hidden: true,
},
"pkg",
"." + dataStreamTypeLogs + "-custom",
},
}

for name, test := range cases {
Expand Down