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

Simplify identical key-value pairs in descriptors #785

Closed
rofafor opened this issue Dec 9, 2024 · 3 comments
Closed

Simplify identical key-value pairs in descriptors #785

rofafor opened this issue Dec 9, 2024 · 3 comments
Labels

Comments

@rofafor
Copy link
Contributor

rofafor commented Dec 9, 2024

Currently Envoy Gateway passes descriptors to ratelimit with identical key and value. This makes Prometheus metrics rather unusable:, e.g.:

# HELP ratelimit_service_rate_limit_envoy_gateway_system_internal_https_httproute_envoydemo_envoydemo_rule_0_match_0_envoydemo_domain_com_httproute_envoydemo_envoydemo_rule_0_match_0_envoydemo_domain_com_masked_remote_address_0_0_0_0_0_remote_address_total_hits Metric autogenerated by statsd_exporter.
# TYPE ratelimit_service_rate_limit_envoy_gateway_system_internal_https_httproute_envoydemo_envoydemo_rule_0_match_0_envoydemo_domain_com_httproute_envoydemo_envoydemo_rule_0_match_0_envoydemo_domain_com_masked_remote_address_0_0_0_0_0_remote_address_total_hits counter
ratelimit_service_rate_limit_envoy_gateway_system_internal_https_httproute_envoydemo_envoydemo_rule_0_match_0_envoydemo_domain_com_httproute_envoydemo_envoydemo_rule_0_match_0_envoydemo_domain_com_masked_remote_address_0_0_0_0_0_remote_address_total_hits 1

We can use the following patch to avoid repeating (optional) value if it's identical to key. This will simplify Prometheus labels by removing unnecessary duplication.

diff --git a/src/config/config_impl.go b/src/config/config_impl.go
index 45c276b..3bee97b 100644
--- a/src/config/config_impl.go
+++ b/src/config/config_impl.go
@@ -127,9 +127,9 @@ func (this *rateLimitDescriptor) loadDescriptors(config RateLimitConfigToLoad, p
                        panic(newRateLimitConfigError(config.Name, "descriptor has empty key"))
                }

-               // Value is optional, so the final key for the map is either the key only or key_value.
+               // Value is optional, so the final key for the map is either the key only or key_value if value differs from key.
                finalKey := descriptorConfig.Key
-               if descriptorConfig.Value != "" {
+               if descriptorConfig.Value != "" && descriptorConfig.Value != descriptorConfig.Key {
                        finalKey += "_" + descriptorConfig.Value
                }

The patch originates from #773

@wtrocki
Copy link

wtrocki commented Dec 10, 2024

Metrics are meant to represent actual rate limiting bucket key. Same value or no value might be causing confusion.
If simplification is the key, I would suggest having a new config property to skip using values as keys.

Copy link

github-actions bot commented Jan 9, 2025

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jan 9, 2025
Copy link

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants