Skip to content

Commit

Permalink
Upgrade FluentBit version & support new date format
Browse files Browse the repository at this point in the history
- Upgrade FluentBit image to 2.1.9
- Add support for decoding logs timestamps for newer versions(2.1+)
- Add more info regarding the timestamp that failed to parse
  • Loading branch information
ralongit committed Sep 27, 2023
1 parent b33e18b commit b276f26
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion output/out_logzio.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"github.com/fluent/fluent-bit-go/output"
"os"
"reflect"
"regexp"
"strconv"
"time"
Expand Down Expand Up @@ -308,15 +309,24 @@ func parseJSON(record map[interface{}]interface{}, dedotEnabled bool, dedotNeste
}
func formatTimestamp(ts interface{}) time.Time {
var timestamp time.Time

switch t := ts.(type) {
case output.FLBTime:
timestamp = ts.(output.FLBTime).Time
case uint64:
timestamp = time.Unix(int64(t), 0)
case time.Time:
timestamp = ts.(time.Time)
case []interface{}:
s := reflect.ValueOf(t)
if s.Kind() != reflect.Slice || s.Len() < 2 {
// Expects a non-empty slice of length 2, so we won't extract a timestamp.
} else {
ts = s.Index(0).Interface() // First item is the timestamp.
timestamp = formatTimestamp(ts)
}
default:
fmt.Print("Unknown format, defaulting to now.\n")
fmt.Printf("Unknown format, defaulting to now, timestamp: %v of type: %T.\n", t, t)
timestamp = time.Now()
}
return timestamp
Expand Down
2 changes: 1 addition & 1 deletion test/Dockerfile.amd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WORKDIR /go/src/logzio

RUN make

FROM fluent/fluent-bit:2.0.8
FROM fluent/fluent-bit:2.1.9

COPY --from=gobuilder /go/src/logzio/build/out_logzio.so /fluent-bit/bin/
COPY --from=gobuilder /go/src/logzio/test/fluent-bit.conf /fluent-bit/etc/
Expand Down
2 changes: 1 addition & 1 deletion test/Dockerfile.arm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ WORKDIR /go/src/logzio

RUN make

FROM fluent/fluent-bit:2.0.8
FROM fluent/fluent-bit:2.1.9

COPY --from=gobuilder /go/src/logzio/build/out_logzio.so /fluent-bit/bin/
COPY --from=gobuilder /go/src/logzio/test/fluent-bit.conf /fluent-bit/etc/
Expand Down

0 comments on commit b276f26

Please sign in to comment.