Skip to content

Commit 9d2ada4

Browse files
authored
Fix moderation guidance, warning event counts, and idle-day collection (#1900)
The malware report email now gives a separate action for confirmed malware, a missing package, and an unchecked release. An unchecked release calls for verifying and pinning the intended version. The Grafana warning chart counts each Kubernetes event UID and count once per reason in each ten-minute bucket. The revised query returned 124 distinct updates in a production window containing 1,522 log records. Both hosted Grafana instances loaded the corrected dashboard, and the report policies in both projects now carry the revised instructions. The usage collector records a verified idle day in the existing daily table. It stores zero volumes, no breakdown rows and NULL percentages. The missed-day alert already reads this table. Future scheduled runs skip the day. A positive byte counter, missing counter evidence, or an inconclusive log sample cannot establish a zero-traffic day. The usage collector tests ran against disposable PostgreSQL 17 with the race detector. The deployment Go tests passed. Production receives the collector fix when a release containing this change is promoted.
1 parent 65f726a commit 9d2ada4

8 files changed

Lines changed: 67 additions & 30 deletions

File tree

‎cmd/usage-collector/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ A day is normally **not collected** if something it needs could not be used: the
184184

185185
To collect a degraded day at any other time, name it with `--day` and add `--allow-degraded`. That also applies without the request counters; the read is sized the same way.
186186

187-
**Days with nothing to collect.** A day is skipped, without failing the run and without storing anything, when all of this holds: the gateway's request counter has series that day, they show no registry request, and none of the day's access records is a registry request. The last is checked by reading every record of the day, not a sample; a day with more than twice `MAX_RECORDS` records is not skipped, because not all of them are looked at. A day for which neither the counters nor Cloud Logging hold anything at all is different: that cannot be told from a collector pointed at the wrong place, so it fails like any day without counters. And when the counters did count requests but the whole day holds no access record of one, the day fails too: the records are somewhere the log settings do not point, or were not written.
187+
**Days with nothing to collect.** The collector stores a zero-traffic day when the gateway's counters were recorded and show no registry traffic, and a full log read confirms there were no registry requests. It stores zero volumes, empty breakdowns and undefined percentages. The day counts toward the freshness check and future scheduled runs skip it. A day with more than twice `MAX_RECORDS` records cannot be confirmed idle by this check. A day for which neither the counters nor Cloud Logging hold anything at all is different: that cannot be told from a collector pointed at the wrong place, so it fails like any day without counters. And when the counters did count requests but the whole day holds no access record of one, the day fails too: the records are somewhere the log settings do not point, or were not written.
188188

189189
## Privacy
190190

‎deploy/pkg/k8s/dashboards/registry-deployment-critical-issues.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"type": "victoriametrics-logs-datasource",
6565
"uid": "PD775F2863313E6C7"
6666
},
67-
"description": "Kubernetes events of type Warning about the registry's own objects (pods, jobs, autoscaler), counted in 10-minute steps. Events about nodes are left out; the node panel below covers the ones that matter. Events are collected for the default namespace only.",
67+
"description": "Updates to Kubernetes Warning events about the registry's objects (pods, jobs, autoscaler). Each event UID and count is counted once per 10-minute interval, even when several collectors record it. Events about nodes are left out; the node panel below covers the ones that matter. Events are collected for the default namespace only.",
6868
"fieldConfig": {
6969
"defaults": {
7070
"color": {
@@ -117,14 +117,14 @@
117117
"uid": "PD775F2863313E6C7"
118118
},
119119
"editorMode": "code",
120-
"expr": "severity:Warning k8s.namespace.name:* | stats by (k8s.event.reason) count() as events",
120+
"expr": "severity:Warning k8s.namespace.name:* | stats by (k8s.event.reason) count_uniq(k8s.event.uid, k8s.event.count) as events",
121121
"legendFormat": "{{k8s.event.reason}}",
122122
"queryType": "statsRange",
123123
"refId": "A",
124124
"step": "10m"
125125
}
126126
],
127-
"title": "Warning events per 10 minutes, by reason",
127+
"title": "Warning event updates per 10 minutes, by reason",
128128
"type": "timeseries"
129129
},
130130
{

‎internal/usage/aggregate.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,21 @@ func (s *Sample) row(b breakdown, name string, members []*group, kind string, ro
231231
return out
232232
}
233233

234+
// idleTotals records zero volumes for a day verified against counters and the
235+
// full access log. Percentages and drift ratios have no denominator.
236+
func (s *Sample) idleTotals() Daily {
237+
zero, agents := 0.0, 0
238+
source := totalsMixed // Requests from the counter, zero bytes from the full log.
239+
if s.counters.hasBytes {
240+
source = totalsFromCounters
241+
}
242+
return Daily{
243+
Day: s.Start, UserAgents: &agents, TotalsSource: source, SampleFraction: 1,
244+
BackgroundCount: s.background, ListingRequests: &zero, ListingGiB: &zero,
245+
CompressionKnownRequests: &zero, CompressionKnownGiB: &zero,
246+
}
247+
}
248+
234249
// Rows turns the day into what is stored: its totals and every breakdown.
235250
func (s *Sample) Rows() (Daily, []Share) {
236251
a := s.analyse()

‎internal/usage/collect.go‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ func (c *dayCollector) dayTotals(ctx context.Context) (gatewayTotals, error) {
408408
// and show no registry request. Counters with no data at all are a different
409409
// thing: that cannot be told from looking in the wrong place.
410410
func (c *dayCollector) idle(ctx context.Context) bool {
411-
if !c.sample.counters.hasRequests || c.sample.counters.requests != 0 {
411+
if !c.sample.counters.hasRequests || c.sample.counters.requests != 0 || c.sample.counters.bytes != 0 {
412412
return false
413413
}
414414
rows, err := c.sources.Metrics.Query(ctx, fmt.Sprintf("count(last_over_time(%s[%ds]))", requestsMetric, daySeconds), c.sample.End)
@@ -422,14 +422,17 @@ func (c *dayCollector) idle(ctx context.Context) bool {
422422
// with more records than a read may return.
423423
func (c *dayCollector) noRegistryRecord(ctx context.Context) (bool, error) {
424424
limit := readCapFactor * c.limits.MaxRecords
425-
seen, found := 0, false
425+
seen, background := 0, 0
426426
window := LogWindow{Start: c.sample.Start, End: c.sample.End, Fraction: 1}
427427
err := c.sources.Logs.Read(ctx, window, func(_ string, payload map[string]any) error {
428428
seen++
429-
if registry, _ := registryRecord(payload); registry {
430-
found = true
429+
registry, isBackground := registryRecord(payload)
430+
if registry {
431431
return errStopRead
432432
}
433+
if isBackground {
434+
background++
435+
}
433436
if limit > 0 && seen > limit {
434437
return errOverflow
435438
}
@@ -444,7 +447,8 @@ func (c *dayCollector) noRegistryRecord(ctx context.Context) (bool, error) {
444447
case err != nil:
445448
return false, err
446449
}
447-
return !found, nil
450+
c.sample.background = background
451+
return true, nil
448452
}
449453

450454
// read reads the day's access records, whole if they fit the limit and as a

‎internal/usage/run.go‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,30 +233,33 @@ func (c *Collector) collect(ctx context.Context, day time.Time) error {
233233
limits := c.Limits
234234
limits.Require = c.tolerance(day)
235235
sample, err := CollectDay(ctx, c.Sources, limits, day)
236-
if err != nil && !errors.Is(err, ErrNoRecords) && !errors.Is(err, ErrNoTraffic) {
236+
idle := errors.Is(err, ErrNoTraffic)
237+
if err != nil && !idle && !errors.Is(err, ErrNoRecords) {
237238
return err
238239
}
239240
if reportErr := c.report(sample); reportErr != nil {
240241
return reportErr
241242
}
242-
if errors.Is(err, ErrNoTraffic) {
243-
// Nothing is stored, so the day is looked at again while it is in the
244-
// look-back window. That costs one read of its dashboard and
245-
// background records.
246-
c.logf("%s has nothing to collect: %v", day.Format(dayLayout), err)
243+
if err != nil && !idle {
244+
return err
245+
}
246+
if c.Store == nil {
247247
return nil
248248
}
249-
if err != nil || c.Store == nil {
250-
return err
249+
var daily Daily
250+
var shares []Share
251+
if idle {
252+
daily = sample.idleTotals()
253+
} else {
254+
daily, shares = sample.Rows()
251255
}
252-
daily, shares := sample.Rows()
253256
if err := c.Store.ReplaceDay(ctx, daily, shares, c.Options.Version, c.now()); err != nil {
254257
return fmt.Errorf("could not store the day: %w", err)
255258
}
256259
c.logf("stored %s: %d requests, %.1f GiB, %d rows from %d records; log estimate vs counters: requests %s, data %s",
257260
day.Format(dayLayout), daily.Requests, daily.GiB, len(shares), daily.RecordsSampled,
258261
ratioOrUnknown(daily.LogRequestsRatio), ratioOrUnknown(daily.LogDataRatio))
259-
if missing := sample.Degraded(); len(missing) > 0 {
262+
if missing := sample.Degraded(); !idle && len(missing) > 0 {
260263
c.logf("%s was stored without %s; see its caveats", day.Format(dayLayout), strings.Join(missing, " and "))
261264
}
262265
return nil

‎internal/usage/run_internal_test.go‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,8 @@ func (idleMetrics) Query(_ context.Context, query string, _ time.Time) ([]Metric
248248
return nil, nil
249249
}
250250

251-
// TestRunSkipsADayWithoutTraffic covers a day on which the gateway served the
252-
// registry nothing: its counters were recorded and show no request, and there
253-
// are no access records. That is not a failure, and nothing is stored for it.
254-
func TestRunSkipsADayWithoutTraffic(t *testing.T) {
251+
// A verified idle day counts toward freshness and is read only once.
252+
func TestRunStoresADayWithoutTraffic(t *testing.T) {
255253
f := newFixture(t, "empty")
256254
f.sources.Metrics = idleMetrics{}
257255
store := newStore(t, newDatabase(t))
@@ -260,8 +258,13 @@ func TestRunSkipsADayWithoutTraffic(t *testing.T) {
260258
collector.Lookback = 1
261259

262260
require.NoError(t, collector.Run(t.Context()))
263-
assert.Empty(t, storedDays(t, store))
264-
assert.Contains(t, f.log.String(), "2026-10-06 has nothing to collect: the gateway counted no registry requests and no access record shows one")
261+
require.Equal(t, []string{"2026-10-06"}, storedDays(t, store))
262+
var idle bool
263+
require.NoError(t, store.pool.QueryRow(t.Context(), `SELECT requests = 0 AND gib = 0 AND listing_requests = 0
264+
AND listing_gib = 0 AND sample_fraction = 1 AND cache_hit_pct IS NULL AND log_requests_ratio IS NULL
265+
AND NOT EXISTS (SELECT 1 FROM usage_share) FROM usage_daily`).Scan(&idle))
266+
require.True(t, idle)
267+
require.NoError(t, collector.Run(t.Context()))
265268
assert.Equal(t, 1, f.gateway.logCalls, "one unsampled read")
266269
report, err := os.ReadFile(filepath.Join(reports, "2026-10-06.md"))
267270
require.NoError(t, err)

‎internal/usage/sizing_internal_test.go‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,10 +587,19 @@ func TestDayWithoutRegistryTraffic(t *testing.T) {
587587
day := idleDay(300)
588588
sample, _, err := day.collect(t, CompleteDay)
589589
require.ErrorIs(t, err, ErrNoTraffic)
590+
assert.Equal(t, 150, sample.idleTotals().BackgroundCount)
590591
assert.Contains(t, sample.Markdown(), "No access records were found for this period.")
591592
assert.Equal(t, []syntheticRead{{fraction: 1, delivered: 300}}, day.reads, "every record of the day is looked at, once")
592593
})
593594

595+
t.Run("positive byte counter rules out a zero-traffic day", func(t *testing.T) {
596+
day := idleDay(300)
597+
day.bytes = 5000
598+
_, _, err := day.collect(t, CompleteDay)
599+
require.Error(t, err)
600+
require.NotErrorIs(t, err, ErrNoTraffic)
601+
})
602+
594603
t.Run("counters without any data are not proof of an idle day", func(t *testing.T) {
595604
day := idleDay(300)
596605
day.unrecorded = true

‎tools/admin/configure-malware-alerts.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ def report_policy(name, label, severity, condition, when):
6868
"mimeType": "text/markdown",
6969
"content": "${log.extracted_label.summary}\n\n"
7070
"The whole list, one line for each entry, is in the newest registry-malware-sweep Job's log in "
71-
"default: lines starting with REGISTRY_MALWARE_SWEEP_HIT (points at known malware), "
72-
"REGISTRY_MALWARE_SWEEP_MISSING (its package is gone from its registry) and "
73-
"REGISTRY_MALWARE_SWEEP_UNCHECKED (names no release that can be checked). Confirm each, then take "
74-
"the version down with tools/admin/takedown.sh. Do not discuss an entry in public before it is "
75-
"down. See docs/administration/admin-operations.md, Malware checks, in modelcontextprotocol/registry.",
71+
"default. Review the REGISTRY_MALWARE_SWEEP_ lines by finding type.\n\n"
72+
"- HIT: Confirm the OSV record and the release named by the entry. Take down each affected version.\n"
73+
"- MISSING: Confirm the package is gone upstream. Check for a working install or remote before "
74+
"taking down affected versions.\n"
75+
"- UNCHECKED: Verify the intended release and edit the entry to pin its exact version. If the same "
76+
"package is also reported MISSING, follow the missing-package steps.\n\n"
77+
"Keep findings private during review. See docs/administration/admin-operations.md, Malware checks, "
78+
"in modelcontextprotocol/registry.",
7679
},
7780
}
7881

0 commit comments

Comments
 (0)