Bladeren bron

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 <github@gone.nl>
Sebastiaan van Stijn 5 jaren geleden
bovenliggende
commit
1fab7c6457

+ 1 - 1
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

+ 18 - 11
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{}{

+ 3 - 1
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
 	}