From 3a053a6369acbeffed8a4fd6ad2ce300015f73ee Mon Sep 17 00:00:00 2001 From: Pedro Lambert Date: Fri, 26 Jan 2018 13:40:55 -0200 Subject: [PATCH] WIP: Change cache policy --- agent/service_mapper.go | 21 ++++++++++++++++++++- model/services.go | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/agent/service_mapper.go b/agent/service_mapper.go index b32a8ac29..0d217c16b 100644 --- a/agent/service_mapper.go +++ b/agent/service_mapper.go @@ -67,7 +67,7 @@ func (s *ServiceMapper) update(metadata model.ServicesMetadata) { var changes model.ServicesMetadata for k, v := range metadata { - if _, ok := s.cache[k]; ok { + if s.cacheHit(k, v) { continue } @@ -87,3 +87,22 @@ func (s *ServiceMapper) update(metadata model.ServicesMetadata) { s.out <- changes s.cache.Merge(changes) } + +func (s *ServiceMapper) cacheHit(service string, metadata map[string]string) bool { + cacheEntry, ok := s.cache[service] + + // No cache entry? + if !ok { + return false + } + + // Value in-cache came from integration? + if _, ok = cacheEntry[model.ServiceApp]; ok { + return true + } + + // Was this sent by an integration? + _, ok = metadata[model.ServiceApp] + + return !ok +} diff --git a/model/services.go b/model/services.go index 1cf2f7feb..2f7f58e97 100644 --- a/model/services.go +++ b/model/services.go @@ -14,6 +14,9 @@ type ServicesMetadata map[string]map[string]string // AppType is one of the pieces of information embedded in ServiceMetadata const AppType = "app_type" +// ServiceApp represents the app to which certain integration belongs to +const ServiceApp = "app" + // Merge adds all entries from s2 to s1 func (s1 ServicesMetadata) Merge(s2 ServicesMetadata) { for k, v := range s2 {