-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support envoy to provide stats generated by mixer filter. #891
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2d0a3a7
Support envoy to provide stats generated by mixer filter.
JimmyCYJ 6bd7df7
revise per review comments.
JimmyCYJ 395e960
Revise per comment.
JimmyCYJ 796c80a
Fixed format issues.
JimmyCYJ bf97be5
Revise per comments
JimmyCYJ c1858e4
Revise per comment.
JimmyCYJ cb6e165
Revise per comments.
JimmyCYJ 8178e10
Revise per comments.
JimmyCYJ 6e6947e
Revise per comment.
JimmyCYJ d0f1f09
Always enable timer for next stats update.
JimmyCYJ cd3966d
Remove unnecessary included header file.
JimmyCYJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* Copyright 2017 Istio Authors. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include <chrono> | ||
|
|
||
| #include "src/envoy/mixer/stats.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Http { | ||
| namespace Mixer { | ||
| namespace { | ||
|
|
||
| // The time interval for envoy stats update. | ||
| const int kStatsUpdateIntervalInMs = 10000; | ||
|
|
||
| } // namespace | ||
|
|
||
| MixerStatsObject::MixerStatsObject(Event::Dispatcher& dispatcher, | ||
| const std::string& name, Stats::Scope& scope, | ||
| GetStatsFunc func) | ||
| : stats_{ALL_MIXER_FILTER_STATS(POOL_COUNTER_PREFIX(scope, name))}, | ||
| get_stats_func_(func) { | ||
| memset(&old_stats_, 0, sizeof(old_stats_)); | ||
|
|
||
| if (get_stats_func_) { | ||
| timer_ = dispatcher.createTimer([this]() { OnTimer(); }); | ||
| timer_->enableTimer(std::chrono::milliseconds(kStatsUpdateIntervalInMs)); | ||
| } | ||
| } | ||
|
|
||
| void MixerStatsObject::OnTimer() { | ||
| ::istio::mixer_client::Statistics new_stats; | ||
| bool get_stats = get_stats_func_(&new_stats); | ||
| if (get_stats) { | ||
| CheckAndUpdateStats(new_stats); | ||
| } | ||
| timer_->enableTimer(std::chrono::milliseconds(kStatsUpdateIntervalInMs)); | ||
| } | ||
|
|
||
| void MixerStatsObject::CheckAndUpdateStats( | ||
| const ::istio::mixer_client::Statistics& new_stats) { | ||
| if (new_stats.total_check_calls > old_stats_.total_check_calls) { | ||
| stats_.total_check_calls_.add(new_stats.total_check_calls - | ||
| old_stats_.total_check_calls); | ||
| } | ||
| if (new_stats.total_remote_check_calls > | ||
| old_stats_.total_remote_check_calls) { | ||
| stats_.total_remote_check_calls_.add(new_stats.total_remote_check_calls - | ||
| old_stats_.total_remote_check_calls); | ||
| } | ||
| if (new_stats.total_blocking_remote_check_calls > | ||
| old_stats_.total_blocking_remote_check_calls) { | ||
| stats_.total_blocking_remote_check_calls_.add( | ||
| new_stats.total_blocking_remote_check_calls - | ||
| old_stats_.total_blocking_remote_check_calls); | ||
| } | ||
| if (new_stats.total_quota_calls > old_stats_.total_quota_calls) { | ||
| stats_.total_quota_calls_.add(new_stats.total_quota_calls - | ||
| old_stats_.total_quota_calls); | ||
| } | ||
| if (new_stats.total_remote_quota_calls > | ||
| old_stats_.total_remote_quota_calls) { | ||
| stats_.total_remote_quota_calls_.add(new_stats.total_remote_quota_calls - | ||
| old_stats_.total_remote_quota_calls); | ||
| } | ||
| if (new_stats.total_blocking_remote_quota_calls > | ||
| old_stats_.total_blocking_remote_quota_calls) { | ||
| stats_.total_blocking_remote_quota_calls_.add( | ||
| new_stats.total_blocking_remote_quota_calls - | ||
| old_stats_.total_blocking_remote_quota_calls); | ||
| } | ||
| if (new_stats.total_report_calls > old_stats_.total_report_calls) { | ||
| stats_.total_report_calls_.add(new_stats.total_report_calls - | ||
| old_stats_.total_report_calls); | ||
| } | ||
| if (new_stats.total_remote_report_calls > | ||
| old_stats_.total_remote_report_calls) { | ||
| stats_.total_remote_report_calls_.add(new_stats.total_remote_report_calls - | ||
| old_stats_.total_remote_report_calls); | ||
| } | ||
|
|
||
| // Copy new_stats to old_stats_ for next stats update. | ||
| old_stats_ = new_stats; | ||
| } | ||
|
|
||
| } // namespace Mixer | ||
| } // namespace Http | ||
| } // namespace Envoy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /* Copyright 2017 Istio Authors. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "envoy/event/dispatcher.h" | ||
| #include "envoy/event/timer.h" | ||
| #include "envoy/stats/stats_macros.h" | ||
| #include "include/client.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Http { | ||
| namespace Mixer { | ||
|
|
||
| /** | ||
| * All mixer filter stats. @see stats_macros.h | ||
| */ | ||
| // clang-format off | ||
| #define ALL_MIXER_FILTER_STATS(COUNTER) \ | ||
| COUNTER(total_check_calls) \ | ||
| COUNTER(total_remote_check_calls) \ | ||
| COUNTER(total_blocking_remote_check_calls) \ | ||
| COUNTER(total_quota_calls) \ | ||
| COUNTER(total_remote_quota_calls) \ | ||
| COUNTER(total_blocking_remote_quota_calls) \ | ||
| COUNTER(total_report_calls) \ | ||
| COUNTER(total_remote_report_calls) | ||
| // clang-format on | ||
|
|
||
| /** | ||
| * Struct definition for all mixer filter stats. @see stats_macros.h | ||
| */ | ||
| struct MixerFilterStats { | ||
| ALL_MIXER_FILTER_STATS(GENERATE_COUNTER_STRUCT) | ||
| }; | ||
|
|
||
| typedef std::function<bool(::istio::mixer_client::Statistics* s)> GetStatsFunc; | ||
|
|
||
| // MixerStatsObject maintains statistics for number of check, quota and report | ||
| // calls issued by a mixer filter. | ||
| class MixerStatsObject { | ||
| public: | ||
| MixerStatsObject(Event::Dispatcher& dispatcher, const std::string& name, | ||
| Stats::Scope& scope, GetStatsFunc func); | ||
|
|
||
| private: | ||
| // This function is invoked when timer event fires. | ||
| void OnTimer(); | ||
|
|
||
| // Compares old stats with new stats and updates envoy stats. | ||
| void CheckAndUpdateStats(const ::istio::mixer_client::Statistics& new_stats); | ||
|
|
||
| // A set of Envoy stats for the number of check, quota and report calls. | ||
| MixerFilterStats stats_; | ||
| // Stores a function which gets statistics from mixer controller. | ||
| GetStatsFunc get_stats_func_; | ||
|
|
||
| // stats from last call to get_stats_func_. This is needed to calculate the | ||
| // variances of stats and update envoy stats. | ||
| ::istio::mixer_client::Statistics old_stats_; | ||
|
|
||
| // These members are used for creating a timer which update Envoy stats | ||
| // periodically. | ||
| ::Envoy::Event::TimerPtr timer_; | ||
| }; | ||
|
|
||
| } // namespace Mixer | ||
| } // namespace Http | ||
| } // namespace Envoy | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.?