make ClusterInfo::traffic_stats_ a unique_ptr, so that later we can lazy-init it later.#24406
Conversation
…azyInit it Signed-off-by: Xin Zhuang <stevenzzz@google.com>
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
|
hi Josh, PTAL. |
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
jmarantz
left a comment
There was a problem hiding this comment.
OK I'm done with this round.
Let's not use multiple inheritance for the tests. And the other broad thing is to make a type nickname for your unique_ptr.
envoy/upstream/upstream.h
Outdated
|
|
||
| /** | ||
| * @return ClusterTrafficStats& all traffic related stats for this cluster. | ||
| * @return std::unique_ptr<ClusterTrafficStats>& all traffic related stats for this cluster. |
There was a problem hiding this comment.
can you make a nickname ClusterTrafficStatsPtr for the unique_ptr?
There was a problem hiding this comment.
Since we're not passing the ownership here, just use raw pointer ClusterTrafficStats* instead of returning a reference to unique ptr?
There was a problem hiding this comment.
This is a good point, Lizan. However that will not be convenient for the follow-up for this PR.
That's because we want to (once we sort out some semantic issues around stat continuity) return a LazyInit& here.
I had suggested making this change as an intermediate step because it is a large PR but is (arguably) obviously correct.
Then when we have solved stat continuity across xds updates we would be able to pass around the lazy-init reference, and then the first time a stat is incremented, we'll instantiate the block of stats.
I think this might appear more palatable once Xin adds a nickname for this.
There was a problem hiding this comment.
Sounds good, if this is an intermediate state just add some comment explaining. A nickname helps as well.
| host_->cluster().trafficStats().upstream_rq_total_.inc(); | ||
| host_->cluster().trafficStats().upstream_rq_active_.inc(); | ||
| host_->cluster().trafficStats()->upstream_rq_total_.inc(); | ||
| host_->cluster().trafficStats()->upstream_rq_active_.inc(); |
There was a problem hiding this comment.
capture *host_->cluster().trafficStats() in a temp.
| : parent_(parent), can_send_early_data_(can_send_early_data) { | ||
| parent_.host()->cluster().trafficStats().upstream_rq_pending_total_.inc(); | ||
| parent_.host()->cluster().trafficStats().upstream_rq_pending_active_.inc(); | ||
| parent_.host()->cluster().trafficStats()->upstream_rq_pending_total_.inc(); |
There was a problem hiding this comment.
capture *host_->cluster().trafficStats() in a temp.
| parent_.host()->cluster().trafficStats().upstream_cx_total_.inc(); | ||
| parent_.host()->cluster().trafficStats().upstream_cx_active_.inc(); | ||
| parent_.host()->cluster().trafficStats()->upstream_cx_total_.inc(); | ||
| parent_.host()->cluster().trafficStats()->upstream_cx_active_.inc(); |
There was a problem hiding this comment.
capture *host_->cluster().trafficStats() in a temp.
| time_source_(dispatcher.timeSource()), redis_command_stats_(redis_command_stats), | ||
| scope_(scope), is_transaction_client_(is_transaction_client) { | ||
| host->cluster().trafficStats().upstream_cx_total_.inc(); | ||
| host->cluster().trafficStats()->upstream_cx_total_.inc(); |
There was a problem hiding this comment.
capture *host_->cluster().trafficStats() in a temp.
| }; | ||
|
|
||
| class LookupWithStatNameTest : public ThreadLocalStoreNoMocksTestBase {}; | ||
| class LookupWithStatNameTest : public ThreadLocalStoreNoMocksTestBase, public testing::Test {}; |
There was a problem hiding this comment.
Instead of multiple inheritance, please make ThreadLocalStoreNoMocksTestBase derive from testing::Test.
There was a problem hiding this comment.
this is to be reused later in a BENCHMARK test, the testing class there inherits from not necessarily is a testing::Test.
There was a problem hiding this comment.
Use composition rather than multiple inheritance for that pattern.
There was a problem hiding this comment.
if not feeling strongly, I'd hope it stay this way. I am not sure how much the composition pattern would help with readability here. OTOH, the original ThreadLocalRealThreadsTestBase is already a multiple inheritance impl.
There was a problem hiding this comment.
Actually I agree with you - this is consistent with other test helper classes in Envoy.
One thing that's a little concerning is that usually the needs of performance tests are not consistent from the needs of unit tests, so they may not want to share that much code, but in this case I think it is helpful to do the sharing.
|
/wait |
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
| }; | ||
|
|
||
| class LookupWithStatNameTest : public ThreadLocalStoreNoMocksTestBase {}; | ||
| class LookupWithStatNameTest : public ThreadLocalStoreNoMocksTestBase, public testing::Test {}; |
There was a problem hiding this comment.
this is to be reused later in a BENCHMARK test, the testing class there inherits from not necessarily is a testing::Test.
| time_source_(dispatcher.timeSource()), redis_command_stats_(redis_command_stats), | ||
| scope_(scope), is_transaction_client_(is_transaction_client) { | ||
| host->cluster().trafficStats().upstream_cx_total_.inc(); | ||
| host->cluster().trafficStats()->upstream_cx_total_.inc(); |
| host_->cluster().trafficStats().upstream_rq_total_.inc(); | ||
| host_->cluster().trafficStats().upstream_rq_active_.inc(); | ||
| host_->cluster().trafficStats()->upstream_rq_total_.inc(); | ||
| host_->cluster().trafficStats()->upstream_rq_active_.inc(); |
envoy/upstream/upstream.h
Outdated
|
|
||
| /** | ||
| * @return ClusterTrafficStats& all traffic related stats for this cluster. | ||
| * @return std::unique_ptr<ClusterTrafficStats>& all traffic related stats for this cluster. |
| : parent_(parent), can_send_early_data_(can_send_early_data) { | ||
| parent_.host()->cluster().trafficStats().upstream_rq_pending_total_.inc(); | ||
| parent_.host()->cluster().trafficStats().upstream_rq_pending_active_.inc(); | ||
| parent_.host()->cluster().trafficStats()->upstream_rq_pending_total_.inc(); |
| parent_.host()->cluster().trafficStats().upstream_cx_total_.inc(); | ||
| parent_.host()->cluster().trafficStats().upstream_cx_active_.inc(); | ||
| parent_.host()->cluster().trafficStats()->upstream_cx_total_.inc(); | ||
| parent_.host()->cluster().trafficStats()->upstream_cx_active_.inc(); |
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
| }; | ||
|
|
||
| class LookupWithStatNameTest : public ThreadLocalStoreNoMocksTestBase {}; | ||
| class LookupWithStatNameTest : public ThreadLocalStoreNoMocksTestBase, public testing::Test {}; |
There was a problem hiding this comment.
Actually I agree with you - this is consistent with other test helper classes in Envoy.
One thing that's a little concerning is that usually the needs of performance tests are not consistent from the needs of unit tests, so they may not want to share that much code, but in this case I think it is helpful to do the sharing.
| } | ||
| }; | ||
|
|
||
| for (const Stats::CounterSharedPtr& counter : test_server_->counters()) { |
|
/wait |
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
|
/wait |
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
|
updated. PTAL
…On Mon, Dec 12, 2022 at 11:18 AM Joshua Marantz ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In envoy/upstream/upstream.h
<#24406 (comment)>:
> @@ -765,6 +765,7 @@ MAKE_STATS_STRUCT(ClusterLbStats, ClusterLbStatNames, ALL_CLUSTER_LB_STATS);
*/
MAKE_STAT_NAMES_STRUCT(ClusterTrafficStatNames, ALL_CLUSTER_TRAFFIC_STATS);
MAKE_STATS_STRUCT(ClusterTrafficStats, ClusterTrafficStatNames, ALL_CLUSTER_TRAFFIC_STATS);
+using ClusterTrafficStatsPtr = std::unique_ptr<ClusterTrafficStats>;
I think it'd be better for the CL author not to resolve comments unless it
was a simple suggestion that was implemented.
Otherwise that causes the reviewer to re-review and re-discover the same
issue.
I think if we change the nickname to `LazyClusterTrafficStats' then it can
be commented right here and not at call sites, and that's what I'm learning
toward.
—
Reply to this email directly, view it on GitHub
<#24406 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA2I6TAPYEI3PMA3D444M3LWM5F6PANCNFSM6AAAAAASWGQAXM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
--
Xin Zhuang
|
| EXPECT_EQ(5, factory_context_.cluster_manager_.thread_local_cluster_.cluster_.info_->stats_ | ||
| .upstream_cx_tx_bytes_total_.value()); | ||
| EXPECT_EQ(5, factory_context_.cluster_manager_.thread_local_cluster_.cluster_.info_ | ||
| ->traffic_stats_->upstream_cx_tx_bytes_total_.value()); |
There was a problem hiding this comment.
I'm surprised to see this particular diff; I thought you already partitioned the stat into separate blocks in a previous PR.
There was a problem hiding this comment.
the renaming? it's not included in the previous PRs.
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
Signed-off-by: Xin Zhuang <stevenzzz@google.com>
jmarantz
left a comment
There was a problem hiding this comment.
Thanks -- this looks great!
| // For example, we also want to record the stats in the case of BiDi streaming APIs where we | ||
| // might have already seen the headers. | ||
| cluster_->trafficStats().upstream_rq_timeout_.inc(); | ||
| cluster_->trafficStats()->upstream_rq_timeout_.inc(); |
There was a problem hiding this comment.
just want to point out that this whole lazy optimization change has a lot of sense from the perspective of the mobile Envoy (that runs on iOS and Android devices) too.
For the mobile applications a lot of impact could be realized if we added lazy initiation to virtual cluster stats. They are managed in multiple places but one of them is just a line below the line I commented on. Are there any plans to make the initialization of virtual cluster stats lazy too or is this outside of the scope of work/changes that you are work on?
…-tools * origin/main: (59 commits) Make IsOkAndHolds matcher work with submatchers (#24498) ios: fix platform key value store (#24532) make ClusterInfo::traffic_stats_ a unique_ptr, so that later we can lazy-init it later. (#24406) quic: splitting into client and server (#24513) fixing coverage (#24529) ci: Add `examplesOnly` condition (#24465) ci: sonatype_nexus_upload.py: remove unused format argument (#24471) deps: Bump `build_bazel_rules_apple` -> 1.1.3 (#24527) deps: Bump `com_github_nghttp2_nghttp2` -> 1.51.0 (#24525) deps: Bump `rules_license` -> 0.0.4 (#24523) build(deps): bump sphinxcontrib-httpdomain from 1.8.0 to 1.8.1 in /mobile/docs (#24126) build(deps): bump github/codeql-action from 2.1.35 to 2.1.36 (#24473) build(deps): bump openpolicyagent/opa from 0.47.2-istio to 0.47.3-istio in /examples/ext_authz (#24514) build(deps): bump node from `80844b6` to `2770c78` in /examples/ext_authz/auth/http-service (#24515) build(deps): bump abseil-cpp to latest version (#24386) xDS: add xDS config tracker extension point (#23485) kafka: add shared consumer manager (#24494) coverage: Improve test coverage (#24355) deps: Bump `rules_python` -> 0.16.1 (#24344) ci: revert disable running the Objective-C integration app (#24478)" (#24496) ... Signed-off-by: JP Simard <jp@jpsim.com>
Signed-off-by: kuochunghsu <kuochunghsu@pinterest.com>
Commit Message: make ClusterInfo::traffic_stats_ a unique_ptr, so that later we can lazy-init it later.
Additional Description: Cribbed from #23921, this PR is to split the bulk of "." ==> "->" changes in that PR.
NOTE: in this PR the renaming from ClusterInfoImpl::stats_ --> ClusterInfoImpl::traffic_stats_ is also included, sorry for the extra diffs, but hopefully it's straightforward enough to review.
context issue: #23575
Risk Level: LOW, no behavior change.
Testing: Existing unit test.
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]