Replace the failed-enrolls counter with reported osquery errors - #988
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the failed-enrolls counter with reported osquery errors
The dashboard's "Failed enrolls (24h)" tile read the audit log and filtered client-side for lines starting with
failed enroll. It's replaced by "Reported errors (24h)" — status logs the fleet sent at osquery's ERROR severity — surfaced across the dashboard, the nodes table and the node detail page.Errors only. osquery's ladder is 0=INFO, 1=WARNING, 2=ERROR, and warnings are routine enough (a table unavailable on the platform, a transient permission issue) that counting them would keep the tile permanently lit and train people to ignore it.
Counted at ingest, not at read time
The obvious implementation —
COUNT(*) FROM osquery_status_data WHERE created_at > now()-24h AND severity != '0'— breaks on three things:logger.typeset tos3,splunk,kafka,graylogorelastic, that table is empty and the tile would read a permanent zero.OsqueryStatusDataindexes onlyUUID;gorm.Modeldoesn't indexCreatedAt. That's a full scan of the highest-volume table, every dashboard load, every 5 minutes.Severityis stored as a string, soseverity > '1'is a string comparison — an easy silent bug.Instead osctrl-tls tallies ERROR entries per status batch and increments the existing Redis activity rollup (
pkg/activity). O(1) per log, correct under every log sink, and the dashboard read becomes O(1). The count runs inside the goroutine that already callsProcessLogs, so it stays off the request hot path.No key migration.
bitOffsetis linear in the event-type index anddecodeDayis bounds-checked, so appendingEventStatusErrorat index 6 leaves every existing counter at its offset — old blobs simply decode the new type as zero.EventTypeCountnow carries a comment recording why new types must be appended, never inserted.Drill-down: which nodes are erroring
Reading every node's series to answer this would scale with fleet size, for a question whose answer is a handful of nodes. The write path also does a
ZINCRBYinto a per-env, per-day sorted set, soTopErrorNodesis aZREVRANGE— cost scales with the number of erroring nodes. Only errors pay for it, and only when there are any.GET /api/v1/stats/activity/error-nodes/{env}returns the worst 10 with hostnames resolved; a node deleted since it errored keeps its row and shows by UUID. Clicking the tile opens a dialog listing them, each linking to the node.The tile only becomes a
<button>when there's something behind it — keyboard-reachable and announced as interactive — and stays a plain<div>at zero.Where errors show up
errorsrow alongside status/result/query/config, plus a count badge in the headerNew
--error-brighttoken (#ff4d4fdark /#f01c1clight), deliberately hotter than--danger, which is already used for softer degraded-but-expected states. Every red surface stays neutral at zero — a permanently red panel is one nobody reads.Errors are excluded from every "total" (activity
Totalseries, the heatmap'stotalEvents): they're a subset of the status traffic already counted, so including them would claim the node sent more events than it did.Bugs caught during the work
ReadSerieshad a duplicated fill loop. The per-node path didn't sharefillSerieswithReadEnvSeries, so per-node error counts would have silently read zero — and the drill-down is built on exactly that path. Both now share it.config.mergeNodeActivityBucketsbounded its alignment loop byconfig.length; it now takes the max across all Redis series, so a payload withstatus_errorbut noconfigstill aligns instead of reading zero.Changes
pkg/activity—EventStatusError,StatusErrorseries,ErrorRankKey,TopErrorNodescmd/tls/handlers—countStatusErrors,recordActivityCount, wired into the log POST pathcmd/api/handlers/stats.go,cmd/api/main.go—EnvErrorNodesHandler+ routefrontend/— API client, dashboard tile/chart/panel, nodes-table lane, node-detail row,--error-brightosctrl-api.yamlregeneratedTesting
Totalnot double-counting.pkg/activitytests gainedZINCRBY/ZREVRANGEsupport — it's a hand-rolled RESP server that only implemented the commands used so far.go build/go vet/go test,make openapi-check, frontend 265 tests,tsc.