Skip to content

Commit 13dabfe

Browse files
committed
chore(fluentbit): use valkey replace redis
1 parent 64b867a commit 13dabfe

8 files changed

Lines changed: 102 additions & 69 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ Fluent Bit currently supports integration of Golang plugins built as shared obje
3131
### Drycc Output
3232
Drycc output is a custom fluentbit plugin that was written to forward data directly to drycc components while filtering out data that we did not care about. We have 2 pieces of information we care about currently.
3333

34-
Logs from applications that are written to stdout within the container and the controller logs that represent actions against those applications. These logs are sent to an internal messaging system ([REIDS](https://redis.io/topics/streams-intro)) on a configurable topic. The logger component then reads those messages and stores the data in an ring buffer.
34+
Logs from applications that are written to stdout within the container and the controller logs that represent actions against those applications. These logs are sent to an internal messaging system ([VALKEY](https://valkey.io)) on a configurable topic. The logger component then reads those messages and stores the data in an ring buffer.

charts/fluentbit/templates/logger-fluentbit-daemon.yaml

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ spec:
2020
heritage: drycc
2121
app: drycc-logger-fluentbit
2222
spec:
23+
affinity:
24+
podAffinity:
25+
requiredDuringSchedulingIgnoredDuringExecution:
26+
- labelSelector:
27+
matchLabels:
28+
app.kubernetes.io/name: controller
29+
topologyKey: kubernetes.io/hostname
2330
serviceAccount: drycc-logger-fluentbit
2431
initContainers:
2532
- name: drycc-logger-fluentbit-init
@@ -28,14 +35,24 @@ spec:
2835
args:
2936
- netcat
3037
- -v
31-
- -a
32-
- $(DRYCC_REDIS_ADDRS)
38+
- -u
39+
- $(DRYCC_VALKEY_URL)
3340
env:
34-
- name: DRYCC_REDIS_ADDRS
41+
{{- if (.Values.valkeyUrl) }}
42+
- name: DRYCC_VALKEY_URL
3543
valueFrom:
3644
secretKeyRef:
37-
name: redis-creds
38-
key: addrs
45+
name: logger-fluentbit-creds
46+
key: valkey-url
47+
{{- else if eq .Values.global.valkeyLocation "on-cluster" }}
48+
- name: VALKEY_PASSWORD
49+
valueFrom:
50+
secretKeyRef:
51+
name: valkey-creds
52+
key: password
53+
- name: DRYCC_VALKEY_URL
54+
value: "redis://:$(VALKEY_PASSWORD)@drycc-valkey.{{.Release.Namespace}}.svc.{{.Values.global.clusterDomain}}:16379/2"
55+
{{- end }}
3956
containers:
4057
- name: drycc-logger-fluentbit
4158
image: {{.Values.imageRegistry}}/{{.Values.imageOrg}}/fluentbit:{{.Values.imageTag}}
@@ -55,15 +72,25 @@ spec:
5572
{{- end}}
5673
{{- end}}
5774
env:
58-
- name: DRYCC_REDIS_ADDRS
75+
{{- if (.Values.valkeyUrl) }}
76+
- name: DRYCC_VALKEY_URL
5977
valueFrom:
6078
secretKeyRef:
61-
name: redis-creds
62-
key: addrs
63-
- name: DRYCC_REDIS_PASSWORD
79+
name: logger-fluentbit-creds
80+
key: valkey-url
81+
{{- else if eq .Values.global.valkeyLocation "on-cluster" }}
82+
- name: VALKEY_PASSWORD
83+
valueFrom:
84+
secretKeyRef:
85+
name: valkey-creds
86+
key: password
87+
- name: DRYCC_VALKEY_URL
88+
value: "redis://:$(VALKEY_PASSWORD)@drycc-valkey.{{.Release.Namespace}}.svc.{{.Values.global.clusterDomain}}:16379/2"
89+
{{- end }}
90+
- name: DRYCC_VALKEY_PASSWORD
6491
valueFrom:
6592
secretKeyRef:
66-
name: redis-creds
93+
name: valkey-creds
6794
key: password
6895
volumeMounts:
6996
- name: varlog
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: logger-fluentbit-creds
5+
labels:
6+
heritage: drycc
7+
data:
8+
{{- if (.Values.valkeyUrl) }}
9+
valkey-url: {{ .Values.valkeyUrl | b64enc }}
10+
{{- end }}

charts/fluentbit/values.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ diagnosticMode:
2020
args:
2121
- infinity
2222

23-
redis:
24-
replicas: 1
25-
2623
# Interval to flush output (seconds)
2724
flush: 1
2825

26+
# external valkey configuration
27+
valkeyUrl: ""
28+
2929
## https://docs.fluentbit.io/manual/administration/configuring-fluent-bit/classic-mode/configuration-file
3030
config:
3131
service: |
@@ -65,10 +65,9 @@ config:
6565
[OUTPUT]
6666
Name drycc
6767
Match kubernetes.*
68-
Addrs ${DRYCC_REDIS_ADDRS}
6968
Stream logs
7069
Max_Len 3000
71-
Password ${DRYCC_REDIS_PASSWORD}
70+
Valkey_URL ${DRYCC_VALKEY_URL}
7271
Controller_Name drycc-controller
7372
Controller_Regex ^(INFO|WARN|DEBUG|ERROR)\s+(\[(\S+)\])+:(.*)
7473
Exclude_Namespaces drycc,drycc-manager,drycc-helmbroker,kube-system,metallb

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ go 1.23
44

55
require (
66
github.com/fluent/fluent-bit-go v0.0.0-20230731091245-a7a013e2473c
7-
github.com/redis/go-redis/v9 v9.7.0
7+
github.com/valkey-io/valkey-go v1.0.49
8+
github.com/valkey-io/valkey-go/valkeycompat v1.0.49
89
)
910

1011
require (
11-
github.com/cespare/xxhash/v2 v2.2.0 // indirect
12-
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
1312
github.com/ugorji/go/codec v1.1.7 // indirect
13+
golang.org/x/sys v0.24.0 // indirect
1414
)

go.sum

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1-
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
2-
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
3-
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
4-
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
5-
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
6-
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
7-
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
8-
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
91
github.com/fluent/fluent-bit-go v0.0.0-20230731091245-a7a013e2473c h1:yKN46XJHYC/gvgH2UsisJ31+n4K3S7QYZSfU2uAWjuI=
102
github.com/fluent/fluent-bit-go v0.0.0-20230731091245-a7a013e2473c/go.mod h1:L92h+dgwElEyUuShEwjbiHjseW410WIcNz+Bjutc8YQ=
11-
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
12-
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
3+
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
4+
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
5+
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
6+
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
7+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
8+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
9+
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 h1:FKHo8hFI3A+7w0aUQuYXQ+6EN5stWmeY/AZqtM8xk9k=
10+
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo=
11+
github.com/onsi/ginkgo/v2 v2.20.1 h1:YlVIbqct+ZmnEph770q9Q7NVAz4wwIiVNahee6JyUzo=
12+
github.com/onsi/ginkgo/v2 v2.20.1/go.mod h1:lG9ey2Z29hR41WMVthyJBGUBcBhGOtoPF2VFMvBXFCI=
13+
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
14+
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
1315
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
1416
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
1517
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
18+
github.com/valkey-io/valkey-go v1.0.49 h1:UiFmDClu0hVcbvXAHOJRmjc2weaNEwSSgUkHVJ8I6IU=
19+
github.com/valkey-io/valkey-go v1.0.49/go.mod h1:BXlVAPIL9rFQinSFM+N32JfWzfCaUAqBpZkc4vPY6fM=
20+
github.com/valkey-io/valkey-go/mock v1.0.49 h1:yRGgQRm0mnrKLrg8OR4oKW7aZmnhLIJWQipBAeIAi0k=
21+
github.com/valkey-io/valkey-go/mock v1.0.49/go.mod h1:rVrqxzzh11myQq14W+yNV5KOepN+5V65w8fgX12T7c4=
22+
github.com/valkey-io/valkey-go/valkeycompat v1.0.49 h1:+D0u0kQ2y392+Mc0prstVA3wdykqtPWGlSgzryrlGRM=
23+
github.com/valkey-io/valkey-go/valkeycompat v1.0.49/go.mod h1:+M/IJPezmrDEkpWC5Ahccr9nlXsyguH3VuH6S63YeIg=
24+
go.uber.org/mock v0.4.0 h1:VcM4ZOtdbR4f6VXfiOpwpVJDL6lCReaZ6mw31wqh7KU=
25+
go.uber.org/mock v0.4.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
26+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
27+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
28+
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
29+
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
30+
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
31+
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
32+
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
33+
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
34+
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
35+
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
36+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
37+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

plugin/out_drycc.go

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"unsafe"
66

77
"context"
8-
"sort"
98
"strings"
109

1110
"github.com/fluent/fluent-bit-go/output"
12-
redis "github.com/redis/go-redis/v9"
11+
"github.com/valkey-io/valkey-go"
12+
"github.com/valkey-io/valkey-go/valkeycompat"
1313
)
1414
import (
1515
"encoding/json"
@@ -27,13 +27,13 @@ var (
2727
ControllerName string
2828
ControllerRegex *regexp.Regexp
2929
ExcludeNamespaces []string
30-
ClusterClient *redis.ClusterClient
30+
ValkeyClient valkey.Client
3131
)
3232

3333
//export FLBPluginRegister
3434
func FLBPluginRegister(ctx unsafe.Pointer) int {
3535
fmt.Printf("Drycc output version %s %s", Revision, BuildDate)
36-
return output.FLBPluginRegister(ctx, "drycc", "Ship fluent-bit logs to redis xstream")
36+
return output.FLBPluginRegister(ctx, "drycc", "Ship fluent-bit logs to valkey xstream")
3737
}
3838

3939
// (fluentbit will call this)
@@ -42,42 +42,20 @@ func FLBPluginRegister(ctx unsafe.Pointer) int {
4242
//export FLBPluginInit
4343
func FLBPluginInit(ctx unsafe.Pointer) int {
4444
var err error
45-
addrs := strings.Split(output.FLBPluginConfigKey(ctx, "Addrs"), ",")
46-
sort.Strings(addrs)
4745
Stream = output.FLBPluginConfigKey(ctx, "Stream")
4846
MaxLen, err = strconv.ParseInt(output.FLBPluginConfigKey(ctx, "Max_Len"), 10, 64)
4947
if err != nil {
5048
MaxLen = 1000
5149
}
52-
username := output.FLBPluginConfigKey(ctx, "Username")
53-
password := output.FLBPluginConfigKey(ctx, "Password")
50+
ValkeyURL := output.FLBPluginConfigKey(ctx, "Valkey_URL")
5451
ControllerName = output.FLBPluginConfigKey(ctx, "Controller_Name")
5552
ControllerRegex = regexp.MustCompile(output.FLBPluginConfigKey(ctx, "Controller_Regex"))
5653
ExcludeNamespaces = strings.Split(output.FLBPluginConfigKey(ctx, "Exclude_Namespaces"), ",")
57-
ClusterClient = redis.NewClusterClient(&redis.ClusterOptions{
58-
ClusterSlots: func(context.Context) ([]redis.ClusterSlot, error) {
59-
const slotsSize = 16383
60-
var size = len(addrs)
61-
var slotsRange = slotsSize / size
62-
var slots []redis.ClusterSlot
63-
for index, addr := range addrs {
64-
start := slotsRange * index
65-
end := start + slotsRange
66-
if (slotsSize - end) < slotsRange {
67-
end = slotsSize
68-
}
69-
slots = append(slots, redis.ClusterSlot{
70-
Start: start,
71-
End: end,
72-
Nodes: []redis.ClusterNode{{Addr: addr}},
73-
})
74-
}
75-
return slots, nil
76-
},
77-
Username: username,
78-
Password: password, // "" == no password
79-
RouteRandomly: true,
80-
})
54+
55+
ValkeyClient, err = valkey.NewClient(valkey.MustParseURL(ValkeyURL))
56+
if err != nil {
57+
return output.FLB_ERROR
58+
}
8159
return output.FLB_OK
8260
}
8361

@@ -87,7 +65,7 @@ func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, _ *C.char) int {
8765
context, cancel := context.WithTimeout(context.Background(), time.Second*30)
8866
defer cancel()
8967
decoder := output.NewDecoder(data, int(length))
90-
pipeline := ClusterClient.Pipeline()
68+
pipeline := valkeycompat.NewAdapter(ValkeyClient).Pipeline()
9169
for {
9270
ret, ts, rec := output.GetRecord(decoder)
9371
if ret != 0 {
@@ -99,16 +77,14 @@ func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, _ *C.char) int {
9977
continue
10078
}
10179
if values, err := toValues(rec); err == nil {
102-
if err := pipeline.XAdd(context, &redis.XAddArgs{
80+
pipeline.XAdd(context, valkeycompat.XAddArgs{
10381
Stream: Stream,
10482
NoMkStream: false,
10583
MaxLen: MaxLen,
10684
Approx: true,
10785
ID: "*",
10886
Values: values,
109-
}).Err(); err != nil {
110-
status = output.FLB_ERROR
111-
}
87+
})
11288
} else {
11389
status = output.FLB_ERROR
11490
}
@@ -121,7 +97,7 @@ func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, _ *C.char) int {
12197

12298
//export FLBPluginExit
12399
func FLBPluginExit() int {
124-
ClusterClient.Close()
100+
ValkeyClient.Close()
125101
return output.FLB_OK
126102
}
127103

rootfs/opt/drycc/fluent-bit/templates/fluent-bit.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@
2727
[OUTPUT]
2828
Name drycc
2929
Match kubernetes.*
30-
Addrs ${DRYCC_REDIS_ADDRS}
3130
Stream logs
3231
Max_Len 3000
33-
Password ${DRYCC_REDIS_PASSWORD}
32+
Valkey_URL ${DRYCC_VALKEY_URL}
3433
Controller_Name drycc-controller
3534
Controller_Regex ^(INFO|WARN|DEBUG|ERROR)\s+(\[(\S+)\])+:(.*)
3635
Exclude_Namespaces drycc,drycc-manager,drycc-helmbroker,kube-system,metallb

0 commit comments

Comments
 (0)