Skip to content

Commit d39db69

Browse files
authored
fix filter mechanism in the access log module (#148)
1 parent f800504 commit d39db69

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

pkg/accesslog/common/connection.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ func (c *ConnectionManager) isLocalTarget(pair *ip.SocketPair) addressProcessTyp
482482

483483
func (c *ConnectionManager) AddNewProcess(pid int32, entities []api.ProcessInterface) {
484484
// filtering the namespace
485-
if c.shouldExcludeTheProcess(entities) {
485+
monitorProcesses := c.shouldMonitorProcesses(entities)
486+
if len(monitorProcesses) == 0 {
486487
c.RemoveProcess(pid, entities)
487488
return
488489
}
@@ -491,9 +492,9 @@ func (c *ConnectionManager) AddNewProcess(pid int32, entities []api.ProcessInter
491492
defer c.monitoringProcessLock.Unlock()
492493

493494
// adding monitoring process and IP addresses
494-
c.monitoringProcesses[pid] = entities
495+
c.monitoringProcesses[pid] = monitorProcesses
495496
c.updateMonitorStatusForProcess(pid, true)
496-
for _, entity := range entities {
497+
for _, entity := range monitorProcesses {
497498
for _, host := range entity.ExposeHosts() {
498499
c.localIPWithPid[host] = pid
499500
}
@@ -529,8 +530,8 @@ func (c *ConnectionManager) printTotalAddressesWithPid(prefix string) {
529530
log.Debugf("----------------------------")
530531
}
531532

532-
func (c *ConnectionManager) shouldExcludeTheProcess(entities []api.ProcessInterface) bool {
533-
return c.monitorFilter.ShouldExclude(entities)
533+
func (c *ConnectionManager) shouldMonitorProcesses(entities []api.ProcessInterface) []api.ProcessInterface {
534+
return c.monitorFilter.ShouldIncludeProcesses(entities)
534535
}
535536

536537
func (c *ConnectionManager) RemoveProcess(pid int32, entities []api.ProcessInterface) {
@@ -549,10 +550,11 @@ func (c *ConnectionManager) RemoveProcess(pid int32, entities []api.ProcessInter
549550
func (c *ConnectionManager) RecheckAllProcesses(processes map[int32][]api.ProcessInterface) {
550551
shouldMonitoringProcesses := make(map[int32][]api.ProcessInterface)
551552
for pid, p := range processes {
552-
if c.shouldExcludeTheProcess(p) {
553+
monitorProcesses := c.shouldMonitorProcesses(p)
554+
if len(monitorProcesses) == 0 {
553555
continue
554556
}
555-
shouldMonitoringProcesses[pid] = p
557+
shouldMonitoringProcesses[pid] = monitorProcesses
556558
}
557559
// checking the monitoring process
558560
c.monitoringProcesses = shouldMonitoringProcesses

pkg/accesslog/common/filter.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525
)
2626

2727
type MonitorFilter interface {
28-
// ShouldExclude returns true if the process should be excluded from monitoring.
29-
ShouldExclude(process []api.ProcessInterface) bool
28+
// ShouldIncludeProcesses returns true if the processes should be included in monitoring.
29+
ShouldIncludeProcesses(process []api.ProcessInterface) []api.ProcessInterface
3030
// ExcludeNamespaces returns a list of namespaces that should be excluded from monitoring.
3131
ExcludeNamespaces() []string
3232
}
@@ -45,26 +45,24 @@ func NewStaticMonitorFilter(namespaces, clusters []string) *StaticMonitorFilter
4545
}
4646
}
4747

48-
func (s *StaticMonitorFilter) ShouldExclude(processes []api.ProcessInterface) bool {
49-
containsNotExcludeCluster := false
48+
func (s *StaticMonitorFilter) ShouldIncludeProcesses(processes []api.ProcessInterface) (res []api.ProcessInterface) {
5049
for _, entity := range processes {
5150
if entity.DetectType() != api.Kubernetes { // for now, we only have the kubernetes detected processes
5251
continue
5352
}
5453
namespace := entity.DetectProcess().(*kubernetes.Process).PodContainer().Pod.Namespace
55-
if s.namespaces[namespace] {
56-
return true
54+
nameExclude := s.namespaces[namespace]
55+
clusterExclude := false
56+
if cluster, _, found := strings.Cut(entity.Entity().ServiceName, "::"); found && s.clusters[cluster] {
57+
clusterExclude = true
5758
}
58-
if cluster, _, found := strings.Cut(entity.Entity().ServiceName, "::"); found {
59-
if !s.clusters[cluster] {
60-
containsNotExcludeCluster = true
61-
}
62-
} else {
63-
containsNotExcludeCluster = true
64-
break
59+
60+
// if the namespace and cluster are not excluded, include the process
61+
if !nameExclude && !clusterExclude {
62+
res = append(res, entity)
6563
}
6664
}
67-
return !containsNotExcludeCluster
65+
return
6866
}
6967

7068
func (s *StaticMonitorFilter) ExcludeNamespaces() []string {

test/e2e/cases/profiling/task/offcpu/c/profiling-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trees:
2020
{{- contains .elements }}
2121
- id: "{{ notEmpty .id }}"
2222
parentid: "{{ notEmpty .parentid }}"
23-
symbol: "fprintf"
23+
symbol: "vfprintf"
2424
stacktype: USER_SPACE
2525
dumpcount: {{ gt .dumpcount 0 }}
2626
{{- end }}

0 commit comments

Comments
 (0)