-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decompress option on kinesis-consumer #8891
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e69c61a
allow for decompression of data by kinesis_consumer
tootedom 13f7da2
allow for decompression of data by kinesis_consumer. fix sample align…
tootedom 6f8613c
change decompress to decompress_with, and accept options
tootedom 91e4cf2
assign decompress func in Init
tootedom 10d0bdb
fix readme
tootedom 006ab97
fix go vet reported issues
tootedom 5b59390
simplify decompression func initialiser
tootedom dbc5e26
use tracking accumulator in testutil
tootedom 1fc335b
Rename Decompress to Content Encoding
tootedom 2812fd6
remove empty line
tootedom c1739b6
fmt the test
tootedom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
plugins/inputs/kinesis_consumer/kinesis_consumer_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package kinesis_consumer | ||
|
||
import ( | ||
"encoding/base64" | ||
"github.com/aws/aws-sdk-go/aws" | ||
consumer "github.com/harlow/kinesis-consumer" | ||
"github.com/influxdata/telegraf" | ||
"github.com/influxdata/telegraf/plugins/parsers" | ||
"github.com/influxdata/telegraf/plugins/parsers/json" | ||
"github.com/influxdata/telegraf/testutil" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestKinesisConsumer_onMessage(t *testing.T) { | ||
zlibBytpes, _ := base64.StdEncoding.DecodeString("eF5FjlFrgzAUhf9KuM+2aNB2zdsQ2xe3whQGW8qIeqdhaiSJK0P874u1Y4+Hc/jON0GHxoga858BgUF8fs5fzunHU5Jlj6cEPFDXHvXStGqsrsKWTapq44pW1SetxsF1a8qsRtGt0YyFKbUcrFT9UbYWtQH2frntkm/s7RInkNU6t9JpWNE5WBAFPo3CcHeg+9D703OziUOhCg6MQ/yakrspuZsyEjdYfsm+Jg2K1jZEfZLKQWUvFglylBobZXDLwSP8//EGpD4NNj7dUJpT6hQY3W33h/AhCt84zDBf5l/MDl08") | ||
gzippedBytes, _ := base64.StdEncoding.DecodeString("H4sIAAFXNGAAA0WOUWuDMBSF/0q4z7Zo0HbN2xDbF7fCFAZbyoh6p2FqJIkrQ/zvi7Vjj4dz+M43QYfGiBrznwGBQXx+zl/O6cdTkmWPpwQ8UNce9dK0aqyuwpZNqmrjilbVJ63GwXVryqxG0a3RjIUptRysVP1Rtha1AfZ+ue2Sb+ztEieQ1Tq30mlY0TlYEAU+jcJwd6D70PvTc7OJQ6EKDoxD/JqSuym5mzISN1h+yb4mDYrWNkR9kspBZS8WCXKUGhtlcMvBI/z/8QakPg02Pt1QmlPqFBjdbfeH8CEK3zjMMF/mX0TaxZUpAQAA") | ||
notZippedBytes := []byte(`{"messageType":"CONTROL_MESSAGE","owner":"CloudwatchLogs","logGroup":"","logStream":"", | ||
"subscriptionFilters":[],"logEvents":[ | ||
{"id":"","timestamp":1510254469274,"message":"{\"bob\":\"CWL CONTROL MESSAGE: Checking health of destination Firehose.\", \"timestamp\":\"2021-02-22T22:15:26.794854Z\"},"}, | ||
{"id":"","timestamp":1510254469274,"message":"{\"bob\":\"CWL CONTROL MESSAGE: Checking health of destination Firehose.\", \"timestamp\":\"2021-02-22T22:15:26.794854Z\"}"} | ||
]}`) | ||
parser, _ := json.New(&json.Config{ | ||
MetricName: "json_test", | ||
Query: "logEvents", | ||
StringFields: []string{"message"}, | ||
}) | ||
|
||
type fields struct { | ||
DecompressionType string | ||
parser parsers.Parser | ||
records map[telegraf.TrackingID]string | ||
} | ||
type args struct { | ||
r *consumer.Record | ||
} | ||
type expected struct { | ||
numberOfMetrics int | ||
messageContains string | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
wantErr bool | ||
expected expected | ||
}{ | ||
{ | ||
name: "test no compression", | ||
fields: fields{ | ||
DecompressionType: "none", | ||
parser: parser, | ||
records: make(map[telegraf.TrackingID]string), | ||
}, | ||
args: args{ | ||
r: &consumer.Record{Data: notZippedBytes, SequenceNumber: aws.String("anything")}, | ||
}, | ||
wantErr: false, | ||
expected: expected{ | ||
messageContains: "bob", | ||
numberOfMetrics: 2, | ||
}, | ||
}, | ||
{ | ||
name: "test gzip compression", | ||
fields: fields{ | ||
DecompressionType: "gzip", | ||
parser: parser, | ||
records: make(map[telegraf.TrackingID]string), | ||
}, | ||
args: args{ | ||
r: &consumer.Record{Data: gzippedBytes, SequenceNumber: aws.String("anything")}, | ||
}, | ||
wantErr: false, | ||
expected: expected{ | ||
messageContains: "bob", | ||
numberOfMetrics: 1, | ||
}, | ||
}, | ||
{ | ||
name: "test zlib compression", | ||
fields: fields{ | ||
DecompressionType: "zlib", | ||
parser: parser, | ||
records: make(map[telegraf.TrackingID]string), | ||
}, | ||
args: args{ | ||
r: &consumer.Record{Data: zlibBytpes, SequenceNumber: aws.String("anything")}, | ||
}, | ||
wantErr: false, | ||
expected: expected{ | ||
messageContains: "bob", | ||
numberOfMetrics: 1, | ||
}, | ||
}, | ||
} | ||
|
||
k := &KinesisConsumer{ | ||
DecompressionType: "notsupported", | ||
} | ||
err := k.Init() | ||
assert.NotNil(t, err) | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
k := &KinesisConsumer{ | ||
DecompressionType: tt.fields.DecompressionType, | ||
parser: tt.fields.parser, | ||
records: tt.fields.records, | ||
} | ||
err := k.Init() | ||
assert.Nil(t, err) | ||
|
||
acc := testutil.Accumulator{} | ||
if err := k.onMessage(acc.WithTracking(tt.expected.numberOfMetrics), tt.args.r); (err != nil) != tt.wantErr { | ||
t.Errorf("onMessage() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
|
||
assert.Equal(t, tt.expected.numberOfMetrics, len(acc.Metrics)) | ||
|
||
for _, metric := range acc.Metrics { | ||
if logEventMessage, ok := metric.Fields["message"]; ok { | ||
assert.Contains(t, logEventMessage.(string), tt.expected.messageContains) | ||
} else { | ||
t.Errorf("Expect logEvents to be present") | ||
} | ||
} | ||
}) | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tootedom I think the linter is complaining about this empty line. We need CI to pass before we can merge, including the linter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for the pointer. I was failing miserably at installing revive locally (still not fathomed it).
Have removed the line, and pushed. Linter looks happy.