diff --git a/go.mod b/go.mod index 5ea040e971..284cd9db42 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/google/uuid v1.6.0 github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 github.com/hashicorp/go-hclog v1.6.3 - github.com/hashicorp/go-plugin v1.6.3 + github.com/hashicorp/go-plugin v1.7.0 github.com/iancoleman/strcase v0.3.0 github.com/invopop/jsonschema v0.12.0 github.com/jackc/pgx/v4 v4.18.3 @@ -80,7 +80,6 @@ require ( github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/bufbuild/protocompile v0.14.1 // indirect github.com/buger/goterm v0.0.0-20200322175922-2f3e71b85129 // indirect github.com/buger/jsonparser v1.1.1 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect @@ -100,7 +99,7 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 // indirect github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026 // indirect - github.com/hashicorp/yamux v0.1.1 // indirect + github.com/hashicorp/yamux v0.1.2 // indirect github.com/jackc/chunkreader/v2 v2.0.1 // indirect github.com/jackc/pgconn v1.14.3 // indirect github.com/jackc/pgio v1.0.0 // indirect @@ -123,7 +122,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mr-tron/base58 v1.2.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/oklog/run v1.0.0 // indirect + github.com/oklog/run v1.1.0 // indirect github.com/pierrec/lz4/v4 v4.1.22 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect diff --git a/go.sum b/go.sum index 14918302ac..865d874a13 100644 --- a/go.sum +++ b/go.sum @@ -140,10 +140,10 @@ github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026 h1:BpJ2o0OR5FV7vrkDYf github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026/go.mod h1:5Scbynm8dF1XAPwIwkGPqzkM/shndPm79Jd1003hTjE= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= -github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0UUrwg= -github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0= -github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= -github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= +github.com/hashicorp/go-plugin v1.7.0 h1:YghfQH/0QmPNc/AZMTFE3ac8fipZyZECHdDPshfk+mA= +github.com/hashicorp/go-plugin v1.7.0/go.mod h1:BExt6KEaIYx804z8k4gRzRLEvxKVb+kn0NMcihqOqb8= +github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8= +github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns= github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI= @@ -198,8 +198,8 @@ github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0f github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= -github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= -github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= +github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94= +github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8= github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY= github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4= @@ -272,8 +272,8 @@ github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= -github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= +github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA= +github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU= github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= diff --git a/pkg/loop/internal/test/logger_loop.go b/pkg/loop/internal/test/logger_loop.go index 2e53ca5039..b16427e5c5 100644 --- a/pkg/loop/internal/test/logger_loop.go +++ b/pkg/loop/internal/test/logger_loop.go @@ -3,6 +3,7 @@ package test import ( "context" "errors" + "strconv" "time" "github.com/hashicorp/go-plugin" @@ -24,6 +25,27 @@ const ( DEBUG ) +func FormatLevel(l int) string { + switch l { + case PANIC: + return "panic" + case FATAL: + return "fatal" + case CRITICAL: + return "critical" + case ERROR: + return "error" + case INFO: + return "info" + case WARN: + return "warn" + case DEBUG: + return "debug" + default: + return "unknown-" + strconv.Itoa(l) + } +} + // NOTE: This is part of the test package because it needs to be imported by the test binary at `./internal/test/cmd` // as well as the test at `./pkg/loop/logger_loop_test.go` type GRPCPluginLoggerTest struct { diff --git a/pkg/loop/logger.go b/pkg/loop/logger.go index 76b6bd11a0..19e0c65b8a 100644 --- a/pkg/loop/logger.go +++ b/pkg/loop/logger.go @@ -114,9 +114,8 @@ func parseJSON(input string) (*logMessage, error) { return entry, nil } -// 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 -// unrecognizable message from stderr as a debug statement -func logDebug(msg string, l logger.SugaredLogger, args ...interface{}) { +// maybeCritical recognizes panic, fatal or critical log message, and logs them again at critical level. +func maybeCritical(msg string, l logger.SugaredLogger, args ...interface{}) { if strings.HasPrefix(msg, "panic:") { l.Criticalw(fmt.Sprintf("[PANIC] %s", msg), args...) } else if log, err := parseJSON(msg); err == nil { @@ -125,11 +124,7 @@ func logDebug(msg string, l logger.SugaredLogger, args ...interface{}) { l.Criticalw(fmt.Sprintf("[FATAL] %s", log.Message), flattenExtraArgs(log)...) case "critical", "dpanic": l.Criticalw(log.Message, flattenExtraArgs(log)...) - default: - l.Debugw(log.Message, flattenExtraArgs(log)...) } - } else { - l.Debugw(msg, args...) } } @@ -150,12 +145,14 @@ func (h *hclSinkAdapter) Accept(_ string, level hclog.Level, msg string, args .. case hclog.Trace: l.Debugw(msg, args...) case hclog.Debug: - logDebug(msg, l, args...) + maybeCritical(msg, l, args...) // panic/fatal/critical used to come through as stderr/out which maps to debug + l.Debugw(msg, args...) case hclog.Info: l.Infow(msg, args...) case hclog.Warn: l.Warnw(msg, args...) case hclog.Error: + maybeCritical(msg, l, args...) // as of v1.7.0, panic/fatal errors are send at error level l.Errorw(msg, args...) } } diff --git a/pkg/loop/logger_loop_test.go b/pkg/loop/logger_loop_test.go index 7a58a46925..0ee7576494 100644 --- a/pkg/loop/logger_loop_test.go +++ b/pkg/loop/logger_loop_test.go @@ -17,7 +17,6 @@ func TestHCLogLoggerPanic(t *testing.T) { lggr, ol := logger.TestObservedSugared(t, zapcore.DebugLevel) type testCase struct { - name string level int expectedMessage string expectedCustomKey string @@ -77,7 +76,7 @@ func TestHCLogLoggerPanic(t *testing.T) { } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { + t.Run(test.FormatLevel(tt.level), func(t *testing.T) { loggerTest := &test.GRPCPluginLoggerTest{SugaredLogger: lggr} cc := loggerTest.ClientConfig() cc.Cmd = NewHelperProcessCommand(test.PluginLoggerTestName, false, tt.level)