Skip to content

Commit

Permalink
feat: add support for logs_body_key parameter on Opentelemetry output…
Browse files Browse the repository at this point in the history
… plugin (#1410)

Signed-off-by: yilmazo <[email protected]>
  • Loading branch information
yilmazo committed Nov 15, 2024
1 parent b16f2eb commit fecdd99
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ type OpenTelemetry struct {
AddLabel map[string]string `json:"addLabel,omitempty"`
// If true, remaining unmatched keys are added as attributes.
LogsBodyKeyAttributes *bool `json:"logsBodyKeyAttributes,omitempty"`
*plugins.TLS `json:"tls,omitempty"`
// The log body key to look up in the log events body/message. Sets the Body field of the opentelemtry logs data model.
LogsBodyKey string `json:"logsBodyKey,omitempty"`
*plugins.TLS `json:"tls,omitempty"`
// Include fluentbit networking options for this output-plugin
*plugins.Networking `json:"networking,omitempty"`
}
Expand Down Expand Up @@ -96,6 +98,9 @@ func (o *OpenTelemetry) Params(sl plugins.SecretLoader) (*params.KVs, error) {
if o.LogsBodyKeyAttributes != nil {
kvs.Insert("logs_body_key_attributes", fmt.Sprint(*o.LogsBodyKeyAttributes))
}
if o.LogsBodyKey != "" {
kvs.Insert("logs_body_key", o.LogsBodyKey)
}
if o.TLS != nil {
tls, err := o.TLS.Params(sl)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package output

import (
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins"
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"testing"
)

func TestOpenTelemetry_Params(t *testing.T) {
g := NewGomegaWithT(t)
fcb := fake.ClientBuilder{}
fc := fcb.WithObjects(&v1.Secret{
ObjectMeta: metav1.ObjectMeta{Namespace: "test_namespace", Name: "http_secret"},
Data: map[string][]byte{
"http_user": []byte("expected_http_user"),
"http_passwd": []byte("expected_http_passwd"),
},
}).Build()

sl := plugins.NewSecretLoader(fc, "test_namespace")
ot := OpenTelemetry{
Host: "otlp-collector.example.com",
Port: ptrAny(int32(443)),
HTTPUser: &plugins.Secret{ValueFrom: plugins.ValueSource{SecretKeyRef: v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "http_secret"}, Key: "http_user"}}},
HTTPPasswd: &plugins.Secret{ValueFrom: plugins.ValueSource{SecretKeyRef: v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "http_secret"}, Key: "http_passwd"}}},
Proxy: "expected_proxy",
MetricsUri: "expected_metrics_uri",
LogsUri: "expected_logs_uri",
TracesUri: "expected_traces_uri",
Header: map[string]string{"custom_header_key": "custom_header_val"},
LogResponsePayload: ptrBool(true),
AddLabel: map[string]string{"add_label_key": "add_label_val"},
LogsBodyKeyAttributes: ptrBool(true),
LogsBodyKey: "expected_logs_body_key",
TLS: &plugins.TLS{Verify: ptrBool(false)},
Networking: &plugins.Networking{SourceAddress: ptrAny("expected_source_address")},
}

expected := params.NewKVs()
expected.Insert("host", "otlp-collector.example.com")
expected.Insert("port", "443")
expected.Insert("http_user", "expected_http_user")
expected.Insert("http_passwd", "expected_http_passwd")
expected.Insert("proxy", "expected_proxy")
expected.Insert("metrics_uri", "expected_metrics_uri")
expected.Insert("logs_uri", "expected_logs_uri")
expected.Insert("traces_uri", "expected_traces_uri")
expected.Insert("header", " custom_header_key custom_header_val")
expected.Insert("log_response_payload", "true")
expected.Insert("add_label", " add_label_key add_label_val")
expected.Insert("logs_body_key_attributes", "true")
expected.Insert("logs_body_key", "expected_logs_body_key")
expected.Insert("tls", "On")
expected.Insert("tls.verify", "false")
expected.Insert("net.source_address", "expected_source_address")

kvs, err := ot.Params(sl)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(kvs).To(Equal(expected))
}
Original file line number Diff line number Diff line change
Expand Up @@ -2930,6 +2930,10 @@ spec:
logResponsePayload:
description: Log the response payload within the Fluent Bit log.
type: boolean
logsBodyKey:
description: The log body key to look up in the log events body/message.
Sets the Body field of the opentelemtry logs data model.
type: string
logsBodyKeyAttributes:
description: If true, remaining unmatched keys are added as attributes.
type: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2930,6 +2930,10 @@ spec:
logResponsePayload:
description: Log the response payload within the Fluent Bit log.
type: boolean
logsBodyKey:
description: The log body key to look up in the log events body/message.
Sets the Body field of the opentelemtry logs data model.
type: string
logsBodyKeyAttributes:
description: If true, remaining unmatched keys are added as attributes.
type: boolean
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/fluentbit.fluent.io_clusteroutputs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2930,6 +2930,10 @@ spec:
logResponsePayload:
description: Log the response payload within the Fluent Bit log.
type: boolean
logsBodyKey:
description: The log body key to look up in the log events body/message.
Sets the Body field of the opentelemtry logs data model.
type: string
logsBodyKeyAttributes:
description: If true, remaining unmatched keys are added as attributes.
type: boolean
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/fluentbit.fluent.io_outputs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2930,6 +2930,10 @@ spec:
logResponsePayload:
description: Log the response payload within the Fluent Bit log.
type: boolean
logsBodyKey:
description: The log body key to look up in the log events body/message.
Sets the Body field of the opentelemtry logs data model.
type: string
logsBodyKeyAttributes:
description: If true, remaining unmatched keys are added as attributes.
type: boolean
Expand Down
1 change: 1 addition & 0 deletions docs/plugins/fluentbit/output/open_telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ The OpenTelemetry plugin allows you to take logs, metrics, and traces from Fluen
| logResponsePayload | Log the response payload within the Fluent Bit log. | *bool |
| addLabel | This allows you to add custom labels to all metrics exposed through the OpenTelemetry exporter. You may have multiple of these fields. | map[string]string |
| logsBodyKeyAttributes | If true, remaining unmatched keys are added as attributes. | *bool |
| logsBodyKey | The log body key to look up in the log events body/message. Sets the Body field of the opentelemtry logs data model. | string |
| tls | | *[plugins.TLS](../tls.md) |
| networking | Include fluentbit networking options for this output-plugin | *plugins.Networking |
8 changes: 8 additions & 0 deletions manifests/setup/fluent-operator-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6966,6 +6966,10 @@ spec:
logResponsePayload:
description: Log the response payload within the Fluent Bit log.
type: boolean
logsBodyKey:
description: The log body key to look up in the log events body/message.
Sets the Body field of the opentelemtry logs data model.
type: string
logsBodyKeyAttributes:
description: If true, remaining unmatched keys are added as attributes.
type: boolean
Expand Down Expand Up @@ -35656,6 +35660,10 @@ spec:
logResponsePayload:
description: Log the response payload within the Fluent Bit log.
type: boolean
logsBodyKey:
description: The log body key to look up in the log events body/message.
Sets the Body field of the opentelemtry logs data model.
type: string
logsBodyKeyAttributes:
description: If true, remaining unmatched keys are added as attributes.
type: boolean
Expand Down
8 changes: 8 additions & 0 deletions manifests/setup/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6966,6 +6966,10 @@ spec:
logResponsePayload:
description: Log the response payload within the Fluent Bit log.
type: boolean
logsBodyKey:
description: The log body key to look up in the log events body/message.
Sets the Body field of the opentelemtry logs data model.
type: string
logsBodyKeyAttributes:
description: If true, remaining unmatched keys are added as attributes.
type: boolean
Expand Down Expand Up @@ -35656,6 +35660,10 @@ spec:
logResponsePayload:
description: Log the response payload within the Fluent Bit log.
type: boolean
logsBodyKey:
description: The log body key to look up in the log events body/message.
Sets the Body field of the opentelemtry logs data model.
type: string
logsBodyKeyAttributes:
description: If true, remaining unmatched keys are added as attributes.
type: boolean
Expand Down

0 comments on commit fecdd99

Please sign in to comment.