Support per-method backend ratelimit options
Depends-on: https://review.opendev.org/840542 Change-Id: Ia3b337e4681e03c03bd30581d278a0479df15fdd
This commit is contained in:
		@@ -8,6 +8,41 @@
 | 
				
			|||||||
#   worker.
 | 
					#   worker.
 | 
				
			||||||
#   Defaults to $facts['os_service_default']
 | 
					#   Defaults to $facts['os_service_default']
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					# [*delete_requests_per_device_per_second*]
 | 
				
			||||||
 | 
					#   (optional) Set the maximum rate of DELETE requests per second per device
 | 
				
			||||||
 | 
					#   per worker.
 | 
				
			||||||
 | 
					#   Defaults to $facts['os_service_default']
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# [*get_requests_per_device_per_second*]
 | 
				
			||||||
 | 
					#   (optional) Set the maximum rate of GET requests per second per device per
 | 
				
			||||||
 | 
					#   worker.
 | 
				
			||||||
 | 
					#   Defaults to $facts['os_service_default']
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# [*head_requests_per_device_per_second*]
 | 
				
			||||||
 | 
					#   (optional) Set the maximum rate of HEAD requests per second per device per
 | 
				
			||||||
 | 
					#   worker.
 | 
				
			||||||
 | 
					#   Defaults to $facts['os_service_default']
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# [*post_requests_per_device_per_second*]
 | 
				
			||||||
 | 
					#   (optional) Set the maximum rate of POST requests per second per device per
 | 
				
			||||||
 | 
					#   worker.
 | 
				
			||||||
 | 
					#   Defaults to $facts['os_service_default']
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# [*put_requests_per_device_per_second*]
 | 
				
			||||||
 | 
					#   (optional) Set the maximum rate of PUT requests per second per device per
 | 
				
			||||||
 | 
					#   worker.
 | 
				
			||||||
 | 
					#   Defaults to $facts['os_service_default']
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# [*replicate_requests_per_device_per_second*]
 | 
				
			||||||
 | 
					#   (optional) Set the maximum rate of REPLICATE requests per second per device
 | 
				
			||||||
 | 
					#   per worker.
 | 
				
			||||||
 | 
					#   Defaults to $facts['os_service_default']
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# [*update_requests_per_device_per_second*]
 | 
				
			||||||
 | 
					#   (optional) Set the maximum rate of UPDATE requests per second per device
 | 
				
			||||||
 | 
					#   per worker.
 | 
				
			||||||
 | 
					#   Defaults to $facts['os_service_default']
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
# [*requests_per_device_rate_buffer*]
 | 
					# [*requests_per_device_rate_buffer*]
 | 
				
			||||||
#   (optional) Set the number of seconds of unused rate-limiting allowance that
 | 
					#   (optional) Set the number of seconds of unused rate-limiting allowance that
 | 
				
			||||||
#   can accumulate and be used to allow a subsequent burst of requests.
 | 
					#   can accumulate and be used to allow a subsequent burst of requests.
 | 
				
			||||||
@@ -26,8 +61,15 @@
 | 
				
			|||||||
# Copyright 2022 Red Hat, unless otherwise noted.
 | 
					# Copyright 2022 Red Hat, unless otherwise noted.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
define swift::storage::filter::backend_ratelimit(
 | 
					define swift::storage::filter::backend_ratelimit(
 | 
				
			||||||
  $requests_per_device_per_second  = $facts['os_service_default'],
 | 
					  $requests_per_device_per_second           = $facts['os_service_default'],
 | 
				
			||||||
  $requests_per_device_rate_buffer = $facts['os_service_default'],
 | 
					  $delete_requests_per_device_per_second    = $facts['os_service_default'],
 | 
				
			||||||
 | 
					  $get_requests_per_device_per_second       = $facts['os_service_default'],
 | 
				
			||||||
 | 
					  $head_requests_per_device_per_second      = $facts['os_service_default'],
 | 
				
			||||||
 | 
					  $post_requests_per_device_per_second      = $facts['os_service_default'],
 | 
				
			||||||
 | 
					  $put_requests_per_device_per_second       = $facts['os_service_default'],
 | 
				
			||||||
 | 
					  $replicate_requests_per_device_per_second = $facts['os_service_default'],
 | 
				
			||||||
 | 
					  $update_requests_per_device_per_second    = $facts['os_service_default'],
 | 
				
			||||||
 | 
					  $requests_per_device_rate_buffer          = $facts['os_service_default'],
 | 
				
			||||||
) {
 | 
					) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  include swift::deps
 | 
					  include swift::deps
 | 
				
			||||||
@@ -35,13 +77,34 @@ define swift::storage::filter::backend_ratelimit(
 | 
				
			|||||||
  $config_type = "swift_${name}_config"
 | 
					  $config_type = "swift_${name}_config"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  create_resources($config_type, {
 | 
					  create_resources($config_type, {
 | 
				
			||||||
    'filter:backend_ratelimit/use'                             => {
 | 
					    'filter:backend_ratelimit/use'                                      => {
 | 
				
			||||||
      'value' => 'egg:swift#backend_ratelimit'
 | 
					      'value' => 'egg:swift#backend_ratelimit'
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    'filter:backend_ratelimit/requests_per_device_per_second'  => {
 | 
					    'filter:backend_ratelimit/requests_per_device_per_second'           => {
 | 
				
			||||||
      'value' => $requests_per_device_per_second
 | 
					      'value' => $requests_per_device_per_second
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    'filter:backend_ratelimit/requests_per_device_rate_buffer' => {
 | 
					    'filter:backend_ratelimit/delete_requests_per_device_per_second'    => {
 | 
				
			||||||
 | 
					      'value' => $delete_requests_per_device_per_second
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    'filter:backend_ratelimit/get_requests_per_device_per_second'       => {
 | 
				
			||||||
 | 
					      'value' => $get_requests_per_device_per_second
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    'filter:backend_ratelimit/head_requests_per_device_per_second'      => {
 | 
				
			||||||
 | 
					      'value' => $head_requests_per_device_per_second
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    'filter:backend_ratelimit/post_requests_per_device_per_second'      => {
 | 
				
			||||||
 | 
					      'value' => $post_requests_per_device_per_second
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    'filter:backend_ratelimit/put_requests_per_device_per_second'       => {
 | 
				
			||||||
 | 
					      'value' => $put_requests_per_device_per_second
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    'filter:backend_ratelimit/replicate_requests_per_device_per_second' => {
 | 
				
			||||||
 | 
					      'value' => $replicate_requests_per_device_per_second
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    'filter:backend_ratelimit/update_requests_per_device_per_second'    => {
 | 
				
			||||||
 | 
					      'value' => $update_requests_per_device_per_second
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    'filter:backend_ratelimit/requests_per_device_rate_buffer'          => {
 | 
				
			||||||
      'value' => $requests_per_device_rate_buffer
 | 
					      'value' => $requests_per_device_rate_buffer
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  })
 | 
					  })
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,5 @@
 | 
				
			|||||||
 | 
					---
 | 
				
			||||||
 | 
					features:
 | 
				
			||||||
 | 
					  - |
 | 
				
			||||||
 | 
					    The ``swift::storage::filter::backend_ratelimite`` defined resource type
 | 
				
			||||||
 | 
					    supports options for per-method rate limits.
 | 
				
			||||||
@@ -8,28 +8,82 @@ describe 'swift::storage::filter::backend_ratelimit' do
 | 
				
			|||||||
  shared_examples 'swift::storage::filter::backend_ratelimit' do
 | 
					  shared_examples 'swift::storage::filter::backend_ratelimit' do
 | 
				
			||||||
    describe 'when passing default parameters' do
 | 
					    describe 'when passing default parameters' do
 | 
				
			||||||
      it 'should configure the backend_ratelimit middleware' do
 | 
					      it 'should configure the backend_ratelimit middleware' do
 | 
				
			||||||
        is_expected.to contain_swift_account_config('filter:backend_ratelimit/use').\
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
          with_value('egg:swift#backend_ratelimit')
 | 
					          'filter:backend_ratelimit/use'
 | 
				
			||||||
        is_expected.to contain_swift_account_config('filter:backend_ratelimit/requests_per_device_per_second').\
 | 
					        ).with_value('egg:swift#backend_ratelimit')
 | 
				
			||||||
          with_value('<SERVICE DEFAULT>')
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
        is_expected.to contain_swift_account_config('filter:backend_ratelimit/requests_per_device_rate_buffer').\
 | 
					          'filter:backend_ratelimit/requests_per_device_per_second'
 | 
				
			||||||
          with_value('<SERVICE DEFAULT>')
 | 
					        ).with_value('<SERVICE DEFAULT>')
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/delete_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value('<SERVICE DEFAULT>')
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/get_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value('<SERVICE DEFAULT>')
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/head_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value('<SERVICE DEFAULT>')
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/post_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value('<SERVICE DEFAULT>')
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/put_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value('<SERVICE DEFAULT>')
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/replicate_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value('<SERVICE DEFAULT>')
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/update_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value('<SERVICE DEFAULT>')
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/requests_per_device_rate_buffer'
 | 
				
			||||||
 | 
					        ).with_value('<SERVICE DEFAULT>')
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    describe 'when overriding default parameters' do
 | 
					    describe 'when overriding default parameters' do
 | 
				
			||||||
      let :params do
 | 
					      let :params do
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          :requests_per_device_per_second  => 0.0,
 | 
					          :requests_per_device_per_second           => 10.0,
 | 
				
			||||||
          :requests_per_device_rate_buffer => 1.0
 | 
					          :delete_requests_per_device_per_second    => 11.0,
 | 
				
			||||||
 | 
					          :get_requests_per_device_per_second       => 12.0,
 | 
				
			||||||
 | 
					          :head_requests_per_device_per_second      => 13.0,
 | 
				
			||||||
 | 
					          :post_requests_per_device_per_second      => 14.0,
 | 
				
			||||||
 | 
					          :put_requests_per_device_per_second       => 15.0,
 | 
				
			||||||
 | 
					          :replicate_requests_per_device_per_second => 16.0,
 | 
				
			||||||
 | 
					          :update_requests_per_device_per_second    => 17.0,
 | 
				
			||||||
 | 
					          :requests_per_device_rate_buffer          => 1.0
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it 'should configure the backend_ratelimit middleware' do
 | 
					      it 'should configure the backend_ratelimit middleware' do
 | 
				
			||||||
        is_expected.to contain_swift_account_config('filter:backend_ratelimit/requests_per_device_per_second').\
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
          with_value(0.0)
 | 
					          'filter:backend_ratelimit/requests_per_device_per_second'
 | 
				
			||||||
        is_expected.to contain_swift_account_config('filter:backend_ratelimit/requests_per_device_rate_buffer').\
 | 
					        ).with_value(10.0)
 | 
				
			||||||
          with_value(1.0)
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/delete_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value(11.0)
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/get_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value(12.0)
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/head_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value(13.0)
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/post_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value(14.0)
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/put_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value(15.0)
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/replicate_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value(16.0)
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/update_requests_per_device_per_second'
 | 
				
			||||||
 | 
					        ).with_value(17.0)
 | 
				
			||||||
 | 
					        is_expected.to contain_swift_account_config(
 | 
				
			||||||
 | 
					          'filter:backend_ratelimit/requests_per_device_rate_buffer'
 | 
				
			||||||
 | 
					        ).with_value(1.0)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user