13
13
class _TestAdmisionController :
14
14
def test_inject_admission_controller (self , test_k8s_instance ):
15
15
logger .info (
16
- f"Launching test _test_inject_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .weblog_port } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .agent_port } ]"
16
+ f"Launching test _test_inject_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .get_weblog_port () } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .get_agent_port () } ]"
17
17
)
18
18
test_k8s_instance .deploy_test_agent ()
19
19
test_k8s_instance .deploy_datadog_cluster_agent ()
20
20
test_k8s_instance .deploy_weblog_as_pod ()
21
- traces_json = self ._get_dev_agent_traces (test_k8s_instance .k8s_kind_cluster . agent_port )
21
+ traces_json = self ._get_dev_agent_traces (test_k8s_instance .k8s_kind_cluster )
22
22
assert len (traces_json ) > 0 , "No traces found"
23
23
logger .info (f"Test _test_inject_admission_controller finished" )
24
24
25
25
def test_inject_uds_admission_controller (self , test_k8s_instance ):
26
26
logger .info (
27
- f"Launching test test_inject_uds_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .weblog_port } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .agent_port } ]"
27
+ f"Launching test test_inject_uds_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .get_weblog_port () } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .get_agent_port () } ]"
28
28
)
29
29
test_k8s_instance .deploy_test_agent ()
30
30
test_k8s_instance .deploy_datadog_cluster_agent (use_uds = True )
31
31
test_k8s_instance .deploy_weblog_as_pod ()
32
- traces_json = self ._get_dev_agent_traces (test_k8s_instance .k8s_kind_cluster . agent_port )
32
+ traces_json = self ._get_dev_agent_traces (test_k8s_instance .k8s_kind_cluster )
33
33
assert len (traces_json ) > 0 , "No traces found"
34
34
logger .info (f"Test test_inject_uds_admission_controller finished" )
35
35
36
36
def test_inject_without_admission_controller (self , test_k8s_instance ):
37
37
logger .info (
38
- f"Launching test _test_inject_without_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .weblog_port } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .agent_port } ]"
38
+ f"Launching test _test_inject_without_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .get_weblog_port () } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .get_agent_port () } ]"
39
39
)
40
40
test_k8s_instance .deploy_test_agent ()
41
41
test_k8s_instance .deploy_weblog_as_pod (with_admission_controller = False )
42
- traces_json = self ._get_dev_agent_traces (test_k8s_instance .k8s_kind_cluster . agent_port )
42
+ traces_json = self ._get_dev_agent_traces (test_k8s_instance .k8s_kind_cluster )
43
43
assert len (traces_json ) > 0 , "No traces found"
44
44
logger .info (f"Test _test_inject_without_admission_controller finished" )
45
45
46
46
def test_inject_uds_without_admission_controller (self , test_k8s_instance ):
47
47
logger .info (
48
- f"Launching test test_inject_uds_without_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .weblog_port } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .agent_port } ]"
48
+ f"Launching test test_inject_uds_without_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .get_weblog_port () } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .get_agent_port () } ]"
49
49
)
50
50
test_k8s_instance .deploy_test_agent ()
51
51
test_k8s_instance .deploy_weblog_as_pod (with_admission_controller = False , use_uds = True )
52
- traces_json = self ._get_dev_agent_traces (test_k8s_instance .k8s_kind_cluster . agent_port )
52
+ traces_json = self ._get_dev_agent_traces (test_k8s_instance .k8s_kind_cluster )
53
53
assert len (traces_json ) > 0 , "No traces found"
54
54
logger .info (f"Test test_inject_uds_without_admission_controller finished" )
55
55
56
- def _get_dev_agent_traces (self , agent_port , retry = 10 ):
56
+ def _get_dev_agent_traces (self , k8s_kind_cluster , retry = 10 ):
57
57
for _ in range (retry ):
58
58
logger .info (f"[Check traces] Checking traces:" )
59
- response = requests .get (f"http://localhost:{ agent_port } /test/traces" )
59
+ response = requests .get (
60
+ f"http://{ k8s_kind_cluster .cluster_host_name } :{ k8s_kind_cluster .get_agent_port ()} /test/traces"
61
+ )
60
62
traces_json = response .json ()
61
63
if len (traces_json ) > 0 :
62
64
logger .debug (f"Test traces response: { traces_json } " )
@@ -73,7 +75,7 @@ class _TestAdmisionControllerAsm:
73
75
74
76
def test_inject_asm_admission_controller (self , test_k8s_instance ):
75
77
logger .info (
76
- f"Launching test test_inject_asm_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .weblog_port } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .agent_port } ]"
78
+ f"Launching test test_inject_asm_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .get_weblog_port () } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .get_agent_port () } ]"
77
79
)
78
80
79
81
asm_features = {
@@ -84,15 +86,16 @@ def test_inject_asm_admission_controller(self, test_k8s_instance):
84
86
test_k8s_instance .deploy_datadog_cluster_agent (features = asm_features )
85
87
test_k8s_instance .deploy_agent ()
86
88
87
- weblog_port = test_k8s_instance .k8s_kind_cluster .weblog_port
88
- logger .info (f"Waiting for weblog available [localhost:{ weblog_port } ]" )
89
- wait_for_port (weblog_port , "localhost" , 80.0 )
90
- logger .info (f"[localhost:{ weblog_port } ]: Weblog app is ready!" )
91
- warmup_weblog (f"http://localhost:{ weblog_port } /" )
92
- logger .info (f"Making a request to weblog [localhost:{ weblog_port } ]" )
93
- request_uuid = make_get_request (f"http://localhost:{ weblog_port } /" )
89
+ weblog_port = test_k8s_instance .k8s_kind_cluster .get_weblog_port ()
90
+ weblog_host = test_k8s_instance .k8s_kind_cluster .cluster_host_name
91
+ logger .info (f"Waiting for weblog available [{ weblog_host } :{ weblog_port } ]" )
92
+ wait_for_port (weblog_port , weblog_host , 80.0 )
93
+ logger .info (f"[{ weblog_host } :{ weblog_port } ]: Weblog app is ready!" )
94
+ warmup_weblog (f"http://{ weblog_host } :{ weblog_port } /" )
95
+ logger .info (f"Making a request to weblog [{ weblog_host } :{ weblog_port } ]" )
96
+ request_uuid = make_get_request (f"http://{ weblog_host } :{ weblog_port } /" )
94
97
95
- logger .info (f"Http request done with uuid: [{ request_uuid } ] for [localhost :{ weblog_port } ]" )
98
+ logger .info (f"Http request done with uuid: [{ request_uuid } ] for [{ weblog_host } :{ weblog_port } ]" )
96
99
wait_backend_trace_id (request_uuid , 120.0 , profile = False , validator = backend_trace_validator )
97
100
98
101
@@ -101,13 +104,15 @@ def test_inject_asm_admission_controller(self, test_k8s_instance):
101
104
class TestAdmisionControllerProfiling :
102
105
"""Test profiling activation with the admission controller."""
103
106
104
- def _check_profiling_request_sent (self , agent_port , timeout = 90 ):
107
+ def _check_profiling_request_sent (self , k8s_kind_cluster , timeout = 90 ):
105
108
""" Use test agent profiling endpoint to check if the profiling data has been sent by the injectect library.
106
109
Checks the request made to the profiling endpoint (/profiling/v1/input).
107
110
The profiling post data can take between 12 and 90 seconds (12 if the library supports both env vars, 90 if it supports neither. """
108
111
mustend = time .time () + timeout
109
112
while time .time () < mustend :
110
- response = requests .get (f"http://localhost:{ agent_port } /test/session/requests" )
113
+ response = requests .get (
114
+ f"http://{ k8s_kind_cluster .cluster_host_name } :{ k8s_kind_cluster .get_agent_port ()} /test/session/requests"
115
+ )
111
116
for request in response .json ():
112
117
if request ["url" ].endswith ("/profiling/v1/input" ):
113
118
return True
@@ -117,36 +122,36 @@ def _check_profiling_request_sent(self, agent_port, timeout=90):
117
122
def test_profiling_disabled_by_default (self , test_k8s_instance ):
118
123
logger .info (f"Launching test test_profiling_disabled_by_default" )
119
124
logger .info (
120
- f": Weblog: [{ test_k8s_instance .k8s_kind_cluster .weblog_port } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .agent_port } ]"
125
+ f": Weblog: [{ test_k8s_instance .k8s_kind_cluster .get_weblog_port () } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .get_agent_port () } ]"
121
126
)
122
127
test_k8s_instance .deploy_test_agent ()
123
128
test_k8s_instance .deploy_datadog_cluster_agent ()
124
129
# if profiling is enabled force some profiling data to be sent
125
130
test_k8s_instance .deploy_weblog_as_pod (
126
131
env = {"DD_PROFILING_UPLOAD_PERIOD" : "10" , "DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD" : "1500" }
127
132
)
128
- profiling_request_found = self ._check_profiling_request_sent (test_k8s_instance .k8s_kind_cluster . agent_port )
133
+ profiling_request_found = self ._check_profiling_request_sent (test_k8s_instance .k8s_kind_cluster )
129
134
assert not profiling_request_found , "Profiling should be disabled by default, but a profiling request was found"
130
135
131
136
@bug (context .library > "[email protected] " , reason = "APMON-1496" )
132
137
def test_profiling_admission_controller (self , test_k8s_instance ):
133
138
logger .info (f"Launching test test_profiling_admission_controller" )
134
139
logger .info (
135
- f": Weblog: [{ test_k8s_instance .k8s_kind_cluster .weblog_port } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .agent_port } ]"
140
+ f": Weblog: [{ test_k8s_instance .k8s_kind_cluster .get_weblog_port () } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .get_agent_port () } ]"
136
141
)
137
142
test_k8s_instance .deploy_test_agent ()
138
143
test_k8s_instance .deploy_datadog_cluster_agent (features = {"datadog.profiling.enabled" : "auto" })
139
144
test_k8s_instance .deploy_weblog_as_pod (
140
145
env = {"DD_PROFILING_UPLOAD_PERIOD" : "10" , "DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD" : "1500" }
141
146
)
142
- profiling_request_found = self ._check_profiling_request_sent (test_k8s_instance .k8s_kind_cluster . agent_port )
147
+ profiling_request_found = self ._check_profiling_request_sent (test_k8s_instance .k8s_kind_cluster )
143
148
assert profiling_request_found , "No profiling request found"
144
149
145
150
@bug (context .library > "[email protected] " , reason = "APMON-1496" )
146
151
def test_profiling_override_cluster_env (self , test_k8s_instance ):
147
152
logger .info (f"Launching test test_profiling_override_cluster_env" )
148
153
logger .info (
149
- f": Weblog: [{ test_k8s_instance .k8s_kind_cluster .weblog_port } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .agent_port } ]"
154
+ f": Weblog: [{ test_k8s_instance .k8s_kind_cluster .get_weblog_port () } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .get_agent_port () } ]"
150
155
)
151
156
cluster_agent_config = {
152
157
"clusterAgent.env[0].name" : "DD_ADMISSION_CONTROLLER_AUTO_INSTRUMENTATION_PROFILING_ENABLED" ,
@@ -157,28 +162,29 @@ def test_profiling_override_cluster_env(self, test_k8s_instance):
157
162
test_k8s_instance .deploy_weblog_as_pod (
158
163
env = {"DD_PROFILING_UPLOAD_PERIOD" : "10" , "DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD" : "1500" }
159
164
)
160
- profiling_request_found = self ._check_profiling_request_sent (test_k8s_instance .k8s_kind_cluster . agent_port )
165
+ profiling_request_found = self ._check_profiling_request_sent (test_k8s_instance .k8s_kind_cluster )
161
166
assert profiling_request_found , "No profiling request found"
162
167
163
168
def _test_inject_profiling_admission_controller_real (self , test_k8s_instance ):
164
169
logger .info (
165
- f"Launching test test_inject_profiling_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .weblog_port } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .agent_port } ]"
170
+ f"Launching test test_inject_profiling_admission_controller: Weblog: [{ test_k8s_instance .k8s_kind_cluster .get_weblog_port () } ] Agent: [{ test_k8s_instance .k8s_kind_cluster .get_agent_port () } ]"
166
171
)
167
172
168
173
test_k8s_instance .deploy_datadog_cluster_agent (features = {"datadog.profiling.enabled" : "auto" })
169
174
test_k8s_instance .deploy_agent ()
170
175
test_k8s_instance .deploy_weblog_as_pod (
171
176
env = {"DD_PROFILING_UPLOAD_PERIOD" : "10" , "DD_INTERNAL_PROFILING_LONG_LIVED_THRESHOLD" : "1500" }
172
177
)
173
- weblog_port = test_k8s_instance .k8s_kind_cluster .weblog_port
174
- logger .info (f"Waiting for weblog available [localhost:{ weblog_port } ]" )
175
- wait_for_port (weblog_port , "localhost" , 80.0 )
176
- logger .info (f"[localhost:{ weblog_port } ]: Weblog app is ready!" )
177
- warmup_weblog (f"http://localhost:{ weblog_port } /" )
178
- logger .info (f"Making a request to weblog [localhost:{ weblog_port } ]" )
179
- request_uuid = make_get_request (f"http://localhost:{ weblog_port } /" )
180
-
181
- logger .info (f"Http request done with uuid: [{ request_uuid } ] for [localhost:{ weblog_port } ]" )
178
+ weblog_port = test_k8s_instance .k8s_kind_cluster .get_weblog_port ()
179
+ weblog_host = test_k8s_instance .k8s_kind_cluster .cluster_host_name
180
+ logger .info (f"Waiting for weblog available [{ weblog_host } :{ weblog_port } ]" )
181
+ wait_for_port (weblog_port , weblog_host , 80.0 )
182
+ logger .info (f"[{ weblog_host } :{ weblog_port } ]: Weblog app is ready!" )
183
+ warmup_weblog (f"http://{ weblog_host } :{ weblog_port } /" )
184
+ logger .info (f"Making a request to weblog [{ weblog_host } :{ weblog_port } ]" )
185
+ request_uuid = make_get_request (f"http://{ weblog_host } :{ weblog_port } /" )
186
+
187
+ logger .info (f"Http request done with uuid: [{ request_uuid } ] for [{ weblog_host } :{ weblog_port } ]" )
182
188
wait_backend_trace_id (request_uuid , 120.0 , profile = True )
183
189
184
190
0 commit comments