Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

Commit

Permalink
WIP: Change cache policy
Browse files Browse the repository at this point in the history
  • Loading branch information
p-lambert committed Jan 26, 2018
1 parent cb1cf79 commit 3a053a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 20 additions & 1 deletion agent/service_mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
3 changes: 3 additions & 0 deletions model/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3a053a6

Please sign in to comment.