1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-06 16:06:56 +00:00
kyverno/test/e2e/common/common.go
NoSkillGirl a886539899 considering time difference less than 1 sec
Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
2021-06-21 20:35:51 +05:30

57 lines
1.8 KiB
Go

package common
import (
"fmt"
"strings"
"time"
)
func ProcessMetrics(newStr, e2ePolicyName string, e2eTime time.Time) bool {
fmt.Println("e2ePolicyName: ", e2ePolicyName, "e2eTime: ", e2eTime)
var action, policyName string
var timeInTimeFormat time.Time
var err error
splitByNewLine := strings.Split(newStr, "\n")
for _, lineSplitedByNewLine := range splitByNewLine {
if strings.HasPrefix(lineSplitedByNewLine, "kyverno_policy_changes_info{") {
splitByComma := strings.Split(lineSplitedByNewLine, ",")
for _, lineSplitedByComma := range splitByComma {
if strings.HasPrefix(lineSplitedByComma, "policy_change_type=") {
splitByQuote := strings.Split(lineSplitedByComma, "\"")
action = splitByQuote[1]
}
if strings.HasPrefix(lineSplitedByComma, "policy_name=") {
splitByQuote := strings.Split(lineSplitedByComma, "\"")
policyName = splitByQuote[1]
}
if strings.HasPrefix(lineSplitedByComma, "timestamp=") {
splitByQuote := strings.Split(lineSplitedByComma, "\"")
layout := "2006-01-02 15:04:05 -0700 MST"
timeInTimeFormat, err = time.Parse(layout, splitByQuote[1])
if err != nil {
fmt.Println("error occurred: ", err)
}
}
}
if policyName == e2ePolicyName {
fmt.Println("--------------------------------------------------------")
fmt.Println(lineSplitedByNewLine)
fmt.Println("action: ", action)
fmt.Println("policyName: ", policyName)
fmt.Println("timeInTimeFormat: ", timeInTimeFormat)
diff := e2eTime.Sub(timeInTimeFormat)
fmt.Println("diff: ", diff)
if diff < time.Second {
fmt.Println("****** condition ******")
if action == "created" {
fmt.Println("************policy created**************")
return true
}
}
}
}
}
return false
}