From 02875536f8d355d3c12c8f02d34ec26248a97522 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Tue, 13 Apr 2021 13:19:14 +0200 Subject: [PATCH] Explicitely spec out default/custom tags Do not expect them all the time, it's has become a bit too implicit. --- .../action_controller_metrics_spec.rb | 29 ++++++++++---- .../action_mailer_deliver_metrics_spec.rb | 13 ++---- .../action_view_collection_metrics_spec.rb | 21 +++------- .../action_view_partial_metrics_spec.rb | 19 +++------ .../action_view_template_metrics_spec.rb | 19 +++------ .../active_job_enqueue_metrics_spec.rb | 19 +++------ .../active_job_perform_metrics_spec.rb | 14 ++----- ...ctive_record_instantiation_metrics_spec.rb | 21 +++------- .../active_record_sql_metrics_spec.rb | 40 ++++++------------- spec/requests/block_inistrumentation_spec.rb | 23 ++++------- 10 files changed, 74 insertions(+), 144 deletions(-) diff --git a/spec/requests/action_controller_metrics_spec.rb b/spec/requests/action_controller_metrics_spec.rb index 288c9ea..15ac743 100644 --- a/spec/requests/action_controller_metrics_spec.rb +++ b/spec/requests/action_controller_metrics_spec.rb @@ -18,11 +18,27 @@ 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, @@ -30,10 +46,7 @@ ), 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 diff --git a/spec/requests/action_mailer_deliver_metrics_spec.rb b/spec/requests/action_mailer_deliver_metrics_spec.rb index 9ff84f3..94e734d 100644 --- a/spec/requests/action_mailer_deliver_metrics_spec.rb +++ b/spec/requests/action_mailer_deliver_metrics_spec.rb @@ -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 diff --git a/spec/requests/action_view_collection_metrics_spec.rb b/spec/requests/action_view_collection_metrics_spec.rb index c176bc1..b898a21 100644 --- a/spec/requests/action_view_collection_metrics_spec.rb +++ b/spec/requests/action_view_collection_metrics_spec.rb @@ -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 @@ -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 ) @@ -58,8 +50,7 @@ expect_no_metric( name: "rails", tags: a_hash_including( - location: "MetricsController#index", - hook: "render_collection" + hook: "render_collection" ) ) end diff --git a/spec/requests/action_view_partial_metrics_spec.rb b/spec/requests/action_view_partial_metrics_spec.rb index 67a3d19..f74e1be 100644 --- a/spec/requests/action_view_partial_metrics_spec.rb +++ b/spec/requests/action_view_partial_metrics_spec.rb @@ -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 @@ -40,8 +33,7 @@ expect_metric( tags: a_hash_including( - location: "MetricsController#index", - hook: "render_partial" + hook: "render_partial" ), timestamp: 1_514_797_200 ) @@ -54,8 +46,7 @@ expect_no_metric( tags: a_hash_including( - location: "MetricsController#index", - hook: "render_partial" + hook: "render_partial" ) ) end diff --git a/spec/requests/action_view_template_metrics_spec.rb b/spec/requests/action_view_template_metrics_spec.rb index 31a48d8..23c6b91 100644 --- a/spec/requests/action_view_template_metrics_spec.rb +++ b/spec/requests/action_view_template_metrics_spec.rb @@ -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 @@ -40,8 +33,7 @@ expect_metric( tags: a_hash_including( - location: "MetricsController#index", - hook: "render_template" + hook: "render_template" ), timestamp: 1_514_797_200 ) @@ -54,8 +46,7 @@ expect_no_metric( tags: a_hash_including( - location: "MetricsController#index", - hook: "render_template" + hook: "render_template" ) ) end diff --git a/spec/requests/active_job_enqueue_metrics_spec.rb b/spec/requests/active_job_enqueue_metrics_spec.rb index db959c0..580096c 100644 --- a/spec/requests/active_job_enqueue_metrics_spec.rb +++ b/spec/requests/active_job_enqueue_metrics_spec.rb @@ -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 @@ -43,7 +36,6 @@ expect_metric( tags: a_hash_including( - location: "MetricsController#index", hook: "enqueue" ), timestamp: 1_514_797_200 @@ -57,7 +49,6 @@ expect_no_metric( tags: a_hash_including( - location: "MetricsController#index", hook: "enqueue" ) ) diff --git a/spec/requests/active_job_perform_metrics_spec.rb b/spec/requests/active_job_perform_metrics_spec.rb index 93940b0..0e6ac8c 100644 --- a/spec/requests/active_job_perform_metrics_spec.rb +++ b/spec/requests/active_job_perform_metrics_spec.rb @@ -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) @@ -44,7 +40,6 @@ expect_metric( tags: a_hash_including( - location: "MetricsController#index", hook: "perform" ), timestamp: 1_514_797_200 @@ -60,7 +55,6 @@ expect_no_metric( tags: a_hash_including( - location: "MetricsController#index", hook: "perform" ) ) diff --git a/spec/requests/active_record_instantiation_metrics_spec.rb b/spec/requests/active_record_instantiation_metrics_spec.rb index 1a4b731..ec3e905 100644 --- a/spec/requests/active_record_instantiation_metrics_spec.rb +++ b/spec/requests/active_record_instantiation_metrics_spec.rb @@ -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 @@ -43,8 +36,7 @@ expect_metric( tags: a_hash_including( - location: "MetricsController#show", - hook: "instantiation" + hook: "instantiation" ), timestamp: 1_514_797_200 ) @@ -57,8 +49,7 @@ expect_no_metric( tags: a_hash_including( - location: "MetricsController#show", - hook: "instantiation" + hook: "instantiation" ) ) end diff --git a/spec/requests/active_record_sql_metrics_spec.rb b/spec/requests/active_record_sql_metrics_spec.rb index f768d9c..2404134 100644 --- a/spec/requests/active_record_sql_metrics_spec.rb +++ b/spec/requests/active_record_sql_metrics_spec.rb @@ -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 @@ -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 @@ -71,7 +57,6 @@ expect_metric( tags: a_hash_including( - location: "MetricsController#index", hook: "sql" ), timestamp: 1_514_797_200 @@ -85,7 +70,6 @@ expect_no_metric( tags: a_hash_including( - location: "MetricsController#index", hook: "sql" ) ) diff --git a/spec/requests/block_inistrumentation_spec.rb b/spec/requests/block_inistrumentation_spec.rb index 558d26b..15fa722 100644 --- a/spec/requests/block_inistrumentation_spec.rb +++ b/spec/requests/block_inistrumentation_spec.rb @@ -17,20 +17,13 @@ expect_metric( tags: a_hash_including( - location: "MetricsController#index", - hook: "block_instrumentation", - additional_tag: :value, - server: Socket.gethostname, - app_name: :app_name, - tags_middleware: :tags_middleware, - block_tag: :block_tag, - name: "name" + hook: "block_instrumentation", + block_tag: :block_tag, + name: "name" ), values: a_hash_including( - additional_value: :value, - request_id: :request_id, - block_value: :block_value, - value: be_between(1, 500) + block_value: :block_value, + value: be_between(1, 500) ) ) end @@ -42,8 +35,7 @@ expect_metric( tags: a_hash_including( - location: "MetricsController#index", - hook: "block_instrumentation" + hook: "block_instrumentation" ), timestamp: 1_514_797_200 ) @@ -56,8 +48,7 @@ expect_no_metric( tags: a_hash_including( - location: "MetricsController#index", - hook: "block_instrumentation" + hook: "block_instrumentation" ) ) end