Support envoy to provide stats generated by mixer filter.#891
Support envoy to provide stats generated by mixer filter.#891qiwzhang merged 11 commits intoistio:masterfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Assign the PR to them by writing The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:You can indicate your approval by writing |
src/envoy/mixer/http_filter.cc
Outdated
| */ | ||
| // clang-format off | ||
| #define ALL_HTTP_MIXER_FILTER_STATS(COUNTER, GAUGE) \ | ||
| COUNTER(total_check_calls) \ |
There was a problem hiding this comment.
We also want separate check and report latencies as histograms. The histograms should use the same bucketization as used by envoy upstream_XXX counters.
upstream_mixer_XXX stats mash checks and reports together.
There was a problem hiding this comment.
@JimmyCYJ please file a separate issue to add Check/Report latency stats. Don't want to put too much change into one PR.
There was a problem hiding this comment.
I filed a another issue here. istio/old_mixerclient_repo#324
Thanks.
src/envoy/mixer/http_filter.cc
Outdated
| &check_data, &header_update, | ||
| CheckTransport::GetFunc(mixer_control_.cm(), &headers), | ||
| [this](const Status& status) { completeCheck(status); }); | ||
| CheckAndUpdateStats(old_stats); |
There was a problem hiding this comment.
Use a timer of every 10 seconds to update counters. Not on every call.
src/envoy/mixer/http_filter.cc
Outdated
| */ | ||
| struct InstanceStats { | ||
| ALL_HTTP_MIXER_FILTER_STATS(GENERATE_COUNTER_STRUCT) | ||
| }; |
There was a problem hiding this comment.
Maybe we can extract this into a separate header file so tcp_filter can use it too. tcp has the same counters with a different prefix.
src/envoy/mixer/stats.h
Outdated
| /** | ||
| * Struct definition for all mixer filter stats. @see stats_macros.h | ||
| */ | ||
| struct InstanceStats { |
src/envoy/mixer/mixer_control.h
Outdated
|
|
||
| // MixerStatsObject maintains statistics for number of check, quota and report | ||
| // calls issued by a mixer filter. | ||
| class MixerStatsObject { |
There was a problem hiding this comment.
can move this class into stats.h
src/envoy/mixer/mixer_control.cc
Outdated
| // Start timer for updating envoy stats periodically. | ||
| timer_.reset(new EnvoyTimer( | ||
| dispatcher.createTimer([this]() { StatsUpdateCallback(); }))); | ||
| timer_->Start(MixerStatsObject::kStatsUpdateIntervalInMs); |
There was a problem hiding this comment.
Don't use EnvoyTimer.
use dispatcher.createTimer() directly
src/envoy/mixer/mixer_control.cc
Outdated
| } | ||
|
|
||
| // Copy new_stats to old_stats_ for next stats update. | ||
| old_stats_.total_check_calls = new_stats.total_check_calls; |
There was a problem hiding this comment.
can you just do
old_stats_ = new_stats;
src/envoy/mixer/mixer_control.h
Outdated
|
|
||
| // These members are needed to update envoy stats periodically. | ||
| MixerStatsObject stats_; | ||
| std::unique_ptr<::istio::mixer_client::Timer> timer_; |
There was a problem hiding this comment.
I think the timer logic can be moved into MixerStatsObj class.
It will take a function call in the contructor to call controller_->GetStatistitis()
src/envoy/mixer/stats.h
Outdated
| * All http mixer filter stats. @see stats_macros.h | ||
| */ | ||
| // clang-format off | ||
| #define ALL_HTTP_MIXER_FILTER_STATS(COUNTER) \ |
src/envoy/mixer/stats.h
Outdated
| // calls issued by a mixer filter. | ||
| class MixerStatsObject { | ||
| public: | ||
| static const int kStatsUpdateIntervalInMs; |
There was a problem hiding this comment.
this "const int" can be anonymous in cc file?
src/envoy/mixer/stats.h
Outdated
|
|
||
| private: | ||
| MixerFilterStats stats_; | ||
| GetStatsFunc get_statistics_; |
There was a problem hiding this comment.
get_stats_func_? suffixed with func.
also add comment for each class variable.
src/envoy/mixer/mixer_control.cc
Outdated
|
|
||
| void MixerControlBase::SetUpStatsTimer() { | ||
| timer_ = dispatcher_.createTimer([this]() -> void { StatsUpdateCallback(); }); | ||
| timer_->enableTimer(std::chrono::milliseconds(MixerStatsObject::kStatsUpdateIntervalInMs)); |
There was a problem hiding this comment.
can move timer_ into StatsObj class
src/envoy/mixer/mixer_control.h
Outdated
|
|
||
| private: | ||
| Event::Dispatcher& dispatcher_; | ||
| ::Envoy::Event::TimerPtr timer_; |
There was a problem hiding this comment.
if you move timer_ into StatsObject, you may not need MixerControlBase class
src/envoy/mixer/mixer_control.cc
Outdated
| ::istio::mixer_client::Statistics new_stats; | ||
| stats_.GetStatistics(&new_stats); | ||
| stats_.CheckAndUpdateStats(new_stats); | ||
| timer_->enableTimer(std::chrono::milliseconds(MixerStatsObject::kStatsUpdateIntervalInMs)); |
There was a problem hiding this comment.
I don't think you need to call "enable" for each call. Only need to enable it once.
src/envoy/mixer/mixer_control.cc
Outdated
| timer_->enableTimer(std::chrono::milliseconds(MixerStatsObject::kStatsUpdateIntervalInMs)); | ||
| } | ||
|
|
||
| void MixerControlBase::StatsUpdateCallback() { |
|
Please take a look. Thanks! |
src/envoy/mixer/mixer_control.h
Outdated
| Upstream::ClusterManager& cm, Event::Dispatcher& dispatcher, | ||
| Runtime::RandomGenerator& random); | ||
| Runtime::RandomGenerator& random, | ||
| const std::string& stats_prefix, Stats::Scope& scope); |
There was a problem hiding this comment.
Not need to pass in stats_prefix. It is already in HttpMixerControl constructor.
| void OnTimer(); | ||
|
|
||
| // Compares old stats with new stats and updates envoy stats. | ||
| void CheckAndUpdateStats(const ::istio::mixer_client::Statistics& new_stats); |
There was a problem hiding this comment.
Only constructor is public, all these functions can be private.
Can we pass GetStatsFunc in the constructor, not use a separate function to set it.?
src/envoy/mixer/stats.h
Outdated
| // These members are used for creating a timer which update Envoy stats | ||
| // periodically. | ||
| ::Envoy::Event::TimerPtr timer_; | ||
| ::Envoy::Event::Dispatcher& dispatcher_; |
There was a problem hiding this comment.
do you need to store dispatcher_?
src/envoy/mixer/stats.cc
Outdated
| } | ||
|
|
||
| void MixerStatsObject::SetUpStatsTimer() { | ||
| timer_ = dispatcher_.createTimer([this]() -> void { OnTimer(); }); |
There was a problem hiding this comment.
can we create timer at constructor so dispatcher_ doesn't need to be kept?
src/envoy/mixer/stats.cc
Outdated
|
|
||
| void MixerStatsObject::OnTimer() { | ||
| ::istio::mixer_client::Statistics new_stats; | ||
| GetStatistics(&new_stats); |
There was a problem hiding this comment.
at constructor, if get_stats_func_ is null, don't create timer.
src/envoy/mixer/stats.cc
Outdated
| } | ||
|
|
||
| void MixerStatsObject::InitGetStatisticsFunc(GetStatsFunc get_stats) { | ||
| if (get_stats) { |
There was a problem hiding this comment.
set function as constructor.
src/envoy/mixer/stats.cc
Outdated
| if (get_stats_func_) { | ||
| get_stats_func_(stats); | ||
| } else { | ||
| auto& logger = Logger::Registry::getLog(Logger::Id::config); |
There was a problem hiding this comment.
at constructor, if get_stats_func_ is null, don't create timer. not need for this check
src/envoy/mixer/http_filter.cc
Outdated
| }; | ||
|
|
||
| const std::string kStatsPrefix("http_mixer_filter."); | ||
|
|
There was a problem hiding this comment.
move these two prefix into mixer_control.cc to be used at their constructors
src/envoy/mixer/mixer_control.cc
Outdated
|
|
||
| stats_obj_.InitGetStatisticsFunc( | ||
| std::bind(&::istio::mixer_control::tcp::Controller::GetStatistics, | ||
| controller(), std::placeholders::_1)); |
There was a problem hiding this comment.
please use lambda function, such as
do it in the consturctor.
stats_obj_(dispatcher, "tcp_mixer_filter.", scope,
[this](STat *stat) -> bool {
if (!controller_) return false;
controler_->GetStats(stat);
return true;
});
qiwzhang
left a comment
There was a problem hiding this comment.
Very good. Almost there.
We need integration test. Can be a separate PR if you like.
src/envoy/mixer/stats.cc
Outdated
| } else { | ||
| auto& logger = Logger::Registry::getLog(Logger::Id::config); | ||
| ENVOY_LOG_TO_LOGGER(logger, error, "get_stats_func_ is empty"); | ||
| timer_ = dispatcher.createTimer([this]() -> void { OnTimer(); }); |
There was a problem hiding this comment.
src/envoy/mixer/stats.cc
Outdated
| CheckAndUpdateStats(new_stats); | ||
| timer_->enableTimer(std::chrono::milliseconds(kStatsUpdateIntervalInMs)); | ||
| } else { | ||
| auto& logger = Logger::Registry::getLog(Logger::Id::config); |
There was a problem hiding this comment.
not need to log anything for else cast
src/envoy/mixer/mixer_control.h
Outdated
| #include "control/include/http/controller.h" | ||
| #include "control/include/tcp/controller.h" | ||
| #include "envoy/event/dispatcher.h" | ||
| #include "envoy/event/timer.h" |
src/envoy/mixer/mixer_control.cc
Outdated
|
|
||
| #include "src/envoy/mixer/mixer_control.h" | ||
| #include <chrono> | ||
| #include <memory> |
There was a problem hiding this comment.
why these two header files are needed here?
| namespace Mixer { | ||
| namespace { | ||
|
|
||
| const int kStatsUpdateIntervalInMs = 10000; |
There was a problem hiding this comment.
Add comment for const variable.
src/envoy/mixer/stats.cc
Outdated
|
|
||
| if (get_stats_func_) { | ||
| timer_ = dispatcher.createTimer([this]() -> void { OnTimer(); }); | ||
| timer_ = dispatcher.createTimer([this] { OnTimer(); }); |
src/envoy/mixer/mixer_control.cc
Outdated
|
|
||
| #include "src/envoy/mixer/mixer_control.h" | ||
| #include "src/envoy/mixer/grpc_transport.h" | ||
| #include "src/envoy/mixer/stats.h" |
There was a problem hiding this comment.
no need for this include. already included in the mxer_control.h
src/envoy/mixer/stats.cc
Outdated
| bool get_stats = get_stats_func_(&new_stats); | ||
| if (get_stats) { | ||
| CheckAndUpdateStats(new_stats); | ||
| timer_->enableTimer(std::chrono::milliseconds(kStatsUpdateIntervalInMs)); |
There was a problem hiding this comment.
should always enable timer
2e84e4e to
cd3966d
Compare
What this PR does / why we need it:
Which issue this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close that issue when PR gets merged): fixes #132istio/old_mixerclient_repo#132
Special notes for your reviewer:
Release note: