Skip to content

Commit

Permalink
fix: remove old configurations from conf store (#41)
Browse files Browse the repository at this point in the history
* fix: remove old configurations from conf store
  • Loading branch information
mikeykhalil authored May 4, 2020
1 parent d7adde8 commit 37cbced
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion e2e/docker-compose-async.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
environment:
GUARDIAN_FLAG_REDIS_ADDRESS: "redis:6379"
GUARDIAN_FLAG_LOG_LEVEL: "debug"
GUARDIAN_FLAG_CONF_UPDATE_INTERVAL: "1s"
GUARDIAN_FLAG_CONF_UPDATE_INTERVAL: "500ms"
GUARDIAN_FLAG_SYNCHRONOUS: "false"
depends_on:
- redis
Expand Down
2 changes: 1 addition & 1 deletion e2e/docker-compose-sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
environment:
GUARDIAN_FLAG_REDIS_ADDRESS: "redis:6379"
GUARDIAN_FLAG_LOG_LEVEL: "debug"
GUARDIAN_FLAG_CONF_UPDATE_INTERVAL: "1s"
GUARDIAN_FLAG_CONF_UPDATE_INTERVAL: "500ms"
GUARDIAN_FLAG_SYNCHRONOUS: "true"
depends_on:
- redis
Expand Down
2 changes: 2 additions & 0 deletions pkg/guardian/redis_conf_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ func (rs *RedisConfStore) UpdateCachedConf() {
rs.conf.reportOnly = *fetched.reportOnly
}

rs.conf.routeRateLimits = make(map[url.URL]Limit, len(fetched.routeLimitCounts))
for url, count := range fetched.routeLimitCounts {
duration, _ := fetched.routeLimitDurations[url]
enabled, _ := fetched.routeRateLimitsEnabled[url]
Expand All @@ -618,6 +619,7 @@ func (rs *RedisConfStore) UpdateCachedConf() {
}
}

rs.conf.jails = make(map[url.URL]Jail, len(fetched.jailLimitCounts))
for url, count := range fetched.jailLimitCounts {
duration, _ := fetched.jailLimitDurations[url]
enabled, _ := fetched.jailLimitsEnabled[url]
Expand Down
28 changes: 28 additions & 0 deletions pkg/guardian/redis_conf_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ func TestConfStoreAddRemoveRouteRateLimits(t *testing.T) {
t.Errorf("expected: %v, received: %v", fooBarLimit, got)
}

// Ensure configuration cache is updated after a confSyncInterval
c.UpdateCachedConf()
cachedItem := c.GetRouteRateLimit(*fooBarURL)
if !cmp.Equal(cachedItem, fooBarLimit) {
t.Errorf("expected: %v, received: %v", fooBarLimit, cachedItem)
}

var urls []url.URL
urls = append(urls, *fooBarURL)
if err := c.RemoveRouteRateLimits(urls); err != nil {
Expand All @@ -382,6 +389,13 @@ func TestConfStoreAddRemoveRouteRateLimits(t *testing.T) {
t.Fatalf("expected error fetching route limit which didn't exist")
}

// Ensure configuration cache is updated after a confSyncInterval
c.UpdateCachedConf()
cachedItem = c.GetRouteRateLimit(*fooBarURL)
if !cmp.Equal(cachedItem, Limit{}) {
t.Errorf("expected: %v, received: %v", Limit{}, cachedItem)
}

got, err = c.FetchRouteRateLimit(*fooBazURL)
if err != nil {
t.Fatalf("got error: %v", err)
Expand Down Expand Up @@ -522,6 +536,13 @@ func TestConfStoreAddRemoveJails(t *testing.T) {
t.Errorf("expected: %v, received: %v", fooBarJail, got)
}

// Ensure configuration cache is updated after a confSyncInterval
c.UpdateCachedConf()
cachedItem := c.GetJail(*fooBarURL)
if !cmp.Equal(cachedItem, fooBarJail) {
t.Errorf("expected: %v, received: %v", fooBarJail, cachedItem)
}

var urls []url.URL
urls = append(urls, *fooBarURL)
if err := c.RemoveJails(urls); err != nil {
Expand All @@ -534,6 +555,13 @@ func TestConfStoreAddRemoveJails(t *testing.T) {
t.Fatalf("expected error fetching route limit which didn't exist")
}

// Ensure configuration cache is updated after a confSyncInterval
c.UpdateCachedConf()
cachedItem = c.GetJail(*fooBarURL)
if !cmp.Equal(cachedItem, Jail{}) {
t.Errorf("expected: %v, received: %v", Jail{}, cachedItem)
}

got, err = c.FetchJail(*fooBazURL)
if err != nil {
t.Fatalf("got error: %v", err)
Expand Down

0 comments on commit 37cbced

Please sign in to comment.