Skip to content

Commit

Permalink
Merge branch 'master' into open-source-standard
Browse files Browse the repository at this point in the history
  • Loading branch information
jodstrcil committed Oct 26, 2020
2 parents fa44f07 + 415e61f commit e6c09cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
16 changes: 9 additions & 7 deletions record/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"bytes"
"compress/gzip"
"encoding/json"
"github.com/fluent/fluent-bit-go/output"
"github.com/newrelic/newrelic-fluent-bit-output/utils"
"log"
"os"

"github.com/fluent/fluent-bit-go/output"
"github.com/newrelic/newrelic-fluent-bit-output/utils"
)

const maxPacketSize = 1000000 // bytes
Expand All @@ -32,7 +33,6 @@ func RemapRecord(inputRecord FluentBitRecord, inputTimestamp interface{}, plugin
default:
// Unhandled timestamp type, just ignore (don't log, since I assume we'll fill up someone's disk)
}

if val, ok := outputRecord["log"]; ok {
outputRecord["message"] = val
delete(outputRecord, "log")
Expand All @@ -41,10 +41,12 @@ func RemapRecord(inputRecord FluentBitRecord, inputTimestamp interface{}, plugin
if !ok {
source = "BARE-METAL"
}
outputRecord["plugin"] = map[string]string{
"type": "fluent-bit",
"version": pluginVersion,
"source": source,
if _, ok = outputRecord["plugin"]; !ok {
outputRecord["plugin"] = map[string]string{
"type": "fluent-bit",
"version": pluginVersion,
"source": source,
}
}
return
}
Expand Down
20 changes: 18 additions & 2 deletions record/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ var _ = Describe("Out New Relic", func() {
Expect(version).To(Equal(pluginVersion))
Expect(source).To(Equal("BARE-METAL"))
})

It("Doesn't rewrite plugin.type if it exits", func() {
inputMap := make(FluentBitRecord)
var inputTimestamp interface{}
inputTimestamp = output.FLBTime{
time.Now(),
}
expectedType := "something"
inputMap["plugin"] = map[string]string{
"type": expectedType,
}
foundOutput := RemapRecord(inputMap, inputTimestamp, pluginVersion)
pluginMap := foundOutput["plugin"].(map[string]string)
Expect(pluginMap["type"]).To(Equal(expectedType))
})

It("sets the source if it is included as an environment variable", func() {
inputMap := make(FluentBitRecord)
var inputTimestamp interface{}
Expand Down Expand Up @@ -86,7 +102,7 @@ var _ = Describe("Out New Relic", func() {

It("Correctly handles a JSON array in a []interface{}", func() {
// Given
inputRecord := map[interface{}]interface{}{
inputMap := map[interface{}]interface{}{
"nestedArray": []interface{}{
map[interface{}]interface{}{
"stringField": "value1",
Expand All @@ -100,7 +116,7 @@ var _ = Describe("Out New Relic", func() {
}

// When
foundOutput := parseRecord(inputRecord)
foundOutput := parseRecord(inputMap)

// Then
expectedOutput := map[string]interface{}{
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const VERSION = "1.4.2"
const VERSION = "1.4.3"

0 comments on commit e6c09cb

Please sign in to comment.