Skip to content

Commit

Permalink
Explicitely spec out default/custom tags
Browse files Browse the repository at this point in the history
Do not expect them all the time, it's has become a bit too implicit.
  • Loading branch information
hennevogel committed Apr 13, 2021
1 parent 38d59b5 commit 0287553
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 144 deletions.
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
40 changes: 12 additions & 28 deletions spec/requests/active_record_sql_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,14 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "sql",
name: "Metric Create",
class_name: "Metric",
operation: "INSERT",
additional_tag: :value,
server: Socket.gethostname,
app_name: :app_name,
tags_middleware: :tags_middleware
hook: "sql",
name: "Metric Create",
class_name: "Metric",
operation: "INSERT"
),
values: a_hash_including(
additional_value: :value,
request_id: :request_id,
value: be_between(1, 500),
sql: "INSERT INTO \"metrics\" (\"name\", \"created_at\", \"updated_at\") VALUES (xxx)"
value: be_between(1, 500),
sql: "INSERT INTO \"metrics\" (\"name\", \"created_at\", \"updated_at\") VALUES (xxx)"
)
)
end
Expand All @@ -45,21 +38,14 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "sql",
name: "SQL",
class_name: "SQL",
operation: "INSERT",
additional_tag: :value,
server: Socket.gethostname,
app_name: :app_name,
tags_middleware: :tags_middleware
hook: "sql",
name: "SQL",
class_name: "SQL",
operation: "INSERT"
),
values: a_hash_including(
additional_value: :value,
request_id: :request_id,
value: be_between(1, 500),
sql: "INSERT INTO \"metrics\" (\"name\", \"created_at\", \"updated_at\") VALUES (xxx)"
value: be_between(1, 500),
sql: "INSERT INTO \"metrics\" (\"name\", \"created_at\", \"updated_at\") VALUES (xxx)"
)
)
end
Expand All @@ -71,7 +57,6 @@

expect_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "sql"
),
timestamp: 1_514_797_200
Expand All @@ -85,7 +70,6 @@

expect_no_metric(
tags: a_hash_including(
location: "MetricsController#index",
hook: "sql"
)
)
Expand Down
Loading

0 comments on commit 0287553

Please sign in to comment.