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

add new metric for Oban Job, total time inserted #141

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- New Oban plugin metric, total inserted time, the diff of inserted_at and attempted_at

## [1.7.1] - 2021-03-02

### Fixed
Expand Down
19 changes: 19 additions & 0 deletions lib/prom_ex/plugins/oban.ex
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ if Code.ensure_loaded?(Oban) do
unit: {:native, :millisecond},
keep: keep_function_filter
),
distribution(
metric_prefix ++ [:job, :inserted, :time, :milliseconds],
event_name: @job_complete_event,
measurement: &job_inserted_time_in_queue/2,
description: "The amount of time from Oban job insertion to job attempt.",
reporter_options: [
buckets: job_duration_buckets
],
tag_values: &job_complete_tag_values/1,
tags: [:name, :queue, :state, :worker],
unit: {:native, :millisecond},
keep: &filter_snoozed_jobs(&1, keep_function_filter)
),
distribution(
metric_prefix ++ [:job, :complete, :attempts],
event_name: @job_complete_event,
Expand Down Expand Up @@ -317,6 +330,9 @@ if Code.ensure_loaded?(Oban) do
)
end

defp job_inserted_time_in_queue(_measure, metadata),
do: DateTime.diff(metadata.job.attempted_at, metadata.job.inserted_at, :millisecond)

defp job_complete_tag_values(metadata) do
config =
case metadata do
Expand Down Expand Up @@ -444,6 +460,9 @@ if Code.ensure_loaded?(Oban) do
end
end

defp filter_snoozed_jobs(%{state: :snoozed}, _original_keep_filter), do: false
defp filter_snoozed_jobs(metadata, original_keep_filter), do: original_keep_filter.(metadata)

defp keep_oban_instance_metrics(oban_supervisors) do
fn
%{conf: %{name: name}} ->
Expand Down
29 changes: 29 additions & 0 deletions test/support/metrics/oban.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,35 @@ web_app_prom_ex_oban_job_queue_time_milliseconds_bucket{name="Oban",queue="media
web_app_prom_ex_oban_job_queue_time_milliseconds_bucket{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker",le="+Inf"} 3
web_app_prom_ex_oban_job_queue_time_milliseconds_sum{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker"} 137.731
web_app_prom_ex_oban_job_queue_time_milliseconds_count{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker"} 3
# HELP web_app_prom_ex_oban_job_inserted_time_milliseconds The amount of time from Oban job insertion to job attempt.
# TYPE web_app_prom_ex_oban_job_inserted_time_milliseconds histogram
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="default",state="success",worker="WebApp.Jobs.DefaultWorker",le="+Inf"} 8
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="default",state="success",worker="WebApp.Jobs.DefaultWorker",le="10"} 8
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="default",state="success",worker="WebApp.Jobs.DefaultWorker",le="100"} 8
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="default",state="success",worker="WebApp.Jobs.DefaultWorker",le="1000"} 8
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="default",state="success",worker="WebApp.Jobs.DefaultWorker",le="20000"} 8
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="default",state="success",worker="WebApp.Jobs.DefaultWorker",le="500"} 8
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="default",state="success",worker="WebApp.Jobs.DefaultWorker",le="5000"} 8
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="events",state="success",worker="WebApp.Jobs.EventWorker",le="+Inf"} 1
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="events",state="success",worker="WebApp.Jobs.EventWorker",le="10"} 1
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="events",state="success",worker="WebApp.Jobs.EventWorker",le="100"} 1
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="events",state="success",worker="WebApp.Jobs.EventWorker",le="1000"} 1
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="events",state="success",worker="WebApp.Jobs.EventWorker",le="20000"} 1
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="events",state="success",worker="WebApp.Jobs.EventWorker",le="500"} 1
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="events",state="success",worker="WebApp.Jobs.EventWorker",le="5000"} 1
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker",le="+Inf"} 3
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker",le="10"} 3
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker",le="100"} 3
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker",le="1000"} 3
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker",le="20000"} 3
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker",le="500"} 3
web_app_prom_ex_oban_job_inserted_time_milliseconds_bucket{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker",le="5000"} 3
web_app_prom_ex_oban_job_inserted_time_milliseconds_count{name="Oban",queue="default",state="success",worker="WebApp.Jobs.DefaultWorker"} 8
web_app_prom_ex_oban_job_inserted_time_milliseconds_count{name="Oban",queue="events",state="success",worker="WebApp.Jobs.EventWorker"} 1
web_app_prom_ex_oban_job_inserted_time_milliseconds_count{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker"} 3
web_app_prom_ex_oban_job_inserted_time_milliseconds_sum{name="Oban",queue="default",state="success",worker="WebApp.Jobs.DefaultWorker"} 0.38451099999999994
web_app_prom_ex_oban_job_inserted_time_milliseconds_sum{name="Oban",queue="events",state="success",worker="WebApp.Jobs.EventWorker"} 4.2999999999999995e-5
web_app_prom_ex_oban_job_inserted_time_milliseconds_sum{name="Oban",queue="media",state="success",worker="WebApp.Jobs.MediaWorker"} 1.37e-4
# HELP web_app_prom_ex_oban_job_processing_duration_milliseconds The amount of time it takes to processes an Oban job.
# TYPE web_app_prom_ex_oban_job_processing_duration_milliseconds histogram
web_app_prom_ex_oban_job_processing_duration_milliseconds_bucket{name="Oban",queue="default",state="success",worker="WebApp.Jobs.DefaultWorker",le="10"} 0
Expand Down