Add marks parameter for subset test selection - #1054
Conversation
This change introduces a minimal util.Logger interface (Printf, Fatalf) as a first step toward decoupling goss from the standard library's global log package. It addresses some friction reported in goss-org#544 around using goss as a library, and provides a path toward resolving goss-org#991 where log level filtering doesn't catch all messages. What this improves: - Tests can now run with t.Parallel() without racing on log.SetOutput; TestLogger captures output per-test with goroutine-safe buffer - Library consumers can inject custom log sinks via util.WithLogger(), including filtered loggers that could address goss-org#991 - Data races are fixed in: color.NoColor (sync.Once), store.go globals (RWMutex), and format.UseStringerRepresentation (sync.Once) The approach keeps most API signatures stable - core functions return warnings as values and edge layers handle logging. WriteJSON now returns (string, error) to surface its warning message, which is the one public API change. New files: - util/logger.go: interface and DefaultLogger/TestLogger implementations - util/logger_test.go: unit tests including concurrent write coverage - util/color_init.go: shared InitNoColor for race-free color disable This doesn't fully resolve goss-org#544 (os.Exit remains in some paths) or goss-org#991 (a filtered logger would need to be provided), but it removes blockers and provides seams for both library embeddability and log control.
Adds a new top-level 'marks' field ([]string) on all resource types and CLI/HTTP filtering options. Addresses goss-org#544 (library usage improvements) and provides foundation for goss-org#991 (log level filtering). Usage: goss validate --marks critical,fast goss validate --exclude-marks slow,flaky goss serve --marks critical # overridable via ?marks= query param Backward Compatibility: - Resources without marks run by default (existing gossfiles unaffected) - Empty marks omitted from JSON output to avoid schema churn - When filters exclude all tests, goss exits 0 with "all skipped" output, consistent with DisabledResourceTypes behavior Why this matters: - Selective alerting: run only critical checks in production - Incident response: filter by category (network, storage, etc.) - Flaky test quarantine: exclude known-broken tests from CI gates - Resource constraints: skip memory/CPU-heavy checks under pressure Filter semantics: - --marks: include only resources with at least one matching mark - --exclude-marks: skip resources with any matching mark - Inclusion evaluated before exclusion when both specified Implementation highlights: - Cache keys encode mark filter to prevent cross-contamination - Query params override server-config without mutating shared state - Skip-state snapshot/restore under gossMu for serve-mode safety - Marks preserved across gossfile re-parses (with Title/Meta) Tests: 382 lines across marks_test.go, validate_marks_test.go, serve_marks_test.go, config_test.go covering round-trip serialization, filter logic, HTTP endpoint, cache isolation, and concurrency safety.
- Add SetMarks() to ResourceRead interface (all 16 resource types) - goss add/autoadd --marks flag for auto-tagging new resources - Debug logging for mark filter summary when -L DEBUG set - README section on marks usage with CLI and HTTP examples The --marks flag on add commands only applies to newly created resources; existing marks in the gossfile are preserved.
|
I managed to resolve all the merge conflicts, but it's now hitting some linter errors. |
|
@dukelion I've fixed the two linter issues I introduced by accident when I was resolving the merge conflict, as well as a number of others that cropped up. While the tests are all passing, I'd appreciate if you'd take a look over things yourself (especially c773da4) to make sure I haven't missed anything. |
|
@kgaughan thanks for your fixes! |
|
I think that would actually be a good thing! It'd nice to have the two changes decoupled, so go for it! |
|
I would guess one of the things you're looking to do is to bundle up |
|
Regarding logging, I've been mulling over the idea of switching to using |
|
Extracted first part. Its somewhat helps with log/slog migration and closes #991 by coincidence. |
|
#1092 is merged, so you should be good to go with the marks PR. Thanks! |
|
Some bad news: after the merge, some tests started failing. Here's an excerpt: Here's the run: https://github.com/goss-org/goss/actions/runs/30939164511/job/92092838295 |
|
I've given the pipeline run another kick: it might fail in interesting ways that'll help diagnose the issue. |
|
Here's the traceback from the second run: Link: https://github.com/goss-org/goss/actions/runs/30939164511/job/92103079669 |
Add
marksparameter for subset test selectionSummary
This PR introduces a
marksfeature that allows users to tag resources and run only specific subsets of tests, similar to pytest's-mflag. This enables more flexible test workflows in CI/CD and local development.Changes
Core Feature:
Marks []stringfield to all 16 resource types (addr, command, dns, file, gossfile, group, http, interface, kernel_param, matching, mount, package, port, process, service, user)--marksand--exclude-marksCLI flags forvalidateandservecommands?marks=and?exclude_marks=query parameters to HTTP endpoints--marksflag togoss addandgoss autoaddcommands for tagging new resourcesInfrastructure:
-L DEBUG)Usage
Testing
go test -race -count=3 ./...Related
📚 Documentation preview 📚: https://goss--1054.org.readthedocs.build/en/1054/