Skip to content

Commit

Permalink
add python tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jalvz committed Oct 8, 2019
1 parent cd40ddb commit 8155615
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 5 deletions.
1 change: 1 addition & 0 deletions tests/system/apmserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def ilm_index(self, index):
class ServerSetUpBaseTest(BaseTest):
host = "http://localhost:8200"
agent_config_url = "{}/{}".format(host, "config/v1/agents")
rum_agent_config_url = "{}/{}".format(host, "config/v1/rum/agents")
intake_url = "{}/{}".format(host, 'intake/v2/events')
expvar_url = "{}/{}".format(host, 'debug/vars')

Expand Down
89 changes: 84 additions & 5 deletions tests/system/test_integration_acm.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
from beat.beat import INTEGRATION_TESTS


class AgentConfigurationIntegrationTest(ElasticTest):
class AgentConfigurationTest(ElasticTest):
config_overrides = {
"logging_json": "true",
"kibana_enabled": "true",
"acm_cache_expiration": "1s",
}

@classmethod
def setUpClass(cls):
super(AgentConfigurationTest, cls).setUpClass()

def config(self):
cfg = super(ElasticTest, self).config()
cfg.update({
Expand All @@ -24,15 +28,17 @@ def config(self):
cfg.update(self.config_overrides)
return cfg

def create_service_config(self, settings, name, env=None, _id="new"):
def create_service_config(self, settings, name, agent="python", env=None, _id="new"):
data = {
"agent_name": agent,
"service": {"name": name},
"settings": settings
}
if env is not None:
data["service"]["environment"] = env
meth = requests.post if _id == "new" else requests.put
return meth(

method = requests.post if _id == "new" else requests.put
return method(
urljoin(self.kibana_url, "/api/apm/settings/agent-configuration/{}".format(_id)),
headers={
"Accept": "*/*",
Expand All @@ -43,7 +49,10 @@ def create_service_config(self, settings, name, env=None, _id="new"):
)

def update_service_config(self, settings, _id, name, env=None):
return self.create_service_config(settings, name, env, _id=_id)
return self.create_service_config(settings, name, agent="python", env=env, _id=_id)


class AgentConfigurationIntegrationTest(AgentConfigurationTest):

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
def test_config_requests(self):
Expand Down Expand Up @@ -194,6 +203,17 @@ def test_config_requests(self):
for want, got in zip(expect_log, config_request_logs):
self.assertDictContainsSubset(want, got)

@unittest.skipUnless(INTEGRATION_TESTS, "integration test")
def test_rum_disabled(self):
r = requests.get(self.rum_agent_config_url,
params={
"service.name": "rum-service",
},
headers={"Content-Type": "application/json"}
)
assert r.status_code == 403
assert r.json() == {'error': 'forbidden request: endpoint is disabled'}


class AgentConfigurationKibanaDownIntegrationTest(ElasticTest):
config_overrides = {
Expand Down Expand Up @@ -254,3 +274,62 @@ def test_log_kill_switch_active(self):
"error": "forbidden request: endpoint is disabled",
"response_code": 403,
}, config_request_logs[0])


class RumAgentConfigurationIntegrationTest(AgentConfigurationTest):
config_overrides = {
"enable_rum": "true",
}

def test_rum_ok(self):
service_name = "rum-service"
create_config_rsp = self.create_service_config({"transaction_sample_rate": 0.2}, service_name, agent="rum-js")
create_config_rsp.raise_for_status()
assert create_config_rsp.status_code == 200, create_config_rsp.status_code
create_config_result = create_config_rsp.json()
assert create_config_result["result"] == "created"

r1 = requests.get(self.rum_agent_config_url,
params={"service.name": service_name},
headers={"Content-Type": "application/json"})

assert r1.status_code == 200
assert r1.json() == {'transaction_sample_rate': '0.2'}
etag = r1.headers["Etag"]

r2 = requests.get(self.rum_agent_config_url,
params={"service.name": service_name, "ifnonematch": etag.replace('"', '')},
headers={"Content-Type": "application/json"})
assert r2.status_code == 304

def test_backend_not_ok(self):
service_name = "backend-service"
create_config_rsp = self.create_service_config({"transaction_sample_rate": 0.3}, service_name)
create_config_rsp.raise_for_status()
assert create_config_rsp.status_code == 200, create_config_rsp.status_code
create_config_result = create_config_rsp.json()
assert create_config_result["result"] == "created"

r1 = requests.get(self.rum_agent_config_url,
params={"service.name": service_name},
headers={"Content-Type": "application/json"})

assert r1.status_code == 200, r1.status_code
assert r1.json() == {}, r1.json()

def test_all_agents(self):
service_name = "any-service"
create_config_rsp = self.create_service_config(
{"transaction_sample_rate": 0.4, "capture_body": "all"}, service_name, agent="")
create_config_rsp.raise_for_status()
assert create_config_rsp.status_code == 200, create_config_rsp.status_code
create_config_result = create_config_rsp.json()
assert create_config_result["result"] == "created"

r1 = requests.get(self.rum_agent_config_url,
params={"service.name": service_name},
headers={"Content-Type": "application/json"})

assert r1.status_code == 200, r1.status_code
# only return settings applicable to RUM
assert r1.json() == {"transaction_sample_rate": "0.4"}, r1.json()

0 comments on commit 8155615

Please sign in to comment.