Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into ci_gcs_remote_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
lizan committed Aug 7, 2018
2 parents ddcc25d + 4e52589 commit 6ec7ebf
Show file tree
Hide file tree
Showing 22 changed files with 1,281 additions and 16 deletions.
1 change: 1 addition & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The `./ci/run_envoy_docker.sh './ci/do_ci.sh <TARGET>'` targets are:
* `bazel.debug.server_only` &mdash; build Envoy static binary under `-c dbg`.
* `bazel.dev` &mdash; build Envoy static binary and run tests under `-c fastbuild` with gcc.
* `bazel.release` &mdash; build Envoy static binary and run tests under `-c opt` with gcc.
* `bazel.release <test>` &mdash; build Envoy static binary and run a specified test or test dir under `-c opt` with gcc.
* `bazel.release.server_only` &mdash; build Envoy static binary under `-c opt` with gcc.
* `bazel.coverage` &mdash; build and run tests under `-c dbg` with gcc, generating coverage information in `$ENVOY_DOCKER_BUILD_DIR/envoy/generated/coverage/coverage.html`.
* `bazel.coverity` &mdash; build Envoy static binary and run Coverity Scan static analysis.
Expand Down
23 changes: 16 additions & 7 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,25 @@ if [[ "$1" == "bazel.release" ]]; then
echo 'Ignoring build for git tag event'
exit 0
fi

setup_gcc_toolchain
echo "bazel release build with tests..."
bazel_release_binary_build
echo "Testing..."
# We have various test binaries in the test directory such as tools, benchmarks, etc. We
# run a build pass to make sure they compile.
bazel --batch build ${BAZEL_BUILD_OPTIONS} -c opt //include/... //source/... //test/...
# Now run all of the tests which should already be compiled.
bazel --batch test ${BAZEL_TEST_OPTIONS} -c opt //test/...

if [[ $# > 1 ]]; then
shift
echo "Testing $* ..."
# Run only specified tests. Argument can be a single test
# (e.g. '//test/common/common:assert_test') or a test group (e.g. '//test/common/...')
bazel --batch test ${BAZEL_TEST_OPTIONS} -c opt $*
else
echo "Testing..."
# We have various test binaries in the test directory such as tools, benchmarks, etc. We
# run a build pass to make sure they compile.
bazel --batch build ${BAZEL_BUILD_OPTIONS} -c opt //include/... //source/... //test/...
# Now run all of the tests which should already be compiled.
bazel --batch test ${BAZEL_TEST_OPTIONS} -c opt //test/...
fi
exit 0
elif [[ "$1" == "bazel.release.server_only" ]]; then
setup_gcc_toolchain
Expand Down
7 changes: 7 additions & 0 deletions include/envoy/request_info/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ envoy_cc_library(
hdrs = ["request_info.h"],
external_deps = ["abseil_optional"],
deps = [
":dynamic_metadata_interface",
"//include/envoy/common:time_interface",
"//include/envoy/http:protocol_interface",
"//include/envoy/upstream:upstream_interface",
],
)

envoy_cc_library(
name = "dynamic_metadata_interface",
hdrs = ["dynamic_metadata.h"],
external_deps = ["abseil_optional"],
)
70 changes: 70 additions & 0 deletions include/envoy/request_info/dynamic_metadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#pragma once

#include <memory>

#include "envoy/common/exception.h"
#include "envoy/common/pure.h"

#include "common/common/fmt.h"

#include "absl/strings/string_view.h"

namespace Envoy {
namespace RequestInfo {

class DynamicMetadata {
public:
class Object {
public:
virtual ~Object(){};
};

virtual ~DynamicMetadata(){};

/**
* @param data_name the name of the data being set.
* @param data an owning pointer to the data to be stored.
* Note that it is an error to call setData() twice with the same data_name; this is to
* enforce a single authoritative source for each piece of data stored in DynamicMetadata.
*/
virtual void setData(absl::string_view data_name, std::unique_ptr<Object>&& data) PURE;

/**
* @param data_name the name of the data being set.
* @return a reference to the stored data.
* Note that it is an error to access data that has not previously been set.
* This function will fail if the data stored under |data_name| cannot be
* dynamically cast to the type specified.
*/
template <typename T> const T& getData(absl::string_view data_name) const {
const T* result = dynamic_cast<const T*>(getDataGeneric(data_name));
if (!result) {
throw EnvoyException(
fmt::format("Data stored under {} cannot be coerced to specified type", data_name));
}
return *result;
}

/**
* @param data_name the name of the data being probed.
* @return Whether data of the type and name specified exists in the
* data store.
*/
template <typename T> bool hasData(absl::string_view data_name) const {
return (hasDataWithName(data_name) &&
(dynamic_cast<const T*>(getDataGeneric(data_name)) != nullptr));
}

/**
* @param data_name the name of the data being probed.
* @return Whether data of any type and the name specified exists in the
* data store.
*/
virtual bool hasDataWithName(absl::string_view data_name) const PURE;

protected:
virtual const Object* getDataGeneric(absl::string_view data_name) const PURE;
};

} // namespace RequestInfo
} // namespace Envoy
1 change: 1 addition & 0 deletions include/envoy/request_info/request_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "envoy/common/pure.h"
#include "envoy/common/time.h"
#include "envoy/http/protocol.h"
#include "envoy/request_info/dynamic_metadata.h"
#include "envoy/upstream/upstream.h"

#include "absl/types/optional.h"
Expand Down
9 changes: 9 additions & 0 deletions source/common/request_info/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "dynamic_metadata_lib",
srcs = ["dynamic_metadata_impl.cc"],
hdrs = ["dynamic_metadata_impl.h"],
deps = [
"//include/envoy/request_info:dynamic_metadata_interface",
],
)

envoy_cc_library(
name = "utility_lib",
srcs = ["utility.cc"],
Expand Down
32 changes: 32 additions & 0 deletions source/common/request_info/dynamic_metadata_impl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "common/request_info/dynamic_metadata_impl.h"

#include "envoy/common/exception.h"

namespace Envoy {
namespace RequestInfo {

void DynamicMetadataImpl::setData(absl::string_view data_name, std::unique_ptr<Object>&& data) {
if (data_storage_.find(data_name) != data_storage_.end()) {
throw EnvoyException("DynamicMetadata::setData<T> called twice with same name.");
}
// absl::string_view will not convert to std::string without an explicit case; see
// https://github.com/abseil/abseil-cpp/blob/master/absl/strings/string_view.h#L328
data_storage_[static_cast<std::string>(data_name)] = std::move(data);
}

bool DynamicMetadataImpl::hasDataWithName(absl::string_view data_name) const {
return data_storage_.count(data_name) > 0;
}

const DynamicMetadata::Object*
DynamicMetadataImpl::getDataGeneric(absl::string_view data_name) const {
const auto& it = data_storage_.find(data_name);

if (it == data_storage_.end()) {
throw EnvoyException("DynamicMetadata::getData<T> called for unknown data name.");
}
return it->second.get();
}

} // namespace RequestInfo
} // namespace Envoy
27 changes: 27 additions & 0 deletions source/common/request_info/dynamic_metadata_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <map>

#include "envoy/request_info/dynamic_metadata.h"

#include "absl/strings/string_view.h"

namespace Envoy {
namespace RequestInfo {

class DynamicMetadataImpl : public DynamicMetadata {
public:
// DynamicMetadata
void setData(absl::string_view data_name, std::unique_ptr<Object>&& data) override;
bool hasDataWithName(absl::string_view) const override;
const Object* getDataGeneric(absl::string_view data_name) const override;

private:
// The explicit non-type-specific comparator is necessary to allow use of find() method
// with absl::string_view. See
// https://stackoverflow.com/questions/20317413/what-are-transparent-comparators.
std::map<std::string, std::unique_ptr<Object>, std::less<>> data_storage_;
};

} // namespace RequestInfo
} // namespace Envoy
14 changes: 12 additions & 2 deletions source/extensions/tracers/lightstep/lightstep_tracer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ void LightStepLogger::operator()(lightstep::LogLevel level,
LightStepDriver::LightStepTransporter::LightStepTransporter(LightStepDriver& driver)
: driver_(driver) {}

// If the default min_flush_spans value is too small, the larger number of reports can overwhelm
// LightStep's satellites. Hence, we need to choose a number that's large enough; though, it's
// somewhat arbitrary.
//
// See https://github.com/lightstep/lightstep-tracer-cpp/issues/106
const size_t LightStepDriver::DefaultMinFlushSpans = 200U;

LightStepDriver::LightStepTransporter::~LightStepTransporter() {
if (active_request_ != nullptr) {
active_request_->cancel();
Expand Down Expand Up @@ -150,8 +157,11 @@ LightStepDriver::LightStepDriver(const Json::Object& config,
tls_options.use_thread = false;
tls_options.use_single_key_propagation = true;
tls_options.logger_sink = LightStepLogger{};
tls_options.max_buffered_spans = std::function<size_t()>{
[this] { return runtime_.snapshot().getInteger("tracing.lightstep.min_flush_spans", 5U); }};

tls_options.max_buffered_spans = std::function<size_t()>{[this] {
return runtime_.snapshot().getInteger("tracing.lightstep.min_flush_spans",
DefaultMinFlushSpans);
}};
tls_options.metrics_observer.reset(new LightStepMetricsObserver{*this});
tls_options.transporter.reset(new LightStepTransporter{*this});
std::shared_ptr<lightstep::LightStepTracer> tracer =
Expand Down
2 changes: 2 additions & 0 deletions source/extensions/tracers/lightstep/lightstep_tracer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class LightStepDriver : public Common::Ot::OpenTracingDriver {
Runtime::Loader& runtime() { return runtime_; }
LightstepTracerStats& tracerStats() { return tracer_stats_; }

static const size_t DefaultMinFlushSpans;

// Tracer::OpenTracingDriver
opentracing::Tracer& tracer() override;
PropagationMode propagationMode() const override { return propagation_mode_; }
Expand Down
21 changes: 21 additions & 0 deletions test/common/http/http2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,33 @@ licenses(["notice"]) # Apache 2

load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_fuzz_test",
"envoy_cc_test",
"envoy_package",
"envoy_proto_library",
)

envoy_package()

envoy_proto_library(
name = "codec_impl_fuzz_proto",
srcs = ["codec_impl_fuzz.proto"],
external_deps = ["well_known_protos"],
)

envoy_cc_fuzz_test(
name = "codec_impl_fuzz_test",
srcs = ["codec_impl_fuzz_test.cc"],
corpus = "codec_impl_corpus",
deps = [
":codec_impl_fuzz_proto",
"//source/common/http:header_map_lib",
"//source/common/http/http2:codec_lib",
"//test/mocks/http:http_mocks",
"//test/mocks/network:network_mocks",
],
)

envoy_cc_test(
name = "codec_impl_test",
srcs = ["codec_impl_test.cc"],
Expand Down
56 changes: 56 additions & 0 deletions test/common/http/http2/codec_impl_corpus/100-continue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
actions {
new_stream {
request_headers {
headers {
key: ":method"
value: "GET"
}
headers {
key: ":path"
value: "/"
}
headers {
key: ":scheme"
value: "http"
}
headers {
key: ":authority"
value: "foo.com"
}
headers {
key: "expect"
value: "100-continue"
}
}
}
}
actions { quiesce_drain {} }
actions {
stream_action {
stream_id: 0
response {
continue_100_headers {
headers {
key: ":status"
value: "100"
}
}
}
}
}
actions { quiesce_drain {} }
actions {
stream_action {
stream_id: 0
response {
headers {
headers {
key: ":status"
value: "404"
}
}
end_stream: true
}
}
}
actions { quiesce_drain {} }
Empty file.
Loading

0 comments on commit 6ec7ebf

Please sign in to comment.