Skip to content

Commit

Permalink
Don't include 'unknown' revision value in logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dprotaso authored Jul 16, 2022
1 parent e1dbd0a commit 512c6b4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion changeset/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"sync"
)

const Unknown = "unknown"

var (
shaRegexp = regexp.MustCompile(`^[a-f0-9]{40,64}$`)
rev string
Expand Down Expand Up @@ -65,7 +67,7 @@ func get() (string, error) {
}

if revision == "" {
return "unknown", nil
return Unknown, nil
}

if shaRegexp.MatchString(revision) {
Expand Down
2 changes: 1 addition & 1 deletion changeset/commit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestGet(t *testing.T) {
name: "missing revision",
ok: true,
info: &debug.BuildInfo{},
result: "unknown",
result: Unknown,
}, {
name: "SHA1 revision is truncated",
ok: true,
Expand Down
4 changes: 2 additions & 2 deletions logging/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func NewLogger(configJSON string, levelOverride string, opts ...zap.Option) (*za

func enrichLoggerWithCommitID(logger *zap.Logger) *zap.SugaredLogger {
revision, err := changeset.Get()
if err != nil {
logger.Info("Fetch git commit sha", zap.Error(err))
if err != nil || revision == changeset.Unknown {
logger.Info("Unable to read vcs.revision from binary", zap.Error(err))
return logger.Sugar()
}

Expand Down

0 comments on commit 512c6b4

Please sign in to comment.