gocron icon indicating copy to clipboard operation
gocron copied to clipboard

[FEATURE] - Add Prometheus Metrics For Job

Open vaxilicaihouxian opened this issue 4 years ago • 3 comments

We can add prometheus metrics for job execution.Then outside monitor system can use these metrics to track jobs. Maybe I can send a pr.

vaxilicaihouxian avatar Mar 24 '22 03:03 vaxilicaihouxian

I think having optionally enabled prometheus metrics could be a nice a feature to add.

JohnRoesler avatar Mar 24 '22 12:03 JohnRoesler

metrics collector (counter,summary...)should always track job's state. metrics exporter could be a function like gocron.MetricsServe(ListenPort,Path)

vaxilicaihouxian avatar Mar 24 '22 13:03 vaxilicaihouxian

Yeah. It'd be nice to make the metrics an interface so we can implement with prometheus now and then later it could be implemented with influx and others.

JohnRoesler avatar Mar 24 '22 13:03 JohnRoesler

Please weigh in if you have input on what sort of metrics you'd like to see from gocron -> https://github.com/go-co-op/gocron/pull/417#discussion_r1174015307

JohnRoesler avatar Apr 21 '23 17:04 JohnRoesler

I think it’d be ideal to use otel like https://github.com/open-telemetry/opentelemetry-go/blob/main/example/prometheus/main.go

JohnRoesler avatar May 03 '23 03:05 JohnRoesler

Agreed that we may use OTEL to export the inner tracing data since gocron is a library instead of a service. For the metrics like the Prometheus, should be exported by the user service itself, and you can request gocron to export the way to get the metric's value you want, like the number of scheduling jobs, and so on.

git-hulk avatar May 12 '23 08:05 git-hulk

If anyone is looking to work on implementing this, what I'd like to see is:

  • An interface for the metrics provider defined in gocron
    • This keeps the dependency for metrics out of gocron and only add the dependency if the user imports the specific metrics implementation gocron repo (same pattern that is used for the distributed locker)
    • This should have some reasonable methods for incrementing metrics like counters with labels
  • A separate repository for each provider implementation
    • I would think either OTEL or Prometheus directly first
    • OTEL enables a broad scope of metrics providers and so it may be enough to implement only OTEL

JohnRoesler avatar Jun 12 '23 16:06 JohnRoesler