MCPcopy Create free account
hub / github.com/ceph/ceph / Reporter

Class Reporter

src/ceph-node-proxy/ceph_node_proxy/reporter.py:14–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12
13
14class Reporter(BaseThread):
15 def __init__(
16 self,
17 system: SystemForReporter,
18 cephx: Dict[str, Any],
19 reporter_scheme: str = "https",
20 reporter_hostname: str = "",
21 reporter_port: str = "443",
22 reporter_endpoint: str = "/node-proxy/data",
23 max_retries: int = DEFAULT_MAX_RETRIES,
24 ) -> None:
25 super().__init__()
26 self.system = system
27 self.data: Dict[str, Any] = {}
28 self.stop: bool = False
29 self.cephx = cephx
30 self.data["cephx"] = self.cephx["cephx"]
31 self.reporter_scheme: str = reporter_scheme
32 self.reporter_hostname: str = reporter_hostname
33 self.reporter_port: str = reporter_port
34 self.reporter_endpoint: str = reporter_endpoint
35 self.max_retries: int = max_retries
36 self.log = get_logger(__name__)
37 self.reporter_url: str = (
38 f"{reporter_scheme}://{reporter_hostname}:"
39 f"{reporter_port}{reporter_endpoint}"
40 )
41 self.log.info(f"Reporter url set to {self.reporter_url}")
42
43 def _send_with_retries(self) -> bool:
44 """Send data to mgr. Returns True on success, False after max_retries failures."""
45 for attempt in range(1, self.max_retries + 1):
46 try:
47 self.log.debug(
48 f"sending data to {self.reporter_url} (attempt {attempt}/{self.max_retries})"
49 )
50 http_req(
51 hostname=self.reporter_hostname,
52 port=self.reporter_port,
53 method="POST",
54 headers={"Content-Type": "application/json"},
55 endpoint=self.reporter_endpoint,
56 scheme=self.reporter_scheme,
57 data=json.dumps(self.data),
58 )
59 return True
60 except (HTTPError, URLError) as e:
61 self.log.error(
62 f"The reporter couldn't send data to the mgr (attempt {attempt}/{self.max_retries}): {e}"
63 )
64 if attempt < self.max_retries:
65 time.sleep(RETRY_SLEEP_SEC)
66 return False
67
68 def _log_data_delta(
69 self,
70 new_data: Dict[str, Any],
71 max_log_len: int = 2048,

Callers 1

init_reporterMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected