Log sink categories: route different data classes to different sinks - #998
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.
Log sink categories: route different data classes to different sinks
Problem
Every configured log sink received every type of osquery data — status logs, scheduled-query results, on-demand query results, and carve lifecycle events. Operators could not say "send status logs to Splunk but keep results in the DB" or "route carve metadata to Kafka only." Adding a second sink meant both got the full firehose.
Change
Added per-sink category routing so operators choose which data classes each sink receives. Five categories are supported:
statusresultquerycarve.metacarve.dataBackend:
pkg/logsinks/categories.go(new): category constants,MatchesCategory,ValidateCategories,NormalizeCategories(collapses explicit "all five" to empty),DecodeCategories/encodeCategorieshelperspkg/logsinks/logsinks.go: AddedCategoriestext column toLogSinkmodel (JSON-encoded array; empty = all).Create/Updateaccept and validate categories.CloneEnvironmentcopies them.BuildExporterspasses them toExporterEntrypkg/logging/exporter.go: AddedCategoriestoExporterEntry.MultiExporterstores a parallel categories slice and skips exporters whose categories don't match the incominglogTypeinExport(nil/empty = all, backwards-compatible)cmd/tls/handlers/carves.go:ProcessCarveWrite/ProcessCarveInit/ProcessCarveBlocknow emitcarve.metaandcarve.dataevents viaLoggerTLS.LogWithEnvso external sinks can track carve lifecycle. Raw block data is NOT sent through the fan-out — it stays in the DB/S3 viapkg/carvespkg/types/types.go: AddedCategoriestoLogSinkCreateRequest,LogSinkUpdateRequest,LogSinkTypeSpeccmd/api/handlers/log_sinks.go: AddedCategoriestologSinkDTO; create/update handlers pass categories through; types endpoint advertisesAllCategoriesFrontend:
frontend/src/api/log-sinks.ts: AddedcategoriestoLogSink, create/update request types, andLogSinkTypeSpecfrontend/src/features/log-sinks/LogSinksPage.tsx: Categories checkbox section in the sink editor (All checkbox + individual category toggles). New Destination column in the table showing color-coded category badges per sink — "all" badge when unscoped, individual badges when categories are explicitly setMigration:
Categoriesis a new nullable text column added byAutoMigrate. Existing rows get""= all categories — no behavior change. No YAML changes; seeded sinks get empty categories. Rollback by clearing the column.Validation
go test ./pkg/logsinks/...—TestMatchesCategory*,TestValidateCategories,TestNormalizeCategories,TestEncodeDecodeCategories,TestCreateWithCategories,TestUpdateWithCategories,TestCreateRejectsInvalidCategory,TestClonePreservesCategoriesgo test ./pkg/logging/...—TestMultiExporterCategoryFilteringverifies status-only, all, and query+result sinks receive the correct logTypesgo test ./pkg/... ./cmd/...— full Go test suite passes (no regressions)npm run check— TypeScript typecheck passesnpm run test— 292 frontend tests pass (no regressions)