diff --git a/proxysql/assets/configuration/spec.yaml b/proxysql/assets/configuration/spec.yaml index acc6eda7d9ab0..89fea5775a561 100644 --- a/proxysql/assets/configuration/spec.yaml +++ b/proxysql/assets/configuration/spec.yaml @@ -34,6 +34,15 @@ files: value: type: string example: + - name: database_name + required: false + description: | + Sets the name of the database to query for stats. For proxysql admin users, this is "stats" (default). + For stats users (defined in Proxysql's admin-stats_credentials), this is "main". + See https://github.com/sysown/proxysql/issues/1661 for more details. + value: + type: string + example: stats - name: tls_verify value: example: false diff --git a/proxysql/datadog_checks/proxysql/data/conf.yaml.example b/proxysql/datadog_checks/proxysql/data/conf.yaml.example index cc34c8a34312f..3835e9f2a5f5b 100644 --- a/proxysql/datadog_checks/proxysql/data/conf.yaml.example +++ b/proxysql/datadog_checks/proxysql/data/conf.yaml.example @@ -33,6 +33,13 @@ instances: # password: + ## @param database_name - string - optional - default: stats + ## Sets the name of the database to query for stats. For proxysql admin users, this is "stats" (default). + ## For stats users (defined in Proxysql's admin-stats_credentials), this is "main". + ## See https://github.com/sysown/proxysql/issues/1661 for more details. + # + # database_name: stats + ## @param tls_verify - boolean - optional - default: false ## Instructs the check to use SSL when connecting to ProxySQL # diff --git a/proxysql/datadog_checks/proxysql/proxysql.py b/proxysql/datadog_checks/proxysql/proxysql.py index 2d98758714b8a..803b5ec1852c2 100644 --- a/proxysql/datadog_checks/proxysql/proxysql.py +++ b/proxysql/datadog_checks/proxysql/proxysql.py @@ -44,6 +44,7 @@ def __init__(self, name, init_config, instances): if not all((self.host, self.port, self.user, self.password)): raise ConfigurationError("ProxySQL host, port, username and password are needed") + self.database_name = self.instance.get("database_name", "stats") self.tls_verify = self.instance.get("tls_verify", False) self.validate_hostname = self.instance.get("validate_hostname", True) self.tls_ca_cert = self.instance.get("tls_ca_cert") @@ -102,6 +103,7 @@ def connect(self): user=self.user, port=self.port, passwd=self.password, + database=self.database_name, connect_timeout=self.connect_timeout, read_timeout=self.read_timeout, ssl=ssl_context, diff --git a/proxysql/datadog_checks/proxysql/queries.py b/proxysql/datadog_checks/proxysql/queries.py index 4bcce29b84075..6a36ba4aaf6b7 100644 --- a/proxysql/datadog_checks/proxysql/queries.py +++ b/proxysql/datadog_checks/proxysql/queries.py @@ -6,7 +6,7 @@ STATS_MYSQL_GLOBAL = Query( { 'name': 'stats_mysql_global', - 'query': 'SELECT * FROM stats.stats_mysql_global', + 'query': 'SELECT * FROM stats_mysql_global', 'columns': [ { 'name': 'Variable_Name', @@ -112,7 +112,7 @@ 'name': 'stats_mysql_commands_counters', 'query': 'SELECT Command, Total_time_us, Total_cnt, cnt_100us, cnt_500us, cnt_1ms, cnt_5ms, cnt_10ms, ' 'cnt_50ms, cnt_100ms, cnt_500ms, cnt_1s, cnt_5s, cnt_10s, cnt_INFs FROM ' - 'stats.stats_mysql_commands_counters', + 'stats_mysql_commands_counters', 'columns': [ # the type of SQL command that has been executed. Examples: FLUSH, INSERT, KILL, SELECT FOR UPDATE, etc. {'name': 'sql_command', 'type': 'tag'}, @@ -145,7 +145,7 @@ 'name': 'stats_mysql_connection_pool', # Need explicit selections as some columns are unusable. 'query': 'SELECT hostgroup, srv_host, srv_port, status, ConnUsed, ConnFree, ConnOK, ConnERR, Queries, ' - 'Bytes_data_sent, Bytes_data_recv, Latency_us FROM stats.stats_mysql_connection_pool', + 'Bytes_data_sent, Bytes_data_recv, Latency_us FROM stats_mysql_connection_pool', 'columns': [ # the hostgroup in which the backend server belongs. Note that a single backend server can belong to more # than one hostgroup @@ -190,7 +190,7 @@ STATS_MYSQL_USERS = Query( { 'name': 'stats_mysql_users', - 'query': 'SELECT username, frontend_connections, frontend_max_connections FROM stats.stats_mysql_users', + 'query': 'SELECT username, frontend_connections, frontend_max_connections FROM stats_mysql_users', 'columns': [ {'name': 'username', 'type': 'tag'}, {'name': 'frontend.user_connections', 'type': 'gauge'}, @@ -202,7 +202,7 @@ STATS_MEMORY_METRICS = Query( { 'name': 'stats_memory_metrics', - 'query': 'SELECT * FROM stats.stats_memory_metrics', + 'query': 'SELECT * FROM stats_memory_metrics', 'columns': [ { 'name': 'Variable_Name', @@ -242,7 +242,7 @@ STATS_MYSQL_QUERY_RULES = Query( { 'name': 'stats_mysql_query_rules', - 'query': 'SELECT rule_id, hits FROM stats.stats_mysql_query_rules', + 'query': 'SELECT rule_id, hits FROM stats_mysql_query_rules', 'columns': [{'name': 'rule_id', 'type': 'tag'}, {'name': 'query_rules.rule_hits', 'type': 'rate'}], } ) diff --git a/proxysql/tests/compose/proxysql.cnf b/proxysql/tests/compose/proxysql.cnf index c5b6e6709d380..8bab4473a8a4a 100644 --- a/proxysql/tests/compose/proxysql.cnf +++ b/proxysql/tests/compose/proxysql.cnf @@ -3,6 +3,7 @@ datadir="/var/lib/proxysql" admin_variables= { admin_credentials="admin:admin;proxy:proxy" + stats_credentials="stats:stats;proxystats:proxystats" mysql_ifaces="0.0.0.0:6032" } diff --git a/proxysql/tests/conftest.py b/proxysql/tests/conftest.py index 9e7c51713f1b0..d3a64389d1a12 100644 --- a/proxysql/tests/conftest.py +++ b/proxysql/tests/conftest.py @@ -18,7 +18,10 @@ MYSQL_PASS = 'pass' PROXY_ADMIN_USER = 'proxy' PROXY_ADMIN_PASS = 'proxy' +PROXY_STATS_USER = 'proxystats' +PROXY_STATS_PASS = 'proxystats' MYSQL_DATABASE = 'test' +PROXY_MAIN_DATABASE = 'main' PROXYSQL_VERSION = os.environ['PROXYSQL_VERSION'] BASIC_INSTANCE = { @@ -45,6 +48,22 @@ ], } +INSTANCE_ALL_METRICS_STATS = { + 'host': DOCKER_HOST, + 'port': PROXY_ADMIN_PORT, + 'username': PROXY_STATS_USER, + 'password': PROXY_STATS_PASS, + 'database_name': PROXY_MAIN_DATABASE, + 'tags': ["application:test"], + 'additional_metrics': [ + 'command_counters_metrics', + 'connection_pool_metrics', + 'users_metrics', + 'memory_metrics', + 'query_rules_metrics', + ], +} + @pytest.fixture def instance_basic(): @@ -56,6 +75,11 @@ def instance_all_metrics(instance_basic): return deepcopy(INSTANCE_ALL_METRICS) +@pytest.fixture() +def instance_stats_user(instance_basic): + return deepcopy(INSTANCE_ALL_METRICS_STATS) + + @pytest.fixture(scope='session') def dd_environment(): compose_file = os.path.join(get_here(), 'compose', 'docker-compose.yml') diff --git a/proxysql/tests/test_proxysql.py b/proxysql/tests/test_proxysql.py index 81edc674057e3..b1f62cda5c6f0 100644 --- a/proxysql/tests/test_proxysql.py +++ b/proxysql/tests/test_proxysql.py @@ -166,6 +166,14 @@ def test_all_metrics(aggregator, instance_all_metrics, dd_run_check): _assert_all_metrics(aggregator) +@pytest.mark.integration +@pytest.mark.usefixtures('dd_environment') +def test_all_metrics_stats_user(aggregator, instance_stats_user, dd_run_check): + check = get_check(instance_stats_user) + dd_run_check(check) + _assert_all_metrics(aggregator) + + @pytest.mark.e2e def test_e2e(dd_agent_check): aggregator = dd_agent_check(rate=True)