Skip to content

Commit

Permalink
Merge pull request #171 from hennevogel/bugfix/custom-tags
Browse files Browse the repository at this point in the history
Do not reject FalseClass from tags/values
  • Loading branch information
hennevogel authored Apr 13, 2021
2 parents 38d59b5 + 383f436 commit d10cae3
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 146 deletions.
2 changes: 1 addition & 1 deletion lib/influxdb/rails/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(config:, tags: {}, additional_tags: InfluxDB::Rails.current.tags)

def to_h
expanded_tags.reject do |_, value|
value.blank?
value.to_s.blank?
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/influxdb/rails/values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(values: {}, additional_values: InfluxDB::Rails.current.values)

def to_h
expanded_values.reject do |_, value|
value.blank?
value.to_s.blank?
end
end

Expand Down
29 changes: 21 additions & 8 deletions spec/requests/action_controller_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,35 @@
expect_metric(
name: "rails",
tags: a_hash_including(
method: "MetricsController#index",
hook: "process_action",
status: 200,
format: :html,
http_method: "GET"
),
values: a_hash_including(
view: be_between(1, 500),
db: be_between(1, 500),
controller: be_between(1, 500)
)
)
end

it "writes default and custom tags" do
get "/metrics"

expect_metric(
name: "rails",
tags: a_hash_including(
hook: "process_action",
status: 200,
format: :html,
http_method: "GET",
location: "MetricsController#index",
additional_tag: :value,
server: Socket.gethostname,
app_name: :app_name,
tags_middleware: :tags_middleware
),
values: a_hash_including(
additional_value: :value,
request_id: :request_id,
view: be_between(1, 500),
db: be_between(1, 500),
controller: be_between(1, 500)
request_id: :request_id
)
)
end
Expand Down
13 changes: 3 additions & 10 deletions spec/requests/action_mailer_deliver_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,11 @@

expect_metric(
tags: a_hash_including(
hook: "deliver",
mailer: "MetricMailer",
location: "MetricsController#index",
additional_tag: :value,
server: Socket.gethostname,
app_name: :app_name,
tags_middleware: :tags_middleware
hook: "deliver",
mailer: "MetricMailer"
),
values: a_hash_including(
additional_value: :value,
request_id: :request_id,
value: 1
value: 1
)
)
end
Expand Down
21 changes: 6 additions & 15 deletions spec/requests/action_view_collection_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,12 @@
expect_metric(
name: "rails",
tags: a_hash_including(
location: "MetricsController#index",
hook: "render_collection",
additional_tag: :value,
filename: include("spec/support/views/metrics/_item.html.erb"),
server: Socket.gethostname,
app_name: :app_name,
tags_middleware: :tags_middleware
hook: "render_collection",
filename: include("spec/support/views/metrics/_item.html.erb")
),
values: a_hash_including(
additional_value: :value,
count: 3,
request_id: :request_id,
value: be_between(1, 500)
count: 3,
value: be_between(1, 500)
)
)
end
Expand All @@ -43,8 +36,7 @@
expect_metric(
name: "rails",
tags: a_hash_including(
location: "MetricsController#index",
hook: "render_collection"
hook: "render_collection"
),
timestamp: 1_514_797_200
)
Expand All @@ -58,8 +50,7 @@
expect_no_metric(
name: "rails",
tags: a_hash_including(
location: "MetricsController#index",
hook: "render_collection"
hook: "render_collection"
)
)
end
Expand Down
19 changes: 5 additions & 14 deletions spec/requests/action_view_partial_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "render_partial",
additional_tag: :value,
filename: include("spec/support/views/metrics/_item.html.erb"),
server: Socket.gethostname,
app_name: :app_name,
tags_middleware: :tags_middleware
hook: "render_partial",
filename: include("spec/support/views/metrics/_item.html.erb")
),
values: a_hash_including(
additional_value: :value,
request_id: :request_id,
value: be_between(1, 500)
value: be_between(1, 500)
)
)
end
Expand All @@ -40,8 +33,7 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "render_partial"
hook: "render_partial"
),
timestamp: 1_514_797_200
)
Expand All @@ -54,8 +46,7 @@

expect_no_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "render_partial"
hook: "render_partial"
)
)
end
Expand Down
19 changes: 5 additions & 14 deletions spec/requests/action_view_template_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "render_template",
additional_tag: :value,
filename: include("spec/support/views/metrics/index.html.erb"),
server: Socket.gethostname,
app_name: :app_name,
tags_middleware: :tags_middleware
hook: "render_template",
filename: include("spec/support/views/metrics/index.html.erb")
),
values: a_hash_including(
additional_value: :value,
request_id: :request_id,
value: be_between(1, 500)
value: be_between(1, 500)
)
)
end
Expand All @@ -40,8 +33,7 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "render_template"
hook: "render_template"
),
timestamp: 1_514_797_200
)
Expand All @@ -54,8 +46,7 @@

expect_no_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "render_template"
hook: "render_template"
)
)
end
Expand Down
19 changes: 5 additions & 14 deletions spec/requests/active_job_enqueue_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,13 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "enqueue",
job: "MetricJob",
queue: "default",
state: "queued",
additional_tag: :value,
server: Socket.gethostname,
app_name: :app_name,
tags_middleware: :tags_middleware
hook: "enqueue",
job: "MetricJob",
queue: "default",
state: "queued"
),
values: a_hash_including(
additional_value: :value,
request_id: :request_id,
value: 1
value: 1
)
)
end
Expand All @@ -43,7 +36,6 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "enqueue"
),
timestamp: 1_514_797_200
Expand All @@ -57,7 +49,6 @@

expect_no_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "enqueue"
)
)
Expand Down
14 changes: 4 additions & 10 deletions spec/requests/active_job_perform_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "perform",
state: "succeeded",
job: "MetricJob",
queue: "default",
server: Socket.gethostname,
app_name: :app_name,
tags_middleware: :tags_middleware
hook: "perform",
state: "succeeded",
job: "MetricJob",
queue: "default"
),
values: a_hash_including(
value: be_between(0, 30)
Expand All @@ -44,7 +40,6 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "perform"
),
timestamp: 1_514_797_200
Expand All @@ -60,7 +55,6 @@

expect_no_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "perform"
)
)
Expand Down
21 changes: 6 additions & 15 deletions spec/requests/active_record_instantiation_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,12 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#show",
hook: "instantiation",
class_name: "Metric",
additional_tag: :value,
server: Socket.gethostname,
app_name: :app_name,
tags_middleware: :tags_middleware
hook: "instantiation",
class_name: "Metric"
),
values: a_hash_including(
additional_value: :value,
request_id: :request_id,
value: be_between(1, 500),
record_count: 1
value: be_between(1, 500),
record_count: 1
)
)
end
Expand All @@ -43,8 +36,7 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#show",
hook: "instantiation"
hook: "instantiation"
),
timestamp: 1_514_797_200
)
Expand All @@ -57,8 +49,7 @@

expect_no_metric(
tags: a_hash_including(
location: "MetricsController#show",
hook: "instantiation"
hook: "instantiation"
)
)
end
Expand Down
Loading

0 comments on commit d10cae3

Please sign in to comment.