Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# S3 Key Prefix
[transforms.s3_key_prefix]
type = "remap"
inputs = ["s3-forward"]
source = '''
._internal.s3_key_prefix = "app-" + to_string!(._internal.log_type||"missing")
'''

# Amazon S3
[sinks.s3]
type = "aws_s3"
inputs = ["s3_key_prefix"]
region = "us-east-test"
compression = "gzip"
bucket = "my-test-bucket"
key_prefix = "{{ _internal.s3_key_prefix }}"
auth.access_key_id = "SECRET[kubernetes_secret.s3-secret/aws_access_key_id]"
auth.secret_access_key = "SECRET[kubernetes_secret.s3-secret/aws_secret_access_key]"
healthcheck.enabled = false
endpoint = "http://mylogreceiver"

[sinks.s3.encoding]
codec = "json"
except_fields = ["_internal"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# S3 Key Prefix
[transforms.s3_key_prefix]
type = "remap"
inputs = ["s3-forward"]
source = '''
._internal.s3_key_prefix = "app-" + to_string!(._internal.log_type||"missing")
'''

# Amazon S3
[sinks.s3]
type = "aws_s3"
inputs = ["s3_key_prefix"]
region = "us-east-test"
compression = "none"
bucket = "my-test-bucket"
key_prefix = "{{ _internal.s3_key_prefix }}"
auth.access_key_id = "SECRET[kubernetes_secret.s3-secret/aws_access_key_id]"
auth.secret_access_key = "SECRET[kubernetes_secret.s3-secret/aws_secret_access_key]"
healthcheck.enabled = false
endpoint = "http://mylogreceiver"

[sinks.s3.encoding]
codec = "json"
except_fields = ["_internal"]
36 changes: 4 additions & 32 deletions internal/generator/vector/output/aws/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,13 @@ func (e Endpoint) Template() (ret string) {
return
}

type Compression struct {
Algorithm string
}

func (c Compression) Name() string {
return "awsS3CompressionTemplate"
}

func (c Compression) Template() (ret string) {
ret = `{{define "` + c.Name() + `" -}}`
if c.Algorithm != "" && c.Algorithm != "none" {
ret += `compression = "{{ .Algorithm }}"`
}
ret += `{{end}}`
return
}

type S3 struct {
Desc string
ComponentID string
Inputs string
Region string
Bucket string
KeyPrefix string
Compression framework.Element
EndpointConfig framework.Element
SecurityConfig framework.Element
common.RootMixin
Expand All @@ -76,7 +58,7 @@ func (e S3) Template() string {
type = "aws_s3"
inputs = {{.Inputs}}
region = "{{.Region}}"
{{compose_one .Compression}}
{{.Compression}}
bucket = "{{.Bucket}}"
key_prefix = "{{"{{"}} _internal.{{.KeyPrefix}} {{"}}"}}"
{{compose_one .SecurityConfig}}
Expand All @@ -87,9 +69,7 @@ healthcheck.enabled = false
}

func (s *S3) SetCompression(algo string) {
s.Compression = Compression{
Algorithm: algo,
}
s.Compression.Value = algo
}

func New(id string, o obs.OutputSpec, inputs []string, secrets observability.Secrets, strategy common.ConfigStrategy, op utils.Options) []framework.Element {
Expand Down Expand Up @@ -124,10 +104,9 @@ func sink(id string, o obs.OutputSpec, inputs []string, secrets observability.Se
Region: region,
Bucket: bucket,
KeyPrefix: keyPrefix,
Compression: compressionConfig(o.S3),
SecurityConfig: aws.AuthConfig(o.Name, o.S3.Authentication, op, secrets),
EndpointConfig: endpointConfig(o.S3),
RootMixin: common.NewRootMixin("none"),
RootMixin: common.NewRootMixin(nil),
}
}

Expand All @@ -140,11 +119,4 @@ func endpointConfig(s3 *obs.S3) framework.Element {
}
}

func compressionConfig(s3 *obs.S3) framework.Element {
if s3 == nil || s3.Tuning == nil || s3.Tuning.Compression == "" {
return Compression{}
}
return Compression{
Algorithm: s3.Tuning.Compression,
}
}

11 changes: 11 additions & 0 deletions internal/generator/vector/output/aws/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package s3_test

import (
"fmt"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
obs "github.com/openshift/cluster-logging-operator/api/observability/v1"
Expand Down Expand Up @@ -154,6 +155,16 @@ var _ = Describe("Generating vector config for s3 output", func() {
spec.S3.KeyPrefix = "app-{.log_type||\"missing\"}"
spec.S3.URL = "http://mylogreceiver"
}, false, framework.NoOptions, "files/s3_with_url.toml"),
Entry("should pass with 'none' compression", func(spec *obs.OutputSpec) {
spec.S3.KeyPrefix = "app-{.log_type||\"missing\"}"
spec.S3.URL = "http://mylogreceiver"
spec.S3.Tuning = &obs.S3TuningSpec{Compression: "none"}
} ,true, framework.NoOptions, "files/s3_with_none_compession.toml"),
Entry("should pass with 'gzip' compression", func(spec *obs.OutputSpec) {
spec.S3.KeyPrefix = "app-{.log_type||\"missing\"}"
spec.S3.URL = "http://mylogreceiver"
spec.S3.Tuning = &obs.S3TuningSpec{Compression: "gzip"}
} ,true, framework.NoOptions, "files/s3_with_gzip_compession.toml"),
)
})

Expand Down