Skip to content

Commit

Permalink
Merge branch 'main' into fix_proto_cache_path
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Nov 24, 2024
2 parents fb99a61 + fcdd526 commit 2440bc8
Show file tree
Hide file tree
Showing 9 changed files with 195 additions and 259 deletions.
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# Enable automatic configs based on platform
common --enable_platform_specific_config

# Make globs that don't match anything fail
common --incompatible_disallow_empty_glob

# Needed by gRPC to build on some platforms.
build --copt -DGRPC_BAZEL_BUILD

Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "github_nlohma
bazel_dep(name = "opentelemetry-proto", version = "1.3.2", repo_name = "com_github_opentelemetry_proto")
bazel_dep(name = "opentracing-cpp", version = "1.6.0", repo_name = "com_github_opentracing")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "prometheus-cpp", version = "1.2.4", repo_name = "com_github_jupp0r_prometheus_cpp")
bazel_dep(name = "prometheus-cpp", version = "1.3.0", repo_name = "com_github_jupp0r_prometheus_cpp")
bazel_dep(name = "protobuf", version = "26.0", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "zlib", version = "1.3.1.bcr.1")
Expand Down
2 changes: 1 addition & 1 deletion cmake/opentelemetry-cpp-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ endif()

if(@WITH_ABSEIL@ OR @WITH_OTLP_GRPC@)
find_package(absl CONFIG)
elseif(OR @WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@)
elseif(@WITH_OTLP_HTTP@ OR @WITH_OTLP_FILE@)
if("@Protobuf_VERSION@" VERSION_GREATER_EQUAL "3.22.0")
find_package(absl CONFIG)
endif()
Expand Down
4 changes: 3 additions & 1 deletion cmake/opentelemetry-proto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ add_custom_command(
${LOGS_PROTO} ${METRICS_PROTO} ${TRACE_SERVICE_PROTO} ${LOGS_SERVICE_PROTO}
${METRICS_SERVICE_PROTO} ${PROFILES_PROTO}
${PROFILES_SERVICE_PROTO}
COMMENT "[Run]: ${PROTOBUF_RUN_PROTOC_COMMAND}")
COMMENT "[Run]: ${PROTOBUF_RUN_PROTOC_COMMAND}"
DEPENDS ${PROTOBUF_PROTOC_EXECUTABLE}
)

include_directories("${GENERATED_PROTOBUF_PATH}")

Expand Down
92 changes: 69 additions & 23 deletions exporters/elasticsearch/test/es_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,48 @@
// SPDX-License-Identifier: Apache-2.0

#include "opentelemetry/exporters/elasticsearch/es_log_record_exporter.h"
#include "opentelemetry/ext/http/server/http_server.h"
#include "opentelemetry/logs/provider.h"
#include "opentelemetry/common/timestamp.h"
#include "opentelemetry/exporters/elasticsearch/es_log_recordable.h"
#include "opentelemetry/logs/severity.h"
#include "opentelemetry/nostd/span.h"
#include "opentelemetry/nostd/string_view.h"
#include "opentelemetry/sdk/instrumentationscope/instrumentation_scope.h"
#include "opentelemetry/sdk/logs/exporter.h"
#include "opentelemetry/sdk/logs/logger_provider.h"
#include "opentelemetry/sdk/logs/simple_log_record_processor.h"
#include "opentelemetry/sdk/resource/resource.h"

#include <gtest/gtest.h>
#include <iostream>
#include <chrono>
#include <string>

namespace sdklogs = opentelemetry::sdk::logs;
namespace logs_api = opentelemetry::logs;
namespace nostd = opentelemetry::nostd;
namespace logs_exporter = opentelemetry::exporter::logs;

TEST(ElasticsearchLogsExporterTests, Dummy)
{
// to enable linking
}

#if 0
// Attempt to write a log to an invalid host/port, test that the Export() returns failure
TEST(ElasticsearchLogsExporterTests, InvalidEndpoint)
TEST(DISABLED_ElasticsearchLogsExporterTests, InvalidEndpoint)
{
// Create invalid connection options for the elasticsearch exporter
logs_exporter::ElasticsearchExporterOptions options("localhost", -1);

// Create an elasticsearch exporter
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogRecordExporter(options));
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
new logs_exporter::ElasticsearchLogRecordExporter(options));

// Create a log record and send to the exporter
auto record = exporter->MakeRecordable();
auto result = exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

// Ensure the return value is failure
ASSERT_EQ(result, sdk::common::ExportResult::kFailure);
ASSERT_EQ(result, opentelemetry::sdk::common::ExportResult::kFailure);
}

// Test that when the exporter is shutdown, any call to Export should return failure
TEST(ElasticsearchLogsExporterTests, Shutdown)
TEST(DISABLED_ElasticsearchLogsExporterTests, Shutdown)
{
// Create an elasticsearch exporter and immediately shut it down
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogRecordExporter);
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
new logs_exporter::ElasticsearchLogRecordExporter);
bool shutdownResult = exporter->Shutdown();
ASSERT_TRUE(shutdownResult);

Expand All @@ -54,15 +52,15 @@ TEST(ElasticsearchLogsExporterTests, Shutdown)
auto result = exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));

// Ensure the return value is failure
ASSERT_EQ(result, sdk::common::ExportResult::kFailure);
ASSERT_EQ(result, opentelemetry::sdk::common::ExportResult::kFailure);
}

// Test the elasticsearch recordable object
TEST(ElasticsearchLogsExporterTests, RecordableCreation)
TEST(DISABLED_ElasticsearchLogsExporterTests, RecordableCreation)
{
// Create an elasticsearch exporter
auto exporter =
std::unique_ptr<sdklogs::LogRecordExporter>(new logs_exporter::ElasticsearchLogRecordExporter);
auto exporter = std::unique_ptr<sdklogs::LogRecordExporter>(
new logs_exporter::ElasticsearchLogRecordExporter);

// Create a recordable
auto record = exporter->MakeRecordable();
Expand All @@ -79,4 +77,52 @@ TEST(ElasticsearchLogsExporterTests, RecordableCreation)

exporter->Export(nostd::span<std::unique_ptr<sdklogs::Recordable>>(&record, 1));
}
#endif

TEST(ElasticsearchLogRecordableTests, BasicTests)
{
const auto severity = logs_api::Severity::kFatal;
const std::array<nostd::string_view, 2> stringlist{
{nostd::string_view("string1"), nostd::string_view("string2")}};

const std::int64_t expected_observed_ts = 1732063944999647774LL;
const std::string expected_timestamp("2024-11-20T00:52:24.999647Z");
const std::string expected_severity(
opentelemetry::logs::SeverityNumToText[static_cast<std::size_t>(severity)]);
const std::string expected_body("Body of the log message");
const std::string expected_scope_name("scope_name");
const bool expected_boolean = false;
const int expected_int = 1;
const double expected_double = 2.0;

const nlohmann::json expected{
{"@timestamp", expected_timestamp},
{"boolean", expected_boolean},
{"double", expected_double},
{"ecs", {{"version", "8.11.0"}}},
{"int", expected_int},
{"log", {{"level", expected_severity}, {"logger", expected_scope_name}}},
{"message", expected_body},
{"observedtimestamp", expected_observed_ts},
{"stringlist", {stringlist[0], stringlist[1]}}};

const opentelemetry::common::SystemTimestamp now{std::chrono::nanoseconds(expected_observed_ts)};

const auto scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create(expected_scope_name);

opentelemetry::exporter::logs::ElasticSearchRecordable recordable;
recordable.SetTimestamp(now);
recordable.SetObservedTimestamp(now);
recordable.SetSeverity(severity);
recordable.SetBody(expected_body);
recordable.SetInstrumentationScope(*scope);

recordable.SetAttribute("boolean", expected_boolean);
recordable.SetAttribute("int", expected_int);
recordable.SetAttribute("double", expected_double);
recordable.SetAttribute("stringlist", stringlist);

const auto actual = recordable.GetJSON();

EXPECT_EQ(actual, expected);
}
Loading

0 comments on commit 2440bc8

Please sign in to comment.