Giter Club home page Giter Club logo

Comments (4)

bclozel avatar bclozel commented on August 30, 2024

I'm not sure I understand the use case here.

  1. For some of them, we first check if they are on pause or not (pause is triggered by an external event) and we only want an observation (and sub observations) if it's not on pause

How would you detect that a scheduled method would be on pause? What do you mean by that? Would it require the execution to be ongoing?

Then, I tried the following

All the solutions you've described could be implemented with an ObservationPredicate that looks at the observation context and checks the ScheduledTaskObservationContext#getMethod() for custom annotations. I don't think you would need to override any Spring Boot configuration nor implement your own ScheduledAnnotationBeanPostProcessor.

I'm probably missing something here.

from spring-boot.

nvervelle avatar nvervelle commented on August 30, 2024

Hi @bclozel

How would you detect that a scheduled method would be on pause? What do you mean by that? Would it require the execution to be ongoing?

I have some scheduled tasks that are triggered frequently, but can decide by themselves to be on pause until a given time depending on some conditions.
For example, one scheduled task is used to purge data older than 30 days. Each time it's triggered, it retrieves the oldest data and purge it if it's older than 30 days. If it's not, then it decides to be on pause until this oldest data is 30 days old. That's just an example.

I'm probably missing something here.

Well, the problem is with children spans : if the ObservationPredicate says false, a NOOP observation is created and becomes the current observation. If the code called by the scheduled task creates also an observation, as its parent span is a NOOP, it will also be a NOOP. That's why it works for behavior 2, the scheduled task and children spans are NOOP. For behavior 3, I want children spans to be actual spans. With the ObservationPredicate, I can't have behavior 2 and behavior 3 depending on the use case.

from spring-boot.

bclozel avatar bclozel commented on August 30, 2024

I see, thanks for the feedback.

So it sounds like you would like to change the active/noop status of an observation after it's been created.

Unfortunately, I don't think there is anything we can do in the Spring Framework @Scheduled instrumentation or in the Spring Boot auto-configuration. Please see this Micrometer issue (and especially the related ones) as I think this is really a Micrometer concern.

from spring-boot.

bclozel avatar bclozel commented on August 30, 2024

Some additional thoughts.

The Observation API is one of the strengths of Micrometer. One can instrument apps and libraries for metrics, traces or both without introducing specific dependencies. Micrometer uses observation handlers that listen for the lifecycle of observations and turn them into metrics and traces. In this case, starting an observation has side-effects like starting to record a metric, adding headers to messages for tracing, and more. "Cancelling" an observation after it has started is challenging and would probably require specific checks that would hurt performance for instrumentations.

In your case, I understand that you probably don't want to record metrics for "paused jobs" as they're very short lived and are probably skewing numbers. For this, I think you could maybe let the observation be recorded, but add metadata to the observation context stating that it's been paused. This way, you can build your metrics dashboard using this dimension and avoid conflating paused/unpaused jobs.

from spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.