Skip to content

Conversation

@wangzhuzhen
Copy link

@wangzhuzhen wangzhuzhen commented Apr 25, 2022

This patch is to support retain messages if rate limit is exceeded.
https://github.com/fluent/fluent-bit/blob/master/plugins/filter_throttle/throttle.c#L84-L87
https://github.com/fluent/fluent-bit/blob/master/plugins/filter_throttle/throttle.c#L108-L115
https://github.com/fluent/fluent-bit/blob/master/plugins/filter_throttle/throttle.c#L212-L213
https://github.com/fluent/fluent-bit/blob/master/plugins/filter_throttle/throttle.c#L240-L241
https://github.com/fluent/fluent-bit/blob/master/plugins/filter_throttle/throttle.c#L247-L252
https://github.com/fluent/fluent-bit/blob/master/plugins/filter_throttle/throttle.c#L302-L306
https://github.com/fluent/fluent-bit/blob/master/plugins/filter_throttle/throttle.h#L35
https://github.com/fluent/fluent-bit/blob/master/plugins/filter_throttle/throttle.h#L42

For now, if rate limit is exceeded, throttle will drop the messages.
For now, if before fluent-bit first running, there is a input with huge messages which exceeded the throttle's (window * rate * interval), then only the first (window * rate * interval) records will be save, the others before fluent-bit running will be dropped.

Fixes #5356

Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

Configuration

[SERVICE]
    Log_Level     info
[INPUT]
    name tail
    tag  xxx
    path /home/wong/fluent-bit-test/input.log
    DB   /home/wong/fluent-bit-test/flb.db
    read_from_head true
    Static_Batch_Size 50M

[FILTER]
    Name     throttle
    Match    *
    Rate     1000
    Window   15
    Interval 1s
    Print_Status true 
    Retain   false

[OUTPUT]
    name  file
    match *
    path  /home/wong/fluent-bit-test/output.log

For file /home/wong/fluent-bit-test/input.log with 150,000 lines records with format:

"[$id] aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

we can check the result in output file /home/wong/fluent-bit-test/output.log by timestamp and account lines

Debug log

# fluent-bit  -c fluent-bit.conf
Fluent Bit v1.9.3
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2022/04/25 16:40:33] [ info] [fluent bit] version=1.9.3, commit=, pid=23178
[2022/04/25 16:40:33] [ info] [storage] version=1.1.6, type=memory-only, sync=normal, checksum=disabled, max_chunks_up=128
[2022/04/25 16:40:33] [ info] [cmetrics] version=0.3.1
[2022/04/25 16:40:33] [ info] [filter:throttle:throttle.0] 1650876033: limit is 1000.00 per 1s with window size of 15, retain is 1, current rate is: 0 per interval
[2022/04/25 16:40:33] [ info] [sp] stream processor started
[2022/04/25 16:40:33] [ info] [output:file:file.0] worker #0 started
[2022/04/25 16:40:34] [ info] [filter:throttle:throttle.0] 1650876034: limit is 1000.00 per 1s with window size of 15, retain is 1, current rate is: 1000 per interval
[2022/04/25 16:40:35] [ info] [filter:throttle:throttle.0] 1650876035: limit is 1000.00 per 1s with window size of 15, retain is 1, current rate is: 1000 per interval
[2022/04/25 16:40:36] [ info] [filter:throttle:throttle.0] 1650876036: limit is 1000.00 per 1s with window size of 15, retain is 1, current rate is: 1000 per interval
[2022/04/25 16:40:37] [ info] [filter:throttle:throttle.0] 1650876037: limit is 1000.00 per 1s with window size of 15, retain is 1, current rate is: 1000 per interval
[2022/04/25 16:40:38] [ info] [filter:throttle:throttle.0] 1650876038: limit is 1000.00 per 1s with window size of 15, retain is 1, current rate is: 1000 per interval
[2022/04/25 16:40:39] [ info] [filter:throttle:throttle.0] 1650876039: limit is 1000.00 per 1s with window size of 15, retain is 1, current rate is: 1000 per interval
[2022/04/25 16:40:40] [ info] [filter:throttle:throttle.0] 1650876040: limit is 1000.00 per 1s with window size of 15, retain is 1, current rate is: 1000 per interval
[2022/04/25 16:40:41] [ info] [filter:throttle:throttle.0] 1650876041: limit is 1000.00 per 1s with window size of 15, retain is 1, current rate is: 1000 per interval
[2022/04/25 16:40:42] [ info] [filter:throttle:throttle.0] 1650876042: limit is 1000.00 per 1s with window size of 15, retain is 1, current rate is: 1000 per interval
....

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

Documentation

  • Documentation required for this feature

fluent/fluent-bit-docs#796

Backporting

  • [ N/A] Backport to latest stable release.

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

@wangzhuzhen wangzhuzhen force-pushed the throttle_support_retain branch from 837efb0 to cf25d05 Compare April 25, 2022 11:10
@wangzhuzhen
Copy link
Author

@koleini @fujimotos @leonardo-albertovich @edsiper Please review this PR and give some feedbacks, Thank you very much!

@github-actions
Copy link
Contributor

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions
Copy link
Contributor

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Nov 26, 2024
@github-actions github-actions bot removed the Stale label Mar 21, 2025
@github-actions
Copy link
Contributor

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Aug 27, 2025
@eschabell
Copy link

@patrick-stephens can you maybe review this PR?

@eschabell
Copy link

eschabell commented Oct 22, 2025

The docs-required tag can be removed @patrick-stephens as the docs PR fluent/fluent-bit-docs#796 is waiting.

@github-actions github-actions bot removed the Stale label Oct 23, 2025
Copy link
Collaborator

@patrick-stephens patrick-stephens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify the use case?

Why would you use a throttle plugin that retains data instead of dropping it? Just don't use it if you want to retain data?

Comment on lines 110 to 118
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems redundant, all it does is return the value of ctx->retain_data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Throttle: Support retain messages if rate limit is exceeded

3 participants