Skip to content

Conversation

@danielmitterdorfer
Copy link
Member

With this commit we amend the default lifecycle policy for Universal Profiling with a version field in the metadata section and add infrastructure to determine whether a lifecycle policy should be upgraded to a newer version.

With this commit we amend the default lifecycle policy for Universal Profiling with a version field in the metadata section and add infrastructure to determine whether a lifecycle policy should be upgraded to a newer version.
@danielmitterdorfer danielmitterdorfer added >enhancement v8.9.0 :UniversalProfiling/Application Elastic Universal Profiling REST APIs and infrastructure labels Jun 5, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/profiling (Team:Universal Profiling)

@elasticsearchmachine
Copy link
Collaborator

Hi @danielmitterdorfer, I've created a changelog YAML for you.

@danielmitterdorfer
Copy link
Member Author

@gmarouli I've assigned you as reviewer as this PR also touches IndexTemplateRegistry.

Copy link
Contributor

@gmarouli gmarouli left a comment

Choose a reason for hiding this comment

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

Looks very good, almost done, I added some small comments. Let me know what you think :).

protected boolean isUpgradeRequired(LifecyclePolicy currentPolicy, LifecyclePolicy newPolicy) {
try {
return getVersion(currentPolicy) < getVersion(newPolicy);
} catch (NumberFormatException ex) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I would move this to the getVersion method and I would add the name of the policy in the log line, for example, Invalid version for profiling lifecycle policy 'my-policy-with-invalid-version'.. I know it's unlikely that this will happen and effectively there is only one policy, but I think it's a small change that in the future might prove to be helpful.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've restructured the code now in a90bf43. To avoid complicating the control flow I kept the catch block here but raise a specific exception now on parse errors in #getVersion().

});

ClusterChangedEvent newEvent = createClusterChangedEvent(
Collections.emptyMap(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: (delayed comment) I just noticed this, we prefer to use Map.of() in the code base since it is supported.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good to know. Corrected in a90bf43.

if (Objects.isNull(currentPolicy)) {
logger.debug("adding lifecycle policy [{}] for [{}], because it doesn't exist", policy.getName(), getOrigin());
putPolicy(policy, creationCheck);
} else if (isUpgradeRequired(currentPolicy, policy)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I can see that this functionality is tested in the ProfilingIndexTemplateRegistryTests but since this is implemented and it would remain even if ProfilingIndexTemplateRegistry would be deprecated/removed, I think it would be good to add a test also in IndexTemplateRegistryTests. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've amended test cases for the base class in a90bf43.

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 the review @gmarouli! I've addressed your feedback in a90bf43. Could you please take another look?

Yes, on it.

@danielmitterdorfer
Copy link
Member Author

Thanks for the review @gmarouli! I've addressed your feedback in a90bf43. Could you please take another look?

@danielmitterdorfer
Copy link
Member Author

@elasticmachine merge upstream

Copy link
Contributor

@gmarouli gmarouli left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for addressing the comments! 🚀

@danielmitterdorfer danielmitterdorfer merged commit 3591566 into elastic:main Jun 12, 2023
@danielmitterdorfer danielmitterdorfer deleted the profiling-updateable-policy branch June 12, 2023 09:28
@danielmitterdorfer
Copy link
Member Author

Many thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :UniversalProfiling/Application Elastic Universal Profiling REST APIs and infrastructure v8.9.0

4 participants