Skip to content

Commit

Permalink
Postpone metric registration in adapters until all configuration applied
Browse files Browse the repository at this point in the history
  • Loading branch information
Envek committed Jul 15, 2020
1 parent 30c9d5e commit d745cf7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## not released

### Fixed

- Default tags were not sent to adapters for metrics declared before `default_tag` declaration. [@Envek]

## 0.5.0 - 2020-01-29

### Added
Expand Down
10 changes: 10 additions & 0 deletions lib/yabeda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def configured?

# Perform configuration: registration of metrics and collector blocks
# @return [void]
# rubocop: disable Metrics/MethodLength, Metrics/AbcSize
def configure!
raise(AlreadyConfiguredError, @configured_by) if already_configured?

Expand All @@ -69,8 +70,17 @@ def configure!
group nil
end

# Register metrics in adapters after evaluating all configuration blocks
# to ensure that all global settings (like default tags) will be applied.
adapters.each_value do |adapter|
metrics.each_value do |metric|
adapter.register!(metric)
end
end

@configured_by = caller_locations(1, 1)[0].to_s
end
# rubocop: enable Metrics/MethodLength, Metrics/AbcSize

# Forget all the configuration.
# For testing purposes as it doesn't rollback changes in adapters.
Expand Down
1 change: 0 additions & 1 deletion lib/yabeda/dsl/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def register_metric(metric)
name = [metric.group, metric.name].compact.join("_")
::Yabeda.define_singleton_method(name) { metric }
::Yabeda.metrics[name] = metric
::Yabeda.adapters.each_value { |adapter| adapter.register!(metric) }
register_group_for(metric) if metric.group
metric
end
Expand Down

0 comments on commit d745cf7

Please sign in to comment.