fluent-plugin-throttle 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -8
- data/fluent-plugin-throttle.gemspec +2 -2
- data/lib/fluent/plugin/filter_throttle.rb +20 -16
- metadata +3 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 96baca37d87b547aadf4ef128d973f5605477242
         | 
| 4 | 
            +
              data.tar.gz: bb0ec1c1d81b4db2048dafac99d7b795caf2fc68
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: a85cdcbdae70af12c549012a58a2e640727c8fb9dbb12e0753499ee0091a124bd8ac90097bf89193293849de9aea6cdab4e0e3b986856aab6396f18759dfe88b
         | 
| 7 | 
            +
              data.tar.gz: 21482c46242a78e2d7d2150cead76734afdaf937be5c2d714c1d2c6ac8afa79472a89ced7cffcea7a44ab0e6807c6d17bd9b4b5c5dab6adc54a851243a2dfacd
         | 
    
        data/README.md
    CHANGED
    
    | @@ -26,7 +26,7 @@ $ gem install fluent-plugin-throttle | |
| 26 26 |  | 
| 27 27 | 
             
            ## Configuration
         | 
| 28 28 |  | 
| 29 | 
            -
             | 
| 29 | 
            +
            #### group\_key
         | 
| 30 30 |  | 
| 31 31 | 
             
            Default: `kubernetes.container_name`.
         | 
| 32 32 |  | 
| @@ -40,13 +40,13 @@ the group key resolve to "random": | |
| 40 40 |  | 
| 41 41 | 
             
            If the group cannot be resolved, am anonymous group is used.
         | 
| 42 42 |  | 
| 43 | 
            -
             | 
| 43 | 
            +
            #### group\_bucket\_period\_s
         | 
| 44 44 |  | 
| 45 45 | 
             
            Default: `60` (60 second).
         | 
| 46 46 |  | 
| 47 47 | 
             
            This is the period of of time over which `group_bucket_limit` applies.
         | 
| 48 48 |  | 
| 49 | 
            -
             | 
| 49 | 
            +
            #### group\_bucket\_limit
         | 
| 50 50 |  | 
| 51 51 | 
             
            Default: `6000` (logs per `group_bucket_period_s`).
         | 
| 52 52 |  | 
| @@ -69,10 +69,10 @@ logs per minute. However `60/60s` will readily emit 60 logs within the first | |
| 69 69 | 
             
            second then nothing for the remaining 59 seconds. While the `1/1s` will only
         | 
| 70 70 | 
             
            emit the first log of every second.
         | 
| 71 71 |  | 
| 72 | 
            -
             | 
| 72 | 
            +
            #### group\_reset\_rate\_s
         | 
| 73 73 |  | 
| 74 74 | 
             
            Default: `group_bucket_limit/group_bucket_period_s` (logs per `group_bucket_period_s`).
         | 
| 75 | 
            -
             | 
| 75 | 
            +
            Maximum: `group_bucket_limit/group_bucket_period_s`.
         | 
| 76 76 |  | 
| 77 77 | 
             
            After a group has exceeded its bucket limit, logs are dropped until the rate
         | 
| 78 78 | 
             
            per second falls below or equal to `group_reset_rate_s`.
         | 
| @@ -105,12 +105,13 @@ after a single breach of the limit until the next restart of fluentd. | |
| 105 105 |  | 
| 106 106 | 
             
            A value of `-1` disables the feature.
         | 
| 107 107 |  | 
| 108 | 
            -
             | 
| 108 | 
            +
            #### group\_warning\_delay\_s
         | 
| 109 109 |  | 
| 110 | 
            -
            Default: ` | 
| 110 | 
            +
            Default: `10` (seconds).
         | 
| 111 111 |  | 
| 112 112 | 
             
            When a group reaches its limit and as long as it is not reset, a warning
         | 
| 113 | 
            -
            message with the current log rate  | 
| 113 | 
            +
            message with the current log rate of the group is emitted repeatedly. This is
         | 
| 114 | 
            +
            the delay between every repetition.
         | 
| 114 115 |  | 
| 115 116 | 
             
            ## Copyright
         | 
| 116 117 |  | 
| @@ -4,11 +4,11 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | |
| 4 4 |  | 
| 5 5 | 
             
            Gem::Specification.new do |spec|
         | 
| 6 6 | 
             
              spec.name          = "fluent-plugin-throttle"
         | 
| 7 | 
            -
              spec.version       = "0.0. | 
| 7 | 
            +
              spec.version       = "0.0.3"
         | 
| 8 8 | 
             
              spec.authors       = ["François-Xavier Bourlet"]
         | 
| 9 9 | 
             
              spec.email         = ["fx.bourlet@rubrik.com"]
         | 
| 10 10 | 
             
              spec.summary       = %q{Fluentd filter for throttling logs based on a configurable key.}
         | 
| 11 | 
            -
              spec.homepage      = "https://github.com/ | 
| 11 | 
            +
              spec.homepage      = "https://github.com/rubrikinc/fluent-plugin-throttle"
         | 
| 12 12 | 
             
              spec.license       = "Apache-2.0"
         | 
| 13 13 |  | 
| 14 14 | 
             
              spec.files         = `git ls-files`.split($/)
         | 
| @@ -8,9 +8,8 @@ module Fluent | |
| 8 8 | 
             
                config_param :group_bucket_period_s, :integer, :default => 60
         | 
| 9 9 | 
             
                config_param :group_bucket_limit, :integer, :default => 6000
         | 
| 10 10 | 
             
                config_param :group_reset_rate_s, :integer, :default => nil
         | 
| 11 | 
            -
                config_param : | 
| 11 | 
            +
                config_param :group_warning_delay_s, :integer, :default => 10
         | 
| 12 12 |  | 
| 13 | 
            -
                Bucket = Struct.new(:emitted, :last_reset)
         | 
| 14 13 | 
             
                Group = Struct.new(
         | 
| 15 14 | 
             
                  :rate_count,
         | 
| 16 15 | 
             
                  :rate_last_reset,
         | 
| @@ -40,7 +39,8 @@ module Fluent | |
| 40 39 | 
             
                  raise "group_reset_rate_s must be <= group_bucket_limit / group_bucket_period_s" \
         | 
| 41 40 | 
             
                    unless @group_reset_rate_s <= @group_rate_limit
         | 
| 42 41 |  | 
| 43 | 
            -
                   | 
| 42 | 
            +
                  raise "group_warning_delay_s must be >= 1" \
         | 
| 43 | 
            +
                    unless @group_warning_delay_s >= 1
         | 
| 44 44 | 
             
                end
         | 
| 45 45 |  | 
| 46 46 | 
             
                def start
         | 
| @@ -73,35 +73,34 @@ module Fluent | |
| 73 73 |  | 
| 74 74 | 
             
                  if (now.to_i / @group_bucket_period_s) \
         | 
| 75 75 | 
             
                      > (counter.bucket_last_reset.to_i / @group_bucket_period_s)
         | 
| 76 | 
            -
                    # next time period reached | 
| 76 | 
            +
                    # next time period reached.
         | 
| 77 77 |  | 
| 78 | 
            +
                    # wait until rate drops back down (if enabled).
         | 
| 78 79 | 
             
                    if counter.bucket_count == -1 and @group_reset_rate_s != -1
         | 
| 79 | 
            -
                      # wait until rate drops back down if needed.
         | 
| 80 80 | 
             
                      if counter.aprox_rate < @group_reset_rate_s
         | 
| 81 81 | 
             
                        log_rate_back_down(now, group, counter)
         | 
| 82 82 | 
             
                      else
         | 
| 83 | 
            -
                         | 
| 84 | 
            -
                        if since_last_warning >= @warning_delay
         | 
| 85 | 
            -
                          log_rate_limit_exceeded(now, group, counter)
         | 
| 86 | 
            -
                          counter.last_warning = now
         | 
| 87 | 
            -
                        end
         | 
| 83 | 
            +
                        log_rate_limit_exceeded(now, group, counter)
         | 
| 88 84 | 
             
                        return nil
         | 
| 89 85 | 
             
                      end
         | 
| 90 86 | 
             
                    end
         | 
| 91 87 |  | 
| 88 | 
            +
                    # reset counter for the rest of time period.
         | 
| 92 89 | 
             
                    counter.bucket_count = 0
         | 
| 93 90 | 
             
                    counter.bucket_last_reset = now
         | 
| 94 | 
            -
                   | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
             | 
| 91 | 
            +
                  else
         | 
| 92 | 
            +
                    # if current time period credit is exhausted, drop the record.
         | 
| 93 | 
            +
                    if counter.bucket_count == -1
         | 
| 94 | 
            +
                      log_rate_limit_exceeded(now, group, counter)
         | 
| 95 | 
            +
                      return nil
         | 
| 96 | 
            +
                    end
         | 
| 98 97 | 
             
                  end
         | 
| 99 98 |  | 
| 100 99 | 
             
                  counter.bucket_count += 1
         | 
| 101 100 |  | 
| 101 | 
            +
                  # if we are out of credit, we drop logs for the rest of the time period.
         | 
| 102 102 | 
             
                  if counter.bucket_count > @group_bucket_limit
         | 
| 103 103 | 
             
                    log_rate_limit_exceeded(now, group, counter)
         | 
| 104 | 
            -
                    counter.last_warning = now
         | 
| 105 104 | 
             
                    counter.bucket_count = -1
         | 
| 106 105 | 
             
                    return nil
         | 
| 107 106 | 
             
                  end
         | 
| @@ -114,7 +113,12 @@ module Fluent | |
| 114 113 | 
             
                end
         | 
| 115 114 |  | 
| 116 115 | 
             
                def log_rate_limit_exceeded(now, group, counter)
         | 
| 117 | 
            -
                   | 
| 116 | 
            +
                  emit = counter.last_warning == nil ? true \
         | 
| 117 | 
            +
                    : (now - counter.last_warning) >= @group_warning_delay_s
         | 
| 118 | 
            +
                  if emit
         | 
| 119 | 
            +
                    $log.warn("rate exceeded", log_items(now, group, counter))
         | 
| 120 | 
            +
                    counter.last_warning = now
         | 
| 121 | 
            +
                  end
         | 
| 118 122 | 
             
                end
         | 
| 119 123 |  | 
| 120 124 | 
             
                def log_rate_back_down(now, group, counter)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: fluent-plugin-throttle
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - François-Xavier Bourlet
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2018-03- | 
| 11 | 
            +
            date: 2018-03-27 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: bundler
         | 
| @@ -105,7 +105,7 @@ files: | |
| 105 105 | 
             
            - README.md
         | 
| 106 106 | 
             
            - fluent-plugin-throttle.gemspec
         | 
| 107 107 | 
             
            - lib/fluent/plugin/filter_throttle.rb
         | 
| 108 | 
            -
            homepage: https://github.com/ | 
| 108 | 
            +
            homepage: https://github.com/rubrikinc/fluent-plugin-throttle
         | 
| 109 109 | 
             
            licenses:
         | 
| 110 110 | 
             
            - Apache-2.0
         | 
| 111 111 | 
             
            metadata: {}
         |