-
Notifications
You must be signed in to change notification settings - Fork 5.5k
cryptomb: add queue size statistics #19180
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
Changes from 2 commits
5ca6d3c
30768ff
b2df330
2e51af7
e634b2e
1728354
3a86b6d
95d11b6
2f0528f
7d784fe
024ab51
c790431
a6c3626
a906fee
3fe1d40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -330,10 +330,10 @@ ssl_private_key_result_t rsaPrivateKeyDecryptForTest(CryptoMbPrivateKeyConnectio | |
| } | ||
|
|
||
| CryptoMbQueue::CryptoMbQueue(std::chrono::milliseconds poll_delay, enum KeyType type, int keysize, | ||
| IppCryptoSharedPtr ipp, Event::Dispatcher& d) | ||
| IppCryptoSharedPtr ipp, Event::Dispatcher& d, CryptoMbStats& stats) | ||
| : us_(std::chrono::duration_cast<std::chrono::microseconds>(poll_delay)), type_(type), | ||
| key_size_(keysize), ipp_(ipp), | ||
| timer_(d.createTimer([this]() -> void { processRequests(); })) { | ||
| key_size_(keysize), ipp_(ipp), timer_(d.createTimer([this]() -> void { processRequests(); })), | ||
| stats_(stats) { | ||
| request_queue_.reserve(MULTIBUFF_BATCH); | ||
| } | ||
|
|
||
|
|
@@ -359,6 +359,8 @@ void CryptoMbQueue::addAndProcessEightRequests(CryptoMbContextSharedPtr mb_ctx) | |
|
|
||
| void CryptoMbQueue::processRequests() { | ||
| if (type_ == KeyType::Rsa) { | ||
| // Increment correct queue size statistic. | ||
| stats_.getQueueSizeCounters()[request_queue_.size() - 1].get().inc(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/getQueueSizeCounters/queueSizeCounters/ per convention
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed after changing counters to histogram. |
||
| processRsaRequests(); | ||
| } | ||
| request_queue_.clear(); | ||
|
|
@@ -486,7 +488,9 @@ CryptoMbPrivateKeyMethodProvider::CryptoMbPrivateKeyMethodProvider( | |
| CryptoMbPrivateKeyMethodConfig& conf, | ||
| Server::Configuration::TransportSocketFactoryContext& factory_context, IppCryptoSharedPtr ipp) | ||
| : api_(factory_context.api()), | ||
| tls_(ThreadLocal::TypedSlot<ThreadLocalData>::makeUnique(factory_context.threadLocal())) { | ||
| tls_(ThreadLocal::TypedSlot<ThreadLocalData>::makeUnique(factory_context.threadLocal())), | ||
| stats_(factory_context.scope(), CryptoMbQueue::MULTIBUFF_BATCH, "cryptomb", | ||
| "rsa_queue_size_") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this does not get called in response to requests, right? this happens at config-time? If this does happen in response to requests then we should pre-symbolize the stat names and I can help you solve that without taking symbol-table locks. If this is called on config it's ok. But given it's not obvious how often this gets created, we should either comment on that assumption, or we should just go ahead and pre-symbolize all the names during config or (better yet) during startup.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This happens at config-time, I added a comment about it. |
||
|
|
||
| if (!ipp->mbxIsCryptoMbApplicable(0)) { | ||
| throw EnvoyException("Multi-buffer CPU instructions not available."); | ||
|
|
@@ -519,7 +523,6 @@ CryptoMbPrivateKeyMethodProvider::CryptoMbPrivateKeyMethodProvider( | |
| method_->complete = privateKeyComplete; | ||
|
|
||
| RSA* rsa = EVP_PKEY_get0_RSA(pkey.get()); | ||
|
|
||
| switch (RSA_bits(rsa)) { | ||
| case 1024: | ||
| key_size = 1024; | ||
|
|
@@ -582,9 +585,9 @@ CryptoMbPrivateKeyMethodProvider::CryptoMbPrivateKeyMethodProvider( | |
| enum KeyType key_type = key_type_; | ||
|
|
||
| // Create a single queue for every worker thread to avoid locking. | ||
| tls_->set([poll_delay, key_type, key_size, ipp](Event::Dispatcher& d) { | ||
| tls_->set([poll_delay, key_type, key_size, ipp, this](Event::Dispatcher& d) { | ||
| ENVOY_LOG(debug, "Created CryptoMb Queue for thread {}", d.name()); | ||
| return std::make_shared<ThreadLocalData>(poll_delay, key_type, key_size, ipp, d); | ||
| return std::make_shared<ThreadLocalData>(poll_delay, key_type, key_size, ipp, d, stats_); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include "contrib/cryptomb/private_key_providers/source/cryptomb_stats.h" | ||
|
|
||
| #include "source/common/stats/utility.h" | ||
|
|
||
| #include "absl/strings/str_cat.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace PrivateKeyMethodProvider { | ||
| namespace CryptoMb { | ||
|
|
||
| CryptoMbStats::CryptoMbStats(Stats::Scope& scope, uint32_t max_queue_size, | ||
| absl::string_view stats_prefix, | ||
| absl::string_view queue_size_stat_prefix) | ||
| : stat_name_pool_(scope.symbolTable()), stats_prefix_(stat_name_pool_.add(stats_prefix)) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. stats_prefix_ is not referenced after the constructor so you can drop the member variable and make this a local.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not exist anymore after the histogram change. |
||
| queue_size_counters_.reserve(max_queue_size); | ||
| for (uint32_t i = 1; i <= max_queue_size; i++) { | ||
| queue_size_counters_.push_back(Stats::Utility::counterFromStatNames( | ||
| scope, {stats_prefix_, stat_name_pool_.add(absl::StrCat(queue_size_stat_prefix, i))})); | ||
| } | ||
| } | ||
|
|
||
| } // namespace CryptoMb | ||
| } // namespace PrivateKeyMethodProvider | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "envoy/stats/scope.h" | ||
|
|
||
| #include "source/common/stats/symbol_table_impl.h" | ||
|
|
||
| #include "absl/strings/string_view.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace PrivateKeyMethodProvider { | ||
| namespace CryptoMb { | ||
|
|
||
| using StatsCounterRef = std::reference_wrapper<Stats::Counter>; | ||
|
|
||
| class CryptoMbStats { | ||
| public: | ||
| CryptoMbStats(Stats::Scope& scope, uint32_t max_queue_size, absl::string_view stats_prefix, | ||
| absl::string_view queue_size_stat_prefix); | ||
| std::vector<StatsCounterRef>& getQueueSizeCounters() { return queue_size_counters_; } | ||
|
|
||
| private: | ||
| Stats::StatNamePool stat_name_pool_; | ||
| const Stats::StatName stats_prefix_; | ||
| // Vector for queue size statistics. | ||
| std::vector<StatsCounterRef> queue_size_counters_; | ||
| }; | ||
|
|
||
| } // namespace CryptoMb | ||
| } // namespace PrivateKeyMethodProvider | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
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.
you don't need the
-> voidThere 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.
Removed
-> voidfrom two places.