Skip to content

Commit

Permalink
Add e2e test for ambari (#10052)
Browse files Browse the repository at this point in the history
* Add e2e test for ambari

* Use better instance

* Fix style

* Fix ambari

* Fix ambari style

* Clean up test

* Wrap exception

* Change to generic Exception
  • Loading branch information
yzhan289 authored Sep 14, 2021
1 parent 76ba8f4 commit 03906c4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
2 changes: 2 additions & 0 deletions ambari/datadog_checks/ambari/ambari.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ def _make_request(self, url):
)
except Timeout:
self.warning("Connection timeout when connecting to %s", url)
except Exception as e:
self.warning("Couldn't connect to URL: %s with exception: %s.", url, e)

def _submit_gauge(self, name, value, tags, hostname=None):
self.gauge('{}.{}'.format(common.METRIC_PREFIX, name), value, tags, hostname=hostname)
Expand Down
30 changes: 17 additions & 13 deletions ambari/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
# (C) Datadog, Inc. 2019-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from copy import deepcopy

import pytest

INSTANCE = {
'url': 'localhost',
'port': 80,
'username': 'admin',
'password': 'admin',
'services': {
"HDFS": {"NAMENODE": [], "DATANODE": []},
"YARN": {"NODEMANANGER": ["cpu", "disk", "load", "memory", "network", "process"], "YARNCLIENT": []},
"MAPREDUCE2": {"HISTORYSERVER": ["BufferPool", "Memory", "jvm"]},
},
}


@pytest.fixture(scope='session')
@pytest.fixture(scope="session")
def dd_environment():
yield
yield deepcopy(INSTANCE)


@pytest.fixture
def instance():
return {
'url': 'localhost',
'port': 80,
'username': 'admin',
'password': 'admin',
'services': {
"HDFS": {"NAMENODE": [], "DATANODE": []},
"YARN": {"NODEMANANGER": ["cpu", "disk", "load", "memory", "network", "process"], "YARNCLIENT": []},
"MAPREDUCE2": {"HISTORYSERVER": ["BufferPool", "Memory", "jvm"]},
},
}
return deepcopy(INSTANCE)


@pytest.fixture
Expand Down
9 changes: 9 additions & 0 deletions ambari/tests/test_ambari.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# (C) Datadog, Inc. 2019-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import pytest
from mock import MagicMock

from datadog_checks.ambari import AmbariCheck
Expand Down Expand Up @@ -278,3 +279,11 @@ def test_should_collect_service_status(instance):

def _mock_clusters(ambari):
ambari.get_clusters = MagicMock(return_value=['LabCluster'])


# Minimal E2E testing
@pytest.mark.e2e
def test_e2e(dd_agent_check, aggregator, instance):
with pytest.raises(Exception):
dd_agent_check(instance, rate=True)
aggregator.assert_service_check("ambari.can_connect", AgentCheck.CRITICAL)
2 changes: 2 additions & 0 deletions ambari/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ envdir =
py27: {toxworkdir}/py27
py38: {toxworkdir}/py38
dd_check_style = true
description =
py{27,38}: e2e ready
usedevelop = true
platform = linux|darwin|win32
deps =
Expand Down

0 comments on commit 03906c4

Please sign in to comment.