checker: implement ShareKey to mutualise pings across targets
A ping result depends only on the set of target addresses and the probe count, never on which domain or service the addresses belong to. Implement sdk.ObservationSharer so the host can collect a single ICMP probe per address set (per user) instead of re-pinging once per record: with 1.2.3.4 present in many domains under several A records, the same address was probed dozens of times for identical data. The share key sorts the resolved addresses and folds in the probe count; evaluation thresholds (warningRTT, ...) are intentionally excluded as they only affect how the shared observation is judged. Unresolvable inputs yield an empty key so the host falls back to per-target caching.
This commit is contained in:
parent
fb1b1204b4
commit
d4e64f6a2d
4 changed files with 88 additions and 3 deletions
|
|
@ -119,3 +119,59 @@ func TestIpsFromServiceEmpty(t *testing.T) {
|
|||
t.Errorf("expected 0 ips, got %v", ips)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShareKeyStableRegardlessOfOrder(t *testing.T) {
|
||||
p := &pingProvider{}
|
||||
a, err := p.ShareKey(sdk.CheckerOptions{"addresses": []string{"1.1.1.1", "2.2.2.2"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := p.ShareKey(sdk.CheckerOptions{"addresses": []string{"2.2.2.2", "1.1.1.1"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if a == "" {
|
||||
t.Fatal("expected a non-empty share key")
|
||||
}
|
||||
if a != b {
|
||||
t.Errorf("share key must not depend on address order: %q != %q", a, b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShareKeyDiffersByAddress(t *testing.T) {
|
||||
p := &pingProvider{}
|
||||
a, _ := p.ShareKey(sdk.CheckerOptions{"address": "1.1.1.1"})
|
||||
b, _ := p.ShareKey(sdk.CheckerOptions{"address": "2.2.2.2"})
|
||||
if a == b {
|
||||
t.Errorf("different addresses must yield different share keys, both %q", a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShareKeyDiffersByCount(t *testing.T) {
|
||||
p := &pingProvider{}
|
||||
a, _ := p.ShareKey(sdk.CheckerOptions{"address": "1.1.1.1", "count": float64(5)})
|
||||
b, _ := p.ShareKey(sdk.CheckerOptions{"address": "1.1.1.1", "count": float64(10)})
|
||||
if a == b {
|
||||
t.Errorf("different probe counts must yield different share keys, both %q", a)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShareKeyIgnoresEvaluationThresholds(t *testing.T) {
|
||||
p := &pingProvider{}
|
||||
a, _ := p.ShareKey(sdk.CheckerOptions{"address": "1.1.1.1", "warningRTT": float64(100)})
|
||||
b, _ := p.ShareKey(sdk.CheckerOptions{"address": "1.1.1.1", "warningRTT": float64(250)})
|
||||
if a != b {
|
||||
t.Errorf("evaluation thresholds must not affect the share key: %q != %q", a, b)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShareKeyEmptyWhenUnresolvable(t *testing.T) {
|
||||
p := &pingProvider{}
|
||||
sk, err := p.ShareKey(sdk.CheckerOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
if sk != "" {
|
||||
t.Errorf("expected empty share key (per-target fallback), got %q", sk)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue