Skip to content

Conversation

@aleksmaus
Copy link
Contributor

Fix elastic-package where it was not correctly deriving the index template name for the hidden datastreams
and failing in CI:

For example PR elastic/integrations#2563

resulting in error:

asset test: index_template logs-osquery_manager.actions is loaded – osquery_manager.actions
no error details
Expand to view the stacktrace
 could not find expected asset: could not find index_template asset "logs-osquery_manager.actions". Assets loaded:
- .logs-osquery_manager.action_results (type: index_template)
- .logs-osquery_manager.action_results@mappings (type: component_template)
- .logs-osquery_manager.action_results@settings (type: component_template)
- .logs-osquery_manager.action_results@custom (type: component_template)
- .logs-osquery_manager.actions (type: index_template)
- .logs-osquery_manager.actions@mappings (type: component_template)
- .logs-osquery_manager.actions@settings (type: component_template)
- .logs-osquery_manager.actions@custom (type: component_template)
- logs-osquery_manager.result (type: index_template)
- logs-osquery_manager.result@mappings (type: component_template)
- logs-osquery_manager.result@settings (type: component_template)
- logs-osquery_manager.result@custom (type: component_template)

Screenshot after this change, showing it passes the tests now:

Screen Shot 2022-01-27 at 2 29 29 PM

@elasticmachine
Copy link
Collaborator

elasticmachine commented Jan 27, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Reason: null

  • Start Time: 2022-01-28T14:18:55.853+0000

  • Duration: 29 min 7 sec

  • Commit: f0dbcca

Test stats 🧪

Test Results
Failed 0
Passed 471
Skipped 0
Total 471

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@mtojek mtojek requested review from a team and removed request for ycombinator January 27, 2022 21:34

// IndexTemplateName returns the name of the Elasticsearch index template that would be installed
// for this data stream.
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

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)
Copy link
Contributor

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?

Copy link
Contributor Author

@aleksmaus aleksmaus Jan 27, 2022

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.

Copy link
Contributor

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)?

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:

https://github.com/elastic/kibana/blob/0ee514b1fe044cdaca253f8f14988fc17635fed3/x-pack/plugins/fleet/server/services/epm/elasticsearch/index.ts#L10-L18

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@aleksmaus aleksmaus requested a review from mtojek January 27, 2022 22:27
Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Left one comment

@aleksmaus aleksmaus requested review from joshdover and mtojek January 28, 2022 13:56
return dsm.IndexTemplateNamePrefix() + fmt.Sprintf("%s-%s", dsm.Type, dsm.Dataset)
}

func (dsm *DataStreamManifest) IndexTemplateNamePrefix() string {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

}

return fmt.Sprintf("%s-%s", dsm.Type, dsm.Dataset)
return dsm.IndexTemplateNamePrefix() + fmt.Sprintf("%s-%s", dsm.Type, dsm.Dataset)
Copy link
Contributor

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(...))

@mtojek mtojek changed the title Correctly process the hidden property in datastream definition Fix: use correct index template name for hidden data streams Jan 28, 2022
@mtojek mtojek merged commit bbb7797 into elastic:main Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants