Instance name on process log lines and every metric (closes #91)
check / check (push) Canceled after 0s

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.

Tests that read metrics expect the label. One test helper replaces the
two alert tests' loops that wait for the metrics.

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
This commit is contained in:
2026-10-07 04:16:39 +00:00
parent 70a8ea1b92
commit 5ceef3edf3
14 changed files with 232 additions and 120 deletions
+2 -5
View File
@@ -6,7 +6,6 @@ import (
"errors"
"io"
"net/http"
"os"
"reflect"
"slices"
"strings"
@@ -123,10 +122,8 @@ func wantAnswer(t *testing.T, got answer, body []byte) {
func wantRequestFields(t *testing.T, line logLine, host string, sent, received int) {
t.Helper()
hostname, _ := os.Hostname()
want := withTimings(line, requestlog.Line{
Type: requestType, Time: line.Time, Instance: hostname,
Type: requestType, Time: line.Time, Instance: "app",
ClientIP: localhost, Method: http.MethodPatch, Scheme: plain, Host: host,
Path: rawPath, Query: rawQuery, Protocol: protocol,
Status: http.StatusTeapot, RequestBytes: int64(sent),
@@ -318,7 +315,7 @@ func TestServerHasTheDefaultLimits(t *testing.T) {
server := proxy.New(proxy.Params{
Config: cfg,
RequestLog: io.Discard,
ProcessLog: requestlog.NewProcessLogger(io.Discard),
ProcessLog: requestlog.NewProcessLogger(io.Discard, cfg.InstanceName),
})
if server.Addr != ":8080" || server.MaxHeaderBytes != 28<<10 ||