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

Added metrics to Scheduler and track in Process state #984

Merged
merged 23 commits into from
Jul 4, 2023

Conversation

AndersGM
Copy link
Contributor

@AndersGM AndersGM commented Jun 19, 2023

@AndersGM AndersGM force-pushed the metrics branch 2 times, most recently from 9173934 to d6e2587 Compare June 19, 2023 20:27
Copy link
Owner

@bensheldon bensheldon left a comment

Choose a reason for hiding this comment

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

I'm happy to accept this. Briefly, it needs:

  • threadsafety
  • have the value show up when the Process serializes the Schedulers so that it can be queried
  • I think the value should be reset when the the Scheduler is restarted (otherwise it might get weird when forking, especially with Puma's worker_fork

lib/good_job/metrics.rb Outdated Show resolved Hide resolved
@AndersGM
Copy link
Contributor Author

AndersGM commented Jun 20, 2023

@bensheldon Thank you for taking your time to look into this! Regarding the serialization - as far as I can see process uses name when serializing, so I've added the metrics to the name here in 78d8aba. Not sure if that is the best place though, but not sure where else to put it, without messing up the enclosing parentheses. What do you think? Also considered adding something like:

succeeded_count: GoodJob::Scheduler.instances.sum(&:succeeded_count),
failed_count: GoodJob::Scheduler.instances.sum(&:failed_count),

to Process.current_state.

@bensheldon
Copy link
Owner

@AndersGM Good things to flag! What do you think about making a method like Scheduler#statistics that contained the name and those values and then dropping that into the Process state? (I also think they should be succeeded_executions_count for clarity).

Ok, and then I have a totally random thought that I want to share, but isn't telling you to do instead: What if we tracked executed_by_process_id on the Execution/DiscreteExecution object in the database? Would that be equivalent? (it could be joined in the database against the Process record)

@AndersGM
Copy link
Contributor Author

AndersGM commented Jun 20, 2023

@bensheldon That would be better, but maybe not statistics since there already is a method named stats so it might be confusing. What about name_with_metrics or just adding a parameter include_metrics to the name method? Agree about the more longer more explicit variable names (succeeded_executions_count).

Sound interesting. I actually do something similar in one of my apps that then sends the metrics to prometheus. However, the issue is that the executions can be destroyed through the UI (and cleanup?). Consequently, the resulting counter could actually decrement, without being reset. That is the reason I implemented it this way, to avoid that. Did you think of another way or have I misunderstood something? :-)

@AndersGM AndersGM marked this pull request as ready for review June 25, 2023 18:56
@AndersGM AndersGM requested a review from bensheldon June 25, 2023 18:56
@bensheldon
Copy link
Owner

@AndersGM I made a few tweaks and pushed this back up. It's looking great!

I just merged in #977 which will update the Process record in the database every 30 seconds.

One thing I noticed that I'd like your feedback on. Currently this PR only records a job failure if it bubbles up to the thread-handler. This will cover only a small number of execution failures. We want to cover all the circumstances where a job's execution does not succeed, right? (e.g. if an execution fails and is retried, we'd still count that). That seem right? If you agree, I can make that tweak.

@AndersGM
Copy link
Contributor Author

AndersGM commented Jul 1, 2023

@bensheldon indeed - thank you! I wasn't aware of that - let me know if I can be of any help!

lib/good_job/metrics.rb Show resolved Hide resolved
app/models/good_job/execution_result.rb Outdated Show resolved Hide resolved
@bensheldon bensheldon added the enhancement New feature or request label Jul 4, 2023
@bensheldon bensheldon changed the title Added metrics to scheduler Added metrics to scheduler and track in Process state Jul 4, 2023
@bensheldon bensheldon changed the title Added metrics to scheduler and track in Process state Added metrics to Scheduler and track in Process state Jul 4, 2023
@bensheldon bensheldon merged commit caf8005 into bensheldon:main Jul 4, 2023
@AndersGM AndersGM deleted the metrics branch July 4, 2023 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

2 participants