Skip to content

Commit

Permalink
Add test environment for activemq (#5204)
Browse files Browse the repository at this point in the history
* Add test env for activemq

* Minor refactor; update setup steps

* Fix hostname reference

* Update file headers

Co-Authored-By: Ofek Lev <ofekmeister@gmail.com>

* Increase CI to 3GB

Co-authored-by: Ofek Lev <ofekmeister@gmail.com>
  • Loading branch information
mgarabed and ofek authored Dec 23, 2019
1 parent bb6d0ed commit 561e217
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion activemq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion activemq/datadog_checks/activemq/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions activemq/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-e ../datadog_checks_dev
10 changes: 2 additions & 8 deletions activemq/setup.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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',
Expand All @@ -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,
)
3 changes: 3 additions & 0 deletions activemq/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# (C) Datadog, Inc. 2019
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
37 changes: 37 additions & 0 deletions activemq/tests/common.py
Original file line number Diff line number Diff line change
@@ -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",
]
12 changes: 12 additions & 0 deletions activemq/tests/compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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"
38 changes: 38 additions & 0 deletions activemq/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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}
16 changes: 16 additions & 0 deletions activemq/tests/test_check.py
Original file line number Diff line number Diff line change
@@ -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)
22 changes: 22 additions & 0 deletions activemq/tox.ini
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 561e217

Please sign in to comment.