Skip to content

Commit

Permalink
Merge branch 'master' into ext_authz_metadata_context
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Plotnick <plotnick@yelp.com>
  • Loading branch information
Ben Plotnick committed Aug 12, 2019
2 parents 9c3792b + c3a7531 commit af0c545
Show file tree
Hide file tree
Showing 22 changed files with 427 additions and 87 deletions.
2 changes: 2 additions & 0 deletions api/envoy/config/bootstrap/v2/bootstrap.proto
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ message RuntimeLayer {
// This follows the :ref:`runtime protobuf JSON representation encoding
// <config_runtime_proto_json>`. Unlike static xDS resources, this static
// layer is overridable by later layers in the runtime virtual filesystem.
option (validate.required) = true;

google.protobuf.Struct static_layer = 2;
DiskLayer disk_layer = 3;
AdminLayer admin_layer = 4;
Expand Down
3 changes: 3 additions & 0 deletions api/envoy/config/trace/v2/trace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ message OpenCensusConfig {

// "X-Cloud-Trace-Context:" header.
CLOUD_TRACE_CONTEXT = 3;

// X-B3-* headers.
B3 = 4;
}

// List of incoming trace context headers we will accept. First one found
Expand Down
4 changes: 4 additions & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ def _io_opencensus_cpp():
name = "opencensus_trace",
actual = "@io_opencensus_cpp//opencensus/trace",
)
native.bind(
name = "opencensus_trace_b3",
actual = "@io_opencensus_cpp//opencensus/trace:b3",
)
native.bind(
name = "opencensus_trace_cloud_trace_context",
actual = "@io_opencensus_cpp//opencensus/trace:cloud_trace_context",
Expand Down
2 changes: 1 addition & 1 deletion ci/build_setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ echo "ENVOY_BAZEL_ROOT: $env:ENVOY_BAZEL_ROOT"
echo "ENVOY_SRCDIR: $env:ENVOY_SRCDIR"

$env:BAZEL_BASE_OPTIONS="--noworkspace_rc --output_base=$env:ENVOY_BAZEL_ROOT --bazelrc=$env:ENVOY_SRCDIR\windows\tools\bazel.rc"
$env:BAZEL_BUILD_OPTIONS="--strategy=Genrule=standalone --spawn_strategy=standalone --verbose_failures --jobs=$env:NUM_CPUS --show_task_finish --cache_test_results=no --test_output=all $env:BAZEL_BUILD_EXTRA_OPTIONS $env:BAZEL_EXTRA_TEST_OPTIONS"
$env:BAZEL_BUILD_OPTIONS="--features=compiler_param_file --strategy=Genrule=standalone --spawn_strategy=standalone --verbose_failures --jobs=$env:NUM_CPUS --show_task_finish --cache_test_results=no --test_output=all $env:BAZEL_BUILD_EXTRA_OPTIONS $env:BAZEL_EXTRA_TEST_OPTIONS"
12 changes: 8 additions & 4 deletions docs/root/configuration/runtime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ be:
.. code-block:: yaml
layers:
- static_layer:
- name: static_layer_0
static_layer:
health_check:
min_interval: 5
- disk_layer: { symlink_root: /srv/runtime/current, subdirectory: envoy }
- disk_layer: { symlink_root: /srv/runtime/current, subdirectory: envoy_override, append_service_cluster: true }
- admin_layer: {}
- name: disk_layer_0
disk_layer: { symlink_root: /srv/runtime/current, subdirectory: envoy }
- name: disk_layer_1
disk_layer: { symlink_root: /srv/runtime/current, subdirectory: envoy_override, append_service_cluster: true }
- name: admin_layer_0
admin_layer: {}
In the deprecated :ref:`runtime <envoy_api_msg_config.bootstrap.v2.Runtime>` bootstrap
configuration, the layering was implicit and fixed:
Expand Down
9 changes: 5 additions & 4 deletions source/common/http/http1/codec_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -326,12 +326,13 @@ const ToLowerTable& ConnectionImpl::toLowerTable() {
}

ConnectionImpl::ConnectionImpl(Network::Connection& connection, Stats::Scope& stats,
http_parser_type type, uint32_t max_headers_kb)
http_parser_type type, uint32_t max_request_headers_kb)
: connection_(connection), stats_{ALL_HTTP1_CODEC_STATS(POOL_COUNTER_PREFIX(stats, "http1."))},
output_buffer_([&]() -> void { this->onBelowLowWatermark(); },
[&]() -> void { this->onAboveHighWatermark(); }),
max_headers_kb_(max_headers_kb), strict_header_validation_(Runtime::runtimeFeatureEnabled(
"envoy.reloadable_features.strict_header_validation")) {
max_request_headers_kb_(max_request_headers_kb),
strict_header_validation_(
Runtime::runtimeFeatureEnabled("envoy.reloadable_features.strict_header_validation")) {
output_buffer_.setWatermarks(connection.bufferLimit());
http_parser_init(&parser_, type);
parser_.data = this;
Expand Down Expand Up @@ -452,7 +453,7 @@ void ConnectionImpl::onHeaderValue(const char* data, size_t length) {

const uint32_t total =
current_header_field_.size() + current_header_value_.size() + current_header_map_->byteSize();
if (total > (max_headers_kb_ * 1024)) {
if (total > (max_request_headers_kb_ * 1024)) {
error_code_ = Http::Code::RequestHeaderFieldsTooLarge;
sendProtocolError();
throw CodecProtocolException("headers size exceeds limit");
Expand Down
2 changes: 1 addition & 1 deletion source/common/http/http1/codec_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class ConnectionImpl : public virtual Connection, protected Logger::Loggable<Log
Buffer::RawSlice reserved_iovec_;
char* reserved_current_{};
Protocol protocol_{Protocol::Http11};
const uint32_t max_headers_kb_;
const uint32_t max_request_headers_kb_;

bool strict_header_validation_;
};
Expand Down
1 change: 1 addition & 0 deletions source/common/singleton/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ envoy_cc_library(
name = "threadsafe_singleton",
hdrs = ["threadsafe_singleton.h"],
external_deps = ["abseil_base"],
deps = ["//source/common/common:assert_lib"],
)
2 changes: 2 additions & 0 deletions source/common/singleton/threadsafe_singleton.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <memory>

#include "common/common/assert.h"

#include "absl/base/call_once.h"

namespace Envoy {
Expand Down
4 changes: 2 additions & 2 deletions source/common/stats/symbol_table_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ class StatNameSet {
void rememberBuiltin(absl::string_view str);

/**
* Finds a StatName by name. If 'str' has been remembered as a built-in, then
* Finds a StatName by name. If 'token' has been remembered as a built-in, then
* no lock is required. Otherwise we first consult dynamic_stat_names_ under a
* lock that's private to the StatNameSet. If that's empty, we need to create
* the StatName in the pool, which requires taking a global lock.
Expand All @@ -661,7 +661,7 @@ class StatNameSet {
* set's mutex and also the SymbolTable mutex which must be taken during
* StatNamePool::add().
*/
StatName getStatName(absl::string_view str);
StatName getStatName(absl::string_view token);

/**
* Adds a StatName using the pool, but without remembering it in any maps.
Expand Down
4 changes: 2 additions & 2 deletions source/extensions/filters/network/kafka/protocol/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def is_nullable(self):

def is_nullable_in_version(self, version):
"""
Whether thie field is nullable in given version.
Whether the field is nullable in given version.
Fields can be non-nullable in earlier versions.
See https://github.com/apache/kafka/tree/2.2.0-rc0/clients/src/main/resources/common/message#nullable-fields
"""
Expand Down Expand Up @@ -435,7 +435,7 @@ def __init__(self, name, fields, versions):

def __compute_declaration_chain(self):
"""
Computes all dependendencies, what means all non-primitive types used by this type.
Computes all dependencies, what means all non-primitive types used by this type.
They need to be declared before this struct is declared.
"""
result = []
Expand Down
1 change: 1 addition & 0 deletions source/extensions/tracers/opencensus/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ envoy_cc_library(
copts = ["-Wno-unused-parameter"],
external_deps = [
"opencensus_trace",
"opencensus_trace_b3",
"opencensus_trace_cloud_trace_context",
"opencensus_trace_grpc_trace_bin",
"opencensus_trace_trace_context",
Expand Down
55 changes: 50 additions & 5 deletions source/extensions/tracers/opencensus/opencensus_tracer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "opencensus/exporters/trace/stackdriver/stackdriver_exporter.h"
#include "opencensus/exporters/trace/stdout/stdout_exporter.h"
#include "opencensus/exporters/trace/zipkin/zipkin_exporter.h"
#include "opencensus/trace/propagation/b3.h"
#include "opencensus/trace/propagation/cloud_trace_context.h"
#include "opencensus/trace/propagation/grpc_trace_bin.h"
#include "opencensus/trace/propagation/trace_context.h"
Expand All @@ -32,6 +33,10 @@ class ConstantValues {
const Http::LowerCaseString TRACEPARENT{"traceparent"};
const Http::LowerCaseString GRPC_TRACE_BIN{"grpc-trace-bin"};
const Http::LowerCaseString X_CLOUD_TRACE_CONTEXT{"x-cloud-trace-context"};
const Http::LowerCaseString X_B3_TRACEID{"x-b3-traceid"};
const Http::LowerCaseString X_B3_SPANID{"x-b3-spanid"};
const Http::LowerCaseString X_B3_SAMPLED{"x-b3-sampled"};
const Http::LowerCaseString X_B3_FLAGS{"x-b3-flags"};
};

using Constants = ConstSingleton<ConstantValues>;
Expand Down Expand Up @@ -101,6 +106,35 @@ startSpanHelper(const std::string& name, bool traced, const Http::HeaderMap& req
}
break;
}

case OpenCensusConfig::B3: {
absl::string_view b3_trace_id;
absl::string_view b3_span_id;
absl::string_view b3_sampled;
absl::string_view b3_flags;
const Http::HeaderEntry* h_b3_trace_id = request_headers.get(Constants::get().X_B3_TRACEID);
if (h_b3_trace_id != nullptr) {
b3_trace_id = h_b3_trace_id->value().getStringView();
}
const Http::HeaderEntry* h_b3_span_id = request_headers.get(Constants::get().X_B3_SPANID);
if (h_b3_span_id != nullptr) {
b3_span_id = h_b3_span_id->value().getStringView();
}
const Http::HeaderEntry* h_b3_sampled = request_headers.get(Constants::get().X_B3_SAMPLED);
if (h_b3_sampled != nullptr) {
b3_sampled = h_b3_sampled->value().getStringView();
}
const Http::HeaderEntry* h_b3_flags = request_headers.get(Constants::get().X_B3_FLAGS);
if (h_b3_flags != nullptr) {
b3_flags = h_b3_flags->value().getStringView();
}
if (h_b3_trace_id != nullptr && h_b3_span_id != nullptr) {
found = true;
parent_ctx = ::opencensus::trace::propagation::FromB3Headers(b3_trace_id, b3_span_id,
b3_sampled, b3_flags);
}
break;
}
}
// First header found wins.
if (found) {
Expand Down Expand Up @@ -153,16 +187,16 @@ void Span::finishSpan() { span_.End(); }

void Span::injectContext(Http::HeaderMap& request_headers) {
using OpenCensusConfig = envoy::config::trace::v2::OpenCensusConfig;
const auto& ctx = span_.context();
for (const auto& outgoing : oc_config_.outgoing_trace_context()) {
switch (outgoing) {
case OpenCensusConfig::TRACE_CONTEXT:
request_headers.setReferenceKey(
Constants::get().TRACEPARENT,
::opencensus::trace::propagation::ToTraceParentHeader(span_.context()));
request_headers.setReferenceKey(Constants::get().TRACEPARENT,
::opencensus::trace::propagation::ToTraceParentHeader(ctx));
break;

case OpenCensusConfig::GRPC_TRACE_BIN: {
std::string val = ::opencensus::trace::propagation::ToGrpcTraceBinHeader(span_.context());
std::string val = ::opencensus::trace::propagation::ToGrpcTraceBinHeader(ctx);
val = Base64::encode(val.data(), val.size(), /*add_padding=*/false);
request_headers.setReferenceKey(Constants::get().GRPC_TRACE_BIN, val);
break;
Expand All @@ -171,7 +205,18 @@ void Span::injectContext(Http::HeaderMap& request_headers) {
case OpenCensusConfig::CLOUD_TRACE_CONTEXT:
request_headers.setReferenceKey(
Constants::get().X_CLOUD_TRACE_CONTEXT,
::opencensus::trace::propagation::ToCloudTraceContextHeader(span_.context()));
::opencensus::trace::propagation::ToCloudTraceContextHeader(ctx));
break;

case OpenCensusConfig::B3:
request_headers.setReferenceKey(Constants::get().X_B3_TRACEID,
::opencensus::trace::propagation::ToB3TraceIdHeader(ctx));
request_headers.setReferenceKey(Constants::get().X_B3_SPANID,
::opencensus::trace::propagation::ToB3SpanIdHeader(ctx));
request_headers.setReferenceKey(Constants::get().X_B3_SAMPLED,
::opencensus::trace::propagation::ToB3SampledHeader(ctx));
// OpenCensus's trace context propagation doesn't produce the
// "X-B3-Flags:" header.
break;
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/common/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ envoy_cc_fuzz_test(
deps = ["//source/common/common:utility_lib"],
)

envoy_cc_fuzz_test(
name = "hash_fuzz_test",
srcs = ["hash_fuzz_test.cc"],
corpus = "hash_corpus",
deps = ["//source/common/common:hash_lib"],
)

envoy_cc_test(
name = "cleanup_test",
srcs = ["cleanup_test.cc"],
Expand Down
1 change: 1 addition & 0 deletions test/common/common/hash_corpus/example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello world
29 changes: 29 additions & 0 deletions test/common/common/hash_fuzz_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "common/common/hash.h"

#include "test/fuzz/fuzz_runner.h"

#include "absl/strings/string_view.h"

namespace Envoy {
namespace Fuzz {
namespace {

DEFINE_FUZZER(const uint8_t* buf, size_t len) {
const std::string input(reinterpret_cast<const char*>(buf), len);
{ HashUtil::xxHash64(input); }
{ HashUtil::djb2CaseInsensitiveHash(input); }
{ MurmurHash::murmurHash2_64(input); }
if (len > 0) {
// Split the input string into two parts to make a key-value pair.
const size_t split_point = *reinterpret_cast<const uint8_t*>(buf) % len;
const std::string key = input.substr(0, split_point);
const std::string value = input.substr(split_point);
StringMap<std::string> map;
map[key] = value;
map.find(key);
}
}

} // namespace
} // namespace Fuzz
} // namespace Envoy
1 change: 1 addition & 0 deletions test/extensions/tracers/opencensus/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ TEST(OpenCensusTracerConfigTest, OpenCensusHttpTracerWithTypedConfig) {
stackdriver_project_id: test_project_id
zipkin_exporter_enabled: true
zipkin_url: http://127.0.0.1:9411/api/v2/spans
incoming_trace_context: b3
incoming_trace_context: trace_context
incoming_trace_context: grpc_trace_bin
incoming_trace_context: cloud_trace_context
Expand Down
Loading

0 comments on commit af0c545

Please sign in to comment.