-
Notifications
You must be signed in to change notification settings - Fork 493
Complete the implementation of moving panics to the Error log level #353
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
8 commits
Select commit
Hold shift + click to select a range
eab686b
cleanup panic logging flag
jbardin ae1c247
add Panic to grpc test service
jbardin 319bdff
update impls with new Panic method
jbardin 0b2553f
test that server panics go to ERROR
jbardin 1063208
CHANGELOG
jbardin 4f14af6
fix test plugin mapping
jbardin 6a167cc
use Debug for logger test to avoid timed output
jbardin a5ada4b
Use buf to generate test proto (#354)
jbardin 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
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 |
|---|---|---|
|
|
@@ -1443,7 +1443,7 @@ func TestClient_mtlsNetRPCClient(t *testing.T) { | |
| } | ||
|
|
||
| func TestClient_logger(t *testing.T) { | ||
| t.Run("net/rpc", func(t *testing.T) { testClient_logger(t, "netrpc") }) | ||
| t.Run("netrpc", func(t *testing.T) { testClient_logger(t, "netrpc") }) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is solely for test ergonomics, the extra |
||
| t.Run("grpc", func(t *testing.T) { testClient_logger(t, "grpc") }) | ||
| } | ||
|
|
||
|
|
@@ -1454,16 +1454,21 @@ func testClient_logger(t *testing.T, proto string) { | |
| // Custom hclog.Logger | ||
| clientLogger := hclog.New(&hclog.LoggerOptions{ | ||
| Name: "test-logger", | ||
| Level: hclog.Trace, | ||
| Level: hclog.Debug, | ||
| Output: stderr, | ||
| Mutex: mutex, | ||
| }) | ||
|
|
||
| plugins := map[string]map[string]Plugin{ | ||
| "netrpc": testPluginMap, | ||
| "grpc": testGRPCPluginMap, | ||
| } | ||
|
|
||
| process := helperProcess("test-interface-logger-" + proto) | ||
| c := NewClient(&ClientConfig{ | ||
| Cmd: process, | ||
| HandshakeConfig: testHandshake, | ||
| Plugins: testGRPCPluginMap, | ||
| Plugins: plugins[proto], | ||
| Logger: clientLogger, | ||
| AllowedProtocols: []Protocol{ProtocolNetRPC, ProtocolGRPC}, | ||
| }) | ||
|
|
@@ -1486,7 +1491,7 @@ func testClient_logger(t *testing.T, proto string) { | |
| t.Fatalf("bad: %#v", raw) | ||
| } | ||
|
|
||
| { | ||
| t.Run("-1", func(t *testing.T) { | ||
| // Discard everything else, and capture the output we care about | ||
| mutex.Lock() | ||
| buffer.Reset() | ||
|
|
@@ -1502,9 +1507,9 @@ func testClient_logger(t *testing.T, proto string) { | |
| if !strings.Contains(line, "foo=bar") { | ||
| t.Fatalf("bad: %q", line) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| { | ||
| t.Run("-2", func(t *testing.T) { | ||
| // Try an integer type | ||
| mutex.Lock() | ||
| buffer.Reset() | ||
|
|
@@ -1520,7 +1525,7 @@ func testClient_logger(t *testing.T, proto string) { | |
| if !strings.Contains(line, "foo=12") { | ||
| t.Fatalf("bad: %q", line) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| // Kill it | ||
| c.Kill() | ||
|
|
@@ -1535,6 +1540,84 @@ func testClient_logger(t *testing.T, proto string) { | |
| } | ||
| } | ||
|
|
||
| func TestServerLogPanic(t *testing.T) { | ||
| var buffer bytes.Buffer | ||
| mutex := new(sync.Mutex) | ||
| stderr := io.MultiWriter(os.Stderr, &buffer) | ||
| // Custom hclog.Logger | ||
| clientLogger := hclog.New(&hclog.LoggerOptions{ | ||
| Name: "test-logger", | ||
| Level: hclog.Error, | ||
| Output: stderr, | ||
| Mutex: mutex, | ||
| }) | ||
|
|
||
| process := helperProcess("test-interface-logger-grpc") | ||
| c := NewClient(&ClientConfig{ | ||
| Cmd: process, | ||
| HandshakeConfig: testHandshake, | ||
| Plugins: testGRPCPluginMap, | ||
| Logger: clientLogger, | ||
| AllowedProtocols: []Protocol{ProtocolNetRPC, ProtocolGRPC}, | ||
| }) | ||
| defer c.Kill() | ||
|
|
||
| // Grab the RPC client | ||
| client, err := c.Client() | ||
| if err != nil { | ||
| t.Fatalf("err should be nil, got %s", err) | ||
| } | ||
|
|
||
| // Grab the impl | ||
| raw, err := client.Dispense("test") | ||
| if err != nil { | ||
| t.Fatalf("err should be nil, got %s", err) | ||
| } | ||
|
|
||
| impl, ok := raw.(testInterface) | ||
| if !ok { | ||
| t.Fatalf("bad: %#v", raw) | ||
| } | ||
|
|
||
| mutex.Lock() | ||
| buffer.Reset() | ||
| mutex.Unlock() | ||
| err = impl.Panic("invalid foo bar") | ||
| time.Sleep(100 * time.Millisecond) | ||
| mutex.Lock() | ||
|
|
||
| panicFound := false | ||
| stackLines := 0 | ||
|
|
||
| for _, line := range strings.Split(buffer.String(), "\n") { | ||
| if strings.Contains(line, "[ERROR] test-logger.go-plugin.test: panic: invalid foo bar") { | ||
| panicFound = true | ||
| continue | ||
| } | ||
|
|
||
| // make sure we are not just capturing the panic line, and have the rest | ||
| // of the output too | ||
| if panicFound { | ||
| // there should only be [ERROR] lines past this point, but the log | ||
| // level is Error, so we can just verify there are lines | ||
| stackLines++ | ||
| } | ||
| } | ||
|
|
||
| if !panicFound { | ||
| t.Fatal("failed to find panic in error log output") | ||
| } | ||
|
|
||
| if stackLines < 10 { | ||
| t.Fatalf("only found %d stack lines after panic", stackLines) | ||
| } | ||
|
|
||
| mutex.Unlock() | ||
| if err == nil { | ||
| t.Fatal("expected error due to panic") | ||
| } | ||
| } | ||
|
|
||
| // Test that we continue to consume stderr over long lines. | ||
| func TestClient_logStderr(t *testing.T) { | ||
| stderr := bytes.Buffer{} | ||
|
|
||
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,14 @@ | ||
| # Copyright (c) HashiCorp, Inc. | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| version: v1 | ||
| plugins: | ||
| - plugin: buf.build/protocolbuffers/go | ||
| out: . | ||
| opt: | ||
| - paths=source_relative | ||
| - plugin: buf.build/grpc/go:v1.3.0 | ||
| out: . | ||
| opt: | ||
| - paths=source_relative | ||
| - require_unimplemented_servers=false |
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,4 @@ | ||
| # Copyright (c) HashiCorp, Inc. | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| version: v1 |
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.