in internal/commands/profiling/continuous/set.go [113:163]
func parsingPolicyConfig(conf *PolicyConfig) ([]*api.ContinuousProfilingPolicyTargetCreation, error) {
result := make([]*api.ContinuousProfilingPolicyTargetCreation, 0)
if len(conf.Policies) == 0 {
return result, nil
}
for _, t := range conf.Policies {
var realTarget api.ContinuousProfilingTargetType
for _, targetType := range api.AllContinuousProfilingTargetType {
if t.Type == targetType.String() {
realTarget = targetType
break
}
}
if realTarget == "" {
return nil, fmt.Errorf("cannot found the target: %s", t.Type)
}
target := &api.ContinuousProfilingPolicyTargetCreation{
TargetType: realTarget,
}
for _, c := range t.Checkers {
var realMonitorType api.ContinuousProfilingMonitorType
for _, monitorType := range api.AllContinuousProfilingMonitorType {
if c.Type == monitorType.String() {
realMonitorType = monitorType
break
}
}
if realMonitorType == "" {
return nil, fmt.Errorf("cannot fount the monitor type: %s", c.Type)
}
item := &api.ContinuousProfilingPolicyItemCreation{
Type: realMonitorType,
Threshold: c.Threshold,
Period: c.Period,
Count: c.Count,
URIList: c.URIList,
}
if c.URIRegex != "" {
item.URIRegex = &c.URIRegex
}
target.CheckItems = append(target.CheckItems, item)
}
result = append(result, target)
}
return result, nil
}