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

fix compiler warnings #1044

Merged
merged 11 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static const struct

inline const char *attr(uint32_t attr)
{
for (int i = 0; i < OTEL_CPP_TRACE_ATTRIBUTES_MAX; i++)
for (size_t i = 0; i < OTEL_CPP_TRACE_ATTRIBUTES_MAX; i++)
{
if (attribute_ids[i].attribute_id == attr)
return attribute_ids[i].attribute_key;
Expand Down
18 changes: 10 additions & 8 deletions exporters/otlp/test/otlp_grpc_exporter_test.cc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@

# if defined(_MSC_VER)
# define putenv _putenv
int setenv(const char *name, const char *value, int)
{
return _putenv_s(name, value);
}
# endif

using namespace testing;
Expand Down Expand Up @@ -139,16 +143,14 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigSslCredentialsTest)
TEST_F(OtlpGrpcExporterTestPeer, ConfigFromEnv)
{
const std::string cacert_str = "--begin and end fake cert--";
const std::string cacert_env = "OTEL_EXPORTER_OTLP_CERTIFICATE_STRING=" + cacert_str;
putenv(const_cast<char *>(cacert_env.data()));
setenv("OTEL_EXPORTER_OTLP_CERTIFICATE_STRING", cacert_str.c_str(), 1);
char ssl_enable_env[] = "OTEL_EXPORTER_OTLP_SSL_ENABLE=True";
putenv(ssl_enable_env);
const std::string endpoint = "http://localhost:9999";
const std::string endpoint_env = "OTEL_EXPORTER_OTLP_ENDPOINT=" + endpoint;
putenv(const_cast<char *>(endpoint_env.data()));
putenv("OTEL_EXPORTER_OTLP_TIMEOUT=20050ms");
putenv("OTEL_EXPORTER_OTLP_HEADERS=k1=v1,k2=v2");
putenv("OTEL_EXPORTER_OTLP_TRACES_HEADERS=k1=v3,k1=v4");
const std::string endpoint = "http://localhost:9999";
setenv("OTEL_EXPORTER_OTLP_ENDPOINT", endpoint.c_str(), 1);
setenv("OTEL_EXPORTER_OTLP_TIMEOUT", "20050ms", 1);
setenv("OTEL_EXPORTER_OTLP_HEADERS", "k1=v1,k2=v2", 1);
setenv("OTEL_EXPORTER_OTLP_TRACES_HEADERS", "k1=v3,k1=v4", 1);

std::unique_ptr<OtlpGrpcExporter> exporter(new OtlpGrpcExporter());
EXPECT_EQ(GetOptions(exporter).ssl_credentials_cacert_as_string, cacert_str);
Expand Down
20 changes: 12 additions & 8 deletions exporters/otlp/test/otlp_http_exporter_test.cc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

# if defined(_MSC_VER)
# define putenv _putenv
lalitb marked this conversation as resolved.
Show resolved Hide resolved
int setenv(const char *name, const char *value, int)
{
return _putenv_s(name, value);
}
# endif

using namespace testing;
Expand Down Expand Up @@ -348,10 +352,10 @@ TEST_F(OtlpHttpExporterTestPeer, ConfigJsonBytesMappingTest)
TEST_F(OtlpHttpExporterTestPeer, ConfigFromEnv)
{
const std::string url = "http://localhost:9999/v1/traces";
putenv("OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:9999");
putenv("OTEL_EXPORTER_OTLP_TIMEOUT=20s");
putenv("OTEL_EXPORTER_OTLP_HEADERS=k1=v1,k2=v2");
putenv("OTEL_EXPORTER_OTLP_TRACES_HEADERS=k1=v3,k1=v4");
setenv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:9999", 1);
setenv("OTEL_EXPORTER_OTLP_TIMEOUT", "20s", 1);
setenv("OTEL_EXPORTER_OTLP_HEADERS", "k1=v1,k2=v2", 1);
setenv("OTEL_EXPORTER_OTLP_TRACES_HEADERS", "k1=v3,k1=v4", 1);

std::unique_ptr<OtlpHttpExporter> exporter(new OtlpHttpExporter());
EXPECT_EQ(GetOptions(exporter).url, url);
Expand Down Expand Up @@ -396,10 +400,10 @@ TEST_F(OtlpHttpExporterTestPeer, ConfigFromEnv)
TEST_F(OtlpHttpExporterTestPeer, ConfigFromTracesEnv)
{
const std::string url = "http://localhost:9999/v1/traces";
putenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:9999/v1/traces");
putenv("OTEL_EXPORTER_OTLP_TIMEOUT=20s");
putenv("OTEL_EXPORTER_OTLP_HEADERS=k1=v1,k2=v2");
putenv("OTEL_EXPORTER_OTLP_TRACES_HEADERS=k1=v3,k1=v4");
setenv("OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", url.c_str(), 1);
setenv("OTEL_EXPORTER_OTLP_TIMEOUT", "20s", 1);
setenv("OTEL_EXPORTER_OTLP_HEADERS", "k1=v1,k2=v2", 1);
setenv("OTEL_EXPORTER_OTLP_TRACES_HEADERS", "k1=v3,k1=v4", 1);

std::unique_ptr<OtlpHttpExporter> exporter(new OtlpHttpExporter());
EXPECT_EQ(GetOptions(exporter).url, url);
Expand Down
20 changes: 12 additions & 8 deletions exporters/otlp/test/otlp_http_log_exporter_test.cc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

# if defined(_MSC_VER)
# define putenv _putenv
int setenv(const char *name, const char *value, int)
{
return _putenv_s(name, value);
}
# endif

using namespace testing;
Expand Down Expand Up @@ -390,10 +394,10 @@ TEST_F(OtlpHttpLogExporterTestPeer, ConfigJsonBytesMappingTest)
TEST_F(OtlpHttpLogExporterTestPeer, ConfigFromEnv)
{
const std::string url = "http://localhost:9999/v1/logs";
putenv("OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:9999");
putenv("OTEL_EXPORTER_OTLP_TIMEOUT=20s");
putenv("OTEL_EXPORTER_OTLP_HEADERS=k1=v1,k2=v2");
putenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS=k1=v3,k1=v4");
setenv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:9999", 1);
setenv("OTEL_EXPORTER_OTLP_TIMEOUT", "20s", 1);
setenv("OTEL_EXPORTER_OTLP_HEADERS", "k1=v1,k2=v2", 1);
setenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS", "k1=v3,k1=v4", 1);

std::unique_ptr<OtlpHttpLogExporter> exporter(new OtlpHttpLogExporter());
EXPECT_EQ(GetOptions(exporter).url, url);
Expand Down Expand Up @@ -438,10 +442,10 @@ TEST_F(OtlpHttpLogExporterTestPeer, ConfigFromEnv)
TEST_F(OtlpHttpLogExporterTestPeer, ConfigFromLogsEnv)
{
const std::string url = "http://localhost:9999/v1/logs";
putenv("OTEL_EXPORTER_OTLP_LOGS_ENDPOINT=http://localhost:9999/v1/logs");
putenv("OTEL_EXPORTER_OTLP_TIMEOUT=20s");
putenv("OTEL_EXPORTER_OTLP_HEADERS=k1=v1,k2=v2");
putenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS=k1=v3,k1=v4");
setenv("OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", url.c_str(), 1);
setenv("OTEL_EXPORTER_OTLP_TIMEOUT", "20s", 1);
setenv("OTEL_EXPORTER_OTLP_HEADERS", "k1=v1,k2=v2", 1);
setenv("OTEL_EXPORTER_OTLP_LOGS_HEADERS", "k1=v3,k1=v4", 1);

std::unique_ptr<OtlpHttpLogExporter> exporter(new OtlpHttpLogExporter());
EXPECT_EQ(GetOptions(exporter).url, url);
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/test/otlp_recordable_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ TEST(OtlpRecordable, SetResource)

auto proto_resource = rec.ProtoResource();
bool found_service_name = false;
for (size_t i = 0; i < proto_resource.attributes_size(); i++)
for (int i = 0; i < proto_resource.attributes_size(); i++)
{
auto attr = proto_resource.attributes(static_cast<int>(i));
if (attr.key() == service_name_key && attr.value().string_value() == service_name)
Expand Down
4 changes: 4 additions & 0 deletions sdk/test/resource/resource_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ TEST(ResourceTest, create_without_servicename)
{
EXPECT_TRUE(expected_attributes.find(e.first) != expected_attributes.end());
if (expected_attributes.find(e.first) != expected_attributes.end())
{
if (e.first == "version")
EXPECT_EQ(opentelemetry::nostd::get<uint32_t>(expected_attributes.find(e.first)->second),
opentelemetry::nostd::get<uint32_t>(e.second));
Expand All @@ -54,6 +55,7 @@ TEST(ResourceTest, create_without_servicename)
else
EXPECT_EQ(opentelemetry::nostd::get<std::string>(expected_attributes.find(e.first)->second),
opentelemetry::nostd::get<std::string>(e.second));
}
lalitb marked this conversation as resolved.
Show resolved Hide resolved
}
EXPECT_EQ(received_attributes.size(), expected_attributes.size()); // for missing service.name
}
Expand Down Expand Up @@ -106,8 +108,10 @@ TEST(ResourceTest, create_with_emptyatrributes)
{
EXPECT_TRUE(expected_attributes.find(e.first) != expected_attributes.end());
if (expected_attributes.find(e.first) != expected_attributes.end())
{
EXPECT_EQ(opentelemetry::nostd::get<std::string>(expected_attributes.find(e.first)->second),
opentelemetry::nostd::get<std::string>(e.second));
}
}
EXPECT_EQ(received_attributes.size(), expected_attributes.size()); // for missing service.name
}
Expand Down