Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/modules/elastic_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self, **options):
elif self.at_least_version("7.3"):
self.apm_server_command_args.extend([
("apm-server.kibana.enabled", "true"),
("apm-server.agent.config.cache.expiration", "1s"),
("apm-server.kibana.host", self.DEFAULT_KIBANA_HOST)])

if self.options.get("enable_kibana", True):
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/localsetup_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ def test_start_master_default(self):
-E, 'setup.kibana.host=kibana:5601', -E, setup.template.settings.index.number_of_replicas=0,
-E, setup.template.settings.index.number_of_shards=1, -E, setup.template.settings.index.refresh_interval=1ms,
-E, monitoring.elasticsearch=true, -E, monitoring.enabled=true,
-E, apm-server.kibana.enabled=true, -E, 'apm-server.kibana.host=kibana:5601',
-E, apm-server.kibana.enabled=true, -E, apm-server.agent.config.cache.expiration=1s, -E, 'apm-server.kibana.host=kibana:5601',
-E, 'output.elasticsearch.hosts=["elasticsearch:9200"]', -E, output.elasticsearch.enabled=true,
-E, "output.elasticsearch.pipelines=[{pipeline: 'apm'}]", -E, 'apm-server.register.ingest.pipeline.enabled=true'
]
Expand Down
2 changes: 1 addition & 1 deletion scripts/tests/service_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ def test_dashboards(self):
def test_apm_server_acm(self):
apm_server = ApmServer(version="7.3").render()["apm-server"]
self.assertTrue("apm-server.kibana.enabled=true" in apm_server["command"],
"APM Server Kbana enabled by default")
"APM Server Kibana enabled by default")
self.assertTrue("apm-server.kibana.host=kibana:5601" in apm_server["command"],
"APM Server Kibana host set by default")

Expand Down
48 changes: 48 additions & 0 deletions tests/agent/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from contextlib import contextmanager
import requests
import time
from urllib.parse import urljoin

from tests.fixtures import default


@contextmanager
def remote_config(kibana_url, sampling_rate=1.0):
def data(sample_rate):
return {
"agent_name": "python",
"service": {"name": default.from_env('FLASK_SERVICE_NAME')},
"settings": {"transaction_sample_rate": sample_rate}
}

headers = {"Content-Type": "application/json", "kbn-xsrf": "1"}
wait = 1.5 # just higher than apm-server.agent.config.cache.expiration

try:
r = requests.post(
urljoin(kibana_url, "/api/apm/settings/agent-configuration/new"),
headers=headers,
json=data(sampling_rate),
)
r.raise_for_status()
config_id = r.json()["_id"]
time.sleep(wait) # give enough time to agent to pick up the config

yield config_id

finally:
# revert to original
r2 = requests.put(
urljoin(kibana_url, "/api/apm/settings/agent-configuration/" + config_id),
headers=headers,
json=data(1.0),
)
r2.raise_for_status()
time.sleep(wait)

r3 = requests.delete(
urljoin(kibana_url, "/api/apm/settings/agent-configuration/" + config_id),
headers=headers,
)
r3.raise_for_status()
time.sleep(wait)
11 changes: 10 additions & 1 deletion tests/agent/test_python.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from tests import utils
from tests import utils, agent
from tests.agent.concurrent_requests import Concurrent


Expand All @@ -27,6 +27,15 @@ def test_concurrent_req_flask(flask):
Concurrent(flask.apm_server.elasticsearch, [foo], iters=2).run()


@pytest.mark.version
@pytest.mark.flask
def test_req_flask_agent_config(flask, kibana):
with agent.remote_config(kibana.url, sampling_rate=0.0):
# 1 transaction, 0 spans
utils.check_agent_transaction(
flask.foo, flask.apm_server.elasticsearch, ct=1)


@pytest.mark.version
@pytest.mark.flask
def test_concurrent_req_flask_foobar(flask):
Expand Down