forked from DataDog/integrations-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sqlserver.py
More file actions
149 lines (121 loc) · 4.05 KB
/
Copy pathtest_sqlserver.py
File metadata and controls
149 lines (121 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# (C) Datadog, Inc. 2010-2016
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)
# stdlib
import copy
from nose.plugins.attrib import attr
# project
from tests.checks.common import AgentCheckTest
"""
Runs against AppVeyor's SQLServer setups with their default configurations
"""
CONFIG = {
'init_config': {
'custom_metrics': [
{
'name': 'sqlserver.clr.execution',
'type': 'gauge',
'counter_name': 'CLR Execution',
},
{
'name': 'sqlserver.exec.in_progress',
'type': 'gauge',
'counter_name': 'OLEDB calls',
'instance_name': 'Cumulative execution time (ms) per second',
},
{
'name': 'sqlserver.db.commit_table_entries',
'type': 'gauge',
'counter_name': 'Log Flushes/sec',
'instance_name': 'ALL',
'tag_by': 'db',
},
],
}
}
SQL2008_INSTANCE = {
'host': '(local)\SQL2008R2SP2',
'username': 'sa',
'password': 'Password12!',
}
SQL2012_INSTANCE = {
'host': '(local)\SQL2012SP1',
'username': 'sa',
'password': 'Password12!',
}
SQL2014_INSTANCE = {
'host': '(local)\SQL2014',
'username': 'sa',
'password': 'Password12!',
}
LINUX_INSTANCE = {
'host': 'localhost',
'username': 'sa',
'password': 'dd-ci',
}
EXPECTED_METRICS = [
'sqlserver.buffer.cache_hit_ratio',
'sqlserver.buffer.page_life_expectancy',
'sqlserver.stats.batch_requests',
'sqlserver.stats.sql_compilations',
'sqlserver.stats.sql_recompilations',
'sqlserver.stats.connections',
'sqlserver.stats.lock_waits',
'sqlserver.access.page_splits',
'sqlserver.stats.procs_blocked',
'sqlserver.buffer.checkpoint_pages',
]
@attr('unix')
@attr('fixme')
@attr(requires='sqlserver')
class TestSqlserverLinux(AgentCheckTest):
"""Basic Test for sqlserver integration."""
CHECK_NAME = 'sqlserver'
def test_check(self):
config = copy.deepcopy(CONFIG)
config['instances'] = [LINUX_INSTANCE]
self.run_check_twice(config, force_reload=True)
# FIXME: assert something, someday
@attr('windows')
@attr(requires='sqlserver')
class TestSqlserver(AgentCheckTest):
"""Basic Test for sqlserver integration."""
CHECK_NAME = 'sqlserver'
def _test_check(self, config):
self.run_check_twice(config, force_reload=True)
# Check our custom metrics
self.assertMetric('sqlserver.clr.execution')
self.assertMetric('sqlserver.exec.in_progress')
# Make sure the ALL custom metric is tagged by db
self.assertMetricTagPrefix('sqlserver.db.commit_table_entries', tag_prefix='db')
for metric in EXPECTED_METRICS:
self.assertMetric(metric, count=1)
self.assertServiceCheckOK('sqlserver.can_connect',
tags=['host:{}'.format(config['instances'][0]['host']), 'db:master'])
self.coverage_report()
@attr('fixme')
def test_check_2008(self):
config = copy.deepcopy(CONFIG)
config['instances'] = [SQL2008_INSTANCE]
self._test_check(config)
def test_check_2012(self):
config = copy.deepcopy(CONFIG)
config['instances'] = [SQL2012_INSTANCE]
self._test_check(config)
@attr('fixme')
def test_check_2014(self):
config = copy.deepcopy(CONFIG)
config['instances'] = [SQL2014_INSTANCE]
self._test_check(config)
def test_check_no_connection(self):
config = copy.deepcopy(CONFIG)
config['instances'] = [{
'host': '(local)\SQL2012SP1',
'username': 'sa',
'password': 'InvalidPassword',
'timeout': 1,
}]
with self.assertRaisesRegexp(Exception, 'Unable to connect to SQL Server'):
self.run_check(config, force_reload=True)
self.assertServiceCheckCritical('sqlserver.can_connect',
tags=['host:(local)\SQL2012SP1', 'db:master'])