Skip to content

Commit

Permalink
[ci] enable coverage tests 🎉
Browse files Browse the repository at this point in the history
In order to do this:
- `elastic`: add tests for new metrics and sc from
  #1507
- `http_check`: add a missing service check test (`http.can_connect` is also
  collected when testing `http.ssl_cert`)
- `disk`: 100% coverage for the 5.4.2 check (full compatibility with old check)
- `lighttpd`: add two missing metrics for 100% coverage
  • Loading branch information
degemer committed Jul 9, 2015
1 parent b53b370 commit d8759e2
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ matrix:
env:
global:
- CONCURRENCY=2
- COVERAGE=true
- NOSE_FILTER="not windows"
- INTEGRATIONS_DIR=$HOME/embedded
- PIP_CACHE=$HOME/.cache/pip
Expand Down
26 changes: 24 additions & 2 deletions tests/checks/integration/test_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
"elasticsearch.cluster_status": ("gauge", "status", lambda v: {"red": 0, "yellow": 1, "green": 2}.get(v, -1)),
}

CLUSTER_PENDING_TASKS = {
"elasticsearch.pending_tasks_total": ("gauge", "pending_task_total"),
"elasticsearch.pending_tasks_priority_high": ("gauge", "pending_tasks_priority_high"),
"elasticsearch.pending_tasks_priority_urgent": ("gauge", "pending_tasks_priority_urgent")
}


def get_es_version():
version = os.environ.get("FLAVOR_VERSION")
Expand Down Expand Up @@ -177,6 +183,7 @@ def test_check(self):
default_tags = ["url:http://localhost:{0}".format(port)]

expected_metrics = STATS_METRICS
CLUSTER_HEALTH_METRICS.update(CLUSTER_PENDING_TASKS)
expected_metrics.update(CLUSTER_HEALTH_METRICS)

instance_config = self.check.get_instance_config(config['instances'][0])
Expand Down Expand Up @@ -219,11 +226,26 @@ def test_check(self):
tags=bad_sc_tags,
count=1)


# Assert service metadata
self.assertServiceMetadata(['version'], count=3)

self.coverage_report()
# FIXME: 0.90.13 returns randomly a red status instead of yellow,
# so we don't do a coverage test for it
# Remove me when we stop supporting 0.90.x (not supported anymore by ES)
if get_es_version() != [0, 90, 13]:
# Warning because elasticsearch status should be yellow, according to
# http://chrissimpson.co.uk/elasticsearch-yellow-cluster-status-explained.html
self.assertServiceCheckWarning('elasticsearch.cluster_health',
tags=good_sc_tags,
count=2)

# Assert event
self.assertEvent('ElasticSearch: foo just reported as yellow', count=1,
tags=default_tags+tags, msg_title='foo is yellow',
event_type='elasticsearch', alert_type='warning',
source_type_name='elasticsearch')

self.coverage_report()

def test_config_parser(self):
check = load_check(self.CHECK_NAME, {}, {})
Expand Down
40 changes: 15 additions & 25 deletions tests/checks/integration/test_http_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import mock

# project
from checks import AgentCheck
from tests.checks.common import AgentCheckTest

RESULTS_TIMEOUT = 5
Expand Down Expand Up @@ -107,33 +106,24 @@ def test_check(self):
# HTTP connection error
tags = ['url:https://thereisnosuchlink.com', 'instance:conn_error']

self.assertServiceCheck("http.can_connect", status=AgentCheck.CRITICAL,
tags=tags
)
self.assertServiceCheckCritical("http.can_connect", tags=tags)

# Wrong HTTP response status code
tags = ['url:http://httpbin.org/404', 'instance:http_error_status_code']
self.assertServiceCheck("http.can_connect",
status=AgentCheck.CRITICAL,
tags=tags)
self.assertServiceCheckCritical("http.can_connect", tags=tags)

self.assertServiceCheck("http.can_connect", status=AgentCheck.OK,
tags=tags, count=0)
self.assertServiceCheckOK("http.can_connect", tags=tags, count=0)

# HTTP response status code match
tags = ['url:http://httpbin.org/404', 'instance:status_code_match', 'foo:bar']
self.assertServiceCheck("http.can_connect", status=AgentCheck.OK,
tags=tags)
self.assertServiceCheckOK("http.can_connect", tags=tags)

# Content match & mismatching
tags = ['url:https://github.com', 'instance:cnt_mismatch']
self.assertServiceCheck("http.can_connect", status=AgentCheck.CRITICAL,
tags=tags)
self.assertServiceCheck("http.can_connect", status=AgentCheck.OK,
tags=tags, count=0)
self.assertServiceCheckCritical("http.can_connect", tags=tags)
self.assertServiceCheckOK("http.can_connect", tags=tags, count=0)
tags = ['url:https://github.com', 'instance:cnt_match']
self.assertServiceCheck("http.can_connect", status=AgentCheck.OK,
tags=tags)
self.assertServiceCheckOK("http.can_connect", tags=tags)

self.coverage_report()

Expand All @@ -142,16 +132,16 @@ def test_check_ssl(self):
# Overrides self.service_checks attribute when values are available
self.service_checks = self.wait_for_async_service_checks(6)
tags = ['url:https://github.com', 'instance:good_cert']
self.assertServiceCheck("http.ssl_cert", status=AgentCheck.OK,
tags=tags)
self.assertServiceCheckOK("http.can_connect", tags=tags)
self.assertServiceCheckOK("http.ssl_cert", tags=tags)

tags = ['url:https://github.com', 'instance:cert_exp_soon']
self.assertServiceCheck("http.ssl_cert", status=AgentCheck.WARNING,
tags=tags)
self.assertServiceCheckOK("http.can_connect", tags=tags)
self.assertServiceCheckWarning("http.ssl_cert", tags=tags)

tags = ['url:https://thereisnosuchlink.com', 'instance:conn_error']
self.assertServiceCheck("http.ssl_cert", status=AgentCheck.CRITICAL,
tags=tags)
self.assertServiceCheckCritical("http.can_connect", tags=tags)
self.assertServiceCheckCritical("http.ssl_cert", tags=tags)

self.coverage_report()

Expand All @@ -162,6 +152,6 @@ def test_mock_case(self, getpeercert_func):
# Needed for the HTTP headers
self.service_checks = self.wait_for_async_service_checks(2)
tags = ['url:https://github.com', 'instance:expired_cert']
self.assertServiceCheck("http.ssl_cert", status=AgentCheck.CRITICAL,
tags=tags)
self.assertServiceCheckOK("http.can_connect", tags=tags)
self.assertServiceCheckCritical("http.ssl_cert", tags=tags)
self.coverage_report()
6 changes: 4 additions & 2 deletions tests/checks/integration/test_lighttpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
class TestLighttpd(AgentCheckTest):
CHECK_NAME = 'lighttpd'
CHECK_GAUGES = [
'lighttpd.performance.busy_servers',
'lighttpd.net.bytes',
'lighttpd.net.bytes_per_s',
'lighttpd.net.hits',
'lighttpd.net.request_per_s',
'lighttpd.performance.busy_servers',
'lighttpd.performance.idle_server',
'lighttpd.performance.uptime'
'lighttpd.performance.uptime',
]

def __init__(self, *args, **kwargs):
Expand Down
2 changes: 2 additions & 0 deletions tests/checks/mock/test_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def test_no_psutil_debian(self, mock_df_output, mock_statvfs):
for metric, value in self.GAUGES_VALUES.iteritems():
self.assertMetric(metric, value=value, tags=[],
device_name=DEFAULT_DEVICE_NAME)
# backward compatibility with the old check
self.assertMetric(metric, tags=[], device_name='udev')

self.coverage_report()

Expand Down

0 comments on commit d8759e2

Please sign in to comment.