in benchmarks/benchmark/tools/model-load-benchmark/suite-generator/generator.go [98:177]
func generateResourceCasesForStruct(base config.Config, structName string, structVal reflect.Value) []config.Config {
var cases []config.Config
for i := 0; i < structVal.Elem().NumField(); i++ {
field := structVal.Elem().Field(i)
fieldType := structVal.Elem().Type().Field(i)
if field.Type() == reflect.TypeOf(config.Resource{}) {
resource := field.Interface().(config.Resource)
if resource.Step > 0 && resource.Max > resource.Base {
// Check if the field is a request that has a limit
limitFieldName, isRequest := RequestLimitMap[fieldType.Name]
limitField := structVal.Elem().FieldByName(limitFieldName)
limitExceeded := false
var limitResource config.Resource
var normalizedLimit int
if limitField.IsValid() {
limitResource = limitField.Interface().(config.Resource)
var e error
normalizedLimit, e = normalizeToBaseUnit(limitResource.Base, limitResource.Unit)
if e != nil {
fmt.Printf("Error normalizing limit: %v\n", e)
continue
}
}
// request should be less than limit
if isRequest {
if limitField.IsValid() {
// Normalize both resources to the same unit for comparison
normalizedRequest, err := normalizeToBaseUnit(resource.Base, resource.Unit)
if err != nil {
fmt.Printf("Error normalizing request: %v\n", err)
continue
}
// Compare the normalized values
if normalizedRequest > normalizedLimit {
limitExceeded = true
}
}
}
// Create cases if limits aren't exceeded
if !limitExceeded {
for val := resource.Base; val <= resource.Max; val += resource.Step {
if val > resource.Max {
break
}
newCase := deepCopyConfig(base)
updatedResource := config.Resource{Base: val, Unit: resource.Unit, Step: resource.Step, Max: resource.Max}
// request should be less than limit
if isRequest {
if limitField.IsValid() {
// Normalize both resources to the same unit for comparison
normalizedRequest, err := normalizeToBaseUnit(updatedResource.Base, updatedResource.Unit)
if err != nil {
fmt.Printf("Error normalizing request: %v\n", err)
continue
}
// Compare the normalized values
if normalizedRequest > normalizedLimit {
continue
}
}
}
if structName == "SideCarResources" {
newCase.SideCarResources = setNestedResourceField(newCase.SideCarResources, fieldType.Name, updatedResource).(*config.SideCarResources)
} else if structName == "VolumeAttributes" {
newCase.VolumeAttributes = setNestedResourceField(newCase.VolumeAttributes, fieldType.Name, updatedResource).(*config.VolumeAttributes)
}
cases = append(cases, newCase)
}
}
}
}
}
return cases
}