From bb67223d7803ca6b74a7c01c7d726ed430e383bc Mon Sep 17 00:00:00 2001 From: Hannah Ramadan <76922290+hannahramadan@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:52:31 -0800 Subject: [PATCH] Map Trilogy -> MySQL (#2966) * Map Trilogy to MySQL Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --------- Co-authored-by: Kayla Reopelle <87386821+kaylareopelle@users.noreply.github.com> --- CHANGELOG.md | 6 ++++++ lib/new_relic/agent/database.rb | 3 +++ .../agent/instrumentation/active_record_helper.rb | 3 +++ test/new_relic/agent/database_test.rb | 7 +++++++ .../agent/instrumentation/active_record_helper_test.rb | 6 ++++++ 5 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c53eca0518..d549502914 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # New Relic Ruby Agent Release Notes +## dev + +- **Feature: Add support for Trilogy database adapter** + + The agent now fully supports Trilogy, a client library for MySQL-compatible database servers, and correctly lists MySQL as the corresponding database in the UI. [PR#2966](https://github.com/newrelic/newrelic-ruby-agent/pull/2966). + ## v9.16.0 Version 9.16.0 introduces the following features and bug fixes: diff --git a/lib/new_relic/agent/database.rb b/lib/new_relic/agent/database.rb index e7d9db9f40..174e364f7c 100644 --- a/lib/new_relic/agent/database.rb +++ b/lib/new_relic/agent/database.rb @@ -277,6 +277,7 @@ def append_sql(new_sql) MYSQL_PREFIX = 'mysql'.freeze MYSQL2_PREFIX = 'mysql2'.freeze SQLITE_PREFIX = 'sqlite'.freeze + TRILOGY_PREFIX = 'trilogy'.freeze def symbolized_adapter(adapter) if adapter.start_with?(POSTGRES_PREFIX) || adapter == POSTGIS_PREFIX @@ -289,6 +290,8 @@ def symbolized_adapter(adapter) :mysql2 elsif adapter.start_with?(SQLITE_PREFIX) :sqlite + elsif adapter == TRILOGY_PREFIX + :trilogy else adapter.to_sym end diff --git a/lib/new_relic/agent/instrumentation/active_record_helper.rb b/lib/new_relic/agent/instrumentation/active_record_helper.rb index 814668410c..8fa4939b56 100644 --- a/lib/new_relic/agent/instrumentation/active_record_helper.rb +++ b/lib/new_relic/agent/instrumentation/active_record_helper.rb @@ -170,6 +170,9 @@ def map_operation(raw_operation) 'sqlite3' => 'SQLite', + # https://rubygems.org/gems/trilogy + 'trilogy' => 'MySQL', + # https://rubygems.org/gems/activerecord-jdbcpostgresql-adapter 'jdbcmysql' => 'MySQL', diff --git a/test/new_relic/agent/database_test.rb b/test/new_relic/agent/database_test.rb index afac64f8a8..26179b5872 100644 --- a/test/new_relic/agent/database_test.rb +++ b/test/new_relic/agent/database_test.rb @@ -52,6 +52,13 @@ def test_adapter_from_config_string_postgis assert_equal(:postgres, statement.adapter) end + def test_adapter_from_config_trilogy + config = {:adapter => 'trilogy'} + statement = NewRelic::Agent::Database::Statement.new('some query', config) + + assert_equal(:trilogy, statement.adapter) + end + # An ActiveRecord::Result is what you get back when executing a # query using exec_query on the connection, which is what we're # doing now for explain plans in AR4 instrumentation diff --git a/test/new_relic/agent/instrumentation/active_record_helper_test.rb b/test/new_relic/agent/instrumentation/active_record_helper_test.rb index a53a559766..f524f73aa3 100644 --- a/test/new_relic/agent/instrumentation/active_record_helper_test.rb +++ b/test/new_relic/agent/instrumentation/active_record_helper_test.rb @@ -55,6 +55,12 @@ def test_product_operation_collection_for_with_product_name_from_adapter assert_equal 'Model', collection end + def test_product_operation_collection_for_with_product_name_from_adapter_trilogy + product, _operation, _collection = ActiveRecordHelper.product_operation_collection_for(nil, '', 'trilogy') + + assert_equal 'MySQL', product + end + def test_product_operation_collection_for_from_sql product, operation, collection = ActiveRecordHelper.product_operation_collection_for('invalid', 'SELECT * FROM boo', nil)