lib/influxdb/rails/middleware/subscriber.rb in influxdb-rails-1.0.0.beta3 vs lib/influxdb/rails/middleware/subscriber.rb in influxdb-rails-1.0.0.beta4
- old
+ new
@@ -1,35 +1,46 @@
-require "influxdb/rails/logger"
-
module InfluxDB
module Rails
module Middleware
# Subscriber acts as base class for different *Subscriber classes,
# which are intended as ActiveSupport::Notifications.subscribe
# consumers.
class Subscriber
- include InfluxDB::Rails::Logger
-
attr_reader :configuration
+ attr_reader :hook_name
- def initialize(configuration)
+ def initialize(configuration, hook_name)
@configuration = configuration
+ @hook_name = hook_name
end
def call(*)
raise NotImplementedError, "must be implemented in subclass"
end
private
+ def timestamp(time)
+ InfluxDB.convert_timestamp(time.utc, client.time_precision)
+ end
+
+ def client
+ @client = configuration.client
+ end
+
def tags(tags)
- merged_tags = tags.merge(InfluxDB::Rails.current.tags).reject { |_, value| value.nil? }
- configuration.tags_middleware.call(merged_tags)
+ result = tags.merge(InfluxDB::Rails.current.tags)
+ result = configuration.tags_middleware.call(result)
+ result.reject! do |_, value|
+ value.nil? || value == ""
+ end
+ result
end
def enabled?
configuration.instrumentation_enabled? &&
- !configuration.ignore_current_environment?
+ !configuration.ignore_current_environment? &&
+ !configuration.ignored_hooks.include?(hook_name)
end
def location
current = InfluxDB::Rails.current
[