Skip to content

Commit

Permalink
[sqlserver] agent jobs metrics are DBM only (#19033)
Browse files Browse the repository at this point in the history
* agent jobs metrics are DBM only

* add changelog
  • Loading branch information
lu-zhengda authored Nov 12, 2024
1 parent 4cdc836 commit 83085c1
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions sqlserver/changelog.d/19033.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update SQLServer agent jobs metrics to be DBM only.
5 changes: 4 additions & 1 deletion sqlserver/datadog_checks/sqlserver/database_metrics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@

from datadog_checks.base.log import get_check_logger
from datadog_checks.base.utils.db.core import QueryExecutor
from datadog_checks.sqlserver.config import SQLServerConfig
from datadog_checks.sqlserver.const import STATIC_INFO_ENGINE_EDITION, STATIC_INFO_MAJOR_VERSION, STATIC_INFO_RDS


class SqlserverDatabaseMetricsBase:
def __init__(
self,
config,
instance_config,
new_query_executor,
server_static_info,
execute_query_handler,
track_operation_time=False,
databases=None,
):
self.instance_config: dict = instance_config
self.config: SQLServerConfig = config
self.instance_config: dict = instance_config # TODO: Remove instance_config and use self.config
self.server_static_info: dict = server_static_info
self.new_query_executor: Callable[
[List[dict], Callable, Optional[List[str]], Optional[bool]], QueryExecutor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@
class SqlserverAgentMetrics(SqlserverDatabaseMetricsBase):
@property
def include_agent_metrics(self) -> bool:
if not self.config.dbm_enabled:
return False
agent_jobs_config = self.instance_config.get('agent_jobs', {})
if agent_jobs_config:
return is_affirmative(agent_jobs_config.get('enabled', False))
Expand Down
1 change: 1 addition & 0 deletions sqlserver/datadog_checks/sqlserver/sqlserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ def check(self, _):

def _new_database_metric_executor(self, database_metric_class, db_names=None):
return database_metric_class(
config=self._config,
instance_config=self.instance,
new_query_executor=self._new_query_executor,
server_static_info=self.static_info_cache,
Expand Down
4 changes: 2 additions & 2 deletions sqlserver/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ sqlserver.access.index_searches,gauge,,operation,second,"Number of index searche
sqlserver.access.page_splits,gauge,,operation,second,The number of page splits per second. (Perf. Counter: `Access Methods - Page Splits/sec`),-1,sql_server,page splits,,
sqlserver.access.probe_scans,gauge,,operation,second,Number of probe scans per second that are used to find at most one single qualified row in an index or base table directly. (Perf. Counter: `Access Methods - Probe Scans/sec`),-1,sql_server,probe scans,,
sqlserver.access.range_scans,gauge,,operation,second,Number of qualified range scans through indexes per second. (Perf. Counter: `Access Methods - Range Scans/sec`),-1,sql_server,range scans,,
sqlserver.agent.active_jobs.duration,gauge,,second,,Duration of currently running jobs on sqlserver agent,0,sql_server,agent job duration,,
sqlserver.agent.active_jobs.step_info,gauge,,,,Presence of a most recent completed step for active jobs running on the sqlserver agent.,0,sql_server,agent job step info,,
sqlserver.agent.active_jobs.duration,gauge,,second,,Duration of currently running jobs on sqlserver agent (DBM Only),0,sql_server,agent job duration,,
sqlserver.agent.active_jobs.step_info,gauge,,,,Presence of a most recent completed step for active jobs running on the sqlserver agent (DBM Only),0,sql_server,agent job step info,,
sqlserver.agent.completed_jobs.duration,gauge,,second,,Duration of completed jobs on sqlserver agent (DBM Only),0,sql_server,agent job duration,,
sqlserver.agent.completed_jobs.executions,gauge,,execution,,Number of executions of completed jobs on sqlserver agent (DBM Only),0,sql_server,agent job executions,,
sqlserver.ao.ag_sync_health,gauge,,,,"Availability group synchronization health: 0 = Not healthy, 1 = Partially healthy, 2 = Healthy. Tags: `availability_group`, `availability_group_name`, `synchronization_health_desc`",0,sql_server,ag sync health,,
Expand Down
20 changes: 20 additions & 0 deletions sqlserver/tests/test_agent_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,26 @@ def agent_jobs_instance(instance_docker):
return copy(instance_docker)


@pytest.mark.usefixtures('dd_environment')
@pytest.mark.parametrize(
"dbm_enabled,agent_jobs_enabled,expected_agent_jobs_enabled",
[
(True, True, True),
(True, False, False),
(False, True, False),
(False, False, False),
],
)
def test_agent_job_enabled(instance_docker, dbm_enabled, agent_jobs_enabled, expected_agent_jobs_enabled):
instance_docker['dbm'] = dbm_enabled
instance_docker['agent_jobs'] = {'enabled': agent_jobs_enabled}
check = SQLServer(CHECK_NAME, {}, [instance_docker])
check.initialize_connection()
agent_jobs_metrics = [m for m in check.database_metrics if m.__class__.__name__ == 'SqlserverAgentMetrics']
assert agent_jobs_metrics is not None
assert agent_jobs_metrics[0].enabled == expected_agent_jobs_enabled


@pytest.mark.usefixtures('dd_environment')
def test_connection_with_agent_history(instance_docker):
check = SQLServer(CHECK_NAME, {}, [instance_docker])
Expand Down
18 changes: 18 additions & 0 deletions sqlserver/tests/test_database_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

file_stats_metrics = SqlserverFileStatsMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -153,6 +154,7 @@ def test_sqlserver_ao_metrics(
]

ao_metrics = SqlserverAoMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -262,6 +264,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

availability_groups_metrics = SqlserverAvailabilityGroupsMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -351,6 +354,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

database_replication_stats_metrics = SqlserverDatabaseReplicationStatsMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -485,6 +489,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

availability_replicas_metrics = SqlserverAvailabilityReplicasMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -555,6 +560,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

fci_metrics = SqlserverFciMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -602,6 +608,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

primary_log_shipping_metrics = SqlserverPrimaryLogShippingMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -661,6 +668,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

primary_log_shipping_metrics = SqlserverSecondaryLogShippingMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -707,6 +715,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

server_state_metrics = SqlserverServerStateMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -747,6 +756,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

tempdb_file_space_usage_metrics = SqlserverTempDBFileSpaceUsageMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -819,6 +829,7 @@ def test_sqlserver_index_usage_metrics(
execute_query_handler_mocked.side_effect = mocked_results

index_usage_metrics = SqlserverIndexUsageMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -922,6 +933,7 @@ def test_sqlserver_db_fragmentation_metrics(
execute_query_handler_mocked.side_effect = mocked_results

db_fragmentation_metrics = SqlserverDBFragmentationMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -1011,6 +1023,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

os_schedulers_metrics = SqlserverOsSchedulersMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -1075,6 +1088,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

os_tasks_metrics = SqlserverOsTasksMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -1140,6 +1154,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

master_files_metrics = SqlserverMasterFilesMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -1210,6 +1225,7 @@ def test_sqlserver_database_files_metrics(
execute_query_handler_mocked.side_effect = mocked_results

database_files_metrics = SqlserverDatabaseFilesMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -1265,6 +1281,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

database_stats_metrics = SqlserverDatabaseStatsMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down Expand Up @@ -1317,6 +1334,7 @@ def execute_query_handler_mocked(query, db=None):
return mocked_results

database_backup_metrics = SqlserverDatabaseBackupMetrics(
config=sqlserver_check._config,
instance_config=instance_docker_metrics,
new_query_executor=sqlserver_check._new_query_executor,
server_static_info=STATIC_SERVER_INFO,
Expand Down

0 comments on commit 83085c1

Please sign in to comment.