-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support envoy to provide stats generated by mixer filter. #891
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.
Needs 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed a another issue here. istio/old_mixerclient_repo#324
Thanks.
src/envoy/mixer/http_filter.cc
Outdated
CheckData check_data(headers, decoder_callbacks_->connection()); | ||
HeaderUpdate header_update(&headers); | ||
cancel_check_ = handler_->Check( | ||
&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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call it MixerFilterStats
src/envoy/mixer/mixer_control.h
Outdated
|
||
namespace Envoy { | ||
namespace Http { | ||
namespace Mixer { | ||
|
||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove "HTTP_"
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call it OnTimer()
Please take a look. Thanks! |
src/envoy/mixer/mixer_control.h
Outdated
@@ -32,7 +34,8 @@ class HttpMixerControl final : public ThreadLocal::ThreadLocalObject { | |||
// The constructor. | |||
HttpMixerControl(const HttpMixerConfig& mixer_config, | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at constructor, if get_stats_func_ is null, don't create timer. not need for this check
src/envoy/mixer/http_filter.cc
Outdated
@@ -74,6 +74,8 @@ const std::set<std::string> RequestHeaderExclusives = { | |||
kIstioAttributeHeader.get(), | |||
}; | |||
|
|||
const std::string kStatsPrefix("http_mixer_filter."); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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;
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not need to log anything for else cast
src/envoy/mixer/mixer_control.h
Outdated
@@ -18,10 +18,12 @@ | |||
#include "control/include/http/controller.h" | |||
#include "control/include/tcp/controller.h" | |||
#include "envoy/event/dispatcher.h" | |||
#include "envoy/event/timer.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timer.h is not needed
src/envoy/mixer/mixer_control.cc
Outdated
@@ -13,14 +13,23 @@ | |||
* limitations under the License. | |||
*/ | |||
|
|||
#include "src/envoy/mixer/mixer_control.h" | |||
#include <chrono> | |||
#include <memory> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why these two header files are needed here?
src/envoy/mixer/stats.cc
Outdated
namespace Mixer { | ||
namespace { | ||
|
||
const int kStatsUpdateIntervalInMs = 10000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment for const variable.
src/envoy/mixer/stats.cc
Outdated
@@ -33,7 +35,7 @@ MixerStatsObject::MixerStatsObject(Event::Dispatcher& dispatcher, | |||
memset(&old_stats_, 0, sizeof(old_stats_)); | |||
|
|||
if (get_stats_func_) { | |||
timer_ = dispatcher.createTimer([this]() -> void { OnTimer(); }); | |||
timer_ = dispatcher.createTimer([this] { OnTimer(); }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format is wrong, the lambda should be:
this {OnTimer(); }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.createTime(this {OnTimer(); });
you need () after square []
src/envoy/mixer/mixer_control.cc
Outdated
@@ -15,12 +15,18 @@ | |||
|
|||
#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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should always enable timer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks!
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: