Skip to content
Open
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
2 changes: 2 additions & 0 deletions apis/fluentbit/v1alpha2/clusterinput_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type InputSpec struct {
KubernetesEvents *input.KubernetesEvents `json:"kubernetesEvents,omitempty"`
// ExecWasi defines the exec wasi input plugin configuration
ExecWasi *input.ExecWasi `json:"execWasi,omitempty"`
// PrometheusRemoteWrite defines the Prometheus Remote Write input plugin configuration
PrometheusRemoteWrite *input.PrometheusRemoteWrite `json:"prometheusRemoteWrite,omitempty"`
// Processors defines the processors configuration
// +kubebuilder:pruning:PreserveUnknownFields
Processors *plugins.Config `json:"processors,omitempty"`
Expand Down
45 changes: 45 additions & 0 deletions apis/fluentbit/v1alpha2/clusterinput_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,48 @@ end`},
i++
}
}

func TestClusterInputList_Load_PrometheusRemoteWrite(t *testing.T) {
g := NewGomegaWithT(t)

sl := plugins.NewSecretLoader(nil, "testnamespace")

inputs := ClusterInputList{
Items: []ClusterInput{
{
TypeMeta: metav1.TypeMeta{
APIVersion: "fluentbit.fluent.io/v1alpha2",
Kind: "ClusterInput",
},
ObjectMeta: metav1.ObjectMeta{
Name: "input-prometheus-remote-write",
},
Spec: InputSpec{
PrometheusRemoteWrite: &input.PrometheusRemoteWrite{
Tag: "prom.rw",
Port: new(int32(8080)),
URI: "/api/prom/push",
},
},
},
},
}

clusterInputs, err := inputs.Load(sl)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(clusterInputs).To(Equal(`[Input]
Name prometheus_remote_write
tag prom.rw
port 8080
uri /api/prom/push
`))

clusterInputs, err = inputs.LoadAsYaml(sl, 0)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(clusterInputs).To(Equal(`inputs:
- name: prometheus_remote_write
tag: prom.rw
port: 8080
uri: /api/prom/push
`))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package input

import (
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins"
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params"
)

// +kubebuilder:object:generate:=true

// The Prometheus Remote Write input plugin receives metrics sent with the Prometheus remote write protocol, <br />
// for example by Prometheus, Grafana Alloy or Fluent Bit's Prometheus Remote Write output. <br />
// **For full documentation, refer to https://docs.fluentbit.io/manual/pipeline/inputs/prometheus-remote-write**
type PrometheusRemoteWrite struct {
// Tag name associated to all metrics coming from this plugin.
Tag string `json:"tag,omitempty"`
// The address to listen on, defaults to 0.0.0.0.
Listen string `json:"listen,omitempty"`
// The port for Fluent Bit to listen on, defaults to 8080.
// Also add it to the ports of the FluentBit resource so that the Fluent Bit Service exposes it.
// +kubebuilder:validation:Minimum:=1
// +kubebuilder:validation:Maximum:=65535
Port *int32 `json:"port,omitempty"`
// The HTTP path that accepts remote write requests, e.g. /api/prom/push.
// If not set, requests are accepted on any path.
// +kubebuilder:validation:Pattern:="^/\\S*$"
URI string `json:"uri,omitempty"`
// Maximum size of a remote write request, defaults to 4M.
// +kubebuilder:validation:Pattern:="^\\d+(k|K|KB|kb|m|M|MB|mb|g|G|GB|gb)?$"
BufferMaxSize string `json:"bufferMaxSize,omitempty"`
// Size of the chunks allocated to read a request, up to bufferMaxSize, defaults to 512K.
// +kubebuilder:validation:Pattern:="^\\d+(k|K|KB|kb|m|M|MB|mb|g|G|GB|gb)?$"
BufferChunkSize string `json:"bufferChunkSize,omitempty"`
// HTTP status code returned for a successfully ingested request, defaults to 201.
// +kubebuilder:validation:Enum:=200;201;204
SuccessfulResponseCode *int32 `json:"successfulResponseCode,omitempty"`
// Run the input in its own thread instead of the main event loop.
Threaded *bool `json:"threaded,omitempty"`
// TLS settings of the listener. Set crtFile and keyFile to accept remote write requests over HTTPS.
*plugins.TLS `json:"tls,omitempty"`
}

func (*PrometheusRemoteWrite) Name() string {
return "prometheus_remote_write"
}

// Params implement Section() method
func (p *PrometheusRemoteWrite) Params(sl plugins.SecretLoader) (*params.KVs, error) {
kvs := params.NewKVs()

plugins.InsertKVString(kvs, "tag", p.Tag)
plugins.InsertKVString(kvs, "listen", p.Listen)
plugins.InsertKVField(kvs, "port", p.Port)
plugins.InsertKVString(kvs, "uri", p.URI)
plugins.InsertKVString(kvs, "buffer_max_size", p.BufferMaxSize)
plugins.InsertKVString(kvs, "buffer_chunk_size", p.BufferChunkSize)
plugins.InsertKVField(kvs, "successful_response_code", p.SuccessfulResponseCode)
plugins.InsertKVField(kvs, "threaded", p.Threaded)

if p.TLS != nil {
tls, err := p.TLS.Params(sl)
if err != nil {
return nil, err
}
kvs.Merge(tls)
}

return kvs, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package input

import (
"testing"

"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"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func TestInput_PrometheusRemoteWrite_Params(t *testing.T) {
g := NewGomegaWithT(t)

sl := plugins.NewSecretLoader(nil, "test namespace")

prw := PrometheusRemoteWrite{
Tag: "prom.rw",
Listen: "0.0.0.0",
Port: new(int32(9090)),
URI: "/api/prom/push",
BufferMaxSize: "8M",
BufferChunkSize: "1M",
SuccessfulResponseCode: new(int32(204)),
Threaded: new(true),
}

expected := params.NewKVs()
expected.Insert("tag", "prom.rw")
expected.Insert("listen", "0.0.0.0")
expected.Insert("port", "9090")
expected.Insert("uri", "/api/prom/push")
expected.Insert("buffer_max_size", "8M")
expected.Insert("buffer_chunk_size", "1M")
expected.Insert("successful_response_code", "204")
expected.Insert("threaded", "true")

kvs, err := prw.Params(sl)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(kvs).To(Equal(expected))
}

func TestInput_PrometheusRemoteWrite_ParamsOnlySetFields(t *testing.T) {
g := NewGomegaWithT(t)

sl := plugins.NewSecretLoader(nil, "test namespace")

kvs, err := (&PrometheusRemoteWrite{}).Params(sl)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(kvs).To(Equal(params.NewKVs()))

kvs, err = (&PrometheusRemoteWrite{Port: new(int32(8080)), Threaded: new(false)}).Params(sl)
g.Expect(err).NotTo(HaveOccurred())
expected := params.NewKVs()
expected.Insert("port", "8080")
expected.Insert("threaded", "false")
g.Expect(kvs).To(Equal(expected))
}

func TestInput_PrometheusRemoteWrite_ParamsTLS(t *testing.T) {
g := NewGomegaWithT(t)

secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "remote-write-tls", Namespace: "test namespace"},
Data: map[string][]byte{
"key-password": []byte("s3cr3t"),
},
}
sl := plugins.NewSecretLoader(fake.NewClientBuilder().WithObjects(secret).Build(), "test namespace")

keyPassword := func(key string) *plugins.Secret {
return &plugins.Secret{ValueFrom: plugins.ValueSource{
SecretKeyRef: corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{Name: "remote-write-tls"},
Key: key,
},
}}
}

prw := PrometheusRemoteWrite{
Port: new(int32(8443)),
TLS: &plugins.TLS{
CRTFile: "/fluent-bit/tls/tls.crt",
KeyFile: "/fluent-bit/tls/tls.key",
KeyPassword: keyPassword("key-password"),
},
}

expected := params.NewKVs()
expected.Insert("port", "8443")
expected.Insert("tls", "On")
expected.Insert("tls.crt_file", "/fluent-bit/tls/tls.crt")
expected.Insert("tls.key_file", "/fluent-bit/tls/tls.key")
expected.Insert("tls.key_passwd", "s3cr3t")

kvs, err := prw.Params(sl)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(kvs).To(Equal(expected))

prw.KeyPassword = keyPassword("missing")
kvs, err = prw.Params(sl)
g.Expect(err).To(HaveOccurred())
g.Expect(kvs).To(BeNil())
}
35 changes: 35 additions & 0 deletions apis/fluentbit/v1alpha2/plugins/input/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions apis/fluentbit/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading