mirror of
https://github.com/Horizontal42/netsleuth.git
synced 2026-11-10 18:02:04 +03:00
🧹 [Code Health] Remove redundant state variable received from PingResult
Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
8c99ac78b7
commit
571e0060e6
7 changed files with 11 additions and 14 deletions
|
|
@ -266,7 +266,6 @@ class PingResult:
|
||||||
resolved_ip: str | None = None
|
resolved_ip: str | None = None
|
||||||
method: str = "none"
|
method: str = "none"
|
||||||
sent: int = 0
|
sent: int = 0
|
||||||
received: int = 0
|
|
||||||
loss_pct: float = 0.0
|
loss_pct: float = 0.0
|
||||||
min_ms: float | None = None
|
min_ms: float | None = None
|
||||||
avg_ms: float | None = None
|
avg_ms: float | None = None
|
||||||
|
|
@ -278,6 +277,10 @@ class PingResult:
|
||||||
cv: float | None = None
|
cv: float | None = None
|
||||||
samples: list[float | None] = field(default_factory=list)
|
samples: list[float | None] = field(default_factory=list)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def received(self) -> int:
|
||||||
|
return self.sent - int(round(self.sent * self.loss_pct / 100.0))
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TraceConfig:
|
class TraceConfig:
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ def summarize_ping(
|
||||||
resolved_ip=resolved_ip,
|
resolved_ip=resolved_ip,
|
||||||
method=method,
|
method=method,
|
||||||
sent=s.sent,
|
sent=s.sent,
|
||||||
received=s.received,
|
|
||||||
loss_pct=s.loss_pct,
|
loss_pct=s.loss_pct,
|
||||||
min_ms=s.min_ms,
|
min_ms=s.min_ms,
|
||||||
avg_ms=s.avg_ms,
|
avg_ms=s.avg_ms,
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ def modules() -> dict[str, ModuleResult]:
|
||||||
"latency": ModuleResult(
|
"latency": ModuleResult(
|
||||||
name="latency",
|
name="latency",
|
||||||
status="partial",
|
status="partial",
|
||||||
data=[PingResult(label="cloudflare-dns", host="1.1.1.1", method="icmp_win", sent=5, received=5)],
|
data=[PingResult(label="cloudflare-dns", host="1.1.1.1", method="icmp_win", sent=5)],
|
||||||
errors=[ProbeError(source="quad9-dns", kind="timeout", message="2s", retryable=True)],
|
errors=[ProbeError(source="quad9-dns", kind="timeout", message="2s", retryable=True)],
|
||||||
warnings=["quad9 did not answer"],
|
warnings=["quad9 did not answer"],
|
||||||
duration_ms=1500,
|
duration_ms=1500,
|
||||||
|
|
@ -421,14 +421,13 @@ def full_modules() -> dict[str, ModuleResult]:
|
||||||
host="1.1.1.1",
|
host="1.1.1.1",
|
||||||
method="icmp_win",
|
method="icmp_win",
|
||||||
sent=5,
|
sent=5,
|
||||||
received=5,
|
|
||||||
avg_ms=12.4,
|
avg_ms=12.4,
|
||||||
min_ms=11.0,
|
min_ms=11.0,
|
||||||
max_ms=15.1,
|
max_ms=15.1,
|
||||||
jitter_ms=1.9,
|
jitter_ms=1.9,
|
||||||
samples=[11.0, 12.0, None, 15.1, 12.4],
|
samples=[11.0, 12.0, None, 15.1, 12.4],
|
||||||
),
|
),
|
||||||
PingResult(label="github", host="github.com", method="tcp", sent=5, received=4, loss_pct=20.0, avg_ms=42.0),
|
PingResult(label="github", host="github.com", method="tcp", sent=5, loss_pct=20.0, avg_ms=42.0),
|
||||||
],
|
],
|
||||||
duration_ms=2400,
|
duration_ms=2400,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ def ping(**kw) -> PingResult:
|
||||||
resolved_ip="1.1.1.1",
|
resolved_ip="1.1.1.1",
|
||||||
method="icmp_dgram",
|
method="icmp_dgram",
|
||||||
sent=20,
|
sent=20,
|
||||||
received=20,
|
|
||||||
loss_pct=0.0,
|
loss_pct=0.0,
|
||||||
min_ms=10.0,
|
min_ms=10.0,
|
||||||
avg_ms=12.0,
|
avg_ms=12.0,
|
||||||
|
|
@ -75,7 +74,7 @@ def test_high_latency_produces_a_warn_finding_with_metric_and_threshold(threshol
|
||||||
|
|
||||||
|
|
||||||
def test_high_jitter_and_loss_each_produce_their_own_finding(thresholds):
|
def test_high_jitter_and_loss_each_produce_their_own_finding(thresholds):
|
||||||
findings = latency_findings([ping(jitter_ms=25.0, loss_pct=5.0, received=19)], thresholds)
|
findings = latency_findings([ping(jitter_ms=25.0, loss_pct=5.0)], thresholds)
|
||||||
ids = sorted(f.id for f in findings)
|
ids = sorted(f.id for f in findings)
|
||||||
assert ids == ["latency.jitter.cloudflare-dns", "latency.loss.cloudflare-dns"]
|
assert ids == ["latency.jitter.cloudflare-dns", "latency.loss.cloudflare-dns"]
|
||||||
|
|
||||||
|
|
@ -89,7 +88,7 @@ def test_tcp_measured_loss_is_labelled_as_connection_failures_not_packet_loss(th
|
||||||
|
|
||||||
def test_a_fully_dead_host_is_critical_regardless_of_bands(thresholds):
|
def test_a_fully_dead_host_is_critical_regardless_of_bands(thresholds):
|
||||||
findings = latency_findings(
|
findings = latency_findings(
|
||||||
[ping(received=0, loss_pct=100.0, avg_ms=None, min_ms=None, max_ms=None, jitter_ms=None)],
|
[ping(loss_pct=100.0, avg_ms=None, min_ms=None, max_ms=None, jitter_ms=None)],
|
||||||
thresholds,
|
thresholds,
|
||||||
)
|
)
|
||||||
assert [f.severity for f in findings] == ["crit"]
|
assert [f.severity for f in findings] == ["crit"]
|
||||||
|
|
@ -103,7 +102,7 @@ def test_dual_family_findings_silent_when_no_v6_hosts_present():
|
||||||
def test_dual_family_findings_reports_unreachable_when_every_v6_host_is_dead():
|
def test_dual_family_findings_reports_unreachable_when_every_v6_host_is_dead():
|
||||||
pings = [
|
pings = [
|
||||||
ping(),
|
ping(),
|
||||||
ping(label="cloudflare-dns-v6", host="2606:4700:4700::1111", received=0, avg_ms=None, loss_pct=100.0),
|
ping(label="cloudflare-dns-v6", host="2606:4700:4700::1111", avg_ms=None, loss_pct=100.0),
|
||||||
]
|
]
|
||||||
findings = dual_family_findings(pings)
|
findings = dual_family_findings(pings)
|
||||||
assert [f.id for f in findings] == ["net.ipv6_unreachable"]
|
assert [f.id for f in findings] == ["net.ipv6_unreachable"]
|
||||||
|
|
@ -507,8 +506,8 @@ def has_cyrillic(text: str) -> bool:
|
||||||
def test_latency_findings_carry_russian_siblings():
|
def test_latency_findings_carry_russian_siblings():
|
||||||
findings = latency_findings(
|
findings = latency_findings(
|
||||||
[
|
[
|
||||||
ping(received=0, loss_pct=100.0, avg_ms=None, min_ms=None, max_ms=None, jitter_ms=None),
|
ping(loss_pct=100.0, avg_ms=None, min_ms=None, max_ms=None, jitter_ms=None),
|
||||||
ping(avg_ms=130.0, jitter_ms=25.0, loss_pct=5.0, received=19),
|
ping(avg_ms=130.0, jitter_ms=25.0, loss_pct=5.0),
|
||||||
],
|
],
|
||||||
thresholds_fixture(),
|
thresholds_fixture(),
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,6 @@ def test_ping_result_round_trips_through_json():
|
||||||
resolved_ip="1.1.1.1",
|
resolved_ip="1.1.1.1",
|
||||||
method="icmp_win",
|
method="icmp_win",
|
||||||
sent=20,
|
sent=20,
|
||||||
received=20,
|
|
||||||
loss_pct=0.0,
|
loss_pct=0.0,
|
||||||
min_ms=11.0,
|
min_ms=11.0,
|
||||||
avg_ms=12.4,
|
avg_ms=12.4,
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,6 @@ async def test_benchmark_prefixes_probes_selected_hosts_with_mocked_ping_host(mo
|
||||||
resolved_ip=host,
|
resolved_ip=host,
|
||||||
method="tcp",
|
method="tcp",
|
||||||
sent=count,
|
sent=count,
|
||||||
received=count,
|
|
||||||
loss_pct=0.0,
|
loss_pct=0.0,
|
||||||
avg_ms=10.0,
|
avg_ms=10.0,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ def ping(label: str, avg: float | None, loss: float = 0.0) -> PingResult:
|
||||||
resolved_ip="1.1.1.1",
|
resolved_ip="1.1.1.1",
|
||||||
method="icmp_win",
|
method="icmp_win",
|
||||||
sent=5,
|
sent=5,
|
||||||
received=5 if avg is not None else 0,
|
|
||||||
loss_pct=loss,
|
loss_pct=loss,
|
||||||
avg_ms=avg,
|
avg_ms=avg,
|
||||||
jitter_ms=1.5 if avg is not None else None,
|
jitter_ms=1.5 if avg is not None else None,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue