Skip to content

Commit d125d04

Browse files
JimmyCYJistio-merge-robot
authored andcommitted
Pass stats update interval (istio#945)
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 istio#132 istio/old_mixerclient_repo#132 **Special notes for your reviewer**: **Release note**: ```release-note ```
1 parent 85ff9bf commit d125d04

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/envoy/mixer/mixer_control.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,16 @@ HttpMixerControl::HttpMixerControl(const HttpMixerConfig& mixer_config,
6767
Runtime::RandomGenerator& random,
6868
Stats::Scope& scope)
6969
: cm_(cm),
70-
stats_obj_(dispatcher, kHttpStatsPrefix, scope,
71-
[this](Statistics* stat) -> bool {
72-
if (!controller_) {
73-
return false;
74-
}
75-
controller_->GetStatistics(stat);
76-
return true;
77-
}) {
70+
stats_obj_(
71+
dispatcher, kHttpStatsPrefix, scope,
72+
mixer_config.http_config.transport().stats_update_interval_ms(),
73+
[this](Statistics* stat) -> bool {
74+
if (!controller_) {
75+
return false;
76+
}
77+
controller_->GetStatistics(stat);
78+
return true;
79+
}) {
7880
::istio::mixer_control::http::Controller::Options options(
7981
mixer_config.http_config, mixer_config.legacy_quotas);
8082

@@ -91,6 +93,7 @@ TcpMixerControl::TcpMixerControl(const TcpMixerConfig& mixer_config,
9193
Runtime::RandomGenerator& random,
9294
Stats::Scope& scope)
9395
: stats_obj_(dispatcher, kTcpStatsPrefix, scope,
96+
mixer_config.tcp_config.transport().stats_update_interval_ms(),
9497
[this](Statistics* stat) -> bool {
9598
if (!controller_) {
9699
return false;

src/envoy/mixer/stats.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ const int kStatsUpdateIntervalInMs = 10000;
2929

3030
MixerStatsObject::MixerStatsObject(Event::Dispatcher& dispatcher,
3131
const std::string& name, Stats::Scope& scope,
32-
GetStatsFunc func)
32+
int update_interval_ms, GetStatsFunc func)
3333
: stats_{ALL_MIXER_FILTER_STATS(POOL_COUNTER_PREFIX(scope, name))},
3434
get_stats_func_(func) {
3535
memset(&old_stats_, 0, sizeof(old_stats_));
3636

37+
// If stats update interval from config is 0, then set interval to 10 seconds.
38+
int stats_update_interval =
39+
update_interval_ms > 0 ? update_interval_ms : kStatsUpdateIntervalInMs;
3740
if (get_stats_func_) {
3841
timer_ = dispatcher.createTimer([this]() { OnTimer(); });
39-
timer_->enableTimer(std::chrono::milliseconds(kStatsUpdateIntervalInMs));
42+
timer_->enableTimer(std::chrono::milliseconds(stats_update_interval));
4043
}
4144
}
4245

src/envoy/mixer/stats.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ typedef std::function<bool(::istio::mixer_client::Statistics* s)> GetStatsFunc;
5353
class MixerStatsObject {
5454
public:
5555
MixerStatsObject(Event::Dispatcher& dispatcher, const std::string& name,
56-
Stats::Scope& scope, GetStatsFunc func);
56+
Stats::Scope& scope, int update_interval_ms,
57+
GetStatsFunc func);
5758

5859
private:
5960
// This function is invoked when timer event fires.

0 commit comments

Comments
 (0)