Skip to content

Commit d10cae3

Browse files
authored
Merge pull request #171 from hennevogel/bugfix/custom-tags
Do not reject FalseClass from tags/values
2 parents 38d59b5 + 383f436 commit d10cae3

13 files changed

+123
-146
lines changed

lib/influxdb/rails/tags.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def initialize(config:, tags: {}, additional_tags: InfluxDB::Rails.current.tags)
99

1010
def to_h
1111
expanded_tags.reject do |_, value|
12-
value.blank?
12+
value.to_s.blank?
1313
end
1414
end
1515

lib/influxdb/rails/values.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(values: {}, additional_values: InfluxDB::Rails.current.values)
88

99
def to_h
1010
expanded_values.reject do |_, value|
11-
value.blank?
11+
value.to_s.blank?
1212
end
1313
end
1414

spec/requests/action_controller_metrics_spec.rb

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,35 @@
1818
expect_metric(
1919
name: "rails",
2020
tags: a_hash_including(
21-
method: "MetricsController#index",
21+
hook: "process_action",
22+
status: 200,
23+
format: :html,
24+
http_method: "GET"
25+
),
26+
values: a_hash_including(
27+
view: be_between(1, 500),
28+
db: be_between(1, 500),
29+
controller: be_between(1, 500)
30+
)
31+
)
32+
end
33+
34+
it "writes default and custom tags" do
35+
get "/metrics"
36+
37+
expect_metric(
38+
name: "rails",
39+
tags: a_hash_including(
2240
hook: "process_action",
23-
status: 200,
24-
format: :html,
25-
http_method: "GET",
41+
location: "MetricsController#index",
2642
additional_tag: :value,
2743
server: Socket.gethostname,
2844
app_name: :app_name,
2945
tags_middleware: :tags_middleware
3046
),
3147
values: a_hash_including(
3248
additional_value: :value,
33-
request_id: :request_id,
34-
view: be_between(1, 500),
35-
db: be_between(1, 500),
36-
controller: be_between(1, 500)
49+
request_id: :request_id
3750
)
3851
)
3952
end

spec/requests/action_mailer_deliver_metrics_spec.rb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,11 @@
1818

1919
expect_metric(
2020
tags: a_hash_including(
21-
hook: "deliver",
22-
mailer: "MetricMailer",
23-
location: "MetricsController#index",
24-
additional_tag: :value,
25-
server: Socket.gethostname,
26-
app_name: :app_name,
27-
tags_middleware: :tags_middleware
21+
hook: "deliver",
22+
mailer: "MetricMailer"
2823
),
2924
values: a_hash_including(
30-
additional_value: :value,
31-
request_id: :request_id,
32-
value: 1
25+
value: 1
3326
)
3427
)
3528
end

spec/requests/action_view_collection_metrics_spec.rb

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,12 @@
1818
expect_metric(
1919
name: "rails",
2020
tags: a_hash_including(
21-
location: "MetricsController#index",
22-
hook: "render_collection",
23-
additional_tag: :value,
24-
filename: include("spec/support/views/metrics/_item.html.erb"),
25-
server: Socket.gethostname,
26-
app_name: :app_name,
27-
tags_middleware: :tags_middleware
21+
hook: "render_collection",
22+
filename: include("spec/support/views/metrics/_item.html.erb")
2823
),
2924
values: a_hash_including(
30-
additional_value: :value,
31-
count: 3,
32-
request_id: :request_id,
33-
value: be_between(1, 500)
25+
count: 3,
26+
value: be_between(1, 500)
3427
)
3528
)
3629
end
@@ -43,8 +36,7 @@
4336
expect_metric(
4437
name: "rails",
4538
tags: a_hash_including(
46-
location: "MetricsController#index",
47-
hook: "render_collection"
39+
hook: "render_collection"
4840
),
4941
timestamp: 1_514_797_200
5042
)
@@ -58,8 +50,7 @@
5850
expect_no_metric(
5951
name: "rails",
6052
tags: a_hash_including(
61-
location: "MetricsController#index",
62-
hook: "render_collection"
53+
hook: "render_collection"
6354
)
6455
)
6556
end

spec/requests/action_view_partial_metrics_spec.rb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,11 @@
1717

1818
expect_metric(
1919
tags: a_hash_including(
20-
location: "MetricsController#index",
21-
hook: "render_partial",
22-
additional_tag: :value,
23-
filename: include("spec/support/views/metrics/_item.html.erb"),
24-
server: Socket.gethostname,
25-
app_name: :app_name,
26-
tags_middleware: :tags_middleware
20+
hook: "render_partial",
21+
filename: include("spec/support/views/metrics/_item.html.erb")
2722
),
2823
values: a_hash_including(
29-
additional_value: :value,
30-
request_id: :request_id,
31-
value: be_between(1, 500)
24+
value: be_between(1, 500)
3225
)
3326
)
3427
end
@@ -40,8 +33,7 @@
4033

4134
expect_metric(
4235
tags: a_hash_including(
43-
location: "MetricsController#index",
44-
hook: "render_partial"
36+
hook: "render_partial"
4537
),
4638
timestamp: 1_514_797_200
4739
)
@@ -54,8 +46,7 @@
5446

5547
expect_no_metric(
5648
tags: a_hash_including(
57-
location: "MetricsController#index",
58-
hook: "render_partial"
49+
hook: "render_partial"
5950
)
6051
)
6152
end

spec/requests/action_view_template_metrics_spec.rb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,11 @@
1717

1818
expect_metric(
1919
tags: a_hash_including(
20-
location: "MetricsController#index",
21-
hook: "render_template",
22-
additional_tag: :value,
23-
filename: include("spec/support/views/metrics/index.html.erb"),
24-
server: Socket.gethostname,
25-
app_name: :app_name,
26-
tags_middleware: :tags_middleware
20+
hook: "render_template",
21+
filename: include("spec/support/views/metrics/index.html.erb")
2722
),
2823
values: a_hash_including(
29-
additional_value: :value,
30-
request_id: :request_id,
31-
value: be_between(1, 500)
24+
value: be_between(1, 500)
3225
)
3326
)
3427
end
@@ -40,8 +33,7 @@
4033

4134
expect_metric(
4235
tags: a_hash_including(
43-
location: "MetricsController#index",
44-
hook: "render_template"
36+
hook: "render_template"
4537
),
4638
timestamp: 1_514_797_200
4739
)
@@ -54,8 +46,7 @@
5446

5547
expect_no_metric(
5648
tags: a_hash_including(
57-
location: "MetricsController#index",
58-
hook: "render_template"
49+
hook: "render_template"
5950
)
6051
)
6152
end

spec/requests/active_job_enqueue_metrics_spec.rb

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,13 @@
1818

1919
expect_metric(
2020
tags: a_hash_including(
21-
location: "MetricsController#index",
22-
hook: "enqueue",
23-
job: "MetricJob",
24-
queue: "default",
25-
state: "queued",
26-
additional_tag: :value,
27-
server: Socket.gethostname,
28-
app_name: :app_name,
29-
tags_middleware: :tags_middleware
21+
hook: "enqueue",
22+
job: "MetricJob",
23+
queue: "default",
24+
state: "queued"
3025
),
3126
values: a_hash_including(
32-
additional_value: :value,
33-
request_id: :request_id,
34-
value: 1
27+
value: 1
3528
)
3629
)
3730
end
@@ -43,7 +36,6 @@
4336

4437
expect_metric(
4538
tags: a_hash_including(
46-
location: "MetricsController#index",
4739
hook: "enqueue"
4840
),
4941
timestamp: 1_514_797_200
@@ -57,7 +49,6 @@
5749

5850
expect_no_metric(
5951
tags: a_hash_including(
60-
location: "MetricsController#index",
6152
hook: "enqueue"
6253
)
6354
)

spec/requests/active_job_perform_metrics_spec.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@
2020

2121
expect_metric(
2222
tags: a_hash_including(
23-
location: "MetricsController#index",
24-
hook: "perform",
25-
state: "succeeded",
26-
job: "MetricJob",
27-
queue: "default",
28-
server: Socket.gethostname,
29-
app_name: :app_name,
30-
tags_middleware: :tags_middleware
23+
hook: "perform",
24+
state: "succeeded",
25+
job: "MetricJob",
26+
queue: "default"
3127
),
3228
values: a_hash_including(
3329
value: be_between(0, 30)
@@ -44,7 +40,6 @@
4440

4541
expect_metric(
4642
tags: a_hash_including(
47-
location: "MetricsController#index",
4843
hook: "perform"
4944
),
5045
timestamp: 1_514_797_200
@@ -60,7 +55,6 @@
6055

6156
expect_no_metric(
6257
tags: a_hash_including(
63-
location: "MetricsController#index",
6458
hook: "perform"
6559
)
6660
)

spec/requests/active_record_instantiation_metrics_spec.rb

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,12 @@
1919

2020
expect_metric(
2121
tags: a_hash_including(
22-
location: "MetricsController#show",
23-
hook: "instantiation",
24-
class_name: "Metric",
25-
additional_tag: :value,
26-
server: Socket.gethostname,
27-
app_name: :app_name,
28-
tags_middleware: :tags_middleware
22+
hook: "instantiation",
23+
class_name: "Metric"
2924
),
3025
values: a_hash_including(
31-
additional_value: :value,
32-
request_id: :request_id,
33-
value: be_between(1, 500),
34-
record_count: 1
26+
value: be_between(1, 500),
27+
record_count: 1
3528
)
3629
)
3730
end
@@ -43,8 +36,7 @@
4336

4437
expect_metric(
4538
tags: a_hash_including(
46-
location: "MetricsController#show",
47-
hook: "instantiation"
39+
hook: "instantiation"
4840
),
4941
timestamp: 1_514_797_200
5042
)
@@ -57,8 +49,7 @@
5749

5850
expect_no_metric(
5951
tags: a_hash_including(
60-
location: "MetricsController#show",
61-
hook: "instantiation"
52+
hook: "instantiation"
6253
)
6354
)
6455
end

0 commit comments

Comments
 (0)