Skip to content

Commit 99b834f

Browse files
Kevin Oberliesgbanasiak
andauthored
Add apm_tracing mixin car to allow us to enable APM Tracing on es nodes (#85)
Add `apm_tracing` plugin to allow us to enable APM Tracing on ES nodes [APM Tracing][1] [1]: https://github.com/elastic/elasticsearch/blob/main/TRACING.md#how-is-tracing-configured --------- Co-authored-by: Grzegorz Banasiak <[email protected]>
1 parent 9cdc4c1 commit 99b834f

File tree

4 files changed

+132
-0
lines changed

4 files changed

+132
-0
lines changed

cars/v1/apm-tracing.ini

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[meta]
2+
description = APM Tracing
3+
type = mixin
4+
5+
[config]
6+
base = apm_tracing
7+
8+
[variables]
9+
apm_tracing_enabled = true
10+
apm_tracing_server_url = ""
11+
apm_tracing_global_labels = ""

cars/v1/apm_tracing/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
This directory contains the keystore configuration and configuration template for the `apm-tracing` mixin to enable APM Tracing.
2+
3+
## Parameters
4+
5+
This configuration allows to set the following parameters with Rally using `--car-params` in combination
6+
with `--cars="defaults,apm-tracing"`:
7+
8+
- `apm_secret_token`: A string specifying the APM Tracing secretToken in order to properly send telemetry
9+
- `apm_tracing_server_url`: A string specifying the APM Tracing server to send telemetry data to.
10+
- `apm_tracing_global_labels`: A string specifying APM agent global labels added to every trace (useful for filtering).
11+
12+
Example:
13+
14+
`--car="defaults,apm-tracing" --car-params="apm_secret_token:XXXXX,apm_tracing_server_url:'https://example.com:443'"`
15+
16+
Alternatively, the above settings can also be stored in a JSON file that can be specified via `--car-params`.
17+
18+
Example:
19+
20+
```json
21+
{
22+
"apm_secret_token": "XXXXX",
23+
"apm_tracing_server_url": "https://example.com:443"
24+
}
25+
```
26+
27+
Save it as `params.json` and provide it to Rally with `--car="defaults,apm-tracing" --car-params="/path/to/params.json"`.

cars/v1/apm_tracing/config.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import logging
2+
import os
3+
import shlex
4+
import subprocess
5+
6+
from esrally import exceptions
7+
from esrally.utils import process
8+
9+
LOGGER_NAME = "esrally.provisioner.apm_tracing"
10+
11+
12+
def resolve_binary(install_root, binary_name):
13+
return os.path.join(install_root, "bin", binary_name)
14+
15+
16+
def resolve_keystore_config(install_root):
17+
return os.path.join(install_root, "config", "elasticsearch.keystore")
18+
19+
20+
def create_keystore(install_root, keystore_binary, env):
21+
logger = logging.getLogger(LOGGER_NAME)
22+
23+
keystore_create_command = "{keystore} -s create".format(keystore=keystore_binary)
24+
25+
return_code = process.run_subprocess_with_logging(keystore_create_command, env=env)
26+
27+
if return_code != 0:
28+
logger.error(
29+
"%s has exited with code [%d]", keystore_create_command, return_code
30+
)
31+
raise exceptions.SystemSetupError(
32+
"Could not initialize a keystore. Please see the log for details."
33+
)
34+
35+
36+
def add_property_to_keystore(keystore_binary, property_name, property_value, env):
37+
logger = logging.getLogger(LOGGER_NAME)
38+
39+
echo_value = subprocess.Popen(["echo", property_value], stdout=subprocess.PIPE)
40+
41+
keystore_command = "{keystore} --silent add --stdin {key}".format(
42+
keystore=keystore_binary, key=property_name
43+
)
44+
45+
return_code = process.run_subprocess_with_logging(
46+
keystore_command, stdin=echo_value.stdout, env=env
47+
)
48+
49+
if return_code != 0:
50+
logger.error("%s has exited with code [%d]", keystore_command, return_code)
51+
raise exceptions.SystemSetupError(
52+
"Could not add APM tracing keystore secure setting [{}]. Please see the log for details.".format(
53+
property_name
54+
)
55+
)
56+
57+
58+
def configure_keystore(config_names, variables, **kwargs):
59+
logger = logging.getLogger(LOGGER_NAME)
60+
secret_token = variables.get("apm_secret_token")
61+
62+
# skip keystore configuration entirely if any of the mandatory params is missing
63+
if not secret_token:
64+
logger.warning(
65+
"Skipping keystore configuration for apm-tracing "
66+
"as mandatory car-params [`apm_secret_token`] was not supplied",
67+
)
68+
return False
69+
70+
keystore_binary_filename = "elasticsearch-keystore"
71+
install_root = variables["install_root_path"]
72+
keystore_binary = resolve_binary(install_root, keystore_binary_filename)
73+
env = kwargs.get("env")
74+
75+
if not os.path.isfile(resolve_keystore_config(install_root)):
76+
create_keystore(install_root, keystore_binary, env)
77+
78+
add_property_to_keystore(keystore_binary, "telemetry.secret_token", secret_token, env)
79+
80+
# Success
81+
return True
82+
83+
84+
def register(registry):
85+
registry.register("post_install", configure_keystore)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
telemetry.tracing.enabled: {{apm_tracing_enabled}}
3+
{% if apm_tracing_server_url -%}
4+
telemetry.agent.server_url: {{apm_tracing_server_url}}
5+
{%- endif %}
6+
{% if apm_tracing_global_labels -%}
7+
telemetry.agent.global_labels: {{apm_tracing_global_labels}}
8+
{%- endif %}
9+

0 commit comments

Comments
 (0)