Skip to content

Commit

Permalink
Rename job attribute to name to fix prometheus reserved key error
Browse files Browse the repository at this point in the history
  • Loading branch information
skryukov committed Apr 5, 2021
1 parent e561934 commit c5bec1b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Rename `job` attribute to `name` to fix prometheus reserved key error. [@skryukov]

## 0.1.0 (2021-04-03)

### Added

- Initial release of yabeda-schked gem. [@skryukov]

[@skryukov]: https://github.com/skryukov
6 changes: 3 additions & 3 deletions lib/yabeda/schked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ def self.job_name(job)
group :schked

counter :jobs_executed_total,
tags: %i[job success],
tags: %i[name success],
comment: "A counter of the number of jobs executed."

histogram :job_execution_runtime,
comment: "A histogram of the job execution time.",
unit: :seconds,
per: :job,
tags: %i[job success],
tags: %i[name success],
buckets: LONG_RUNNING_JOB_RUNTIME_BUCKETS
end

::Schked.config.register_callback(:after_finish) do |job|
labels = {success: !job.opts[:failed], job: job_name(job)}
labels = {success: !job.opts[:failed], name: job_name(job)}
Yabeda.schked.job_execution_runtime.measure(labels, job.last_work_time.round(3))
Yabeda.schked.jobs_executed_total.increment(labels)
end
Expand Down
12 changes: 6 additions & 6 deletions spec/yabeda/schked_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
job.trigger_off_schedule

expect(Yabeda.schked.jobs_executed_total.values).to include(
{job: job_name, success: true} => 1
{name: job_name, success: true} => 1
)
expect(Yabeda.schked.job_execution_runtime.values).to include(
{job: job_name, success: true} => kind_of(Numeric)
{name: job_name, success: true} => kind_of(Numeric)
)
end
end
Expand All @@ -37,10 +37,10 @@
job.trigger_off_schedule

expect(Yabeda.schked.jobs_executed_total.values).to include(
{job: job_name, success: false} => 1
{name: job_name, success: false} => 1
)
expect(Yabeda.schked.job_execution_runtime.values).to include(
{job: job_name, success: false} => kind_of(Numeric)
{name: job_name, success: false} => kind_of(Numeric)
)
end
end
Expand All @@ -56,10 +56,10 @@
/Warning: No name specified for the job/
).to_stderr
expect(Yabeda.schked.jobs_executed_total.values).to include(
{job: "none", success: true} => 1
{name: "none", success: true} => 1
)
expect(Yabeda.schked.job_execution_runtime.values).to include(
{job: "none", success: true} => kind_of(Numeric)
{name: "none", success: true} => kind_of(Numeric)
)
end
end
Expand Down

0 comments on commit c5bec1b

Please sign in to comment.