Name log fields, metrics and the Core Rule Set package for what they are (closes #192)
check / check (push) Failing after 17m18s
check / check (push) Failing after 17m18s
Log field, metric, action and event names now say what they count and, for timings, the unit. Package internal/waf is internal/coreruleset. Model: opus-5-5
This commit is contained in:
1 parent
aede434f6a
commit
9a5782de68
52 files changed
+638
-591
No files matched your search
@@ -48,8 +48,8 @@ const (
|
||||
reportStatus = "status"
|
||||
reportRequestBytes = "request_bytes"
|
||||
reportResponseBytes = "response_bytes"
|
||||
reportDuration = "duration_total"
|
||||
reportUpstreamDuration = "duration_upstream_total"
|
||||
reportDuration = "duration_total_ms"
|
||||
reportUpstreamDuration = "duration_upstream_total_ms"
|
||||
)
|
||||
|
||||
// Discriminator is a discriminator running for one test, on a clock set to midnight.
|
||||
@@ -693,7 +693,7 @@ func TestQuestionUnderTheOwnPrefixIsDeniedWith404AfterTheChecks(t *testing.T) {
|
||||
wantDisposition(t, got, http.StatusNotFound, discriminator.DispositionDeny)
|
||||
}
|
||||
|
||||
wantLine(t, s.out.requestLine(t), http.StatusNotFound, requestlog.ActionAdmin)
|
||||
wantLine(t, s.out.requestLine(t), http.StatusNotFound, requestlog.ActionOwnEndpoint)
|
||||
|
||||
got := s.ask(otherClient, discriminator.MetricsPath)
|
||||
wantDisposition(t, got, http.StatusForbidden, discriminator.DispositionDeny)
|
||||
@@ -725,9 +725,9 @@ func TestObserveModeRefusalAnsweredAllowCountsForTheErrorBurst(t *testing.T) {
|
||||
}
|
||||
|
||||
lines := s.out.requestLines(t, 2)
|
||||
if lines[0].LimitHit != "" || lines[1].LimitHit != requestlog.LimitHitErrorBurst {
|
||||
if lines[0].LimitHit != "" || lines[1].LimitHit != requestlog.LimitHitMinuteRefusals {
|
||||
t.Errorf("log lines have limit_hit %q and %q, want none and %q",
|
||||
lines[0].LimitHit, lines[1].LimitHit, requestlog.LimitHitErrorBurst)
|
||||
lines[0].LimitHit, lines[1].LimitHit, requestlog.LimitHitMinuteRefusals)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -744,9 +744,9 @@ func TestDeniedQuestionCountsForTheErrorBurst(t *testing.T) {
|
||||
}
|
||||
|
||||
lines := s.out.requestLines(t, 2)
|
||||
if lines[0].LimitHit != "" || lines[1].LimitHit != requestlog.LimitHitErrorBurst {
|
||||
if lines[0].LimitHit != "" || lines[1].LimitHit != requestlog.LimitHitMinuteRefusals {
|
||||
t.Errorf("log lines have limit_hit %q and %q, want none and %q",
|
||||
lines[0].LimitHit, lines[1].LimitHit, requestlog.LimitHitErrorBurst)
|
||||
lines[0].LimitHit, lines[1].LimitHit, requestlog.LimitHitMinuteRefusals)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -901,7 +901,7 @@ func TestDeniedRequestIsFinishedAtItsDecision(t *testing.T) {
|
||||
|
||||
got := s.report(discriminator.Report{
|
||||
RequestID: denied.Header.Get(requestIDHeader), Status: http.StatusForbidden,
|
||||
ResponseBytes: 1000, DurationTotal: 2,
|
||||
ResponseBytes: 1000, DurationTotalMS: 2,
|
||||
})
|
||||
wantStatus(t, got, http.StatusNoContent)
|
||||
|
||||
@@ -935,7 +935,7 @@ func TestMetricsCountAnAllowedRequestFromItsReport(t *testing.T) {
|
||||
got := s.report(discriminator.Report{
|
||||
RequestID: id, Status: http.StatusBadGateway,
|
||||
RequestBytes: bodyBytes, ResponseBytes: answerBytes,
|
||||
DurationTotal: 5, DurationUpstreamTotal: 4,
|
||||
DurationTotalMS: 5, DurationUpstreamTotalMS: 4,
|
||||
})
|
||||
wantStatus(t, got, http.StatusNoContent)
|
||||
|
||||
@@ -951,7 +951,8 @@ func TestMetricsCountAnAllowedRequestFromItsReport(t *testing.T) {
|
||||
unscraped := startDiscriminator(t, "", map[string]string{metricsToken: token})
|
||||
|
||||
got = unscraped.report(discriminator.Report{
|
||||
RequestID: unscraped.allowed(client), Status: http.StatusBadGateway, DurationTotal: 5,
|
||||
RequestID: unscraped.allowed(client), Status: http.StatusBadGateway,
|
||||
DurationTotalMS: 5,
|
||||
})
|
||||
wantStatus(t, got, http.StatusNoContent)
|
||||
wantMetric(t, unscraped.metrics(),
|
||||
@@ -1189,8 +1190,8 @@ func wantReportsFields(t *testing.T, line logLine) {
|
||||
if line.DiscriminatorLine != requestlog.DiscriminatorLineReport ||
|
||||
line.Status != http.StatusCreated ||
|
||||
line.RequestBytes != bodyBytes || line.ResponseBytes != answerBytes ||
|
||||
line.DurationTotal != 12.5 || line.DurationUpstreamTotal == nil ||
|
||||
*line.DurationUpstreamTotal != 10.25 {
|
||||
line.DurationTotalMS != 12.5 || line.DurationUpstreamTotalMS == nil ||
|
||||
*line.DurationUpstreamTotalMS != 10.25 {
|
||||
t.Errorf("the report's line lacks the report's fields: %+v", line.Line)
|
||||
}
|
||||
}
|
||||
@@ -1205,8 +1206,8 @@ func wantSameDecision(t *testing.T, reported, decided logLine) {
|
||||
same.Status = decided.Status
|
||||
same.RequestBytes = decided.RequestBytes
|
||||
same.ResponseBytes = decided.ResponseBytes
|
||||
same.DurationTotal = decided.DurationTotal
|
||||
same.DurationUpstreamTotal = decided.DurationUpstreamTotal
|
||||
same.DurationTotalMS = decided.DurationTotalMS
|
||||
same.DurationUpstreamTotalMS = decided.DurationUpstreamTotalMS
|
||||
same.Counts.MinuteBytes = decided.Counts.MinuteBytes
|
||||
same.Counts.HourBytes = decided.Counts.HourBytes
|
||||
same.Counts.DayBytes = decided.Counts.DayBytes
|
||||
@@ -1224,7 +1225,7 @@ func wantDecisionsFields(t *testing.T, line logLine, id, query, accept string) {
|
||||
|
||||
if line.DiscriminatorLine != requestlog.DiscriminatorLineDecision ||
|
||||
line.Status != http.StatusOK || line.ResponseBytes != 0 ||
|
||||
line.DurationUpstreamTotal != nil || line.DurationChecks == nil ||
|
||||
line.DurationUpstreamTotalMS != nil || line.DurationChecksMS == nil ||
|
||||
line.RequestID != id || line.Query != query ||
|
||||
!line.HasAuthorization || !line.HasCookie ||
|
||||
line.RequestHeaders["accept"] != accept || len(line.RuleIDs) != 1 ||
|
||||
@@ -1260,7 +1261,7 @@ func TestReportWritesTheLastLineWithTheDecisionsAndTheReportsFields(t *testing.T
|
||||
got := s.report(discriminator.Report{
|
||||
RequestID: id, Status: http.StatusCreated,
|
||||
RequestBytes: bodyBytes, ResponseBytes: answerBytes,
|
||||
DurationTotal: 12.5, DurationUpstreamTotal: 10.25,
|
||||
DurationTotalMS: 12.5, DurationUpstreamTotalMS: 10.25,
|
||||
})
|
||||
wantStatus(t, got, http.StatusNoContent)
|
||||
|
||||
@@ -1305,7 +1306,7 @@ func TestEveryDeniedRequestsReportGetsItsLastLine(t *testing.T) {
|
||||
0, requestlog.ActionClientDenied,
|
||||
},
|
||||
{"own prefix", nil, discriminator.HealthPath, http.StatusNotFound,
|
||||
requestlog.ActionAdmin},
|
||||
requestlog.ActionOwnEndpoint},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -1317,7 +1318,7 @@ func TestEveryDeniedRequestsReportGetsItsLastLine(t *testing.T) {
|
||||
do(t, req)
|
||||
|
||||
got := s.report(discriminator.Report{
|
||||
RequestID: id, Status: tc.status, ResponseBytes: 8, DurationTotal: 3,
|
||||
RequestID: id, Status: tc.status, ResponseBytes: 8, DurationTotalMS: 3,
|
||||
})
|
||||
wantStatus(t, got, http.StatusNoContent)
|
||||
|
||||
@@ -1325,8 +1326,8 @@ func TestEveryDeniedRequestsReportGetsItsLastLine(t *testing.T) {
|
||||
wantLine(t, line, tc.status, tc.action)
|
||||
|
||||
if line.DiscriminatorLine != requestlog.DiscriminatorLineReport ||
|
||||
line.RequestID != id || line.ResponseBytes != 8 || line.DurationTotal != 3 ||
|
||||
line.DurationUpstreamTotal != nil {
|
||||
line.RequestID != id || line.ResponseBytes != 8 || line.DurationTotalMS != 3 ||
|
||||
line.DurationUpstreamTotalMS != nil {
|
||||
t.Errorf("the report's line is %+v", line.Line)
|
||||
}
|
||||
})
|
||||
@@ -1583,9 +1584,10 @@ func TestCoreRuleSetAlertNamesTheSite(t *testing.T) {
|
||||
wantDisposition(t, got, http.StatusForbidden, discriminator.DispositionDeny)
|
||||
|
||||
waiting := s.queue.Snapshot().Waiting[alerts.DestinationWebhook]
|
||||
if len(waiting) != 1 || waiting[0].Event != alerts.EventWAFBlock ||
|
||||
if len(waiting) != 1 || waiting[0].Event != alerts.EventCoreRuleSetMatch ||
|
||||
waiting[0].Host != siteA {
|
||||
t.Errorf("alerts waiting are %+v, want a waf_block naming %s", waiting, siteA)
|
||||
t.Errorf("alerts waiting are %+v, want a core_rule_set_match naming %s",
|
||||
waiting, siteA)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user