Skip to content

Commit

Permalink
Add detailed_metric support for xds-config
Browse files Browse the repository at this point in the history
  • Loading branch information
akondapuram committed Dec 21, 2023
1 parent 97c2f6f commit 23b17b6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
18 changes: 4 additions & 14 deletions api/ratelimit/config/ratelimit/v3/rls_conf.proto
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ message RateLimitDescriptor {

// Mark the descriptor as shadow. When the values is true, rate limit service allow requests to the backend.
bool shadow_mode = 5;

// Setting the `detailed_metric: true` for a descriptor will extend the metrics that are produced.
bool detailed_metric = 6;
}

// Rate-limit policy.
Expand Down Expand Up @@ -88,17 +91,4 @@ enum RateLimitUnit {

// The time unit representing a day.
DAY = 4;
}

// [#protodoc-title: Rate Limit Config Discovery Service (RLS Conf DS)]

// Return list of all rate limit configs that rate limit service should be configured with.
service RateLimitConfigDiscoveryService {
rpc StreamRlsConfigs(stream envoy.service.discovery.v3.DiscoveryRequest)
returns (stream envoy.service.discovery.v3.DiscoveryResponse) {
}

rpc FetchRlsConfigs(envoy.service.discovery.v3.DiscoveryRequest)
returns (envoy.service.discovery.v3.DiscoveryResponse) {
}
}
}
1 change: 1 addition & 0 deletions examples/xds-sotw-config-server/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func makeRlsConfig() []types.Resource {
Unit: rls_config.RateLimitUnit_MINUTE,
RequestsPerUnit: 3,
},
DetailedMetric: true,
},
{
Key: "bar",
Expand Down
14 changes: 7 additions & 7 deletions src/config/config_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ type YamlRateLimit struct {
}

type YamlDescriptor struct {
Key string
Value string
RateLimit *YamlRateLimit `yaml:"rate_limit"`
Descriptors []YamlDescriptor
ShadowMode bool `yaml:"shadow_mode"`
IncludeMetricsForUnspecifiedValue bool `yaml:"detailed_metric"`
Key string
Value string
RateLimit *YamlRateLimit `yaml:"rate_limit"`
Descriptors []YamlDescriptor
ShadowMode bool `yaml:"shadow_mode"`
DetailedMetric bool `yaml:"detailed_metric"`
}

type YamlRoot struct {
Expand Down Expand Up @@ -167,7 +167,7 @@ func (this *rateLimitDescriptor) loadDescriptors(config RateLimitConfigToLoad, p
rateLimit = NewRateLimit(
descriptorConfig.RateLimit.RequestsPerUnit, pb.RateLimitResponse_RateLimit_Unit(value),
statsManager.NewStats(newParentKey), unlimited, descriptorConfig.ShadowMode,
descriptorConfig.RateLimit.Name, replaces, descriptorConfig.IncludeMetricsForUnspecifiedValue,
descriptorConfig.RateLimit.Name, replaces, descriptorConfig.DetailedMetric,
)
rateLimitDebugString = fmt.Sprintf(
" ratelimit={requests_per_unit=%d, unit=%s, unlimited=%t, shadow_mode=%t}", rateLimit.Limit.RequestsPerUnit,
Expand Down
11 changes: 6 additions & 5 deletions src/config/config_xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ func rateLimitDescriptorsPbToYaml(pb []*rls_conf_v3.RateLimitDescriptor) []YamlD
descriptors := make([]YamlDescriptor, len(pb))
for i, d := range pb {
descriptors[i] = YamlDescriptor{
Key: d.Key,
Value: d.Value,
RateLimit: rateLimitPolicyPbToYaml(d.RateLimit),
Descriptors: rateLimitDescriptorsPbToYaml(d.Descriptors),
ShadowMode: d.ShadowMode,
Key: d.Key,
Value: d.Value,
RateLimit: rateLimitPolicyPbToYaml(d.RateLimit),
Descriptors: rateLimitDescriptorsPbToYaml(d.Descriptors),
ShadowMode: d.ShadowMode,
DetailedMetric: d.DetailedMetric,
}
}

Expand Down

0 comments on commit 23b17b6

Please sign in to comment.