Skip to content

Commit

Permalink
Fix for lint
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmo0920 committed Aug 5, 2019
1 parent d4e22cf commit fba2cfb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
5 changes: 4 additions & 1 deletion fluent-bit/fluent-bit-go-loki/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ func getLokiConfig(url string, batchWait string, batchSize string, labels string
`
}

json.Unmarshal(([]byte)(labels), &labelValues)
err = json.Unmarshal(([]byte)(labels), &labelValues)
if err != nil {
return nil, fmt.Errorf("Failed to parse Labels")
}
labelSet := make(model.LabelSet)
for _, v := range labelValues.Labels {
labelSet[model.LabelName(v.Key)] = model.LabelValue(v.Label)
Expand Down
14 changes: 7 additions & 7 deletions fluent-bit/fluent-bit-go-loki/loki_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package main

import (
"github.com/stretchr/testify/assert"
"testing"
"time"
"github.com/stretchr/testify/assert"
)

func TestGetLokiConfig(t* testing.T) {
func TestGetLokiConfig(t *testing.T) {
c, err := getLokiConfig("", "", "", "")
if err != nil {
t.Fatalf("failed test %#v", err)
}

assert.Equal(t, "http://localhost:3100/api/prom/push", c.url.String(), "Use default value of URL")
assert.Equal(t, 10 * time.Millisecond, c.batchWait, "Use default value of batchWait")
assert.Equal(t, 10 * 1024, c.batchSize, "Use default value of batchSize")
assert.Equal(t, 10*time.Millisecond, c.batchWait, "Use default value of batchWait")
assert.Equal(t, 10*1024, c.batchSize, "Use default value of batchSize")

// Invalid URL
c, err = getLokiConfig("invalid---URL+*#Q(%#Q", "", "", "")
_, err = getLokiConfig("invalid---URL+*#Q(%#Q", "", "", "")
if err == nil {
t.Fatalf("failed test %#v", err)
}
Expand All @@ -28,8 +28,8 @@ func TestGetLokiConfig(t* testing.T) {
if err != nil {
t.Fatalf("failed test %#v", err)
}
assert.Equal(t, 15 * time.Millisecond, c.batchWait, "Use user-defined value of batchWait")
assert.Equal(t, 30 * 1024, c.batchSize, "Use user-defined value of batchSize")
assert.Equal(t, 15*time.Millisecond, c.batchWait, "Use user-defined value of batchWait")
assert.Equal(t, 30*1024, c.batchSize, "Use user-defined value of batchSize")

// LabelSets
labelJSON := `
Expand Down
2 changes: 1 addition & 1 deletion fluent-bit/fluent-bit-go-loki/out_loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (p *fluentPlugin) GetRecord(dec *output.FLBDecoder) (int, interface{}, map[
}

func (p *fluentPlugin) NewDecoder(data unsafe.Pointer, length int) *output.FLBDecoder {
return output.NewDecoder(data, int(length))
return output.NewDecoder(data, length)
}

func (p *fluentPlugin) Exit(code int) {
Expand Down
23 changes: 16 additions & 7 deletions fluent-bit/fluent-bit-go-loki/out_loki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"unsafe"

"github.com/fluent/fluent-bit-go/output"
"github.com/stretchr/testify/assert"
"github.com/prometheus/common/model"
"github.com/stretchr/testify/assert"
)

func TestCreateJSON(t *testing.T) {
Expand Down Expand Up @@ -59,7 +59,7 @@ func (p *testFluentPlugin) PluginConfigKey(ctx unsafe.Pointer, key string) strin
case "BatchSize":
return p.batchSize
case "Labels":
return `
return `
{"labels": [{"key": "job", "label": "fluent-bit"}]}
`
}
Expand All @@ -76,15 +76,15 @@ func (p *testFluentPlugin) GetRecord(dec *output.FLBDecoder) (int, interface{},
return -1, nil, nil
}
func (p *testFluentPlugin) NewDecoder(data unsafe.Pointer, length int) *output.FLBDecoder { return nil }
func (p *testFluentPlugin) Exit(code int) {}
func (p *testFluentPlugin) Exit(code int) {}
func (p *testFluentPlugin) HandleLine(ls model.LabelSet, timestamp time.Time, line string) error {
data := ([]byte)(line)
events := &events{data: data}
p.events = append(p.events, events)
return nil
}
func (p *testFluentPlugin) addrecord(rc int, ts interface{}, line map[interface{}]interface{}) {
p.records = append(p.records, testrecord{rc: rc, ts: ts, data: line})
p.records = append(p.records, testrecord{rc: rc, ts: ts, data: line})
}

func TestPluginInitialization(t *testing.T) {
Expand All @@ -107,8 +107,17 @@ func TestPluginFlusher(t *testing.T) {
assert.Equal(t, output.FLB_OK, res)
assert.Len(t, testplugin.events, len(testplugin.records))
var parsed map[string]interface{}
json.Unmarshal(testplugin.events[0].data, &parsed)
err := json.Unmarshal(testplugin.events[0].data, &parsed)
if err != nil {
assert.Fail(t, "unmarshal of json fails:%v", err)
}
assert.Equal(t, testrecords["mykey"], parsed["mykey"])
json.Unmarshal(testplugin.events[1].data, &parsed)
json.Unmarshal(testplugin.events[2].data, &parsed)
err = json.Unmarshal(testplugin.events[1].data, &parsed)
if err != nil {
assert.Fail(t, "unmarshal of json fails:%v", err)
}
err = json.Unmarshal(testplugin.events[2].data, &parsed)
if err != nil {
assert.Fail(t, "unmarshal of json fails:%v", err)
}
}

0 comments on commit fba2cfb

Please sign in to comment.