Skip to content

Commit

Permalink
Rev to go-build v0.20 and fix up lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
fasaxc committed Dec 20, 2018
1 parent fb4f2c8 commit b88e814
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ PUSH_NONMANIFEST_IMAGES=$(filter-out $(PUSH_MANIFEST_IMAGES),$(PUSH_IMAGES))
# location of docker credentials to push manifests
DOCKER_CONFIG ?= $(HOME)/.docker/config.json

GO_BUILD_VER?=v0.17
GO_BUILD_VER?=v0.20
# For building, we use the go-build image for the *host* architecture, even if the target is different
# the one for the host should contain all the necessary cross-compilation tools
# we do not need to use the arch since go-build:v0.15 now is multi-arch manifest
Expand Down
44 changes: 33 additions & 11 deletions pkg/logutils/logutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,14 @@ func (f *Formatter) Format(entry *log.Entry) ([]byte, error) {
if b == nil {
b = &bytes.Buffer{}
}
fmt.Fprintf(b, "%s [%s][%d] %v %v: %v", stamp, levelStr, pid, fileName, lineNo, entry.Message)
appendKVsAndNewLine(b, entry)
_, err := fmt.Fprintf(b, "%s [%s][%d] %v %v: %v", stamp, levelStr, pid, fileName, lineNo, entry.Message)
if err != nil {
return nil, err
}
err = appendKVsAndNewLine(b, entry)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

Expand All @@ -239,22 +245,28 @@ func (f *Formatter) Format(entry *log.Entry) ([]byte, error) {
//
// INFO endpoint_mgr.go 434: Skipping configuration of interface because it is oper down.
// ifaceName="cali1234"
func FormatForSyslog(entry *log.Entry) string {
func FormatForSyslog(entry *log.Entry) (string, error) {
levelStr := strings.ToUpper(entry.Level.String())
fileName := entry.Data["__file__"]
lineNo := entry.Data["__line__"]
b := entry.Buffer
if b == nil {
b = &bytes.Buffer{}
}
fmt.Fprintf(b, "%s %v %v: %v", levelStr, fileName, lineNo, entry.Message)
appendKVsAndNewLine(b, entry)
return b.String()
_, err := fmt.Fprintf(b, "%s %v %v: %v", levelStr, fileName, lineNo, entry.Message)
if err != nil {
return "", err
}
err = appendKVsAndNewLine(b, entry)
if err != nil {
return "", err
}
return b.String(), nil
}

// appendKeysAndNewLine writes the KV pairs attached to the entry to the end of the buffer, then
// finishes it with a newline.
func appendKVsAndNewLine(b *bytes.Buffer, entry *log.Entry) {
func appendKVsAndNewLine(b *bytes.Buffer, entry *log.Entry) error {
// Sort the keys for consistent output.
var keys []string = make([]string, 0, len(entry.Data))
for k := range entry.Data {
Expand All @@ -275,7 +287,10 @@ func appendKVsAndNewLine(b *bytes.Buffer, entry *log.Entry) {
stringifiedValue = stringer.String()
} else {
// No string method, use %#v to get a more thorough dump.
fmt.Fprintf(b, " %v=%#v", key, value)
_, err := fmt.Fprintf(b, " %v=%#v", key, value)
if err != nil {
return err
}
continue
}
b.WriteByte(' ')
Expand All @@ -284,6 +299,7 @@ func appendKVsAndNewLine(b *bytes.Buffer, entry *log.Entry) {
b.WriteString(stringifiedValue)
}
b.WriteByte('\n')
return nil
}

// NullWriter is a dummy writer that always succeeds and does nothing.
Expand Down Expand Up @@ -361,8 +377,11 @@ func NewStreamDestination(
channel: c,
writeLog: func(ql QueuedLog) error {
if ql.NumSkippedLogs > 0 {
fmt.Fprintf(writer, "... dropped %d logs ...\n",
_, err := fmt.Fprintf(writer, "... dropped %d logs ...\n",
ql.NumSkippedLogs)
if err != nil {
return err
}
}
_, err := writer.Write(ql.Message)
return err
Expand Down Expand Up @@ -440,7 +459,7 @@ func (d *Destination) LoopWritingLogs() {
err := d.writeLog(ql)
if err != nil {
counterLogErrors.Inc()
fmt.Fprintf(os.Stderr, "Failed to write to log: %v", err)
_, _ = fmt.Fprintf(os.Stderr, "Failed to write to log: %v", err)
}
ql.OnLogDone()
}
Expand Down Expand Up @@ -530,7 +549,10 @@ func (h *BackgroundHook) Fire(entry *log.Entry) (err error) {
if entry.Level <= h.syslogLevel {
// syslog gets its own log string since our default log string duplicates a lot of
// syslog metadata. Only calculate that string if it's needed.
ql.SyslogMessage = FormatForSyslog(entry)
ql.SyslogMessage, err = FormatForSyslog(entry)
if err != nil {
ql.SyslogMessage = "Failed to format message: " + err.Error()
}
}

var waitGroup *sync.WaitGroup
Expand Down
2 changes: 1 addition & 1 deletion pkg/tlsutils/tlsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func MakeCACert(name string) (*x509.Certificate, *rsa.PrivateKey) {
// https://golang.org/pkg/crypto/x509/#VerifyOptions
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
BasicConstraintsValid: true,
IsCA: true,
IsCA: true,
}

derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &key.PublicKey, key)
Expand Down

0 comments on commit b88e814

Please sign in to comment.