From 561e2176966e8fd34a7299e68fab353c0a949095 Mon Sep 17 00:00:00 2001 From: Mike Garabedian Date: Mon, 23 Dec 2019 16:29:50 -0500 Subject: [PATCH] Add test environment for activemq (#5204) * Add test env for activemq * Minor refactor; update setup steps * Fix hostname reference * Update file headers Co-Authored-By: Ofek Lev * Increase CI to 3GB Co-authored-by: Ofek Lev --- .../linux/50_increase_docker_memory.sh | 10 +++++ activemq/README.md | 2 +- .../activemq/data/conf.yaml.example | 2 +- activemq/requirements-dev.txt | 1 + activemq/setup.py | 10 +---- activemq/tests/__init__.py | 3 ++ activemq/tests/common.py | 37 ++++++++++++++++++ activemq/tests/compose/docker-compose.yaml | 12 ++++++ activemq/tests/conftest.py | 38 +++++++++++++++++++ activemq/tests/test_check.py | 16 ++++++++ activemq/tox.ini | 22 +++++++++++ 11 files changed, 143 insertions(+), 10 deletions(-) create mode 100755 .azure-pipelines/scripts/activemq/linux/50_increase_docker_memory.sh create mode 100644 activemq/requirements-dev.txt create mode 100644 activemq/tests/__init__.py create mode 100644 activemq/tests/common.py create mode 100644 activemq/tests/compose/docker-compose.yaml create mode 100644 activemq/tests/conftest.py create mode 100644 activemq/tests/test_check.py create mode 100644 activemq/tox.ini diff --git a/.azure-pipelines/scripts/activemq/linux/50_increase_docker_memory.sh b/.azure-pipelines/scripts/activemq/linux/50_increase_docker_memory.sh new file mode 100755 index 0000000000000..6c3db7e081f27 --- /dev/null +++ b/.azure-pipelines/scripts/activemq/linux/50_increase_docker_memory.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -ex + +# Allocate 3GB for activemq +# The default number of memory addresses is 65536, i.e. 512MB (Linux 64-bit). +# => To get 3GB, we multiply that amount by 6. +sudo sysctl -w vm.max_map_count=$(expr 6 \* 65536) + +set +ex diff --git a/activemq/README.md b/activemq/README.md index 7d839434ea3ab..40f2f1ea88547 100644 --- a/activemq/README.md +++ b/activemq/README.md @@ -26,7 +26,7 @@ Follow the instructions below to configure this check for an Agent running on a ```yaml instances: - host: localhost - port: 7199 + port: 1616 user: username password: password name: activemq_instance diff --git a/activemq/datadog_checks/activemq/data/conf.yaml.example b/activemq/datadog_checks/activemq/data/conf.yaml.example index 09b3e345ea65f..9b4a248dba6e8 100644 --- a/activemq/datadog_checks/activemq/data/conf.yaml.example +++ b/activemq/datadog_checks/activemq/data/conf.yaml.example @@ -13,7 +13,7 @@ instances: ## @param port - integer - required ## ActiveMQ port to connect to. # - port: 1099 + port: 1616 ## @param auth_type - string - optional ## The type of authentication to use. diff --git a/activemq/requirements-dev.txt b/activemq/requirements-dev.txt new file mode 100644 index 0000000000000..98b5456bbd0e2 --- /dev/null +++ b/activemq/requirements-dev.txt @@ -0,0 +1 @@ +-e ../datadog_checks_dev diff --git a/activemq/setup.py b/activemq/setup.py index 4ae191bee3a06..196474a7e6509 100644 --- a/activemq/setup.py +++ b/activemq/setup.py @@ -1,10 +1,11 @@ # (C) Datadog, Inc. 2018 # All rights reserved # Licensed under a 3-clause BSD style license (see LICENSE) -from setuptools import setup from codecs import open # To use a consistent encoding from os import path +from setuptools import setup + HERE = path.dirname(path.abspath(__file__)) # Get version info @@ -30,17 +31,13 @@ def get_requirements(fpath): long_description=long_description, long_description_content_type='text/markdown', keywords='datadog agent activemq check', - # The project's main homepage. url='https://github.com/DataDog/integrations-core', - # Author details author='Datadog', author_email='packages@datadoghq.com', - # License license='BSD', - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ 'Development Status :: 5 - Production/Stable', @@ -51,13 +48,10 @@ def get_requirements(fpath): 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', ], - # The package we're going to ship packages=['datadog_checks.activemq'], - # Run-time dependencies install_requires=['datadog_checks_base'], - # Extra files to ship with the wheel package include_package_data=True, ) diff --git a/activemq/tests/__init__.py b/activemq/tests/__init__.py new file mode 100644 index 0000000000000..b76d6b83ebdd1 --- /dev/null +++ b/activemq/tests/__init__.py @@ -0,0 +1,3 @@ +# (C) Datadog, Inc. 2019 +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) diff --git a/activemq/tests/common.py b/activemq/tests/common.py new file mode 100644 index 0000000000000..10f85ad16a308 --- /dev/null +++ b/activemq/tests/common.py @@ -0,0 +1,37 @@ +# (C) Datadog, Inc. 2019 +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) +from datadog_checks.dev import get_docker_hostname, get_here + +CHECK_NAME = 'activemq' + +HERE = get_here() +HOST = get_docker_hostname() + +TEST_QUEUES = ('FOO_QUEUE', 'TEST_QUEUE') +TEST_TOPICS = ('FOO_TOPIC', 'TEST_TOPIC') +TEST_MESSAGE = {'body': 'test_message'} +TEST_AUTH = ('admin', 'admin') + +TEST_PORT = 8161 +BASE_URL = 'http://{}:{}/api/message'.format(HOST, TEST_PORT) + +# not all metrics will be available in our E2E environment, specifically: +# "activemq.queue.dequeue_count", +# "activemq.queue.dispatch_count", +# "activemq.queue.enqueue_count", +# "activemq.queue.expired_count", +# "activemq.queue.in_flight_count", + +ACTIVEMQ_E2E_METRICS = [ + "activemq.queue.avg_enqueue_time", + "activemq.queue.consumer_count", + "activemq.queue.producer_count", + "activemq.queue.max_enqueue_time", + "activemq.queue.min_enqueue_time", + "activemq.queue.memory_pct", + "activemq.queue.size", + "activemq.broker.store_pct", + "activemq.broker.temp_pct", + "activemq.broker.memory_pct", +] diff --git a/activemq/tests/compose/docker-compose.yaml b/activemq/tests/compose/docker-compose.yaml new file mode 100644 index 0000000000000..f77fb5920b136 --- /dev/null +++ b/activemq/tests/compose/docker-compose.yaml @@ -0,0 +1,12 @@ +version: "3" + +services: + namenode: + image: rmohr/activemq:${ACTIVEMQ_VERSION} + container_name: dd-test-activemq-server + environment: + ACTIVEMQ_SUNJMX_START: "-Dcom.sun.management.jmxremote.port=1616 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false" + ports: + - "61616:61616" + - "8161:8161" + - "1616:1616" diff --git a/activemq/tests/conftest.py b/activemq/tests/conftest.py new file mode 100644 index 0000000000000..024f9754181aa --- /dev/null +++ b/activemq/tests/conftest.py @@ -0,0 +1,38 @@ +# (C) Datadog, Inc. 2019 +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) + +import os +import time + +import pytest +import requests + +from datadog_checks.dev import docker_run +from datadog_checks.dev.conditions import WaitForPortListening +from datadog_checks.dev.utils import load_jmx_config + +from .common import BASE_URL, HERE, HOST, TEST_AUTH, TEST_MESSAGE, TEST_PORT, TEST_QUEUES, TEST_TOPICS + + +def populate_server(): + """Add some queues and topics to ensure more metrics are available.""" + time.sleep(3) + + for queue in TEST_QUEUES: + url = '{}/{}?type=queue'.format(BASE_URL, queue) + requests.post(url, data=TEST_MESSAGE, auth=TEST_AUTH) + + for topic in TEST_TOPICS: + url = '{}/{}?type=topic'.format(BASE_URL, topic) + requests.post(url, data=TEST_MESSAGE, auth=TEST_AUTH) + + +@pytest.fixture(scope="session") +def dd_environment(): + with docker_run( + os.path.join(HERE, 'compose', 'docker-compose.yaml'), + log_patterns=['ActiveMQ Jolokia REST API available'], + conditions=[WaitForPortListening(HOST, TEST_PORT), populate_server], + ): + yield load_jmx_config(), {'use_jmx': True} diff --git a/activemq/tests/test_check.py b/activemq/tests/test_check.py new file mode 100644 index 0000000000000..80d378b868022 --- /dev/null +++ b/activemq/tests/test_check.py @@ -0,0 +1,16 @@ +# (C) Datadog, Inc. 2019 +# All rights reserved +# Licensed under a 3-clause BSD style license (see LICENSE) + +import pytest + +from .common import ACTIVEMQ_E2E_METRICS + + +@pytest.mark.e2e +def test(dd_agent_check): + instance = {} + aggregator = dd_agent_check(instance) + + for metric in ACTIVEMQ_E2E_METRICS: + aggregator.assert_metric(metric) diff --git a/activemq/tox.ini b/activemq/tox.ini new file mode 100644 index 0000000000000..f5b1ca50afd20 --- /dev/null +++ b/activemq/tox.ini @@ -0,0 +1,22 @@ +[tox] +minversion = 2.0 +skip_missing_interpreters = true +basepython = py37 +envlist = + py37 + +[testenv] +description = + py37: e2e ready +usedevelop = true +dd_check_style = true +platform = linux|darwin|win32 +deps = + -e../datadog_checks_base[deps] + -rrequirements-dev.txt +passenv = + DOCKER* + COMPOSE* +setenv = ACTIVEMQ_VERSION=5.15.9 +commands = + pytest -v {posargs}