Skip to content

Commit 34c0f5f

Browse files
authored
Merge pull request #2282 from vyncint/feat-fluentbit-flush-on-shutdown
2 parents 91ba997 + e90dcc0 commit 34c0f5f

9 files changed

Lines changed: 73 additions & 0 deletions

File tree

charts/logging-operator/charts/logging-operator-crds/templates/logging.banzaicloud.io_fluentbitagents.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ spec:
478478
type: object
479479
bufferStorage:
480480
properties:
481+
storage.backlog.flush_on_shutdown:
482+
type: string
481483
storage.backlog.mem_limit:
482484
type: string
483485
storage.checksum:

charts/logging-operator/charts/logging-operator-crds/templates/logging.banzaicloud.io_loggings.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,8 @@ spec:
13391339
type: object
13401340
bufferStorage:
13411341
properties:
1342+
storage.backlog.flush_on_shutdown:
1343+
type: string
13421344
storage.backlog.mem_limit:
13431345
type: string
13441346
storage.checksum:

charts/logging-operator/crds/logging.banzaicloud.io_fluentbitagents.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ spec:
475475
type: object
476476
bufferStorage:
477477
properties:
478+
storage.backlog.flush_on_shutdown:
479+
type: string
478480
storage.backlog.mem_limit:
479481
type: string
480482
storage.checksum:

charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,8 @@ spec:
13361336
type: object
13371337
bufferStorage:
13381338
properties:
1339+
storage.backlog.flush_on_shutdown:
1340+
type: string
13391341
storage.backlog.mem_limit:
13401342
type: string
13411343
storage.checksum:

config/crd/bases/logging.banzaicloud.io_fluentbitagents.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ spec:
475475
type: object
476476
bufferStorage:
477477
properties:
478+
storage.backlog.flush_on_shutdown:
479+
type: string
478480
storage.backlog.mem_limit:
479481
type: string
480482
storage.checksum:

config/crd/bases/logging.banzaicloud.io_loggings.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,8 @@ spec:
13361336
type: object
13371337
bufferStorage:
13381338
properties:
1339+
storage.backlog.flush_on_shutdown:
1340+
type: string
13391341
storage.backlog.mem_limit:
13401342
type: string
13411343
storage.checksum:

docs/configuration/crds/v1beta1/fluentbit_types.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ Default: disabled
364364

365365
BufferStorage is the Service Section Configuration of fluent-bit
366366

367+
### storage.backlog.flush_on_shutdown (string, optional) {#bufferstorage-storage.backlog.flush_on_shutdown}
368+
369+
If enabled, Fluent Bit attempts to flush all backlog filesystem chunks to their destination during the shutdown process. This avoids losing buffered records when a node is drained or a spot instance is reclaimed.
370+
371+
Default: Off
372+
367373
### storage.backlog.mem_limit (string, optional) {#bufferstorage-storage.backlog.mem_limit}
368374

369375
If storage.path is set, Fluent Bit will look for data chunks that were not delivered and are still in the storage layer, these are called backlog data. This option configure a hint of maximum value of memory to use when processing these records.

pkg/resources/fluentbit/configsecret_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ import (
1818
"testing"
1919

2020
"github.com/stretchr/testify/assert"
21+
"github.com/stretchr/testify/require"
2122

2223
"github.com/kube-logging/logging-operator/pkg/sdk/logging/api/v1beta1"
24+
"github.com/kube-logging/logging-operator/pkg/sdk/logging/model/types"
2325
)
2426

2527
func TestInvalidFilterGrepConfig(t *testing.T) {
@@ -53,3 +55,54 @@ func TestValidFilterGrepConfig(t *testing.T) {
5355
assert.NoError(t, err)
5456
assert.EqualValues(t, parserFluentdFilterGrep, expectedFluentFilterGrep)
5557
}
58+
59+
func TestBufferStorageServiceSection(t *testing.T) {
60+
testCases := []struct {
61+
name string
62+
bufferStorage v1beta1.BufferStorage
63+
expected []string
64+
notExpected []string
65+
}{
66+
{
67+
name: "flush_on_shutdown enabled",
68+
bufferStorage: v1beta1.BufferStorage{
69+
StoragePath: "/buffers",
70+
StorageBacklogFlushOnShutdown: "On",
71+
},
72+
expected: []string{
73+
"storage.path /buffers",
74+
"storage.backlog.flush_on_shutdown On",
75+
},
76+
},
77+
{
78+
name: "flush_on_shutdown disabled explicitly",
79+
bufferStorage: v1beta1.BufferStorage{
80+
StorageBacklogFlushOnShutdown: "Off",
81+
},
82+
expected: []string{"storage.backlog.flush_on_shutdown Off"},
83+
},
84+
{
85+
name: "flush_on_shutdown unset stays out of the config",
86+
bufferStorage: v1beta1.BufferStorage{StoragePath: "/buffers"},
87+
expected: []string{"storage.path /buffers"},
88+
notExpected: []string{"storage.backlog.flush_on_shutdown"},
89+
},
90+
}
91+
92+
for _, testCase := range testCases {
93+
t.Run(testCase.name, func(t *testing.T) {
94+
mapped, err := types.NewStructToStringMapper(nil).StringsMap(testCase.bufferStorage)
95+
require.NoError(t, err)
96+
97+
rendered, err := generateConfig(fluentBitConfig{BufferStorage: mapped})
98+
require.NoError(t, err)
99+
100+
for _, expected := range testCase.expected {
101+
assert.Contains(t, rendered, expected)
102+
}
103+
for _, notExpected := range testCase.notExpected {
104+
assert.NotContains(t, rendered, notExpected)
105+
}
106+
})
107+
}
108+
}

pkg/sdk/logging/api/v1beta1/fluentbit_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ type BufferStorage struct {
222222
StorageDeleteIrrecoverableChunks string `json:"storage.delete_irrecoverable_chunks,omitempty"`
223223
// If storage.path is set, Fluent Bit will look for data chunks that were not delivered and are still in the storage layer, these are called backlog data. This option configure a hint of maximum value of memory to use when processing these records. (default:5M)
224224
StorageBacklogMemLimit string `json:"storage.backlog.mem_limit,omitempty"`
225+
// If enabled, Fluent Bit attempts to flush all backlog filesystem chunks to their destination during the shutdown process. This avoids losing buffered records when a node is drained or a spot instance is reclaimed. (default:Off)
226+
StorageBacklogFlushOnShutdown string `json:"storage.backlog.flush_on_shutdown,omitempty"`
225227
// Available in Logging operator version 4.4 and later. If the `http_server` option has been enabled in the main Service configuration section, this option registers a new endpoint where internal metrics of the storage layer can be consumed. (default:Off)
226228
StorageMetrics string `json:"storage.metrics,omitempty"`
227229
// If the input plugin has enabled filesystem storage type, this property sets the maximum number of Chunks that can be up in memory. This is the setting to use to control memory usage when you enable storage.type filesystem. (default: 128)

0 commit comments

Comments
 (0)