Skip to content

Commit

Permalink
fix(collection): set custom content type for cloudwatch logs (#120)
Browse files Browse the repository at this point in the history
CloudWatch logs do not have an inferrable file type. This commit
explicitly overrides the content type based on the file name, since we
know where the logs will show up. For now, us a custom content type to
identify cloudwatch logs. This will allow us to handle this data in a
more targeted manner within filedrop.
  • Loading branch information
jta authored Dec 5, 2023
1 parent 8e6790e commit 1e8ad08
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion apps/collection/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ Resources:
- !Join [",", !Ref SourceTopicArns]
ContentTypeOverrides: !Join
- ","
- !Ref ContentTypeOverrides
- - !Sub "s3://${Bucket}/cloudwatchlogs/=application/x-aws-cloudwatchlogs"
- !Join
- ","
- !Ref ContentTypeOverrides
NameOverride: !If
- UseStackName
- !Ref 'AWS::StackName'
Expand Down
7 changes: 7 additions & 0 deletions handler/forwarder/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ func (c *contentTypeOverride) Match(s string) string {
func NewContentTypeOverrides(kvs []string, delimiter string) (Matcher, error) {
var m matches
for _, pair := range kvs {
if pair == "" {
// treat empty values as noops
// this overcomes a cloudformation limitation in concatenating
// multiple values, which can result in trailing commas
continue
}

split := strings.SplitN(pair, delimiter, 2)
if len(split) != 2 {
return nil, fmt.Errorf("error parsing %q: %w", pair, errMissingDelimiter)
Expand Down
3 changes: 2 additions & 1 deletion handler/forwarder/overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestContentTypeOverridesErrors(t *testing.T) {
t.Parallel()

testcases := []string{
"",
"nonono",
"\\=",
}

Expand All @@ -40,6 +40,7 @@ func TestContentTypeOverrides(t *testing.T) {
{
ContentTypeOverrides: []string{
".*=application/json",
"",
},
Delimiter: "=",
Expect: map[string]string{
Expand Down

0 comments on commit 1e8ad08

Please sign in to comment.