Skip to content

Commit

Permalink
undeleting used code
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
  • Loading branch information
alyssawilk committed Oct 4, 2023
1 parent 0af0446 commit 55a65b7
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 22 deletions.
10 changes: 10 additions & 0 deletions envoy/stream_info/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ envoy_cc_library(
],
)

# This library is not currently used by Envoy but as of 2023 was consumed by downstream
# consumers (see https://github.com/envoyproxy/envoy/pull/29906/files)
envoy_cc_library(
name = "uint64_accessor_interface",
hdrs = ["uint64_accessor.h"],
deps = [
":filter_state_interface",
],
)

envoy_cc_library(
name = "stream_id_provider_interface",
hdrs = ["stream_id_provider.h"],
Expand Down
9 changes: 0 additions & 9 deletions envoy/stream_info/stream_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,6 @@ struct UpstreamTiming {
upstream_connect_complete_ = time_source.monotonicTime();
}

void onUpstreamHandshakeComplete(TimeSource& time_source) {
upstream_handshake_complete_ = time_source.monotonicTime();
}

absl::optional<MonotonicTime> upstreamHandshakeComplete() const {
return upstream_handshake_complete_;
}

absl::optional<std::chrono::nanoseconds> connectionPoolCallbackLatency() const {
return connection_pool_callback_latency_;
}
Expand All @@ -311,7 +303,6 @@ struct UpstreamTiming {

absl::optional<MonotonicTime> upstream_connect_start_;
absl::optional<MonotonicTime> upstream_connect_complete_;
absl::optional<MonotonicTime> upstream_handshake_complete_;
};

class DownstreamTiming {
Expand Down
26 changes: 26 additions & 0 deletions envoy/stream_info/uint64_accessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "envoy/common/pure.h"
#include "envoy/stream_info/filter_state.h"

namespace Envoy {
namespace StreamInfo {

/**
* A FilterState object that tracks a single uint64_t value.
*/
class UInt64Accessor : public FilterState::Object {
public:
/**
* Increments the tracked value by 1.
*/
virtual void increment() PURE;

/**
* @return the tracked value.
*/
virtual uint64_t value() const PURE;
};

} // namespace StreamInfo
} // namespace Envoy
10 changes: 10 additions & 0 deletions source/common/stream_info/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ envoy_cc_library(
],
)

# This library is not currently used by Envoy but as of 2023 was consumed by downstream
# consumers (see https://github.com/envoyproxy/envoy/pull/29906/files)
envoy_cc_library(
name = "uint64_accessor_lib",
hdrs = ["uint64_accessor_impl.h"],
deps = [
"//envoy/stream_info:uint64_accessor_interface",
],
)

envoy_cc_library(
name = "upstream_address_lib",
hdrs = ["upstream_address.h"],
Expand Down
31 changes: 31 additions & 0 deletions source/common/stream_info/uint64_accessor_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include "envoy/stream_info/uint64_accessor.h"

namespace Envoy {
namespace StreamInfo {

/*
* A FilterState object that tracks a single uint64_t value.
*/
class UInt64AccessorImpl : public UInt64Accessor {
public:
UInt64AccessorImpl(uint64_t value) : value_(value) {}

// From FilterState::Object
ProtobufTypes::MessagePtr serializeAsProto() const override {
auto message = std::make_unique<ProtobufWkt::UInt64Value>();
message->set_value(value_);
return message;
}

// From UInt64Accessor.
void increment() override { value_++; }
uint64_t value() const override { return value_; }

private:
uint64_t value_;
};

} // namespace StreamInfo
} // namespace Envoy
8 changes: 0 additions & 8 deletions source/common/stream_info/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,6 @@ absl::optional<std::chrono::nanoseconds> TimingUtility::lastUpstreamRxByteReceiv
return duration(timing.value().get().last_upstream_rx_byte_received_, stream_info_);
}

absl::optional<std::chrono::nanoseconds> TimingUtility::upstreamHandshakeComplete() {
OptRef<const UpstreamTiming> timing = getUpstreamTiming(stream_info_);
if (!timing) {
return absl::nullopt;
}
return duration(timing.value().get().upstreamHandshakeComplete(), stream_info_);
}

absl::optional<std::chrono::nanoseconds> TimingUtility::firstDownstreamTxByteSent() {
OptRef<const DownstreamTiming> timing = stream_info_.downstreamTiming();
if (!timing) {
Expand Down
1 change: 0 additions & 1 deletion source/common/stream_info/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ class TimingUtility {
absl::optional<std::chrono::nanoseconds> lastUpstreamTxByteSent();
absl::optional<std::chrono::nanoseconds> firstUpstreamRxByteReceived();
absl::optional<std::chrono::nanoseconds> lastUpstreamRxByteReceived();
absl::optional<std::chrono::nanoseconds> upstreamHandshakeComplete();
absl::optional<std::chrono::nanoseconds> firstDownstreamTxByteSent();
absl::optional<std::chrono::nanoseconds> lastDownstreamTxByteSent();
absl::optional<std::chrono::nanoseconds> lastDownstreamRxByteReceived();
Expand Down
8 changes: 8 additions & 0 deletions test/common/stream_info/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ envoy_cc_test(
],
)

envoy_cc_test(
name = "uint64_accessor_impl_test",
srcs = ["uint64_accessor_impl_test.cc"],
deps = [
"//source/common/stream_info:uint64_accessor_lib",
],
)

envoy_cc_test(
name = "bool_accessor_impl_test",
srcs = ["bool_accessor_impl_test.cc"],
Expand Down
4 changes: 0 additions & 4 deletions test/common/stream_info/stream_info_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ TEST_F(StreamInfoImplTest, TimingTest) {
info.downstreamTiming().onDownstreamHandshakeComplete(test_time_.timeSystem());
dur = checkDuration(dur, timing.downstreamHandshakeComplete());

EXPECT_FALSE(timing.upstreamHandshakeComplete());
upstream_timing.onUpstreamHandshakeComplete(test_time_.timeSystem());
dur = checkDuration(dur, timing.upstreamHandshakeComplete());

EXPECT_FALSE(timing.lastDownstreamAckReceived());
info.downstreamTiming().onLastDownstreamAckReceived(test_time_.timeSystem());
dur = checkDuration(dur, timing.lastDownstreamAckReceived());
Expand Down
36 changes: 36 additions & 0 deletions test/common/stream_info/uint64_accessor_impl_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "source/common/stream_info/uint64_accessor_impl.h"

#include "gtest/gtest.h"

namespace Envoy {
namespace StreamInfo {
namespace {

TEST(UInt64AccessorImplTest, ConstructorInitsValue) {
uint64_t init_value = 0xdeadbeefdeadbeef;
UInt64AccessorImpl accessor(init_value);
EXPECT_EQ(init_value, accessor.value());
}

TEST(UInt64AccessorImplTest, IncrementValue) {
uint64_t init_value = 0xdeadbeefdeadbeef;
UInt64AccessorImpl accessor(init_value);
accessor.increment();

EXPECT_EQ(0xdeadbeefdeadbef0, accessor.value());
}

TEST(UInt64AccessorImplTest, TestProto) {
uint64_t init_value = 0xdeadbeefdeadbeef;
UInt64AccessorImpl accessor(init_value);
auto message = accessor.serializeAsProto();
EXPECT_NE(nullptr, message);

auto* uint64_struct = dynamic_cast<ProtobufWkt::UInt64Value*>(message.get());
EXPECT_NE(nullptr, uint64_struct);
EXPECT_EQ(init_value, uint64_struct->value());
}

} // namespace
} // namespace StreamInfo
} // namespace Envoy

0 comments on commit 55a65b7

Please sign in to comment.