Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions mysql/datadog_checks/mysql/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
from .metadata import MySQLMetadata
from .queries import (
QUERY_DEADLOCKS,
QUERY_ERRORS_RAISED,
QUERY_USER_CONNECTIONS,
SQL_95TH_PERCENTILE,
SQL_AVG_QUERY_RUN_TIME,
Expand Down Expand Up @@ -427,6 +428,8 @@ def _get_runtime_queries(self, db):

if self.global_variables.performance_schema_enabled:
queries.extend([QUERY_USER_CONNECTIONS])
if self.version.version_compatible((8, 0, 0)):
queries.extend([QUERY_ERRORS_RAISED])
if self._index_metrics.include_index_metrics:
queries.extend(self._index_metrics.queries)
self._runtime_queries_cached = self._new_query_executor(queries)
Expand Down
19 changes: 19 additions & 0 deletions mysql/datadog_checks/mysql/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,25 @@
],
}

QUERY_ERRORS_RAISED = {
'name': 'performance_schema.events_errors_summary_by_user_by_error',
'query': """
SELECT
SUM_ERROR_RAISED as errors_raised,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUM_ERROR_RAISED is a monotonic counter. We should report the delta between executions, not the raw value.

ERROR_NUMBER as error_number,
ERROR_NAME as error_name,
USER as user
FROM performance_schema.events_errors_summary_by_user_by_error
WHERE SUM_ERROR_RAISED > 0
""".strip(),
'columns': [
{'name': 'mysql.performance.errors_raised_by_user', 'type': 'gauge'},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try using monotonic_count, example:

{"name": "index.user_seeks", "type": "monotonic_count"},
{"name": "index.user_scans", "type": "monotonic_count"},
{"name": "index.user_lookups", "type": "monotonic_count"},
{"name": "index.user_updates", "type": "monotonic_count"},

{'name': 'error_number', 'type': 'tag'},
{'name': 'error_name', 'type': 'tag'},
{'name': 'user', 'type': 'tag'},
],
}


def show_replica_status_query(version, is_mariadb, channel=''):
if version.version_compatible((10, 5, 1)) or not is_mariadb and version.version_compatible((8, 0, 22)):
Expand Down
1 change: 1 addition & 0 deletions mysql/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ mysql.performance.created_tmp_disk_tables,gauge,,table,second,The rate of intern
mysql.performance.created_tmp_files,gauge,,file,second,The rate of temporary files created by second.,-1,mysql,tmp files created,
mysql.performance.created_tmp_tables,gauge,,table,second,The rate of internal temporary tables created by second by the server while executing statements.,0,mysql,tmp tables created,
mysql.performance.digest_95th_percentile.avg_us,gauge,,microsecond,,Query response time 95th percentile per schema.,0,mysql,mysql response time 95th,
mysql.performance.errors_raised_by_user,gauge,,error,,"The number of errors raised per user, error code and name. Tags: `user`, `error_number`, `error_name`",0,mysql,errors raised,
mysql.performance.handler_commit,gauge,,operation,second,The number of internal COMMIT statements.,0,mysql,mysql performance handler_commit,
mysql.performance.handler_delete,gauge,,operation,second,The number of internal DELETE statements.,0,mysql,mysql performance handler_delete,
mysql.performance.handler_prepare,gauge,,operation,second,The number of internal PREPARE statements.,0,mysql,mysql performance handler_prepare,
Expand Down
2 changes: 2 additions & 0 deletions mysql/tests/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def _assert_complex_config(
),
at_least=0, # TODO this metric includes processlist_host tag which contains a random IP address
)
elif mname == 'mysql.performance.errors_raised' and MYSQL_VERSION_PARSED < parse_version('8.0'):
continue
elif mname == 'mysql.replication.group.member_status':
aggregator.assert_metric(mname, tags=metric_tags + group_replication_tags, count=expected_counts)
elif mname in variables.GROUP_REPLICATION_VARS + variables.GROUP_REPLICATION_VARS_8_0_2:
Expand Down
2 changes: 1 addition & 1 deletion mysql/tests/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@

PERFORMANCE_VARS = ['mysql.performance.query_run_time.avg', 'mysql.performance.digest_95th_percentile.avg_us']

COMMON_PERFORMANCE_VARS = ['mysql.performance.user_connections']
COMMON_PERFORMANCE_VARS = ['mysql.performance.user_connections', 'mysql.performance.errors_raised']

# This exists to comply with some of the testing patterns with the old API.
QUERY_EXECUTOR_METRIC_SETS = {
Expand Down
Loading