Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable aggregation for kubearmor summary data - process/file #542

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/observability/kubearmor.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,41 @@ func deDuplicateServerInOutConn(connList []types.SysObsNwData) []types.SysObsNwD
return result
}

func aggregateProcFileData(data []types.SysObsProcFileData) []types.SysObsProcFileData {
if len(data) <= 0 {
return nil
}
res := []types.SysObsProcFileData{}

for _, locData := range data {
locKey := types.SysObsProcFileMapKey{
Source: locData.Source,
Destination: locData.Destination[:strings.LastIndex(locData.Destination, "/")+1],
Status: locData.Status,
}

v := ProcFileMap[locKey]

ProcFileMap[locKey] = types.SysObsProcFileMapValue{
Count: v.Count + locData.Count,
UpdatedTime: locData.UpdatedTime,
}
}

for k, v := range ProcFileMap {
res = append(res, types.SysObsProcFileData{
Source: k.Source,
Destination: k.Destination,
Status: k.Status,
Count: v.Count,
UpdatedTime: v.UpdatedTime,
})
delete(ProcFileMap, k)
}

return res
}

func GetKubearmorSummaryData(req *opb.Request) ([]types.SysObsProcFileData, []types.SysObsProcFileData, []types.SysObsNwData, types.ObsPodDetail) {
var err error
var processData, fileData []types.SysObsProcFileData
Expand Down Expand Up @@ -288,5 +323,10 @@ func GetKubearmorSummaryData(req *opb.Request) ([]types.SysObsProcFileData, []ty
nwData = deDuplicateServerInOutConn(nwData)
}

if req.Aggregate {
processData = aggregateProcFileData(processData)
fileData = aggregateProcFileData(fileData)
}

return processData, fileData, nwData, podInfo
}
2 changes: 2 additions & 0 deletions src/observability/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var (
ObsCronJob *cron.Cron
//Kubearmor log map
KubeArmorLogMap map[types.KubeArmorLog]int
ProcFileMap map[types.SysObsProcFileMapKey]types.SysObsProcFileMapValue
)

// =================== //
Expand All @@ -51,6 +52,7 @@ func initMutex() {

func initMap() {
KubeArmorLogMap = make(map[types.KubeArmorLog]int)
ProcFileMap = make(map[types.SysObsProcFileMapKey]types.SysObsProcFileMapValue)
}

func InitObservability() {
Expand Down