Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE-4600 - Quotas: disable produce quota by default #20142

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/v/config/configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,12 @@ configuration::configuration()
, target_quota_byte_rate(
*this,
"target_quota_byte_rate",
"Target request size quota byte rate (bytes per second) - 2GB default",
"Target request size quota byte rate (bytes per second)",
{.needs_restart = needs_restart::no,
.example = "1073741824",
.visibility = visibility::user},
target_produce_quota_byte_rate_default,
{.min = 1_MiB})
{.min = 0})
BenPope marked this conversation as resolved.
Show resolved Hide resolved
, target_fetch_quota_byte_rate(
*this,
"target_fetch_quota_byte_rate",
Expand Down
3 changes: 2 additions & 1 deletion src/v/config/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ namespace config {
/// can not depend on any other module to prevent cyclic dependencies.

struct configuration final : public config_store {
constexpr static auto target_produce_quota_byte_rate_default = 2_GiB;
constexpr static auto target_produce_quota_byte_rate_default
= 0; // disabled

// WAL
bounded_property<uint64_t> log_segment_size;
Expand Down
18 changes: 16 additions & 2 deletions src/v/kafka/server/client_quota_translator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <seastar/core/shard_id.hh>
#include <seastar/util/variant_utils.hh>

#include <absl/algorithm/container.h>

#include <optional>

namespace kafka {

using cluster::client_quota::entity_key;
Expand Down Expand Up @@ -292,8 +296,11 @@ client_quota_translator::get_quota_config(client_quota_type qt) const {
std::optional<uint64_t>
client_quota_translator::get_default_config(client_quota_type qt) const {
switch (qt) {
case kafka::client_quota_type::produce_quota:
return _default_target_produce_tp_rate();
case kafka::client_quota_type::produce_quota: {
auto produce_quota = _default_target_produce_tp_rate();
return (produce_quota > 0) ? std::make_optional<uint64_t>(produce_quota)
: std::nullopt;
}
case kafka::client_quota_type::fetch_quota:
return _default_target_fetch_tp_rate();
case kafka::client_quota_type::partition_mutation_quota:
Expand Down Expand Up @@ -325,4 +332,11 @@ void client_quota_translator::maybe_log_deprecated_configs_nag() const {
}
}

bool client_quota_translator::is_empty() const {
return _quota_store.local().size() == 0
&& absl::c_all_of(all_client_quota_types, [this](auto qt) {
return !get_default_config(qt);
});
}

} // namespace kafka
3 changes: 3 additions & 0 deletions src/v/kafka/server/client_quota_translator.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ class client_quota_translator {
/// `watch` can be used to register for quota changes
void watch(on_change_fn&& fn);

/// Returns true if there are no quotas configured
bool is_empty() const;

private:
using quota_config
= std::unordered_map<ss::sstring, config::client_group_quota>;
Expand Down
12 changes: 12 additions & 0 deletions src/v/kafka/server/quota_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ ss::future<std::chrono::milliseconds> quota_manager::record_partition_mutations(
/// KIP-599 throttles create_topics / delete_topics / create_partitions
/// request. This delay should only be applied to these requests if the
/// quota has been exceeded
if (_translator.is_empty()) {
co_return 0ms;
}
auto ctx = client_quota_request_ctx{
.q_type = client_quota_type::partition_mutation_quota,
.client_id = client_id,
Expand Down Expand Up @@ -391,6 +394,9 @@ ss::future<clock::duration> quota_manager::record_produce_tp_and_throttle(
std::optional<std::string_view> client_id,
uint64_t bytes,
clock::time_point now) {
if (_translator.is_empty()) {
co_return 0ms;
}
auto ctx = client_quota_request_ctx{
.q_type = client_quota_type::produce_quota,
.client_id = client_id,
Expand Down Expand Up @@ -440,6 +446,9 @@ ss::future<> quota_manager::record_fetch_tp(
std::optional<std::string_view> client_id,
uint64_t bytes,
clock::time_point now) {
if (_translator.is_empty()) {
co_return;
}
auto ctx = client_quota_request_ctx{
.q_type = client_quota_type::fetch_quota,
.client_id = client_id,
Expand Down Expand Up @@ -469,6 +478,9 @@ ss::future<> quota_manager::record_fetch_tp(

ss::future<clock::duration> quota_manager::throttle_fetch_tp(
std::optional<std::string_view> client_id, clock::time_point now) {
if (_translator.is_empty()) {
co_return 0ms;
}
auto ctx = client_quota_request_ctx{
.q_type = client_quota_type::fetch_quota,
.client_id = client_id,
Expand Down
4 changes: 3 additions & 1 deletion src/v/kafka/server/tests/client_quota_translator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ SEASTAR_THREAD_TEST_CASE(quota_translator_default_test) {
fixture f;

auto default_limits = client_quota_limits{
.produce_limit = scale_to_smp_count(2147483648),
.produce_limit = std::nullopt,
.fetch_limit = std::nullopt,
.partition_mutation_limit = std::nullopt,
};
Expand All @@ -96,6 +96,7 @@ SEASTAR_THREAD_TEST_CASE(quota_translator_default_test) {
auto limits = f.tr.find_quota_value(key);
BOOST_CHECK_EQUAL(test_client_id_key, key);
BOOST_CHECK_EQUAL(default_limits, limits);
BOOST_CHECK(f.tr.is_empty());
}

SEASTAR_THREAD_TEST_CASE(quota_translator_modified_default_test) {
Expand All @@ -116,6 +117,7 @@ SEASTAR_THREAD_TEST_CASE(quota_translator_modified_default_test) {
auto limits = f.tr.find_quota_value(key);
BOOST_CHECK_EQUAL(test_client_id_key, key);
BOOST_CHECK_EQUAL(expected_limits, limits);
BOOST_CHECK(!f.tr.is_empty());
}

void run_quota_translator_client_group_test(fixture& f) {
Expand Down
Loading