in pkg/profiling/continuous/checker/common/http_checker.go [39:114]
func NewHTTPBasedChecker(checkType base.CheckType,
thresholdGenerator func(val string) (float64, error), dataGenerator func() base.WindowData[network.BufferEvent, float64],
monitorType v3.ContinuousProfilingTriggeredMonitorType) *HTTPBasedChecker {
checker := &HTTPBasedChecker{
CheckType: checkType,
ThresholdGenerate: thresholdGenerator,
MonitorType: monitorType,
}
checker.BaseChecker = NewBaseChecker[*HTTPBasedCheckerProcessInfo](
func(p api.ProcessInterface, older *HTTPBasedCheckerProcessInfo, items []*base.PolicyItem) *HTTPBasedCheckerProcessInfo {
result := &HTTPBasedCheckerProcessInfo{
Process: p,
PolicyWithWindows: make(map[*base.PolicyItem]*HTTPBasedCheckerPolicyItemWindows),
}
for _, item := range items {
val, _ := thresholdGenerator(item.Threshold)
policyInfo := &HTTPBasedCheckerPolicyItemWindows{
threshold: val,
}
timeWindowsUpdated := false
if older != nil {
for olderItem, olderInfo := range older.PolicyWithWindows {
// reading from the older policy info
if olderItem.SameURIFilter(item) {
if len(item.URIList) > 0 {
for _, w := range olderInfo.uriWithTimeWindows {
w.ScalePeriod([]*base.PolicyItem{item})
}
policyInfo.uriWithTimeWindows = olderInfo.uriWithTimeWindows
} else {
policyInfo.defaultTimeWindows = olderInfo.defaultTimeWindows
policyInfo.defaultTimeWindows.ScalePeriod([]*base.PolicyItem{item})
}
timeWindowsUpdated = true
break
}
}
}
if timeWindowsUpdated {
result.PolicyWithWindows[item] = policyInfo
continue
}
// otherwise, create the time windows
if len(item.URIList) > 0 {
uriWithWindows := make(map[string]*base.TimeWindows[network.BufferEvent, float64])
for _, uri := range item.URIList {
uriWithWindows[uri] = base.NewTimeWindows[network.BufferEvent, float64](
[]*base.PolicyItem{item}, func() base.WindowData[network.BufferEvent, float64] {
return dataGenerator()
})
}
policyInfo.uriWithTimeWindows = uriWithWindows
} else if item.URIRegex != "" {
regex, err := regexp.Compile(item.URIRegex)
if err != nil {
log.Warnf("error to compile the URI regex for policy, ignore this policy. regex: %s", item.URIRegex)
continue
}
policyInfo.uriRegex = regex
}
policyInfo.defaultTimeWindows = base.NewTimeWindows[network.BufferEvent, float64](
[]*base.PolicyItem{item}, func() base.WindowData[network.BufferEvent, float64] {
return dataGenerator()
})
result.PolicyWithWindows[item] = policyInfo
}
return result
})
network.AddEventNotify(checker)
return checker
}