Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/controllers/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -493,3 +493,14 @@ func (c *Cache) GetAnnotatedNamespaces() []string {
sort.Strings(ns)
return ns
}

// GetAllNamespaces returns all namespaces that have endpoints in the cache
func (c *Cache) GetAllNamespaces() []string {
c.RLock()
defer c.RUnlock()
namespaces := make([]string, 0, len(c.nsMap))
for ns := range c.nsMap {
namespaces = append(namespaces, ns)
}
return namespaces
}
2 changes: 2 additions & 0 deletions pkg/controllers/cache/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type CacheInterface interface {
GetIPsByNamespace(ns string) []net.IP
// GetAnnotatedNamespaces returns list of namespaces that are annotated with retina to observe.
GetAnnotatedNamespaces() []string
// GetAllNamespaces returns all namespaces that have endpoints in the cache.
GetAllNamespaces() []string

// UpdateRetinaEndpoint updates the retina endpoint in the cache.
UpdateRetinaEndpoint(ep *common.RetinaEndpoint) error
Expand Down
20 changes: 20 additions & 0 deletions pkg/managers/filtermanager/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ package filtermanager
import (
"net"
"sync"

"github.com/microsoft/retina/pkg/log"
"go.uber.org/zap"
)

var fc = &filterCache{data: make(map[string]requests)}
Expand Down Expand Up @@ -61,13 +64,15 @@ func (f *filterCache) addIP(ip net.IP, r Requestor, m RequestMetadata) {
defer f.mu.Unlock()

key := ip.String()

if _, ok := f.data[key]; !ok {
f.data[key] = make(requests)
}
if _, ok := f.data[key][r]; !ok {
f.data[key][r] = make(map[RequestMetadata]bool)
}
f.data[key][r][m] = true

}

// Return true if the IP was deleted from the cache.
Expand All @@ -91,6 +96,21 @@ func (f *filterCache) deleteIP(ip net.IP, r Requestor, m RequestMetadata) bool {
delete(f.data, key)
ipDeleted = true
}

} else {
if log.Logger() != nil {
log.Logger().Warn("deleteIP - requestor not found",
zap.String("ip", key),
zap.String("requestor", string(r)),
zap.String("metadata_ruleID", m.RuleID))
}
}
} else {
if log.Logger() != nil {
log.Logger().Warn("deleteIP - IP not found in cache",
zap.String("ip", key),
zap.String("requestor", string(r)),
zap.String("metadata_ruleID", m.RuleID))
}
}
return ipDeleted
Expand Down
Loading