Skip to content

Commit

Permalink
Fix time interval setup. (#954)
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue.

Fix time interval setup.

**What this PR does / why we need it**: Before this change, we always set stats update interval to 10s inside MixerStatsObject::OnTimer(). This PR uses configured stats interval if that interval is larger than zero.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
  • Loading branch information
JimmyCYJ authored and istio-merge-robot committed Jan 30, 2018
1 parent b2f016e commit 8d2fc52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/envoy/mixer/stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ MixerStatsObject::MixerStatsObject(Event::Dispatcher& dispatcher,
const std::string& name, Stats::Scope& scope,
int update_interval_ms, GetStatsFunc func)
: stats_{ALL_MIXER_FILTER_STATS(POOL_COUNTER_PREFIX(scope, name))},
get_stats_func_(func) {
get_stats_func_(func),
stats_update_interval_(update_interval_ms > 0
? update_interval_ms
: kStatsUpdateIntervalInMs) {
memset(&old_stats_, 0, sizeof(old_stats_));

// If stats update interval from config is 0, then set interval to 10 seconds.
int stats_update_interval =
update_interval_ms > 0 ? update_interval_ms : kStatsUpdateIntervalInMs;
if (get_stats_func_) {
timer_ = dispatcher.createTimer([this]() { OnTimer(); });
timer_->enableTimer(std::chrono::milliseconds(stats_update_interval));
timer_->enableTimer(std::chrono::milliseconds(stats_update_interval_));
}
}

Expand All @@ -49,7 +49,7 @@ void MixerStatsObject::OnTimer() {
if (get_stats) {
CheckAndUpdateStats(new_stats);
}
timer_->enableTimer(std::chrono::milliseconds(kStatsUpdateIntervalInMs));
timer_->enableTimer(std::chrono::milliseconds(stats_update_interval_));
}

void MixerStatsObject::CheckAndUpdateStats(
Expand Down
5 changes: 5 additions & 0 deletions src/envoy/mixer/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class MixerStatsObject {
// These members are used for creating a timer which update Envoy stats
// periodically.
::Envoy::Event::TimerPtr timer_;

// Time interval at which Envoy stats get updated. If stats update interval
// from config is larger than 0, then store configured interval here.
// Otherwise, set interval to 10 seconds.
const int stats_update_interval_;
};

} // namespace Mixer
Expand Down

0 comments on commit 8d2fc52

Please sign in to comment.