Skip to content

Commit

Permalink
Fixes to satisfy envoy CI (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgilmour authored Jul 26, 2019
1 parent 8cf643b commit 11311ab
Show file tree
Hide file tree
Showing 8 changed files with 9,517 additions and 5,958 deletions.
15,372 changes: 9,457 additions & 5,915 deletions 3rd_party/include/nlohmann/json.hpp

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
workspace(name = "com_github_datadog_dd_opentracing_cpp")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

git_repository(
http_archive(
name = "io_opentracing_cpp",
remote = "https://github.com/opentracing/opentracing-cpp",
commit = "ac50154a7713877f877981c33c3375003b6ebfe1",
sha256 = "015c4187f7a6426a2b5196f0ccd982aa87f010cf61f507ae3ce5c90523f92301",
strip_prefix = "opentracing-cpp-1.5.1",
urls = ["https://github.com/opentracing/opentracing-cpp/archive/v1.5.1.tar.gz"],
)

new_http_archive(
http_archive(
name = "com_github_msgpack_msgpack_c",
sha256 = "9859d44d336f9b023a79a3026bb6a558b2ea346107ab4eadba58236048650690",
strip_prefix = "msgpack-3.0.1",
urls = [
"https://github.com/msgpack/msgpack-c/releases/download/cpp-3.0.1/msgpack-3.0.1.tar.gz",
],
build_file = "bazel/external/msgpack.BUILD"
build_file = "@//:bazel/external/msgpack.BUILD"
)
2 changes: 1 addition & 1 deletion include/datadog/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace datadog {
namespace version {

const std::string tracer_version = "v1.0.0";
const std::string tracer_version = "v1.0.1";
const std::string cpp_version = std::to_string(__cplusplus);

} // namespace version
Expand Down
2 changes: 1 addition & 1 deletion scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
set -e

OPENTRACING_VERSION=${OPENTRACING_VERSION:-1.5.0}
OPENTRACING_VERSION=${OPENTRACING_VERSION:-1.5.1}
CURL_VERSION=${CURL_VERSION:-7.64.0}
MSGPACK_VERSION=${MSGPACK_VERSION:-3.1.1}
ZLIB_VERSION=${ZLIB_VERSION:-1.2.11}
Expand Down
5 changes: 3 additions & 2 deletions src/propagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <algorithm>
#include <iostream>
#include <nlohmann/json.hpp>
#include <sstream>
#include <utility>
#include "sample.h"
#include "span_buffer.h"
Expand Down Expand Up @@ -366,10 +367,10 @@ ot::expected<std::unique_ptr<ot::SpanContext>> SpanContext::deserialize(std::ist
}
}
if (j.find(json_origin_key) != j.end()) {
origin = j[json_origin_key];
j.at(json_origin_key).get_to(origin);
}
if (j.find(json_baggage_key) != j.end()) {
baggage = j[json_baggage_key].get<std::unordered_map<std::string, std::string>>();
j.at(json_baggage_key).get_to(baggage);
}

auto context = std::make_unique<SpanContext>(parent_id, trace_id, origin, std::move(baggage));
Expand Down
22 changes: 12 additions & 10 deletions src/tracer_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,32 @@ ot::expected<TracerOptions> optionsFromConfig(const char *configuration,
error_message = "configuration argument 'service' is missing";
return ot::make_unexpected(std::make_error_code(std::errc::invalid_argument));
}
options.service = config["service"];
config.at("service").get_to(options.service);
// Optional.
if (config.find("agent_host") != config.end()) {
options.agent_host = config["agent_host"];
config.at("agent_host").get_to(options.agent_host);
}
if (config.find("agent_port") != config.end()) {
options.agent_port = config["agent_port"];
config.at("agent_port").get_to(options.agent_port);
}
if (config.find("type") != config.end()) {
options.type = config["type"];
config.at("type").get_to(options.type);
}
if (config.find("environment") != config.end()) {
options.environment = config["environment"];
config.at("environment").get_to(options.environment);
}
if (config.find("sample_rate") != config.end()) {
options.sample_rate = config["sample_rate"];
config.at("sample_rate").get_to(options.sample_rate);
}
if (config.find("dd.priority.sampling") != config.end()) {
options.priority_sampling = config["dd.priority.sampling"];
config.at("dd.priority.sampling").get_to(options.priority_sampling);
}
if (config.find("operation_name_override") != config.end()) {
options.operation_name_override = config["operation_name_override"];
config.at("operation_name_override").get_to(options.operation_name_override);
}
if (config.find("propagation_style_extract") != config.end()) {
auto styles = asPropagationStyle(config["propagation_style_extract"]);
auto styles = asPropagationStyle(
config.at("propagation_style_extract").get<std::vector<std::string>>());
if (!styles || styles.value().size() == 0) {
error_message =
"Invalid value for propagation_style_extract, must be a list of at least one element "
Expand All @@ -61,7 +62,8 @@ ot::expected<TracerOptions> optionsFromConfig(const char *configuration,
options.extract = styles.value();
}
if (config.find("propagation_style_inject") != config.end()) {
auto styles = asPropagationStyle(config["propagation_style_inject"]);
auto styles = asPropagationStyle(
config.at("propagation_style_inject").get<std::vector<std::string>>());
if (!styles || styles.value().size() == 0) {
error_message =
"Invalid value for propagation_style_inject, must be a list of at least one element "
Expand Down
25 changes: 13 additions & 12 deletions test/agent_writer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,28 @@ TEST_CASE("writer") {

auto bad_response_test_case = GENERATE(values<BadResponseTest>(
{{"// Error at start, short body",
("Unable to parse response from agent.\n"
"Error was: [json.exception.parse_error.101] parse error at 1: syntax error - "
"invalid literal; last read: '/'\n"
"Error near: // Error at start, short body\n")},
"Unable to parse response from agent.\n"
"Error was: [json.exception.parse_error.101] parse error at line 1, column 1: "
"syntax error while parsing value - invalid literal; last read: '/'\n"
"Error near: // Error at start, short body\n"},
{"{\"lol\" // Error near start, error message should have truncated "
"body. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9",
"Unable to parse response from agent.\n"
"Error was: [json.exception.parse_error.101] parse error at 8: syntax error - invalid "
"literal; last read: '\"lol\" /'; expected ':'\n"
"Error was: [json.exception.parse_error.101] parse error at line 1, column 8: syntax "
"error while parsing object separator - invalid literal; last read: '\"lol\" /'; "
"expected ':'\n"
"Error near: {\"lol\" // Error near start, error message should h...\n"},
{"{\"Error near the end, should be truncated. 0 1 2 3 4 5 6 7 8 9 \", oh noes",
"Unable to parse response from agent.\n"
"Error was: [json.exception.parse_error.101] parse error at 65: syntax error - "
"unexpected ','; expected ':'\n"
"Error was: [json.exception.parse_error.101] parse error at line 1, column 65: syntax "
"error while parsing object separator - unexpected ','; expected ':'\n"
"Error near: ...d. 0 1 2 3 4 5 6 7 8 9 \", oh noes\n"},
{"{\"Error in the middle, truncated from both ends\" lol 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 "
"6 7 8 9",
"Unable to parse response from agent.\n"
"Error was: [json.exception.parse_error.101] parse error at 50: syntax error - invalid "
"literal; last read: '\"Error in the middle, truncated from both ends\" l'; expected "
"':'\n"
"Error was: [json.exception.parse_error.101] parse error at line 1, column 50: syntax "
"error while parsing object separator - invalid literal; last read: '\"Error in the "
"middle, truncated from both ends\" l'; expected ':'\n"
"Error near: ...uncated from both ends\" lol 0 1 2 3 4 5 6 7 8 9 0 ...\n"}}));

handle->response = bad_response_test_case.response;
Expand All @@ -123,8 +124,8 @@ TEST_CASE("writer") {
std::stringstream error_message;
std::streambuf* stderr = std::cerr.rdbuf(error_message.rdbuf());
writer.flush(std::chrono::seconds(10));
REQUIRE(error_message.str() == bad_response_test_case.error);
std::cerr.rdbuf(stderr); // Restore stderr.
REQUIRE(error_message.str() == bad_response_test_case.error);
REQUIRE(sampler->config == "");
}

Expand Down
35 changes: 23 additions & 12 deletions test/tracer_factory_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,40 +180,51 @@ TEST_CASE("tracer") {
}

SECTION("handles bad propagation style") {
auto bad_value = GENERATE(
values<std::string>({"\"i dunno\"", "[]", "[\"Not a real propagation style!\"]"}));
struct BadValueTest {
std::string value;
std::string error_extract;
std::string error_inject;
};

std::string incorrect_type = "configuration has an argument with an incorrect type";
std::string invalid_value_extract =
"Invalid value for propagation_style_extract, must be a list of at least one element with "
"value 'Datadog', or 'B3'";
std::string invalid_value_inject =
"Invalid value for propagation_style_inject, must be a list of at least one element with "
"value 'Datadog', or 'B3'";

auto bad_value = GENERATE_COPY(values<BadValueTest>(
{{"\"i dunno\"", incorrect_type, incorrect_type},
{"[]", invalid_value_extract, invalid_value_inject},
{"[\"Not a real propagation style!\"]", invalid_value_extract, invalid_value_inject}}));

SECTION("extract") {
std::ostringstream input;
input << R"(
{
"service": "my-service",
"propagation_style_extract": )"
<< bad_value << R"(
<< bad_value.value << R"(
})";
std::string error = "";
auto result = factory.MakeTracer(input.str().c_str(), error);
REQUIRE(error ==
"Invalid value for propagation_style_extract, must be a list of at least one "
"element "
"with value 'Datadog', or 'B3'");
REQUIRE(error == bad_value.error_extract);
REQUIRE(!result);
REQUIRE(result.error() == std::make_error_code(std::errc::invalid_argument));
}

SECTION("hinject") {
SECTION("inject") {
std::ostringstream input;
input << R"(
{
"service": "my-service",
"propagation_style_inject": )"
<< bad_value << R"(
<< bad_value.value << R"(
})";
std::string error = "";
auto result = factory.MakeTracer(input.str().c_str(), error);
REQUIRE(error ==
"Invalid value for propagation_style_inject, must be a list of at least one element "
"with value 'Datadog', or 'B3'");
REQUIRE(error == bad_value.error_inject);
REQUIRE(!result);
REQUIRE(result.error() == std::make_error_code(std::errc::invalid_argument));
}
Expand Down

0 comments on commit 11311ab

Please sign in to comment.