Skip to content

Commit edfaa4e

Browse files
authored
Revert agent dev fix (#4013)
1 parent f2c28e7 commit edfaa4e

File tree

5 files changed

+44
-16
lines changed

5 files changed

+44
-16
lines changed

Diff for: .github/workflows/ci.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ jobs:
7575
env:
7676
TARGET_BRANCH: "${{ steps.get-target-branch.outputs.target-branch }}"
7777

78-
# temporary ski : dev agent removed content-type header from traces response
79-
# causing lot of trace to be dropped
80-
# - name: Get agent artifact
81-
# run: ./utils/scripts/load-binary.sh agent
78+
- name: Get agent artifact
79+
run: ./utils/scripts/load-binary.sh agent
8280

8381
# ### appsec-event-rules is now a private repo. The GH_TOKEN provided can't read private repos.
8482
# ### skipping this, waiting for a proper solution

Diff for: .github/workflows/run-end-to-end.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ jobs:
138138
if: always() && steps.build.outcome == 'success' && contains(inputs.scenarios, '"IPV6"') && inputs.library != 'ruby'
139139
run: ./run.sh IPV6
140140
- name: Run CROSSED_TRACING_LIBRARIES scenario
141-
if: always() && steps.build.outcome == 'success' && matrix.weblog != 'python3.12' && matrix.weblog != 'django-py3.13' && (matrix.weblog != 'spring-boot-payara' || inputs.ci_environment != 'prod') && contains(inputs.scenarios, '"CROSSED_TRACING_LIBRARIES"')
141+
if: always() && steps.build.outcome == 'success' && matrix.weblog != 'python3.12' && matrix.weblog != 'django-py3.13' && matrix.weblog != 'spring-boot-payara' && contains(inputs.scenarios, '"CROSSED_TRACING_LIBRARIES"')
142142
# python 3.13 issue : APMAPI-1096
143143
run: ./run.sh CROSSED_TRACING_LIBRARIES
144144
env:

Diff for: tests/test_data_integrity.py

+12
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,17 @@ def validator(data):
210210
interfaces.library.validate(validator, success_by_default=True)
211211

212212

213+
@features.data_integrity
214+
class Test_Agent:
215+
@missing_feature(library="cpp", reason="Trace are not reported")
216+
def test_headers(self):
217+
"""All required headers are present in all requests sent by the agent"""
218+
interfaces.library.assert_response_header(
219+
path_filters=interfaces.library.trace_paths,
220+
header_name_pattern="content-type",
221+
header_value_pattern="application/json",
222+
)
223+
224+
213225
def _empty_request(data):
214226
return "content" not in data["request"] or not data["request"]["content"]

Diff for: utils/interfaces/_core.py

+26-8
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,17 @@ def load_data_from_logs(self):
119119
def _append_data(self, data):
120120
self._data_list.append(data)
121121

122-
def get_data(self, path_filters=None):
122+
def get_data(self, path_filters: list[str] | str | None = None):
123123
if path_filters is not None:
124124
if isinstance(path_filters, str):
125125
path_filters = [path_filters]
126126

127-
path_filters = [re.compile(path) for path in path_filters]
127+
path_regexes = [re.compile(path) for path in path_filters]
128+
else:
129+
path_regexes = None
128130

129131
for data in self._data_list:
130-
if path_filters is not None and all(path.fullmatch(data["path"]) is None for path in path_filters):
132+
if path_regexes is not None and all(path.fullmatch(data["path"]) is None for path in path_regexes):
131133
continue
132134

133135
yield data
@@ -207,23 +209,39 @@ def assert_schema_points(self, excluded_points=None):
207209

208210
assert not has_error, f"Schema validation failed for {self.name}"
209211

210-
def assert_request_header(self, path, header_name_pattern: str, header_value_pattern: str) -> None:
212+
def assert_response_header(self, path_filters, header_name_pattern: str, header_value_pattern: str) -> None:
213+
"""Assert that a header, and its value are present in all requests for a given path
214+
header_name_pattern: a regular expression to match the header name (lower case)
215+
header_value_pattern: a regular expression to match the header value
216+
"""
217+
218+
self._assert_header(path_filters, "response", header_name_pattern, header_value_pattern)
219+
220+
def assert_request_header(self, path_filters, header_name_pattern: str, header_value_pattern: str) -> None:
211221
"""Assert that a header, and its value are present in all requests for a given path
212222
header_name_pattern: a regular expression to match the header name (lower case)
213223
header_value_pattern: a regular expression to match the header value
214224
"""
215225

226+
self._assert_header(path_filters, "request", header_name_pattern, header_value_pattern)
227+
228+
def _assert_header(
229+
self, path_filters, request_or_response: str, header_name_pattern: str, header_value_pattern: str
230+
) -> None:
216231
data_found = False
217232

218-
for data in self.get_data(path):
233+
for data in self.get_data(path_filters):
219234
data_found = True
220235

221236
found = False
222237

223-
for header, value in data["request"]["headers"]:
238+
for header, value in data[request_or_response]["headers"]:
224239
if re.fullmatch(header_name_pattern, header.lower()):
225240
if not re.fullmatch(header_value_pattern, value):
226-
logger.error(f"Header {header} found in {data['log_filename']}, but value is {value}")
241+
logger.error(
242+
f"{request_or_response} header {header} found in "
243+
f"{data['log_filename']}, but value is {value}"
244+
)
227245
else:
228246
found = True
229247
continue
@@ -232,7 +250,7 @@ def assert_request_header(self, path, header_name_pattern: str, header_value_pat
232250
raise ValueError(f"{header_name_pattern} not found (or incorrect) in {data['log_filename']}")
233251

234252
if not data_found:
235-
raise ValueError(f"No data found for {path}")
253+
raise ValueError(f"No data found for {path_filters}")
236254

237255

238256
class ValidationError(Exception):

Diff for: utils/interfaces/_library/core.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
class LibraryInterfaceValidator(ProxyBasedInterfaceValidator):
2525
"""Validate library/agent interface"""
2626

27+
trace_paths = ["/v0.4/traces", "/v0.5/traces"]
28+
2729
def __init__(self, name):
2830
super().__init__(name)
2931
self.ready = threading.Event()
@@ -47,14 +49,12 @@ def wait_function(data):
4749

4850
############################################################
4951
def get_traces(self, request=None):
50-
paths = ["/v0.4/traces", "/v0.5/traces"]
51-
5252
rid = get_rid_from_request(request)
5353

5454
if rid:
5555
logger.debug(f"Try to find traces related to request {rid}")
5656

57-
for data in self.get_data(path_filters=paths):
57+
for data in self.get_data(path_filters=self.trace_paths):
5858
traces = data["request"]["content"]
5959
if not traces: # may be none
6060
continue

0 commit comments

Comments
 (0)