Skip to content

Commit

Permalink
Pass stats update interval (#945)
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue.

Pass stats update interval

**What this PR does / why we need it**:Pass stats update interval from config to proxy, so that we can control the frequency to update Envoy stats.

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

**Special notes for your reviewer**:

**Release note**:

```release-note
```
  • Loading branch information
JimmyCYJ authored and istio-merge-robot committed Jan 25, 2018
1 parent 85ff9bf commit d125d04
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
19 changes: 11 additions & 8 deletions src/envoy/mixer/mixer_control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ HttpMixerControl::HttpMixerControl(const HttpMixerConfig& mixer_config,
Runtime::RandomGenerator& random,
Stats::Scope& scope)
: cm_(cm),
stats_obj_(dispatcher, kHttpStatsPrefix, scope,
[this](Statistics* stat) -> bool {
if (!controller_) {
return false;
}
controller_->GetStatistics(stat);
return true;
}) {
stats_obj_(
dispatcher, kHttpStatsPrefix, scope,
mixer_config.http_config.transport().stats_update_interval_ms(),
[this](Statistics* stat) -> bool {
if (!controller_) {
return false;
}
controller_->GetStatistics(stat);
return true;
}) {
::istio::mixer_control::http::Controller::Options options(
mixer_config.http_config, mixer_config.legacy_quotas);

Expand All @@ -91,6 +93,7 @@ TcpMixerControl::TcpMixerControl(const TcpMixerConfig& mixer_config,
Runtime::RandomGenerator& random,
Stats::Scope& scope)
: stats_obj_(dispatcher, kTcpStatsPrefix, scope,
mixer_config.tcp_config.transport().stats_update_interval_ms(),
[this](Statistics* stat) -> bool {
if (!controller_) {
return false;
Expand Down
7 changes: 5 additions & 2 deletions src/envoy/mixer/stats.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ const int kStatsUpdateIntervalInMs = 10000;

MixerStatsObject::MixerStatsObject(Event::Dispatcher& dispatcher,
const std::string& name, Stats::Scope& scope,
GetStatsFunc func)
int update_interval_ms, GetStatsFunc func)
: stats_{ALL_MIXER_FILTER_STATS(POOL_COUNTER_PREFIX(scope, name))},
get_stats_func_(func) {
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(kStatsUpdateIntervalInMs));
timer_->enableTimer(std::chrono::milliseconds(stats_update_interval));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/envoy/mixer/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ typedef std::function<bool(::istio::mixer_client::Statistics* s)> GetStatsFunc;
class MixerStatsObject {
public:
MixerStatsObject(Event::Dispatcher& dispatcher, const std::string& name,
Stats::Scope& scope, GetStatsFunc func);
Stats::Scope& scope, int update_interval_ms,
GetStatsFunc func);

private:
// This function is invoked when timer event fires.
Expand Down

0 comments on commit d125d04

Please sign in to comment.