-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathconftest.py
85 lines (71 loc) · 2.51 KB
/
conftest.py
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
# (C) Datadog, Inc. 2019-present
# 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 (
ACTIVEMQ_URL,
ARTEMIS_URL,
BASE_URL,
COMPOSE_FILE,
HERE,
HOST,
IS_ARTEMIS,
JMX_PORT,
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)
if IS_ARTEMIS:
s = requests.Session()
s.auth = TEST_AUTH
s.headers = {'accept': 'application/json', 'origin': BASE_URL}
data = s.get(ARTEMIS_URL + '/list')
channels = data.json()['value']['org.apache.activemq.artemis']
broker = [k for k in channels.keys() if k.startswith('broker') and ',' not in k][0]
bean = 'org.apache.activemq.artemis:{}'.format(broker)
for queue in TEST_QUEUES:
body = {
"type": "exec",
"mbean": bean,
"operation": "createQueue("
"java.lang.String,"
"java.lang.String,"
"java.lang.String,"
"java.lang.String,"
"boolean,int,boolean,boolean)",
"arguments": ["activemq.notifications", "ANYCAST", queue, None, True, -1, False, True],
}
s.post(ARTEMIS_URL + '/exec', json=body)
else:
for queue in TEST_QUEUES:
url = '{}/{}?type=queue'.format(ACTIVEMQ_URL, queue)
requests.post(url, data=TEST_MESSAGE, auth=TEST_AUTH)
for topic in TEST_TOPICS:
url = '{}/{}?type=topic'.format(ACTIVEMQ_URL, topic)
requests.post(url, data=TEST_MESSAGE, auth=TEST_AUTH)
@pytest.fixture(scope="session")
def dd_environment():
envs = {'JMX_PORT': str(JMX_PORT)}
log_pattern = 'ActiveMQ Jolokia REST API available'
if IS_ARTEMIS:
log_pattern = 'HTTP Server started at http://0.0.0.0:8161'
with docker_run(
os.path.join(HERE, 'compose', COMPOSE_FILE),
log_patterns=[log_pattern],
conditions=[WaitForPortListening(HOST, TEST_PORT), populate_server],
env_vars=envs,
):
config = load_jmx_config()
config['instances'][0].update({'port': str(JMX_PORT), 'host': HOST})
yield config, {'use_jmx': True}