in pkg/datasource/k8s/controllers/hotspotrules_controller.go [111:152]
func (r *HotspotRulesReconciler) assembleHotspotRules(rs *datasourcev1.HotspotRules) []*hotspot.Rule {
ret := make([]*hotspot.Rule, 0, len(rs.Spec.Rules))
log := r.Logger
for _, rule := range rs.Spec.Rules {
hotspotRule := &hotspot.Rule{
ID: rule.Id,
Resource: rule.Resource,
MetricType: 0,
ControlBehavior: 0,
ParamIndex: int(rule.ParamIndex),
Threshold: rule.Threshold,
MaxQueueingTimeMs: rule.MaxQueueingTimeMs,
BurstCount: rule.BurstCount,
DurationInSec: rule.DurationInSec,
ParamsMaxCapacity: rule.ParamsMaxCapacity,
SpecificItems: parseSpecificItems(rule.SpecificItems),
}
switch rule.MetricType {
case ConcurrencyMetricType:
hotspotRule.MetricType = hotspot.Concurrency
case QPSMetricType:
hotspotRule.MetricType = hotspot.QPS
default:
log.Error(errors.New("unsupported MetricType for hotspot.Rule"), "", "metricType", rule.MetricType)
continue
}
switch rule.ControlBehavior {
case "":
hotspotRule.ControlBehavior = hotspot.Reject
case RejectControlBehavior:
hotspotRule.ControlBehavior = hotspot.Reject
case ThrottlingControlBehavior:
hotspotRule.ControlBehavior = hotspot.Throttling
default:
log.Error(errors.New("unsupported ControlBehavior for hotspot.Rule"), "", "controlBehavior", rule.ControlBehavior)
continue
}
ret = append(ret, hotspotRule)
}
return ret
}