From 4fae4946e4b6eea41973b2a6979237d17611ec76 Mon Sep 17 00:00:00 2001 From: Eduardo Navarro Date: Mon, 27 May 2024 12:23:32 +0200 Subject: [PATCH] Add `cached` key for active_record payloads --- lib/influxdb/rails/middleware/sql_subscriber.rb | 1 + spec/requests/active_record_sql_metrics_spec.rb | 9 ++++++--- spec/requests/context_spec.rb | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/influxdb/rails/middleware/sql_subscriber.rb b/lib/influxdb/rails/middleware/sql_subscriber.rb index 982ed21..9f0f869 100644 --- a/lib/influxdb/rails/middleware/sql_subscriber.rb +++ b/lib/influxdb/rails/middleware/sql_subscriber.rb @@ -21,6 +21,7 @@ def tags class_name: query.class_name, name: query.name, location: :raw, + cached: query.try(:cached) == "true", } end diff --git a/spec/requests/active_record_sql_metrics_spec.rb b/spec/requests/active_record_sql_metrics_spec.rb index f9c2510..6a8eb2e 100644 --- a/spec/requests/active_record_sql_metrics_spec.rb +++ b/spec/requests/active_record_sql_metrics_spec.rb @@ -21,7 +21,8 @@ hook: "sql", name: "Metric Create", class_name: "Metric", - operation: "INSERT" + operation: "INSERT", + cached: false ), fields: a_hash_including( additional_field: :value, @@ -40,7 +41,8 @@ expect_metric( tags: a_hash_including( location: "MetricsController#index", - hook: "sql" + hook: "sql", + cached: false ), time: Time.at(1_514_797_200) ) @@ -53,7 +55,8 @@ expect_no_metric( tags: a_hash_including( - hook: "sql" + hook: "sql", + cached: false ) ) end diff --git a/spec/requests/context_spec.rb b/spec/requests/context_spec.rb index 04917c5..55a28ed 100644 --- a/spec/requests/context_spec.rb +++ b/spec/requests/context_spec.rb @@ -7,7 +7,8 @@ expect_metric( tags: a_hash_including( location: "MetricsController#index", - hook: "sql" + hook: "sql", + cached: false ) )