Skip to content

Commit a4a9d77

Browse files
committed
Refactor: unify logic to include value to stats
Signed-off-by: Nam Dang <[email protected]>
1 parent 8b3be79 commit a4a9d77

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

src/config/config_impl.go

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -403,52 +403,38 @@ func (this *rateLimitConfigImpl) GetLimit(
403403
// Build value_to_metric metrics path for this level
404404
valueToMetricFullKey.WriteString(".")
405405
if nextDescriptor != nil {
406-
// Check if share_threshold is enabled for this entry
406+
// Determine the value to use for this entry
407+
var valueToUse string
407408
hasShareThreshold := shareThresholdPatterns[i] != ""
409+
408410
if matchedWildcardKey != "" {
409-
// If share_threshold: always use wildcard pattern with * (e.g., "foo*")
410-
// Else if value_to_metric: use actual runtime value (e.g., "foo1")
411-
// Else: use wildcard pattern with * (e.g., "foo*")
411+
// Matched via wildcard
412412
if hasShareThreshold {
413413
// share_threshold: always use wildcard pattern with *
414-
valueToMetricFullKey.WriteString(entry.Key)
415-
valueToMetricFullKey.WriteString("_")
416-
valueToMetricFullKey.WriteString(shareThresholdPatterns[i])
414+
valueToUse = shareThresholdPatterns[i]
417415
} else if nextDescriptor.valueToMetric {
418-
valueToMetricFullKey.WriteString(entry.Key)
419-
if entry.Value != "" {
420-
valueToMetricFullKey.WriteString("_")
421-
valueToMetricFullKey.WriteString(entry.Value)
422-
}
416+
// value_to_metric: use actual runtime value
417+
valueToUse = entry.Value
423418
} else {
424-
// No value_to_metric on this descriptor: preserve wildcard pattern
425-
// Extract the value part from the matched wildcard key (e.g., "key_foo*" -> "foo*")
426-
wildcardValue := strings.TrimPrefix(matchedWildcardKey, entry.Key+"_")
427-
valueToMetricFullKey.WriteString(entry.Key)
428-
valueToMetricFullKey.WriteString("_")
429-
valueToMetricFullKey.WriteString(wildcardValue)
419+
// No flags: preserve wildcard pattern
420+
valueToUse = strings.TrimPrefix(matchedWildcardKey, entry.Key+"_")
430421
}
431422
} else if matchedUsingValue {
432-
// Matched explicit key+value in config
433-
// share_threshold can't apply here (only works with wildcards)
434-
valueToMetricFullKey.WriteString(entry.Key)
435-
if entry.Value != "" {
436-
valueToMetricFullKey.WriteString("_")
437-
valueToMetricFullKey.WriteString(entry.Value)
438-
}
423+
// Matched explicit key+value in config (share_threshold can't apply here)
424+
valueToUse = entry.Value
439425
} else {
440426
// Matched default key (no value) in config
441-
// share_threshold can't apply here (only works with wildcards)
442427
if nextDescriptor.valueToMetric {
443-
valueToMetricFullKey.WriteString(entry.Key)
444-
if entry.Value != "" {
445-
valueToMetricFullKey.WriteString("_")
446-
valueToMetricFullKey.WriteString(entry.Value)
447-
}
448-
} else {
449-
valueToMetricFullKey.WriteString(entry.Key)
428+
valueToUse = entry.Value
450429
}
451430
}
431+
432+
// Write key and value (if any)
433+
valueToMetricFullKey.WriteString(entry.Key)
434+
if valueToUse != "" {
435+
valueToMetricFullKey.WriteString("_")
436+
valueToMetricFullKey.WriteString(valueToUse)
437+
}
452438
} else {
453439
// No next descriptor found; still append something deterministic
454440
valueToMetricFullKey.WriteString(entry.Key)

0 commit comments

Comments
 (0)