Skip to content

Commit 5d62787

Browse files
Jacob Steinebronnfacebook-github-bot
authored andcommitted
Support pool counters for CONNECT
Summary: Pool counters including: - conn and new_conn (former is # current conns, latter is a counter for like rate.60 or something) - ingress and egress bytes - req, and class codes (2xx, 3xx, etc) I didn't include server latency because it doesn't really make sense for CONNECT sessions Reviewed By: kwaugh Differential Revision: D81638796 fbshipit-source-id: 9c9c564660370b364bda3b3ff8cd6a6ef9ca4d5e
1 parent 1aef618 commit 5d62787

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

proxygen/lib/http/sink/HTTPConnectSink.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ void HTTPConnectSink::sendBody(std::unique_ptr<folly::IOBuf> body) {
3535
DestructorCheck::Safety safety(*this);
3636
resetIdleTimeout();
3737
++outstandingWrites_;
38+
if (stats_ && body) {
39+
stats_->addEgressBodyBytes(body->computeChainDataLength());
40+
}
3841
sock_->writeChain(this, std::move(body));
3942
if (safety.destroyed()) {
4043
return;
@@ -129,6 +132,9 @@ void HTTPConnectSink::readDataAvailable(size_t readSize) noexcept {
129132
while (readBuf_.front()->length() == 0) {
130133
readBuf_.pop_front();
131134
}
135+
if (stats_) {
136+
stats_->addIngressBodyBytes(readBuf_.front()->length());
137+
}
132138
handler_->onBody(readBuf_.pop_front());
133139
}
134140
}

proxygen/lib/http/sink/HTTPConnectSink.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#pragma once
10+
#include "proxygen/facebook/revproxy/pools/Pool.h"
1011
#include <folly/io/async/AsyncSocket.h>
1112
#include <folly/io/async/AsyncTransport.h>
1213
#include <proxygen/lib/http/session/HTTPTransaction.h>
@@ -27,14 +28,30 @@ class HTTPConnectSink
2728

2829
public:
2930
explicit HTTPConnectSink(folly::AsyncTransport::UniquePtr socket,
30-
HTTPTransactionHandler* handler)
31+
HTTPTransactionHandler* handler,
32+
std::shared_ptr<Pool> pool = nullptr)
3133
: sock_(std::move(socket)), handler_(handler) {
3234
CHECK(sock_);
3335
sock_->getLocalAddress(&localAddress_);
3436
sock_->getPeerAddress(&peerAddress_);
37+
38+
if (pool) {
39+
stats_ = pool->getConnectionStats();
40+
}
41+
if (stats_) {
42+
stats_->recordConnectionOpen();
43+
stats_->recordTcpConnectionOpen();
44+
stats_->recordRequest();
45+
stats_->recordResponse(200);
46+
}
3547
}
3648

37-
~HTTPConnectSink() override = default;
49+
~HTTPConnectSink() override {
50+
if (stats_) {
51+
stats_->recordDuration(millisecondsSince(connStart_).count());
52+
stats_->recordConnectionClose();
53+
}
54+
}
3855

3956
[[nodiscard]] folly::Optional<HTTPCodec::StreamID> getStreamID()
4057
const override {
@@ -197,6 +214,8 @@ class HTTPConnectSink
197214
folly::SocketAddress peerAddress_;
198215
folly::SocketAddress localAddress_;
199216
wangle::TransportInfo transportInfo_;
217+
ConnectionStats* stats_ = nullptr;
218+
const TimePoint connStart_{getCurrentTime()};
200219

201220
/** Chain of ingress IOBufs */
202221
folly::IOBufQueue readBuf_{folly::IOBufQueue::cacheChainLength()};

0 commit comments

Comments
 (0)