From 1fab7c645751ea1c54de059eb222159705cfc9a5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 17 Oct 2019 18:41:03 +0200 Subject: [PATCH] bump Graylog2/go-gelf to 1550ee647df0510058c9d67a45c56f18911d80b8 https://github.com/Graylog2/go-gelf/compare/4143646226541087117ff2f83334ea48b3201841...1550ee647df0510058c9d67a45c56f18911d80b8 includes - Graylog2/go-gelf#20 Prevent panic when unmarshalling JSON - Graylog2/go-gelf#23 Feat: Use more precise time stamps - Graylog2/go-gelf#31 bugfix. Not goroutine safe for TCP writer Signed-off-by: Sebastiaan van Stijn --- vendor.conf | 2 +- .../Graylog2/go-gelf/gelf/message.go | 29 ++++++++++++------- .../Graylog2/go-gelf/gelf/tcpwriter.go | 4 ++- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/vendor.conf b/vendor.conf index 5a4a90e9f1..7478bffa95 100644 --- a/vendor.conf +++ b/vendor.conf @@ -90,7 +90,7 @@ github.com/coreos/go-systemd 39ca1b05acc7ad1220e09f133283 github.com/godbus/dbus 5f6efc7ef2759c81b7ba876593971bfce311eab3 # v4.0.0 # gelf logging driver deps -github.com/Graylog2/go-gelf 4143646226541087117ff2f83334ea48b3201841 +github.com/Graylog2/go-gelf 1550ee647df0510058c9d67a45c56f18911d80b8 # v2 branch # fluent-logger-golang deps github.com/fluent/fluent-logger-golang 7a6c9dcd7f14c2ed5d8c55c11b894e5455ee311b # v1.4.0 diff --git a/vendor/github.com/Graylog2/go-gelf/gelf/message.go b/vendor/github.com/Graylog2/go-gelf/gelf/message.go index 4e5a05ec32..fcb182f912 100644 --- a/vendor/github.com/Graylog2/go-gelf/gelf/message.go +++ b/vendor/github.com/Graylog2/go-gelf/gelf/message.go @@ -3,6 +3,7 @@ package gelf import ( "bytes" "encoding/json" + "fmt" "time" ) @@ -84,29 +85,35 @@ func (m *Message) UnmarshalJSON(data []byte) error { m.Extra[k] = v continue } + + ok := true switch k { case "version": - m.Version = v.(string) + m.Version, ok = v.(string) case "host": - m.Host = v.(string) + m.Host, ok = v.(string) case "short_message": - m.Short = v.(string) + m.Short, ok = v.(string) case "full_message": - m.Full = v.(string) + m.Full, ok = v.(string) case "timestamp": - m.TimeUnix = v.(float64) + m.TimeUnix, ok = v.(float64) case "level": - m.Level = int32(v.(float64)) + var level float64 + level, ok = v.(float64) + m.Level = int32(level) case "facility": - m.Facility = v.(string) + m.Facility, ok = v.(string) + } + + if !ok { + return fmt.Errorf("invalid type for field %s", k) } } return nil } -func (m *Message) toBytes() (messageBytes []byte, err error) { - buf := newBuffer() - defer bufPool.Put(buf) +func (m *Message) toBytes(buf *bytes.Buffer) (messageBytes []byte, err error) { if err = m.MarshalJSONBuf(buf); err != nil { return nil, err } @@ -134,7 +141,7 @@ func constructMessage(p []byte, hostname string, facility string, file string, l Host: hostname, Short: string(short), Full: string(full), - TimeUnix: float64(time.Now().Unix()), + TimeUnix: float64(time.Now().UnixNano()) / float64(time.Second), Level: 6, // info Facility: facility, Extra: map[string]interface{}{ diff --git a/vendor/github.com/Graylog2/go-gelf/gelf/tcpwriter.go b/vendor/github.com/Graylog2/go-gelf/gelf/tcpwriter.go index da1390d1d6..5a637ff19b 100644 --- a/vendor/github.com/Graylog2/go-gelf/gelf/tcpwriter.go +++ b/vendor/github.com/Graylog2/go-gelf/gelf/tcpwriter.go @@ -43,7 +43,9 @@ func NewTCPWriter(addr string) (*TCPWriter, error) { // filled out appropriately. In general, clients will want to use // Write, rather than WriteMessage. func (w *TCPWriter) WriteMessage(m *Message) (err error) { - messageBytes, err := m.toBytes() + buf := newBuffer() + defer bufPool.Put(buf) + messageBytes, err := m.toBytes(buf) if err != nil { return err }