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

rpk: add client quotas support to rpk #18711

Merged
merged 3 commits into from
Jun 6, 2024

Conversation

r-vasquez
Copy link
Contributor

This PR adds rpk support to DescribeClientQuotas and AlterClientQuotas under the rpk cluster quotas command.

Examples:

Creating a Quota

$ rpk cluster quotas alter --add consumer_byte_rate=12000 --name client-id=foo --default user
ENTITY                        STATUS
client-id=foo,user=<default>  OK

Describing Quotas

$ rpk cluster quotas describe --name client-id=testclient                                    
ENTITY                               QUOTA-TYPE          QUOTA-VALUE
client-id=testclient,user=user2      producer_byte_rate  130000
client-id=testclient,user=<default>  producer_byte_rate  140000

All new commands now include support for --format json|yaml flag.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v24.1.x
  • v23.3.x
  • v23.2.x

Release Notes

Features

  • rpk: now you can manage client quotas using rpk cluster quotas.

@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented May 30, 2024

@r-vasquez r-vasquez force-pushed the rpk-client-quotas branch from 57e8080 to 1b7fc43 Compare May 30, 2024 19:53
@r-vasquez
Copy link
Contributor Author

r-vasquez commented May 30, 2024

Last Force Push:

  • Refactor the describe output
  • Add ducktape handler for rpk cluster quotas in 1b7fc43

@pgellert pgellert self-requested a review May 31, 2024 10:26
Copy link
Contributor

@pgellert pgellert left a comment

Choose a reason for hiding this comment

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

Thanks, I've skimmed through the PR and it pretty much looks good to me. I might come back for a deeper review later. But let me add a bit of context in the meantime:

For the time being, Redpanda is only going to support a subset of the quotas that Kafka supports:

  • Only entity=client quotas and only for the consumer_byte_rate, producer_byte_rate and controller_mutation_rate quota types
  • We won’t yet support user entity types or ip entity types. We also won’t support connection_creation_rate and request_percentage quotas.
    I’m wondering if it would be confusing for customers if rpk supports everything but redpanda doesn’t. I think it’s probably fine as long as we propagate the errors returned by redpanda to the user and redpanda handles the validation of which quota combinations are supported. I think that’s already the case, but I just wanted to call this out for context.

Also, redpanda has a client-id-prefix entity type that we’ve introduced. Long story short, redpanda has supported this client quota type from a while ago and we want to be able to configure them through the Kafka API as well. I’m not sure if franz-go would already support this (ie. if it validates the entity type string at all), but if it’s easy, it would be great if rpk could start supporting the client-id-prefix entity type as well. It would make testing easier in redpanda.

@@ -1849,3 +1849,57 @@ def _run_role(self, cmd, output_format="json"):
out = self._execute(cmd)

return json.loads(out) if output_format == "json" else out

def describe_cluster_quotas(self,
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks so much for setting this up!

Feediver1
Feediver1 previously approved these changes May 31, 2024
Copy link

@Feediver1 Feediver1 left a comment

Choose a reason for hiding this comment

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

Left some suggestions for clarity, consistency with docs.

@r-vasquez
Copy link
Contributor Author

@pgellert How does a client-id-prefix entity work along with client-id? how does a default for client-id-prefix work?

Is an entity composed of {client-id=id, client-id-prefix=prefix} or is it like IP, where the prefix is a single entity.

Also, out of curiosity, what's the order of precedence? say I have:

client-id=foo-bar
consumer_byte_rate=200

client-id=<default>
consumer_byte_rate=100

client-id-prefix=foo-
consumer_byte_rate=300

@pgellert
Copy link
Contributor

pgellert commented Jun 5, 2024

@r-vasquez:

How does a client-id-prefix entity work along with client-id? how does a default for client-id-prefix work?

The priority order is:

  1. Explicit match: (client-id, <client-id>)
  2. Prefix match: (client-id-prefix, <client-id-prefix>)
  3. Client default: (client-id, <default>)

There's no specific default for client-id-prefix, (client-id-prefix, <default>) should be "not supported" and we should error out either in rpk/redpanda.

Is an entity composed of {client-id=id, client-id-prefix=prefix} or is it like IP, where the prefix is a single entity.

The client-id and client-id-prefix should be mutually exclusive, but we should allow both {client-id=id, user=user} and {client-id-prefix=prefix, user=user} pairs (at least once redpanda supports user-based quotas). So {client-id-prefix=prefix} should be usable whereever {client-id=id} is used.

Also, out of curiosity, what's the order of precedence? say I have:

client-id=foo-bar
consumer_byte_rate=200

client-id=<default>
consumer_byte_rate=100

client-id-prefix=foo-
consumer_byte_rate=300

Based on the priority order from above, foo-bar would get 200 (explicit match wins over prefix match), foo-abc would get 300 (from the prefix match) and baz would get 100 (from the default).

@r-vasquez r-vasquez force-pushed the rpk-client-quotas branch from 6db00db to 9e4f61e Compare June 5, 2024 15:17
@r-vasquez r-vasquez requested a review from pgellert June 5, 2024 15:17
@r-vasquez
Copy link
Contributor Author

r-vasquez commented Jun 5, 2024

Last 2 force pushes: 1 and 2

  • Removed any reference to user and ip from the help text.
  • Applied the suggested doc changes
  • Added client-id-prefix to the examples.
  • Added an error message when the describe command returns an empty list. (text format)

@pgellert Thanks for the context, I changed the PR to meet what Redpanda will support, the validation happens in Redpanda so we should be fine.

(For example, this is using Kafka:)

// client-id-prefix is not valid in Kafka
$ rpk cluster quotas alter --add producer_byte_rate=12123123 --name client-id-prefix=foo-
ENTITY                 STATUS
client-id-prefix=foo-  Error: Unhandled client quota entity type: client-id-prefix

// From Kafka Logs:
[2024-06-05 15:21:02,385] INFO [Admin Manager on Broker 1]: Error encountered while updating client quotas (kafka.server.ZkAdminManager)
org.apache.kafka.common.errors.InvalidRequestException: Unhandled client quota entity type: client-id-prefix

Please review the examples again.

twmb
twmb previously approved these changes Jun 6, 2024
Copy link
Contributor

@pgellert pgellert left a comment

Choose a reason for hiding this comment

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

There's one error message which is misleading but apart from that lgtm.

src/go/rpk/pkg/cli/cluster/quotas/describe.go Outdated Show resolved Hide resolved
Comment on lines 109 to 111
if !validTypes[def] {
out.Die("default type %q is invalid (allowed: client-id, client-id-prefix)", def)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The error message says that --default client-id-prefix is allowed even though it's not supported. I think there should probably be a separate validTypes for any and default. Alternatively, we could handle the validation in redpanda and rpk will just show the error but at least this error message should be changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added your suggestion in a new commit, thanks! 0ac43ee

client-id-prefix is not a valid entity type to be
used with <default>
@r-vasquez r-vasquez merged commit ad9867f into redpanda-data:dev Jun 6, 2024
23 checks passed
@r-vasquez r-vasquez deleted the rpk-client-quotas branch July 3, 2024 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants