-
Notifications
You must be signed in to change notification settings - Fork 4
feat: fix graceful shutdown, add config validation #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
75fa690
feat: fix graceful shutdown, add config validation, Jaeger warning
ankurs 03f6a28
chore: update deps - errors v0.2.2, log v0.2.6, options v0.2.5, inter…
ankurs b7eb75f
fix: address review - guard force-stop, defer validation log, allow p…
ankurs 7f8ae04
fix: allow zero sampling ratio to mean "sample nothing"
ankurs 6fb6e71
test: harden validation tests - check conflict for port 0, assert war…
ankurs 197a1ae
fix: address review - handle grpc.ErrServerStopped, gate Jaeger warni…
ankurs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestValidateDefaults(t *testing.T) { | ||
| c := Config{ | ||
| GRPCPort: 9090, | ||
| HTTPPort: 9091, | ||
| ShutdownDurationInSeconds: 15, | ||
| HealthcheckWaitDurationInSeconds: 7, | ||
| } | ||
| warnings := c.Validate() | ||
| if len(warnings) > 0 { | ||
| t.Errorf("default config should have no warnings, got: %v", warnings) | ||
| } | ||
| } | ||
|
|
||
| func TestValidatePortZero(t *testing.T) { | ||
| // Port 0 means ephemeral — should be valid | ||
| c := Config{GRPCPort: 0, HTTPPort: 0} | ||
| warnings := c.Validate() | ||
| for _, w := range warnings { | ||
| if strings.Contains(w, "Port") && strings.Contains(w, "range") { | ||
| t.Errorf("port 0 should be valid, got warning: %s", w) | ||
| } | ||
| if strings.Contains(w, "port conflict") { | ||
| t.Errorf("port 0 should not warn about conflict, got warning: %s", w) | ||
| } | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| func TestValidatePortConflict(t *testing.T) { | ||
| c := Config{GRPCPort: 8080, HTTPPort: 8080} | ||
| warnings := c.Validate() | ||
| found := false | ||
| for _, w := range warnings { | ||
| if strings.Contains(w, "port conflict") { | ||
| found = true | ||
| } | ||
| } | ||
| if !found { | ||
| t.Error("same non-zero ports should warn about conflict") | ||
| } | ||
| } | ||
|
|
||
| func TestValidateSamplingRatio(t *testing.T) { | ||
| c := Config{ | ||
| GRPCPort: 9090, | ||
| HTTPPort: 9091, | ||
| NewRelicOpentelemetrySample: 1.5, | ||
| OTLPSamplingRatio: -0.1, | ||
| } | ||
| warnings := c.Validate() | ||
| foundNR := false | ||
| foundOTLP := false | ||
| for _, w := range warnings { | ||
| if strings.Contains(w, "NewRelicOpentelemetrySample") { | ||
| foundNR = true | ||
| } | ||
| if strings.Contains(w, "OTLPSamplingRatio") { | ||
| foundOTLP = true | ||
| } | ||
| } | ||
| if !foundNR || !foundOTLP { | ||
| t.Errorf("expected warnings for both sampling fields, got: %v", warnings) | ||
| } | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| func TestValidateTLSMismatch(t *testing.T) { | ||
| c := Config{ | ||
| GRPCPort: 9090, | ||
| HTTPPort: 9091, | ||
| GRPCTLSCertFile: "/path/to/cert", | ||
| // GRPCTLSKeyFile intentionally empty | ||
| } | ||
| warnings := c.Validate() | ||
| found := false | ||
| for _, w := range warnings { | ||
| if strings.Contains(w, "TLS") { | ||
| found = true | ||
| } | ||
| } | ||
| if !found { | ||
| t.Error("mismatched TLS cert/key should produce a warning") | ||
| } | ||
| } | ||
|
|
||
| func TestValidateShutdownTiming(t *testing.T) { | ||
| c := Config{ | ||
| GRPCPort: 9090, | ||
| HTTPPort: 9091, | ||
| ShutdownDurationInSeconds: 5, | ||
| HealthcheckWaitDurationInSeconds: 10, | ||
| } | ||
| warnings := c.Validate() | ||
| found := false | ||
| for _, w := range warnings { | ||
| if strings.Contains(w, "HealthcheckWaitDurationInSeconds") { | ||
| found = true | ||
| } | ||
| } | ||
| if !found { | ||
| t.Error("healthcheck duration >= shutdown duration should produce a warning") | ||
| } | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.