Skip to content
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

Added absl::optional dependency to replace current optional implementation of envoy #2688

Merged
merged 13 commits into from
Mar 13, 2018
4 changes: 4 additions & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ def _com_google_absl():
name = "abseil_int128",
actual = "@com_google_absl//absl/numeric:int128",
)
native.bind(
name = "abseil_optional",
actual = "@com_google_absl//absl/types:optional",
)

def _com_google_protobuf():
_repository_impl("com_google_protobuf")
Expand Down
5 changes: 0 additions & 5 deletions include/envoy/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ envoy_cc_library(
hdrs = ["interval_set.h"],
)

envoy_cc_library(
name = "optional",
hdrs = ["optional.h"],
)

envoy_cc_library(
name = "callback",
hdrs = ["callback.h"],
Expand Down
70 changes: 0 additions & 70 deletions include/envoy/common/optional.h

This file was deleted.

2 changes: 1 addition & 1 deletion include/envoy/grpc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ envoy_package()
envoy_cc_library(
name = "async_client_interface",
hdrs = ["async_client.h"],
external_deps = ["abseil_optional"],
deps = [
":status",
"//include/envoy/common:optional",
"//include/envoy/http:header_map_interface",
"//include/envoy/tracing:http_tracer_interface",
"//source/common/protobuf",
Expand Down
5 changes: 3 additions & 2 deletions include/envoy/grpc/async_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

#include <chrono>

#include "envoy/common/optional.h"
#include "envoy/common/pure.h"
#include "envoy/grpc/status.h"
#include "envoy/http/header_map.h"
#include "envoy/tracing/http_tracer.h"

#include "common/protobuf/protobuf.h"

#include "absl/types/optional.h"

namespace Envoy {
namespace Grpc {

Expand Down Expand Up @@ -194,7 +195,7 @@ class AsyncClient {
virtual AsyncRequest* send(const Protobuf::MethodDescriptor& service_method,
const Protobuf::Message& request, AsyncRequestCallbacks& callbacks,
Tracing::Span& parent_span,
const Optional<std::chrono::milliseconds>& timeout) PURE;
const absl::optional<std::chrono::milliseconds>& timeout) PURE;

/**
* Start a gRPC stream asynchronously.
Expand Down
2 changes: 1 addition & 1 deletion include/envoy/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ envoy_package()
envoy_cc_library(
name = "async_client_interface",
hdrs = ["async_client.h"],
external_deps = ["abseil_optional"],
deps = [
":message_interface",
"//include/envoy/common:optional",
"//include/envoy/event:dispatcher_interface",
],
)
Expand Down
7 changes: 4 additions & 3 deletions include/envoy/http/async_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
#include <chrono>
#include <memory>

#include "envoy/common/optional.h"
#include "envoy/event/dispatcher.h"
#include "envoy/http/message.h"

#include "absl/types/optional.h"

namespace Envoy {
namespace Http {

Expand Down Expand Up @@ -140,7 +141,7 @@ class AsyncClient {
* handle should just be used to cancel.
*/
virtual Request* send(MessagePtr&& request, Callbacks& callbacks,
const Optional<std::chrono::milliseconds>& timeout) PURE;
const absl::optional<std::chrono::milliseconds>& timeout) PURE;

/**
* Start an HTTP stream asynchronously.
Expand All @@ -156,7 +157,7 @@ class AsyncClient {
* the handle can be used to send more messages or close the stream.
*/
virtual Stream* start(StreamCallbacks& callbacks,
const Optional<std::chrono::milliseconds>& timeout,
const absl::optional<std::chrono::milliseconds>& timeout,
bool buffer_body_for_retry) PURE;

/**
Expand Down
2 changes: 1 addition & 1 deletion include/envoy/ratelimit/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ envoy_package()
envoy_cc_library(
name = "ratelimit_interface",
hdrs = ["ratelimit.h"],
external_deps = ["abseil_optional"],
deps = [
"//include/envoy/common:optional",
"//include/envoy/tracing:http_tracer_interface",
],
)
5 changes: 3 additions & 2 deletions include/envoy/ratelimit/ratelimit.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include <string>
#include <vector>

#include "envoy/common/optional.h"
#include "envoy/common/pure.h"
#include "envoy/tracing/http_tracer.h"

#include "absl/types/optional.h"

namespace Envoy {
namespace RateLimit {

Expand Down Expand Up @@ -92,7 +93,7 @@ class ClientFactory {
/**
* Return a new rate limit client.
*/
virtual ClientPtr create(const Optional<std::chrono::milliseconds>& timeout) PURE;
virtual ClientPtr create(const absl::optional<std::chrono::milliseconds>& timeout) PURE;
};

typedef std::unique_ptr<ClientFactory> ClientFactoryPtr;
Expand Down
2 changes: 1 addition & 1 deletion include/envoy/request_info/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ envoy_package()
envoy_cc_library(
name = "request_info_interface",
hdrs = ["request_info.h"],
external_deps = ["abseil_optional"],
deps = [
"//include/envoy/common:optional",
"//include/envoy/common:time_interface",
"//include/envoy/http:protocol_interface",
"//include/envoy/upstream:upstream_interface",
Expand Down
23 changes: 12 additions & 11 deletions include/envoy/request_info/request_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#include <cstdint>
#include <string>

#include "envoy/common/optional.h"
#include "envoy/common/pure.h"
#include "envoy/common/time.h"
#include "envoy/http/protocol.h"
#include "envoy/upstream/upstream.h"

#include "absl/types/optional.h"

namespace Envoy {

namespace Router {
Expand Down Expand Up @@ -75,7 +76,7 @@ class RequestInfo {
/**
* @return the protocol of the request.
*/
virtual Optional<Http::Protocol> protocol() const PURE;
virtual absl::optional<Http::Protocol> protocol() const PURE;

/**
* @param protocol the request's protocol.
Expand All @@ -85,7 +86,7 @@ class RequestInfo {
/**
* @return the response code.
*/
virtual Optional<uint32_t> responseCode() const PURE;
virtual absl::optional<uint32_t> responseCode() const PURE;

/**
* @return the time that the first byte of the request was received.
Expand All @@ -102,7 +103,7 @@ class RequestInfo {
* @return the duration between the last byte of the request was received and the start of the
* request.
*/
virtual Optional<std::chrono::nanoseconds> lastDownstreamRxByteReceived() const PURE;
virtual absl::optional<std::chrono::nanoseconds> lastDownstreamRxByteReceived() const PURE;

/**
* Sets the time when the last byte of the request was received.
Expand All @@ -114,7 +115,7 @@ class RequestInfo {
* the request. There may be a considerable delta between lastDownstreamByteReceived and this
* value due to filters.
*/
virtual Optional<std::chrono::nanoseconds> firstUpstreamTxByteSent() const PURE;
virtual absl::optional<std::chrono::nanoseconds> firstUpstreamTxByteSent() const PURE;

/**
* Sets the time when the first byte of the request was sent upstream.
Expand All @@ -125,7 +126,7 @@ class RequestInfo {
* @return the duration between the last bye of the request was sent upstream and the start of the
* request.
*/
virtual Optional<std::chrono::nanoseconds> lastUpstreamTxByteSent() const PURE;
virtual absl::optional<std::chrono::nanoseconds> lastUpstreamTxByteSent() const PURE;

/**
* Sets the time when the last bye of the request was sent upstream.
Expand All @@ -136,7 +137,7 @@ class RequestInfo {
* @return the duration between the first byte of the response is received from upstream and the
* start of the request.
*/
virtual Optional<std::chrono::nanoseconds> firstUpstreamRxByteReceived() const PURE;
virtual absl::optional<std::chrono::nanoseconds> firstUpstreamRxByteReceived() const PURE;

/**
* Sets the time when the first byte of the response is received from
Expand All @@ -148,7 +149,7 @@ class RequestInfo {
* @return the duration between the last byte of the response is received from upstream and the
* start of the request.
*/
virtual Optional<std::chrono::nanoseconds> lastUpstreamRxByteReceived() const PURE;
virtual absl::optional<std::chrono::nanoseconds> lastUpstreamRxByteReceived() const PURE;

/**
* Sets the time when the last byte of the response is received from
Expand All @@ -161,7 +162,7 @@ class RequestInfo {
* the request. There may be a considerable delta between lastUpstreamByteReceived and this value
* due to filters.
*/
virtual Optional<std::chrono::nanoseconds> firstDownstreamTxByteSent() const PURE;
virtual absl::optional<std::chrono::nanoseconds> firstDownstreamTxByteSent() const PURE;

/**
* Sets the time when the first byte of the response is sent downstream.
Expand All @@ -172,7 +173,7 @@ class RequestInfo {
* @return the duration between the last byte of the response is sent downstream and the start of
* the request.
*/
virtual Optional<std::chrono::nanoseconds> lastDownstreamTxByteSent() const PURE;
virtual absl::optional<std::chrono::nanoseconds> lastDownstreamTxByteSent() const PURE;

/**
* Sets the time when the last byte of the response is sent downstream.
Expand All @@ -183,7 +184,7 @@ class RequestInfo {
* @return the total duration of the request (i.e., when the request's ActiveStream is destroyed)
* and may be longer than lastDownstreamTxByteSent.
*/
virtual Optional<std::chrono::nanoseconds> requestComplete() const PURE;
virtual absl::optional<std::chrono::nanoseconds> requestComplete() const PURE;

/**
* Sets the end time for the request. This method is called once the request has been fully
Expand Down
2 changes: 1 addition & 1 deletion include/envoy/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ envoy_cc_library(
envoy_cc_library(
name = "router_interface",
hdrs = ["router.h"],
external_deps = ["abseil_optional"],
deps = [
"//include/envoy/access_log:access_log_interface",
"//include/envoy/common:optional",
"//include/envoy/http:codec_interface",
"//include/envoy/http:codes_interface",
"//include/envoy/http:header_map_interface",
Expand Down
17 changes: 9 additions & 8 deletions include/envoy/router/router.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "envoy/access_log/access_log.h"
#include "envoy/api/v2/core/base.pb.h"
#include "envoy/common/optional.h"
#include "envoy/http/codec.h"
#include "envoy/http/codes.h"
#include "envoy/http/header_map.h"
Expand All @@ -20,6 +19,8 @@
#include "common/protobuf/protobuf.h"
#include "common/protobuf/utility.h"

#include "absl/types/optional.h"

namespace Envoy {
namespace Router {

Expand Down Expand Up @@ -111,9 +112,9 @@ class CorsPolicy {
virtual const std::string& maxAge() const PURE;

/**
* @return const Optional<bool>& Whether access-control-allow-credentials should be true.
* @return const absl::optional<bool>& Whether access-control-allow-credentials should be true.
*/
virtual const Optional<bool>& allowCredentials() const PURE;
virtual const absl::optional<bool>& allowCredentials() const PURE;

/**
* @return bool Whether CORS is enabled for the route or virtual host.
Expand Down Expand Up @@ -186,7 +187,7 @@ class RetryState {
* called. Calling code should proceed with error handling.
*/
virtual RetryStatus shouldRetry(const Http::HeaderMap* response_headers,
const Optional<Http::StreamResetReason>& reset_reason,
const absl::optional<Http::StreamResetReason>& reset_reason,
DoRetryCallback callback) PURE;
};

Expand Down Expand Up @@ -282,12 +283,12 @@ class HashPolicy {
* @param headers stores the HTTP headers for the stream
* @param add_cookie is called to add a set-cookie header on the reply sent to the downstream
* host
* @return Optional<uint64_t> an optional hash value to route on. A hash value might not be
* @return absl::optional<uint64_t> an optional hash value to route on. A hash value might not be
* returned if for example the specified HTTP header does not exist.
*/
virtual Optional<uint64_t> generateHash(const std::string& downstream_address,
const Http::HeaderMap& headers,
AddCookieCallback add_cookie) const PURE;
virtual absl::optional<uint64_t> generateHash(const std::string& downstream_address,
const Http::HeaderMap& headers,
AddCookieCallback add_cookie) const PURE;
};

class MetadataMatchCriterion {
Expand Down
Loading