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
23 changes: 15 additions & 8 deletions test/framework/functional/output_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package functional

import (
"bytes"
"github.com/openshift/cluster-logging-operator/internal/generator/helpers"
"os"
"strings"
"text/template"
Expand Down Expand Up @@ -70,6 +71,8 @@ type = "http_server"
address = "127.0.0.1:8090"
decoding.codec = "json"
framing.method = "newline_delimited"
{{ .Username }}
{{ .Password }}

{{ if ne .MinTLS "" }}
[sources.my_source.tls]
Expand Down Expand Up @@ -153,22 +156,26 @@ func VectorConfFactory(profile configv1.TLSProfileType, options ...Option) strin
}
b := &bytes.Buffer{}
if err := tmpl.ExecuteTemplate(b, "", struct {
MinTLS string
Ciphers string
Path string
MinTLS string
Ciphers string
Path string
Username helpers.OptionalPair
Password helpers.OptionalPair
}{
MinTLS: minTLS,
Ciphers: ciphers,
Path: path,
MinTLS: minTLS,
Ciphers: ciphers,
Path: path,
Username: helpers.NewOptionalPair("auth.username", OptionsValue(options, "username", nil)),
Password: helpers.NewOptionalPair("auth.password", OptionsValue(options, "password", nil)),
}); err != nil {
log.V(0).Error(err, "Unable execute vector http conf template")
os.Exit(1)
}
return b.String()
}

func (f *CollectorFunctionalFramework) AddVectorHttpOutput(b *runtime.PodBuilder, output obs.OutputSpec) error {
return f.AddVectorHttpOutputWithConfig(b, output, "", nil)
func (f *CollectorFunctionalFramework) AddVectorHttpOutput(b *runtime.PodBuilder, output obs.OutputSpec, options ...Option) error {
return f.AddVectorHttpOutputWithConfig(b, output, "", nil, options...)
}

func (f *CollectorFunctionalFramework) AddVectorHttpOutputWithConfig(b *runtime.PodBuilder, output obs.OutputSpec, profile configv1.TLSProfileType, secret *corev1.Secret, options ...Option) error {
Expand Down
8 changes: 8 additions & 0 deletions test/framework/functional/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ type Option struct {
Value string
}

// OptionsValue returns the value if found or the default
func OptionsValue(options []Option, name string, notFound any) any {
if found, op := OptionsInclude(name, options); found {
return op.Value
}
return notFound
}

func OptionsInclude(name string, options []Option) (bool, Option) {
for _, o := range options {
if o.Name == name {
Expand Down
20 changes: 19 additions & 1 deletion test/functional/outputs/http/forward_to_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,26 @@ var _ = Describe("[Functional][Outputs][Http] Functional tests", func() {
Expect(logs[0].Kubernetes.Labels).To(HaveKey(MatchRegexp("foo")))
},
Entry("should send message over http to vector", func(f *functional.CollectorFunctionalFramework) runtime.PodBuilderVisitor {
userName := "imauser"
password := "iwonttell"
secretName := "mysecrets"
framework.Forwarder.Spec.Outputs[0].HTTP.Authentication = &obs.HTTPAuthentication{
Username: &obs.SecretReference{
Key: "username",
SecretName: secretName,
},
Password: &obs.SecretReference{
Key: "password",
SecretName: secretName,
},
}
framework.Secrets = append(framework.Secrets, runtime.NewSecret(framework.Namespace, secretName, map[string][]byte{
"username": []byte(userName),
"password": []byte(password),
}))

return func(b *runtime.PodBuilder) error {
return f.AddVectorHttpOutput(b, f.Forwarder.Spec.Outputs[0])
return f.AddVectorHttpOutput(b, f.Forwarder.Spec.Outputs[0], functional.Option{Name: "username", Value: userName}, functional.Option{Name: "password", Value: password})
}
}),
Entry("should send message over http to fluentd", func(f *functional.CollectorFunctionalFramework) runtime.PodBuilderVisitor {
Expand Down