Skip to content

Commit

Permalink
Populate metrics initially in cache before returning (#21)
Browse files Browse the repository at this point in the history
Signed-off-by: Abdul Qadeer <[email protected]>
(cherry picked from commit ef1b4d7)
  • Loading branch information
Abdul Qadeer authored Feb 25, 2021
1 parent fd8dfd7 commit 28de36f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pkg/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,15 @@ func (w *Watcher) StartWatching() {
windowWatcher := func(duration string) {
for {
fetchOnce(duration)
time.Sleep(time.Minute) // This is assuming fetching of metrics won't exceed more than 1 minute. If it happens we need to throttle rate of fetches
// This is assuming fetching of metrics won't exceed more than 1 minute. If it happens we need to throttle rate of fetches
time.Sleep(time.Minute)
}
}

durations := [3]string{FifteenMinutes, TenMinutes, FiveMinutes}
for _, duration := range durations {
// Populate cache initially before returning
fetchOnce(duration)
go windowWatcher(duration)
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/watcher/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"net/url"
"os"
"testing"
"time"

"github.com/francoispqt/gojay"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -125,7 +124,6 @@ func TestMain(m *testing.M) {
client := NewTestMetricsServerClient()
w = NewWatcher(client)
w.StartWatching()
time.Sleep(time.Second * 5) // buffer time fetch metrics for all windows

ret := m.Run()
os.Exit(ret)
Expand Down

0 comments on commit 28de36f

Please sign in to comment.