feat: configurable colour-coding/alert thresholds#26
Merged
Conversation
Externalise the previously hardcoded RTT/Jitter/Loss colour boundaries into a ui.Thresholds value that can be set via CLI flags or the YAML hosts file. warn = orange boundary, crit = red boundary. - ui.Thresholds type with DefaultThresholds() and Validate() (warn < crit, sane ranges); package-level activeThresholds applied once at Run() start - RunOptions.Thresholds threads the config into the TUI - CLI flags: --rtt-warn/--rtt-crit, --jitter-warn/--jitter-crit, --loss-warn/--loss-crit (defaults match previous constants) - YAML: thresholds: block (rtt-warn, rtt-crit, jitter-warn, jitter-crit, loss-warn, loss-crit), CLI flags override YAML - Validation at startup and on YAML reload (validateHostsDoc) - Tests for Validate(), colour fns under custom thresholds, flag/YAML precedence, and reload validation - README.md / README.ja.md updated (Options table, usage example, hosts.yaml block, colour-coding notes) Behaviour is unchanged by default — all defaults equal the prior constants.
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.
Summary
Externalises the previously hardcoded RTT / Jitter / Loss colour boundaries into a configurable
ui.Thresholdsvalue, settable via CLI flags or the YAML hosts file.warnis the orange boundary,critthe red boundary — the same values that drive the Loss Ratio / RTT / Jitter column colours and the Log-pane alert entries.Default behaviour is unchanged — every default equals the prior constant (RTT 50/200 ms, Jitter 10/50 ms, Loss 20/80 %).
Changes
internal/ui/thresholds.go— newThresholdstype withDefaultThresholds()andValidate()(enforceswarn < critand sane ranges). Package-levelactiveThresholdsapplied once atRun()startup (TUI renders single-threaded → no locking needed).RunOptions.Thresholdsthreads config into the TUI;tui_helpers.go/mtr_view.gocolour functions now readactiveThresholds.--rtt-warn/--rtt-crit,--jitter-warn/--jitter-crit,--loss-warn/--loss-crit.thresholds:block; CLI flags override YAML values per-field.validateHostsDoc).hosts.yamlblock, colour-coding notes.Design note
Color helpers are package-level and called from many render sites, so thresholds are stored in a package var set once at startup rather than threaded through every signature — minimal, low-risk diff. Tests swap
activeThresholdsto verify custom-threshold colouring.Test plan
go build ./...,go vet ./...go test ./... -race(all packages green)Thresholds.Validate()table-driven (warn≥crit, out-of-range, zero)thresholds:blockmping --rtt-warn 30 --rtt-crit 100 google.comand confirm colours shift at new boundaries