Skip to content

Commit

Permalink
[Metricbeat][Kibana] Apply backoff when errored at getting usage stats
Browse files Browse the repository at this point in the history
  • Loading branch information
afharo committed Aug 25, 2020
1 parent 03748b3 commit 21b1720
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Move service config under metrics and simplify metric types. {pull}18691[18691]
- Fix ECS compliance of user.id field in system/users metricset {pull}19019[19019]
- Rename googlecloud stackdriver metricset to metrics. {pull}19718[19718]
- The Kibana collector applies backoff when errored at getting usage stats {pull}20772[20772]

*Packetbeat*

Expand Down
11 changes: 8 additions & 3 deletions metricbeat/module/kibana/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ func init() {
}

const (
statsPath = "api/stats"
settingsPath = "api/settings"
usageCollectionPeriod = 24 * time.Hour
statsPath = "api/stats"
settingsPath = "api/settings"
usageCollectionPeriod = 24 * time.Hour
usageCollectionBackoff = 1 * time.Hour
)

var (
Expand Down Expand Up @@ -165,6 +166,10 @@ func (m *MetricSet) fetchStats(r mb.ReporterV2, now time.Time) error {

content, err = m.statsHTTP.FetchContent()
if err != nil {
if shouldCollectUsage {
// When errored in collecting the usage stats it may be counterproductive to try again on the next poll, try to collect the stats again after usageCollectionBackoff
m.usageLastCollectedOn = now.Add(usageCollectionBackoff - usageCollectionPeriod)
}
return err
}

Expand Down
6 changes: 3 additions & 3 deletions metricbeat/module/kibana/stats/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ func TestFetchUsage(t *testing.T) {
w.WriteHeader(503)

case 1: // second call
// Make sure exclude_usage is still false since first call failed
require.Equal(t, "false", excludeUsage)
// Make sure exclude_usage is true since first call failed and it should not try again until usageCollectionBackoff time has passed
require.Equal(t, "true", excludeUsage)
w.WriteHeader(200)

case 2: // third call
// Make sure exclude_usage is now true since second call succeeded
// Make sure exclude_usage is still true
require.Equal(t, "true", excludeUsage)
w.WriteHeader(200)
}
Expand Down

0 comments on commit 21b1720

Please sign in to comment.