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

Open
rofafor opened this issue Dec 9, 2024 · 1 comment
Open

Simplify identical key-value pairs in descriptors #785

rofafor opened this issue Dec 9, 2024 · 1 comment

Comments

@rofafor
Copy link

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.

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

No branches or pull requests

2 participants