Instance name on process log lines and every metric #96

Merged
clawbot merged 1 commits from issue-91-instance-name into next 2026-10-07 06:48:09 +02:00
Collaborator

For #91.

  • Process log lines carry instance, SWWAF_INSTANCE_NAME, as request lines do. config.InstanceName reads that one setting before the others, as config.ListenAddrAndUpstreamURL does for the health check, so that the line saying a setting is invalid carries it too.
  • Every metric, Go's and the process's included, carries the label instance: the metrics are registered through prometheus.WrapRegistererWith, a constant label on the registry, rather than a label each metric declares. README.md says which, and that Prometheus keeps the label as exported_instance unless the scrape sets honor_labels: true.
  • An SWWAF_INSTANCE_NAME, set or read from its file, that is not valid UTF-8 stops the start with a message naming it, since the metrics library panics on such a label.
  • Every expected series in the tests now spells out instance. The proxy tests set the instance name app unless a test sets another, so the request line test that expected the default, the host's name, now expects app; the default stays covered by the config tests.
  • metricsWith, a test helper, replaces the two alert tests' loops that wait for the metrics; without it one of those tests went over the linter's function length limit.

Judgement call: the label is named instance, the name the log lines and alerts use, although Prometheus gives each scraped target an instance label of its own.
Judgement call: the client library's documentation advises against a label on every metric, preferring labels the scraper adds; SPEC.md and the issue ask for one.

Model: opus-5-5

For https://git.eeqj.de/sneak/smallwebwaf/issues/91. - Process log lines carry `instance`, `SWWAF_INSTANCE_NAME`, as request lines do. `config.InstanceName` reads that one setting before the others, as `config.ListenAddrAndUpstreamURL` does for the health check, so that the line saying a setting is invalid carries it too. - Every metric, Go's and the process's included, carries the label `instance`: the metrics are registered through `prometheus.WrapRegistererWith`, a constant label on the registry, rather than a label each metric declares. `README.md` says which, and that Prometheus keeps the label as `exported_instance` unless the scrape sets `honor_labels: true`. - An `SWWAF_INSTANCE_NAME`, set or read from its file, that is not valid UTF-8 stops the start with a message naming it, since the metrics library panics on such a label. - Every expected series in the tests now spells out `instance`. The proxy tests set the instance name `app` unless a test sets another, so the request line test that expected the default, the host's name, now expects `app`; the default stays covered by the config tests. - `metricsWith`, a test helper, replaces the two alert tests' loops that wait for the metrics; without it one of those tests went over the linter's function length limit. Judgement call: the label is named `instance`, the name the log lines and alerts use, although Prometheus gives each scraped target an `instance` label of its own. Judgement call: the client library's documentation advises against a label on every metric, preferring labels the scraper adds; `SPEC.md` and the issue ask for one. Model: opus-5-5
clawbot added the needs-review label 2026-10-07 06:17:01 +02:00
clawbot self-assigned this 2026-10-07 06:17:01 +02:00
Author
Collaborator

Review failed.

  1. internal/metrics/metrics.go line 67, with instanceName in internal/config/config.go: the instance name is now a label on every metric, and the metrics library refuses a label value that is not valid UTF-8. An SWWAF_INSTANCE_NAME, or a file named by SWWAF_INSTANCE_NAME_FILE, holding such bytes (a name saved in Latin-1, for example) therefore makes smallwebwaf panic at start, instead of stopping with a message naming the setting as README.md and "Configuration surface" in SPEC.md promise. Acceptable: the settings refuse an instance name that is not valid UTF-8 with an error naming SWWAF_INSTANCE_NAME, as they already refuse one with a control character while ntfy is set, with a test, and README.md says so.

  2. internal/smallwebwaf/smallwebwaf.go line 90: while SWWAF_LOG_REMOTE_URL is set the process log is built a second time, and no test checks that the lines it writes carry instance, so that half of the rule is unguarded. Acceptable: a test that sees instance on the process lines while SWWAF_LOG_REMOTE_URL is set (TestStalledRemoteLogEndpointHoldsUpNoRequest already sets the name), or the process log built in one place only.

Judgement call accepted: the label is named instance, which Prometheus keeps as exported_instance unless the scrape sets honor_labels: true; README.md states this correctly.

Model: opus-5-5

Review failed. 1. `internal/metrics/metrics.go` line 67, with `instanceName` in `internal/config/config.go`: the instance name is now a label on every metric, and the metrics library refuses a label value that is not valid UTF-8. An `SWWAF_INSTANCE_NAME`, or a file named by `SWWAF_INSTANCE_NAME_FILE`, holding such bytes (a name saved in Latin-1, for example) therefore makes smallwebwaf panic at start, instead of stopping with a message naming the setting as `README.md` and "Configuration surface" in `SPEC.md` promise. Acceptable: the settings refuse an instance name that is not valid UTF-8 with an error naming `SWWAF_INSTANCE_NAME`, as they already refuse one with a control character while ntfy is set, with a test, and `README.md` says so. 2. `internal/smallwebwaf/smallwebwaf.go` line 90: while `SWWAF_LOG_REMOTE_URL` is set the process log is built a second time, and no test checks that the lines it writes carry `instance`, so that half of the rule is unguarded. Acceptable: a test that sees `instance` on the process lines while `SWWAF_LOG_REMOTE_URL` is set (`TestStalledRemoteLogEndpointHoldsUpNoRequest` already sets the name), or the process log built in one place only. Judgement call accepted: the label is named `instance`, which Prometheus keeps as `exported_instance` unless the scrape sets `honor_labels: true`; `README.md` states this correctly. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-07 06:30:40 +02:00
clawbot added 1 commit 2026-10-07 06:39:46 +02:00
Process log lines carry instance, as request lines do; the instance name
is read before the other settings, so the line saying a setting is
invalid carries it too. Every metric, Go's and the process's included,
carries the label instance, set once on the registry. README.md says so,
and that Prometheus keeps it as exported_instance unless the scrape sets
honor_labels. An instance name that is not valid UTF-8 stops the start,
as the metrics library panics on such a label.

Tests that read metrics expect the label; one helper replaces the alert
tests' loops that wait for them.

Judgement call: the label is named instance, as in the log lines and
alerts, although Prometheus gives each target a label of that name.

Model: opus-5-5
clawbot force-pushed issue-91-instance-name from 5ceef3edf3 to 36dafbc48d 2026-10-07 06:39:46 +02:00 Compare
Author
Collaborator
  1. An SWWAF_INSTANCE_NAME, set or read from its file, that is not valid UTF-8 now stops the start with an error naming it; a config test covers both forms, and README.md says so.
  2. Added a test: TestStalledRemoteLogEndpointHoldsUpNoRequest now checks that the start line carries instance while SWWAF_LOG_REMOTE_URL is set. Building the process log in one place would mean holding back the invalid-setting error until the log's writer is chosen, which is not plainer.

Model: opus-5-5

1. An `SWWAF_INSTANCE_NAME`, set or read from its file, that is not valid UTF-8 now stops the start with an error naming it; a config test covers both forms, and `README.md` says so. 2. Added a test: `TestStalledRemoteLogEndpointHoldsUpNoRequest` now checks that the start line carries `instance` while `SWWAF_LOG_REMOTE_URL` is set. Building the process log in one place would mean holding back the invalid-setting error until the log's writer is chosen, which is not plainer. Model: opus-5-5
clawbot added needs-review and removed needs-rework labels 2026-10-07 06:39:57 +02:00
Author
Collaborator

Review passed.

Judgement call accepted: the process log is still built in two places, the second while SWWAF_LOG_REMOTE_URL is set, since the line saying a setting is invalid has to be written before the settings say where the lines go; a test now guards the second.

Model: opus-5-5

Review passed. Judgement call accepted: the process log is still built in two places, the second while `SWWAF_LOG_REMOTE_URL` is set, since the line saying a setting is invalid has to be written before the settings say where the lines go; a test now guards the second. Model: opus-5-5
clawbot merged commit f35cbd01cf into next 2026-10-07 06:48:09 +02:00
clawbot deleted branch issue-91-instance-name 2026-10-07 06:48:10 +02:00
Sign in to join this conversation.