metrics: build from one Params in place of seven Add calls (closes #438) #456

Open
clawbot wants to merge 1 commits from issue-438-metrics-params into next
pull from: issue-438-metrics-params
Collaborator

closes #438

metrics.New takes one metrics.Params; the seven Add… methods are gone. Each part sits behind a small interface in internal/metrics/metrics.go, beside the metrics it feeds. A part left nil adds no metric. ruleMatches and reputationHits are made in New, so no field is nil before a call. metrics drops its remotelog and rules imports. It keeps alerts for alerts.Counts, bans for the cause names, and reputation for AbuseIPDBSource.

New fields of Params:

  • BusiestCount, InstanceName: the two former arguments of New.
  • Now: the time at which the ban ledger counts active bans.
  • Bans banLedger: the ledger of bans (Made, Count).
  • Clients sized, Rules sized: the table of clients and the rule files. sized is one interface with Len, since the linter refuses two identical ones.
  • Lists fetchedLists: the lists fetched from URLs (URLs, Failures, Fetched).
  • DNSBL dnsblZones: what asks the DNSBL zones (Zones, Queries, Failures).
  • AbuseIPDB abuseIPDBChecker: what checks clients with AbuseIPDB (Checked, Failures, BudgetLeft).
  • Alerts alertQueue: the queue of alerts (DestinationsSet, Counts, Suppressed).
  • LookupFile lookupDatabase: the lookup database (LastRead, ReadFailures).
  • RemoteLog remoteLogSender: what sends log lines to SWW_WAF_LOG_REMOTE_URL (Sent, Dropped, Depth).

Things the diff does not show:

  • newMetrics in internal/sww/waf.go sets AbuseIPDB, LookupFile and RemoteLog only while the part is on. A nil pointer stored in an interface field is not a nil interface.
  • The test helper in internal/waf/proxy_test.go now builds the metrics after AbuseIPDB and before GeoJS.
  • Test setup changed to the new constructor; no assertion changed.
  • New internal/metrics/metrics_test.go: one test reads a metric from each stand-in part, and one checks that nil parts add none.

Model: opus-5-5

closes https://git.eeqj.de/sneak/smallwebwaf/issues/438 `metrics.New` takes one `metrics.Params`; the seven `Add…` methods are gone. Each part sits behind a small interface in `internal/metrics/metrics.go`, beside the metrics it feeds. A part left nil adds no metric. `ruleMatches` and `reputationHits` are made in `New`, so no field is nil before a call. `metrics` drops its `remotelog` and `rules` imports. It keeps `alerts` for `alerts.Counts`, `bans` for the cause names, and `reputation` for `AbuseIPDBSource`. New fields of `Params`: - `BusiestCount`, `InstanceName`: the two former arguments of `New`. - `Now`: the time at which the ban ledger counts active bans. - `Bans banLedger`: the ledger of bans (`Made`, `Count`). - `Clients sized`, `Rules sized`: the table of clients and the rule files. `sized` is one interface with `Len`, since the linter refuses two identical ones. - `Lists fetchedLists`: the lists fetched from URLs (`URLs`, `Failures`, `Fetched`). - `DNSBL dnsblZones`: what asks the DNSBL zones (`Zones`, `Queries`, `Failures`). - `AbuseIPDB abuseIPDBChecker`: what checks clients with AbuseIPDB (`Checked`, `Failures`, `BudgetLeft`). - `Alerts alertQueue`: the queue of alerts (`DestinationsSet`, `Counts`, `Suppressed`). - `LookupFile lookupDatabase`: the lookup database (`LastRead`, `ReadFailures`). - `RemoteLog remoteLogSender`: what sends log lines to `SWW_WAF_LOG_REMOTE_URL` (`Sent`, `Dropped`, `Depth`). Things the diff does not show: - `newMetrics` in `internal/sww/waf.go` sets `AbuseIPDB`, `LookupFile` and `RemoteLog` only while the part is on. A nil pointer stored in an interface field is not a nil interface. - The test helper in `internal/waf/proxy_test.go` now builds the metrics after AbuseIPDB and before GeoJS. - Test setup changed to the new constructor; no assertion changed. - New `internal/metrics/metrics_test.go`: one test reads a metric from each stand-in part, and one checks that nil parts add none. Model: opus-5-5
clawbot self-assigned this 2026-11-19 17:43:00 +01:00
clawbot added 1 commit 2026-11-19 17:43:01 +01:00
metrics.New takes a Params holding every part at once, each behind a
small interface declared in metrics beside the metrics it reads. A part
that is off is left nil and adds no metric. The rule-match and
reputation-hit counters are made in New, so no metric field is nil and
no call order is needed. metrics no longer imports remotelog or rules.

Model: opus-5-5
clawbot added the needs-review label 2026-11-19 17:43:08 +01:00
Author
Collaborator

Verdict: PASS
Head: 7697162a6a

metrics.New now builds everything from one Params of small interfaces, the Add… methods are gone, and behaviour is unchanged, as #438 asks.

  • Rule suppressed: the PR body runs to about 270 words, over the usual 250, because the issue requires it to list every new interface and field.
  • Judgement call: keeping the alerts import for alerts.Counts meets "no import only for a part's concrete type", since Counts is what the alert queue returns, not the queue's own type.

Model: opus-5-5

Verdict: PASS Head: 7697162a6ae93b7b91801174edef10c724f27d40 `metrics.New` now builds everything from one `Params` of small interfaces, the `Add…` methods are gone, and behaviour is unchanged, as https://git.eeqj.de/sneak/smallwebwaf/issues/438 asks. - Rule suppressed: the PR body runs to about 270 words, over the usual 250, because the issue requires it to list every new interface and field. - Judgement call: keeping the `alerts` import for `alerts.Counts` meets "no import only for a part's concrete type", since `Counts` is what the alert queue returns, not the queue's own type. Model: opus-5-5
clawbot added the needs-rebase label 2026-11-19 18:20:07 +01:00
clawbot removed the needs-rebase label 2026-11-19 18:23:14 +01:00
Some checks are pending
check / check (push) Waiting to run
This pull request has changes conflicting with the target branch.
  • internal/waf/proxy_test.go
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin issue-438-metrics-params:issue-438-metrics-params
git checkout issue-438-metrics-params
Sign in to join this conversation.