Skip to content

Commit 522b65d

Browse files
committed
bump hashicorp/go-plugin v1.7.0
1 parent 6498ff3 commit 522b65d

File tree

5 files changed

+43
-20
lines changed

5 files changed

+43
-20
lines changed

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/google/uuid v1.6.0
2121
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
2222
github.com/hashicorp/go-hclog v1.6.3
23-
github.com/hashicorp/go-plugin v1.6.3
23+
github.com/hashicorp/go-plugin v1.7.0
2424
github.com/iancoleman/strcase v0.3.0
2525
github.com/invopop/jsonschema v0.13.0
2626
github.com/jackc/pgx/v4 v4.18.3
@@ -83,7 +83,6 @@ require (
8383
github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59 // indirect
8484
github.com/bahlo/generic-list-go v0.2.0 // indirect
8585
github.com/beorn7/perks v1.0.1 // indirect
86-
github.com/bufbuild/protocompile v0.14.1 // indirect
8786
github.com/buger/goterm v1.0.4 // indirect
8887
github.com/buger/jsonparser v1.1.1 // indirect
8988
github.com/cenkalti/backoff/v5 v5.0.2 // indirect
@@ -112,7 +111,6 @@ require (
112111
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
113112
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
114113
github.com/jackc/pgtype v1.14.4 // indirect
115-
github.com/jhump/protoreflect v1.15.3 // indirect
116114
github.com/json-iterator/go v1.1.12 // indirect
117115
github.com/klauspost/compress v1.18.0 // indirect
118116
github.com/klauspost/cpuid/v2 v2.2.10 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026 h1:BpJ2o0OR5FV7vrkDYf
143143
github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026/go.mod h1:5Scbynm8dF1XAPwIwkGPqzkM/shndPm79Jd1003hTjE=
144144
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
145145
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
146-
github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0UUrwg=
147-
github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0=
146+
github.com/hashicorp/go-plugin v1.7.0 h1:YghfQH/0QmPNc/AZMTFE3ac8fipZyZECHdDPshfk+mA=
147+
github.com/hashicorp/go-plugin v1.7.0/go.mod h1:BExt6KEaIYx804z8k4gRzRLEvxKVb+kn0NMcihqOqb8=
148148
github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8=
149149
github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns=
150150
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
@@ -202,8 +202,8 @@ github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0f
202202
github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
203203
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
204204
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
205-
github.com/jhump/protoreflect v1.15.3 h1:6SFRuqU45u9hIZPJAoZ8c28T3nK64BNdp9w6jFonzls=
206-
github.com/jhump/protoreflect v1.15.3/go.mod h1:4ORHmSBmlCW8fh3xHmJMGyul1zNqZK4Elxc8qKP+p1k=
205+
github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94=
206+
github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8=
207207
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
208208
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
209209
github.com/jonboulle/clockwork v0.5.0 h1:Hyh9A8u51kptdkR+cqRpT1EebBwTn1oK9YfGYbdFz6I=

pkg/loop/internal/test/logger_loop.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package test
33
import (
44
"context"
55
"errors"
6+
"strconv"
67
"time"
78

89
"github.com/hashicorp/go-plugin"
@@ -24,6 +25,27 @@ const (
2425
DEBUG
2526
)
2627

28+
func FormatLevel(l int) string {
29+
switch l {
30+
case PANIC:
31+
return "panic"
32+
case FATAL:
33+
return "fatal"
34+
case CRITICAL:
35+
return "critical"
36+
case ERROR:
37+
return "error"
38+
case INFO:
39+
return "info"
40+
case WARN:
41+
return "warn"
42+
case DEBUG:
43+
return "debug"
44+
default:
45+
return "unknown-" + strconv.Itoa(l)
46+
}
47+
}
48+
2749
// NOTE: This is part of the test package because it needs to be imported by the test binary at `./internal/test/cmd`
2850
// as well as the test at `./pkg/loop/logger_loop_test.go`
2951
type GRPCPluginLoggerTest struct {

pkg/loop/logger.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
func HCLogLogger(l logger.Logger) hclog.Logger {
2323
hcl := hclog.NewInterceptLogger(&hclog.LoggerOptions{
2424
Output: io.Discard, // only write through p.Logger Sink
25+
Level: hclog.Debug,
2526
})
2627
hcl.RegisterSink(&hclSinkAdapter{l: logger.Sugared(l)})
2728
return hcl
@@ -116,23 +117,22 @@ func parseJSON(input string) (*logMessage, error) {
116117
return entry, nil
117118
}
118119

119-
// logDebug will parse msg and figure out if it's a panic, fatal or critical log message, this is done here because the hashicorp plugin will push any
120-
// unrecognizable message from stderr as a debug statement
121-
func logDebug(msg string, l logger.SugaredLogger, args ...any) {
120+
// maybeCritical recognizes panic, fatal or critical log message, and logs them again at critical level.
121+
func maybeCritical(msg string, l logger.SugaredLogger, args ...any) bool {
122122
if strings.HasPrefix(msg, "panic:") {
123123
l.Criticalw(fmt.Sprintf("[PANIC] %s", msg), args...)
124+
return true
124125
} else if log, err := parseJSON(msg); err == nil {
125126
switch log.Level {
126127
case "fatal":
127128
l.Criticalw(fmt.Sprintf("[FATAL] %s", log.Message), flattenExtraArgs(log)...)
129+
return true
128130
case "critical", "dpanic":
129131
l.Criticalw(log.Message, flattenExtraArgs(log)...)
130-
default:
131-
l.Debugw(log.Message, flattenExtraArgs(log)...)
132+
return true
132133
}
133-
} else {
134-
l.Debugw(msg, args...)
135134
}
135+
return false
136136
}
137137

138138
func (h *hclSinkAdapter) Accept(_ string, level hclog.Level, msg string, args ...any) {
@@ -152,13 +152,17 @@ func (h *hclSinkAdapter) Accept(_ string, level hclog.Level, msg string, args ..
152152
case hclog.Trace:
153153
l.Debugw(msg, args...)
154154
case hclog.Debug:
155-
logDebug(msg, l, args...)
155+
if !maybeCritical(msg, l, args...) { // panic/fatal/critical used to come through as stderr/out which maps to debug
156+
l.Debugw(msg, args...)
157+
}
156158
case hclog.Info:
157159
l.Infow(msg, args...)
158160
case hclog.Warn:
159161
l.Warnw(msg, args...)
160162
case hclog.Error:
161-
l.Errorw(msg, args...)
163+
if !maybeCritical(msg, l, args...) { // as of v1.7.0, panic/fatal errors are send at error level
164+
l.Errorw(msg, args...)
165+
}
162166
}
163167
}
164168

pkg/loop/logger_loop_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@ import (
1414
)
1515

1616
func TestHCLogLoggerPanic(t *testing.T) {
17-
lggr, ol := logger.TestObservedSugared(t, zapcore.DebugLevel)
18-
1917
type testCase struct {
20-
name string
2118
level int
2219
expectedMessage string
2320
expectedCustomKey string
@@ -77,7 +74,9 @@ func TestHCLogLoggerPanic(t *testing.T) {
7774
}
7875

7976
for _, tt := range tests {
80-
t.Run(tt.name, func(t *testing.T) {
77+
t.Run(test.FormatLevel(tt.level), func(t *testing.T) {
78+
t.Parallel()
79+
lggr, ol := logger.TestObservedSugared(t, zapcore.DebugLevel)
8180
loggerTest := &test.GRPCPluginLoggerTest{SugaredLogger: lggr}
8281
cc := loggerTest.ClientConfig()
8382
cc.Cmd = NewHelperProcessCommand(test.PluginLoggerTestName, false, tt.level)

0 commit comments

Comments
 (0)