Skip to content
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

Publish completed step values on close (StepRegistry) #3864

Conversation

lenin-jaganathan
Copy link
Contributor

fixes #3863

@lenin-jaganathan lenin-jaganathan changed the base branch from main to 1.11.x May 30, 2023 07:39
lenin-jaganathan and others added 2 commits May 30, 2023 13:51
…sh/PushMeterRegistry.java

Co-authored-by: sonatype-lift[bot] <37194012+sonatype-lift[bot]@users.noreply.github.com>
@lenin-jaganathan lenin-jaganathan changed the title Failing test for gh-3863 Publish completed step on close (StepRegistry) May 30, 2023
@lenin-jaganathan lenin-jaganathan changed the title Publish completed step on close (StepRegistry) Publish completed step values on close (StepRegistry) May 30, 2023
Copy link
Member

@shakuzen shakuzen left a comment

Choose a reason for hiding this comment

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

Looks good. I left a nit and a question. This should fix things for the case of closing before scheduled publishing in a step. I think there will still be issues if close happens while scheduled publishing is happening, but we can worry about that separately from this change. That should be a much rarer case.

@@ -60,6 +62,7 @@ protected PushMeterRegistry(PushRegistryConfig config, Clock clock) {
// VisibleForTesting
void publishSafely() {
if (this.publishing.compareAndSet(false, true)) {
this.lastScheduledPublishStartTime = clock.wallTime();
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's a problem with the current implementation, but it feels like it would be more correct to set this directly from the scheduled task rather than in this method. After all, this method could be called from outside scheduling. I'm thinking updating the scheduling to something like:

scheduledExecutorService.scheduleAtFixedRate(() -> {
    this.lastScheduledPublishStartTime = clock.wallTime();
    publishSafely();
}, initialDelayMillis, stepMillis, TimeUnit.MILLISECONDS);

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It has its own drawbacks, we do this check this.publishing.compareAndSet(false, true) in publishSafely which opens up the possibility that either publish can happen or cannot happen when you call publishSafely. So, if it doesn't do a publish then updating lastScheduledPublishStartTime in scheduling might be problematic, because the publish didn't start at that rather it was attempted and turned down.

variable lastScheduledPublishStartTime might be interpreted in 2 ways by its name -

  • the time when the publish was called by the scheduling thread. (which is what I wanted to convey)
  • but it can also be interpreted as you did above.

The Javadoc for getLastScheduledPublishStartTime() says "Returns the time when the last scheduled publish was started by {@link PushMeterRegistry#publishSafely()}." which I guess represents better. If you feel confused or think otherwise, we can reconsider. But be aware that adding it in scheduleAtFixedRate means it no longer represents the time when publish was called rather it represents when publishSafely was called.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, considering everything identified so far it seems like it will be better to leave it as is for now.

@lenin-jaganathan
Copy link
Contributor Author

the build failure seems unrelated to this PR and maybe a flaky one or something. I don't have permission to restart the job.

@shakuzen shakuzen merged commit b0be362 into micrometer-metrics:1.11.x Jun 12, 2023
shakuzen added a commit that referenced this pull request Jun 12, 2023
@lenin-jaganathan lenin-jaganathan deleted the publish_onclose_missed_step branch June 12, 2023 16:32
izeye added a commit to izeye/micrometer that referenced this pull request Jul 22, 2023
shakuzen pushed a commit that referenced this pull request Jul 25, 2023
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.

StepRegistry publish on close before scheduled publish loses previous step data
2 participants