Skip to content

Rollback wrapping of runnables on each schedule for Spring Scheduling#7290

Merged
amarziali merged 1 commit into
masterfrom
andrea.marziali/spring-scheduling-plusplus
Jul 8, 2024
Merged

Rollback wrapping of runnables on each schedule for Spring Scheduling#7290
amarziali merged 1 commit into
masterfrom
andrea.marziali/spring-scheduling-plusplus

Conversation

@amarziali
Copy link
Copy Markdown
Contributor

@amarziali amarziali commented Jul 8, 2024

What Does This Do

This PR rollbacks instrumenting spring scheduling TaskScheduler which was wrapping the Runnable in each schedule.
This was done as part of #6249 in order to have the right Runnable names displayed on actuator's endpoints.

Wrapping the runnable on each schedule can cause side effects if a custom task scheduler is used and if inside the schedule method instanceof is used to check whenever the Runnable is of a certain type since we're wrapping it with SpringSchedulingRunnableWrapper.

In order to be less invasive and, at same time, preserve the right labelling on actuator, I've restored the old approach instrumenting Task instead of TaskScheduler which was causing that bad behaviour. I've also overridden the toString method of SpringSchedulingRunnableWrapper in order to target the wrapped runnable instead. This will work for spring boot actuator since the displayed name is obtained calling toString (https://github.com/spring-projects/spring-boot/blob/69630bba37caa3a092b19392949705a41234d703/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/scheduling/ScheduledTasksEndpoint.java#L285)

Motivation

Additional Notes

Jira ticket: APMS-12578

@amarziali amarziali added type: bug Bug report and fix inst: spring Spring instrumentation labels Jul 8, 2024
@amarziali amarziali requested a review from a team as a code owner July 8, 2024 08:13
@amarziali amarziali changed the title Spring scheduling: do not wrap runnabled on each schedule Spring scheduling: do not wrap runnables on each schedule Jul 8, 2024
Copy link
Copy Markdown
Contributor

@mcculls mcculls left a comment

Choose a reason for hiding this comment

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

Much better, thanks!

@amarziali amarziali enabled auto-merge (squash) July 8, 2024 08:38
@amarziali amarziali merged commit 3daca96 into master Jul 8, 2024
@amarziali amarziali deleted the andrea.marziali/spring-scheduling-plusplus branch July 8, 2024 08:49
@github-actions github-actions Bot added this to the 1.38.0 milestone Jul 8, 2024
@nayeem-kamal nayeem-kamal changed the title Spring scheduling: do not wrap runnables on each schedule Rollback wrapping of runnables on each schedule for Spring Scheduling Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: spring Spring instrumentation type: bug Bug report and fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants