Skip to content

Commit 8daa754

Browse files
committed
velero
1 parent 50cc010 commit 8daa754

21 files changed

Lines changed: 1510 additions & 33 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``kube_discovery`` e2e test helpers, install local base code in helper Agent pods, and add a named-port discovery strategy for generated candidates.

datadog_checks_dev/datadog_checks/dev/_env.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import json
55
import os
6+
import re
67
from base64 import urlsafe_b64decode, urlsafe_b64encode
8+
from typing import Any
79

810
DDTRACE_OPTIONS_LIST = [
911
'DD_TAGS',
@@ -110,6 +112,36 @@ def format_config(config):
110112
return config
111113

112114

115+
def flags_to_argv(flags: dict[str, Any]) -> list[str]:
116+
"""Convert ``agent check`` keyword flags (e.g. ``check_rate=True``) into CLI argv tokens."""
117+
argv = []
118+
for key, value in flags.items():
119+
if value is not False:
120+
argv.append('--{}'.format(key.replace('_', '-')))
121+
if value is not True:
122+
argv.append(str(value))
123+
124+
return argv
125+
126+
127+
JSON_COLLECTOR_PATTERN = r'((?:\{ \[|\[).*?\n(?:\} \]|\]))'
128+
129+
130+
def find_collector_blobs(output: str) -> list[str]:
131+
"""Pull collector JSON blobs out of ``agent check --json`` output."""
132+
return re.findall(JSON_COLLECTOR_PATTERN, output, re.DOTALL)
133+
134+
135+
def replay_collector_blobs(matches: list[str], stub_aggregator: Any, stub_agent: Any) -> None:
136+
"""Parse and replay each collector JSON blob found by ``find_collector_blobs``."""
137+
for raw_json in matches:
138+
try:
139+
collector = json.loads(raw_json)
140+
except json.JSONDecodeError as e:
141+
raise ValueError(f'Error loading json: {e}\nCollector Json Output:\n{raw_json}') from e
142+
replay_check_run(collector, stub_aggregator, stub_agent)
143+
144+
113145
def replay_check_run(agent_collector, stub_aggregator, stub_agent):
114146
errors = []
115147
for collector in agent_collector:

datadog_checks_dev/datadog_checks/dev/docker.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,8 @@ def assert_all_discovery_candidates_stable(
101101
_assert_container_stable(initial_state, current_state, index)
102102

103103
current_stdout, current_stderr = _get_container_logs(current_container_id)
104-
# Diffed separately: stdout/stderr interleaving varies across calls, breaking a combined diff.
105-
new_stdout = _diff_logs(previous_stdout, current_stdout)
106-
new_stderr = _diff_logs(previous_stderr, current_stderr)
107-
new_logs = new_stdout + new_stderr
108-
for line in new_logs.splitlines():
109-
logging.debug('New log line: %s', line)
110-
_assert_no_log_patterns(new_logs, log_patterns, index)
111-
previous_stdout, previous_stderr = current_stdout, current_stderr
104+
previous_stdout = assert_no_new_log_patterns(previous_stdout, current_stdout, log_patterns, index)
105+
previous_stderr = assert_no_new_log_patterns(previous_stderr, current_stderr, log_patterns, index)
112106

113107

114108
def _get_compose_container_id(
@@ -196,11 +190,6 @@ def _get_container_logs(container_id: str) -> tuple[str, str]:
196190
return result.stdout, result.stderr
197191

198192

199-
def _diff_logs(previous: str, current: str) -> str:
200-
"""Return the portion of `current` appended since `previous`."""
201-
return current[len(previous) :] if current.startswith(previous) else current
202-
203-
204193
def _assert_container_stable(
205194
initial_state: Mapping[str, Any], current_state: Mapping[str, Any], candidate_index: int
206195
) -> None:
@@ -237,6 +226,17 @@ def _assert_no_log_patterns(logs: str, patterns: Sequence[str], candidate_index:
237226
)
238227

239228

229+
def assert_no_new_log_patterns(
230+
previous_logs: str, current_logs: str, patterns: Sequence[str], candidate_index: int
231+
) -> str:
232+
"""Assert no dangerous pattern appears in the logs emitted since ``previous_logs``, returning the new baseline."""
233+
new_logs = current_logs[len(previous_logs) :] if current_logs.startswith(previous_logs) else current_logs
234+
for line in new_logs.splitlines():
235+
logging.debug('New log line: %s', line)
236+
_assert_no_log_patterns(new_logs, patterns, candidate_index)
237+
return current_logs
238+
239+
240240
def get_e2e_discovery_metadata(
241241
check_root: str | os.PathLike[str] | None = None,
242242
) -> dict[str, list[str]]:

0 commit comments

Comments
 (0)