Skip to content

Commit cf4da90

Browse files
authored
Merge pull request #11 from sourceplusplus/update
test: probe config tests
2 parents 3fd8825 + f2a4be4 commit cf4da90

File tree

12 files changed

+158
-52
lines changed

12 files changed

+158
-52
lines changed

.github/workflows/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
run: |
4242
until $(curl --header "Authorization: Bearer ${{ env.SPP_JWT_TOKEN }}" --insecure --output /dev/null --silent --fail https://localhost:12800/health); do printf '.'; sleep 5; done
4343
- run: curl -sS https://webinstall.dev/jq | bash
44-
- run: sleep 30s #wait for services to connect; todo: use health endpoint
44+
- run: sleep 45s #wait for services to connect; todo: use health endpoint
4545

4646
- name: Verify probe connected
4747
run: |

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
python {
7-
pip("apache-skywalking:0.7.0")
7+
pip("apache-skywalking:0.8.0")
88
pip("vertx-eventbus-client:1.0.0")
99
}
1010

e2e/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ services:
1212
- "5000:5000"
1313
environment:
1414
- SPP_PLATFORM_HOST=spp-platform
15-
- SPP_OAP_HOST=skywalking-oap
1615
- GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=/usr/local/bin/config/spp-platform.crt
1716
spp-platform:
1817
image: sourceplusplus/spp-platform:latest

e2e/spp-probe.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ skywalking:
3636
logging:
3737
level: "INFO"
3838
agent:
39-
is_cache_enhanced_class: true
40-
class_cache_mode: "FILE"
4139
service_name: "spp"
4240
collector:
4341
backend_service: "spp-platform:11801"

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
vertx-eventbus-client~=1.0.0
2-
apache-skywalking~=0.7.0
3-
nopdb~=0.1.0
4-
pyhumps~=3.0.2
2+
apache-skywalking~=0.8.0
3+
nopdb~=0.2.0
4+
pyhumps~=3.7.2
55
PyYAML~=6.0

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pluginManagement {
22
plugins {
3-
id 'com.avast.gradle.docker-compose' version "0.14.11" apply false
3+
id 'com.avast.gradle.docker-compose' version "0.16.8" apply false
44
}
55
}

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
license='Apache License, Version 2.0',
1111
packages=setuptools.find_packages(),
1212
install_requires=['vertx-eventbus-client>=1.0.0',
13-
'apache-skywalking>=0.7.0',
14-
'nopdb>=0.1.0',
15-
'pyhumps>=3.0.2',
13+
'apache-skywalking>=0.8.0',
14+
'nopdb>=0.2.0',
15+
'pyhumps>=3.7.2',
1616
'PyYAML>=6.0'])

sourceplusplus/SourcePlusPlus.py

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@
1616

1717
class SourcePlusPlus(object):
1818

19-
def get_config_value(self, env, default, true_default):
20-
env_value = os.getenv(env)
21-
if env_value is not None:
22-
return env_value
23-
elif default is not None:
24-
return default
25-
else:
26-
return true_default
19+
@staticmethod
20+
def __set_config_default(config_dict, config_name, env, default):
21+
config_path = config_name.split(".")
22+
tmp_config = config_dict
23+
for i in range(len(config_path)):
24+
if i == len(config_path) - 1 and tmp_config.get(config_path[i]) is None:
25+
if default is bool:
26+
tmp_config[config_path[i]] = str(os.getenv(env, default)).lower() == "true"
27+
else:
28+
tmp_config[config_path[i]] = os.getenv(env, default)
29+
30+
if tmp_config.get(config_path[i]) is None:
31+
tmp_config[config_path[i]] = {}
32+
tmp_config = tmp_config[config_path[i]]
33+
else:
34+
tmp_config = tmp_config[config_path[i]]
2735

2836
def __init__(self, args: dict = None):
2937
if args is None:
@@ -33,41 +41,40 @@ def __init__(self, args: dict = None):
3341
if os.path.exists(probe_config_file):
3442
probe_config = yaml.full_load(open(probe_config_file, "r"))
3543

36-
# ensure probe_config has required keys
37-
if probe_config.get("spp") is None:
38-
probe_config["spp"] = {}
39-
if probe_config.get("skywalking") is None:
40-
probe_config["skywalking"] = {}
41-
if probe_config["skywalking"].get("collector") is None:
42-
probe_config["skywalking"]["collector"] = {}
43-
if probe_config["skywalking"].get("agent") is None:
44-
probe_config["skywalking"]["agent"] = {}
45-
46-
# set default values
47-
probe_config["spp"]["probe_id"] = self.get_config_value(
48-
"SPP_PROBE_ID", probe_config["spp"].get("probe_id"), str(uuid.uuid4())
44+
# set spp default values
45+
self.__set_config_default(
46+
probe_config, "spp.probe_id", "SPP_PROBE_ID",
47+
str(uuid.uuid4())
4948
)
50-
probe_config["spp"]["platform_host"] = self.get_config_value(
51-
"SPP_PLATFORM_HOST", probe_config["spp"].get("platform_host"), "localhost"
49+
self.__set_config_default(
50+
probe_config, "spp.platform_host", "SPP_PLATFORM_HOST",
51+
"localhost"
5252
)
53-
probe_config["spp"]["platform_port"] = self.get_config_value(
54-
"SPP_PLATFORM_PORT", probe_config["spp"].get("platform_port"), 12800
53+
self.__set_config_default(
54+
probe_config, "spp.platform_port", "SPP_PLATFORM_PORT",
55+
12800
5556
)
56-
probe_config["spp"]["verify_host"] = str(self.get_config_value(
57-
"SPP_TLS_VERIFY_HOST", probe_config["spp"].get("verify_host"), True
58-
)).lower() == "true"
59-
probe_config["spp"]["ssl_enabled"] = str(self.get_config_value(
60-
"SPP_HTTP_SSL_ENABLED", probe_config["spp"].get("ssl_enabled"), True
61-
)).lower() == "true"
62-
probe_config["skywalking"]["agent"]["service_name"] = self.get_config_value(
63-
"SPP_SERVICE_NAME", probe_config["skywalking"]["agent"].get("service_name"), "spp"
57+
self.__set_config_default(
58+
probe_config, "spp.verify_host", "SPP_TLS_VERIFY_HOST",
59+
True
60+
)
61+
self.__set_config_default(
62+
probe_config, "spp.ssl_enabled", "SPP_HTTP_SSL_ENABLED",
63+
True
64+
)
65+
self.__set_config_default(
66+
probe_config, "skywalking.agent.service_name", "SPP_SERVICE_NAME",
67+
"spp"
6468
)
6569

66-
skywalking_port = self.get_config_value("SPP_OAP_PORT", 11800, 11800)
67-
probe_config["skywalking"]["collector"]["backend_service"] = self.get_config_value(
68-
"SPP_SKYWALKING_BACKEND_SERVICE",
69-
probe_config["skywalking"]["collector"].get("backend_service"),
70-
probe_config["spp"]["platform_host"] + ":" + str(skywalking_port)
70+
# set sw default values
71+
self.__set_config_default(
72+
probe_config, "skywalking.collector.backend_service", "SPP_SKYWALKING_BACKEND_SERVICE",
73+
probe_config["spp"]["platform_host"] + ":11800"
74+
)
75+
self.__set_config_default(
76+
probe_config, "skywalking.plugin.toolkit.log.transmit_formatted", "SPP_SKYWALKING_LOG_TRANSMIT_FORMATTED",
77+
True
7178
)
7279

7380
for key, val in args.items():
@@ -89,8 +96,8 @@ def attach(self):
8996
collector_address=self.probe_config["skywalking"]["collector"]["backend_service"],
9097
service_name=self.probe_config["skywalking"]["agent"]["service_name"],
9198
log_reporter_active=True,
92-
force_tls=self.probe_config["spp"]["ssl_enabled"] is True,
93-
log_reporter_formatted=False
99+
force_tls=self.probe_config["spp"]["ssl_enabled"],
100+
log_reporter_formatted=self.probe_config["skywalking"]["plugin"]["toolkit"]["log"]["transmit_formatted"]
94101
)
95102
agent.start()
96103

tests/probe_config/__init__.py

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
spp:
2+
platform_host: "spp-platform"
3+
platform_port: 12800
4+
ssl_enabled: false
5+
skywalking:
6+
logging:
7+
level: "WARN"
8+
agent:
9+
service_name: "tutorial-jvm"

0 commit comments

Comments
 (0)