Skip to content

Commit e2f6c80

Browse files
authored
Merge pull request fluent#1411 from yilmazo/master
feat: add support for logs_body_key parameter on Opentelemetry output…
2 parents b16f2eb + 4b2aa28 commit e2f6c80

File tree

9 files changed

+103
-1
lines changed

9 files changed

+103
-1
lines changed

apis/fluentbit/v1alpha2/plugins/output/open_telemetry_types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ type OpenTelemetry struct {
3939
AddLabel map[string]string `json:"addLabel,omitempty"`
4040
// If true, remaining unmatched keys are added as attributes.
4141
LogsBodyKeyAttributes *bool `json:"logsBodyKeyAttributes,omitempty"`
42-
*plugins.TLS `json:"tls,omitempty"`
42+
// The log body key to look up in the log events body/message. Sets the Body field of the opentelemtry logs data model.
43+
LogsBodyKey string `json:"logsBodyKey,omitempty"`
44+
*plugins.TLS `json:"tls,omitempty"`
4345
// Include fluentbit networking options for this output-plugin
4446
*plugins.Networking `json:"networking,omitempty"`
4547
}
@@ -96,6 +98,9 @@ func (o *OpenTelemetry) Params(sl plugins.SecretLoader) (*params.KVs, error) {
9698
if o.LogsBodyKeyAttributes != nil {
9799
kvs.Insert("logs_body_key_attributes", fmt.Sprint(*o.LogsBodyKeyAttributes))
98100
}
101+
if o.LogsBodyKey != "" {
102+
kvs.Insert("logs_body_key", o.LogsBodyKey)
103+
}
99104
if o.TLS != nil {
100105
tls, err := o.TLS.Params(sl)
101106
if err != nil {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package output
2+
3+
import (
4+
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins"
5+
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params"
6+
. "github.com/onsi/gomega"
7+
v1 "k8s.io/api/core/v1"
8+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9+
"sigs.k8s.io/controller-runtime/pkg/client/fake"
10+
"testing"
11+
)
12+
13+
func TestOpenTelemetry_Params(t *testing.T) {
14+
g := NewGomegaWithT(t)
15+
fcb := fake.ClientBuilder{}
16+
fc := fcb.WithObjects(&v1.Secret{
17+
ObjectMeta: metav1.ObjectMeta{Namespace: "test_namespace", Name: "http_secret"},
18+
Data: map[string][]byte{
19+
"http_user": []byte("expected_http_user"),
20+
"http_passwd": []byte("expected_http_passwd"),
21+
},
22+
}).Build()
23+
24+
sl := plugins.NewSecretLoader(fc, "test_namespace")
25+
ot := OpenTelemetry{
26+
Host: "otlp-collector.example.com",
27+
Port: ptrAny(int32(443)),
28+
HTTPUser: &plugins.Secret{ValueFrom: plugins.ValueSource{SecretKeyRef: v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "http_secret"}, Key: "http_user"}}},
29+
HTTPPasswd: &plugins.Secret{ValueFrom: plugins.ValueSource{SecretKeyRef: v1.SecretKeySelector{LocalObjectReference: v1.LocalObjectReference{Name: "http_secret"}, Key: "http_passwd"}}},
30+
Proxy: "expected_proxy",
31+
MetricsUri: "expected_metrics_uri",
32+
LogsUri: "expected_logs_uri",
33+
TracesUri: "expected_traces_uri",
34+
Header: map[string]string{"custom_header_key": "custom_header_val"},
35+
LogResponsePayload: ptrBool(true),
36+
AddLabel: map[string]string{"add_label_key": "add_label_val"},
37+
LogsBodyKeyAttributes: ptrBool(true),
38+
LogsBodyKey: "expected_logs_body_key",
39+
TLS: &plugins.TLS{Verify: ptrBool(false)},
40+
Networking: &plugins.Networking{SourceAddress: ptrAny("expected_source_address")},
41+
}
42+
43+
expected := params.NewKVs()
44+
expected.Insert("host", "otlp-collector.example.com")
45+
expected.Insert("port", "443")
46+
expected.Insert("http_user", "expected_http_user")
47+
expected.Insert("http_passwd", "expected_http_passwd")
48+
expected.Insert("proxy", "expected_proxy")
49+
expected.Insert("metrics_uri", "expected_metrics_uri")
50+
expected.Insert("logs_uri", "expected_logs_uri")
51+
expected.Insert("traces_uri", "expected_traces_uri")
52+
expected.Insert("header", " custom_header_key custom_header_val")
53+
expected.Insert("log_response_payload", "true")
54+
expected.Insert("add_label", " add_label_key add_label_val")
55+
expected.Insert("logs_body_key_attributes", "true")
56+
expected.Insert("logs_body_key", "expected_logs_body_key")
57+
expected.Insert("tls", "On")
58+
expected.Insert("tls.verify", "false")
59+
expected.Insert("net.source_address", "expected_source_address")
60+
61+
kvs, err := ot.Params(sl)
62+
g.Expect(err).NotTo(HaveOccurred())
63+
g.Expect(kvs).To(Equal(expected))
64+
}

charts/fluent-operator/charts/fluent-bit-crds/crds/fluentbit.fluent.io_clusteroutputs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,10 @@ spec:
29302930
logResponsePayload:
29312931
description: Log the response payload within the Fluent Bit log.
29322932
type: boolean
2933+
logsBodyKey:
2934+
description: The log body key to look up in the log events body/message.
2935+
Sets the Body field of the opentelemtry logs data model.
2936+
type: string
29332937
logsBodyKeyAttributes:
29342938
description: If true, remaining unmatched keys are added as attributes.
29352939
type: boolean

charts/fluent-operator/charts/fluent-bit-crds/crds/fluentbit.fluent.io_outputs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,10 @@ spec:
29302930
logResponsePayload:
29312931
description: Log the response payload within the Fluent Bit log.
29322932
type: boolean
2933+
logsBodyKey:
2934+
description: The log body key to look up in the log events body/message.
2935+
Sets the Body field of the opentelemtry logs data model.
2936+
type: string
29332937
logsBodyKeyAttributes:
29342938
description: If true, remaining unmatched keys are added as attributes.
29352939
type: boolean

config/crd/bases/fluentbit.fluent.io_clusteroutputs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,10 @@ spec:
29302930
logResponsePayload:
29312931
description: Log the response payload within the Fluent Bit log.
29322932
type: boolean
2933+
logsBodyKey:
2934+
description: The log body key to look up in the log events body/message.
2935+
Sets the Body field of the opentelemtry logs data model.
2936+
type: string
29332937
logsBodyKeyAttributes:
29342938
description: If true, remaining unmatched keys are added as attributes.
29352939
type: boolean

config/crd/bases/fluentbit.fluent.io_outputs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,6 +2930,10 @@ spec:
29302930
logResponsePayload:
29312931
description: Log the response payload within the Fluent Bit log.
29322932
type: boolean
2933+
logsBodyKey:
2934+
description: The log body key to look up in the log events body/message.
2935+
Sets the Body field of the opentelemtry logs data model.
2936+
type: string
29332937
logsBodyKeyAttributes:
29342938
description: If true, remaining unmatched keys are added as attributes.
29352939
type: boolean

docs/plugins/fluentbit/output/open_telemetry.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ The OpenTelemetry plugin allows you to take logs, metrics, and traces from Fluen
1717
| logResponsePayload | Log the response payload within the Fluent Bit log. | *bool |
1818
| 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 |
1919
| logsBodyKeyAttributes | If true, remaining unmatched keys are added as attributes. | *bool |
20+
| 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 |
2021
| tls | | *[plugins.TLS](../tls.md) |
2122
| networking | Include fluentbit networking options for this output-plugin | *plugins.Networking |

manifests/setup/fluent-operator-crd.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6966,6 +6966,10 @@ spec:
69666966
logResponsePayload:
69676967
description: Log the response payload within the Fluent Bit log.
69686968
type: boolean
6969+
logsBodyKey:
6970+
description: The log body key to look up in the log events body/message.
6971+
Sets the Body field of the opentelemtry logs data model.
6972+
type: string
69696973
logsBodyKeyAttributes:
69706974
description: If true, remaining unmatched keys are added as attributes.
69716975
type: boolean
@@ -35656,6 +35660,10 @@ spec:
3565635660
logResponsePayload:
3565735661
description: Log the response payload within the Fluent Bit log.
3565835662
type: boolean
35663+
logsBodyKey:
35664+
description: The log body key to look up in the log events body/message.
35665+
Sets the Body field of the opentelemtry logs data model.
35666+
type: string
3565935667
logsBodyKeyAttributes:
3566035668
description: If true, remaining unmatched keys are added as attributes.
3566135669
type: boolean

manifests/setup/setup.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6966,6 +6966,10 @@ spec:
69666966
logResponsePayload:
69676967
description: Log the response payload within the Fluent Bit log.
69686968
type: boolean
6969+
logsBodyKey:
6970+
description: The log body key to look up in the log events body/message.
6971+
Sets the Body field of the opentelemtry logs data model.
6972+
type: string
69696973
logsBodyKeyAttributes:
69706974
description: If true, remaining unmatched keys are added as attributes.
69716975
type: boolean
@@ -35656,6 +35660,10 @@ spec:
3565635660
logResponsePayload:
3565735661
description: Log the response payload within the Fluent Bit log.
3565835662
type: boolean
35663+
logsBodyKey:
35664+
description: The log body key to look up in the log events body/message.
35665+
Sets the Body field of the opentelemtry logs data model.
35666+
type: string
3565935667
logsBodyKeyAttributes:
3566035668
description: If true, remaining unmatched keys are added as attributes.
3566135669
type: boolean

0 commit comments

Comments
 (0)