-
Notifications
You must be signed in to change notification settings - Fork 127
Fix: use correct index template name for hidden data streams #673
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
Conversation
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
🤖 GitHub commentsTo re-run your PR in the CI, just comment with:
|
|
|
||
| // IndexTemplateName returns the name of the Elasticsearch index template that would be installed | ||
| // for this data stream. | ||
| func (dsm *DataStreamManifest) IndexTemplateName(pkgName string) string { |
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.
As this isn't a standard, straightforward logic, would you mind adding some unit tests?
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.
Sure will do
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.
Done
internal/packages/packages.go
Outdated
| func (dsm *DataStreamManifest) IndexTemplateName(pkgName string) string { | ||
| if dsm.Dataset == "" { | ||
| return fmt.Sprintf("%s-%s.%s", dsm.Type, pkgName, dsm.Name) | ||
| return dsm.IndexTemplateNamePrefix() + fmt.Sprintf("%s-%s.%s", dsm.Type, pkgName, dsm.Name) |
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.
What would be the value for a hidden data stream without dataset defined? .logs-aPackage.aDataStream?
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.
Not 100% sure what it suppose to be, but currently the kibana behavour is different from the elatic-package validation. Kibana creates templates with "." dot prefix for the package with hidden datastreams.
As far as I understand the consistent behavior would be in both cases with or without dataset name to have hidden property to influence the template name.
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.
Not 100% sure what it suppose to be,
So do I :) I'm not if it's a bug or works as intended. @ruflin @joshdover Could you please confirm the index template name ("hidden" case)?
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.
So this pre-dates my time on Fleet, but this definitely appears to be intentional. We have this function in Kibana which is used for all asset naming:
It appears it was added as part of elastic/kibana#86277 over a year ago, though I don't see any linked package-spec changes. Maybe @kevinlog can provide more context.
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 for diving into code, Josh! @aleksmaus I think you can adjust function implementation to look similar (baseType vs .baseType) and please hard-link to Kibana in the comment.
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 for looking into this. Will update and add comment. Endpoint didn't have issues passing this validation in CI because it lives in a separate repo, maybe skipping this test.
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.
Took a look at kibana code, it looks consistent with this change. Added a comment. Let me know.
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.
Left one comment
internal/packages/packages.go
Outdated
| return dsm.IndexTemplateNamePrefix() + fmt.Sprintf("%s-%s", dsm.Type, dsm.Dataset) | ||
| } | ||
|
|
||
| func (dsm *DataStreamManifest) IndexTemplateNamePrefix() string { |
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.
nit: does it have to be exposed?
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.
valid point. doesn't have to.
internal/packages/packages.go
Outdated
| } | ||
|
|
||
| return fmt.Sprintf("%s-%s", dsm.Type, dsm.Dataset) | ||
| return dsm.IndexTemplateNamePrefix() + fmt.Sprintf("%s-%s", dsm.Type, dsm.Dataset) |
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.
I think you can refactor it into:fmt.Sprintf("%s%s-%s", dsm.optionalIndexTemplateNamePrefix(), dsm.Type, dsm.Dataset) to prevent concatenation and fmt.Sprintf separately.
or maybe:
dsm.withIndexTemplateNamePrefix(fmt.Sprintf(...))
Fix elastic-package where it was not correctly deriving the index template name for the
hiddendatastreamsand failing in CI:
For example PR elastic/integrations#2563
resulting in error:
Screenshot after this change, showing it passes the tests now: