Skip to content

Commit

Permalink
No real need for decimal seconds in otlp grpc exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
chusitoo committed Dec 30, 2024
1 parent 7d422cd commit cb14857
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ namespace exporter
namespace otlp
{

using SecondsDecimal = std::chrono::duration<float, std::ratio<1>>;

inline std::string GetOtlpDefaultUserAgent()
{
return "OTel-OTLP-Exporter-Cpp/" OPENTELEMETRY_SDK_VERSION;
Expand Down Expand Up @@ -158,13 +156,13 @@ std::uint32_t GetOtlpDefaultTracesRetryMaxAttempts();
std::uint32_t GetOtlpDefaultMetricsRetryMaxAttempts();
std::uint32_t GetOtlpDefaultLogsRetryMaxAttempts();

SecondsDecimal GetOtlpDefaultTracesRetryInitialBackoff();
SecondsDecimal GetOtlpDefaultMetricsRetryInitialBackoff();
SecondsDecimal GetOtlpDefaultLogsRetryInitialBackoff();
float GetOtlpDefaultTracesRetryInitialBackoff();
float GetOtlpDefaultMetricsRetryInitialBackoff();
float GetOtlpDefaultLogsRetryInitialBackoff();

SecondsDecimal GetOtlpDefaultTracesRetryMaxBackoff();
SecondsDecimal GetOtlpDefaultMetricsRetryMaxBackoff();
SecondsDecimal GetOtlpDefaultLogsRetryMaxBackoff();
float GetOtlpDefaultTracesRetryMaxBackoff();
float GetOtlpDefaultMetricsRetryMaxBackoff();
float GetOtlpDefaultLogsRetryMaxBackoff();

float GetOtlpDefaultTracesRetryBackoffMultiplier();
float GetOtlpDefaultMetricsRetryBackoffMultiplier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ struct OtlpGrpcClientOptions
std::uint32_t retry_policy_max_attempts{};

/** The initial backoff delay between retry attempts, random between (0, initial_backoff). */
SecondsDecimal retry_policy_initial_backoff{};
float retry_policy_initial_backoff{};

/** The maximum backoff places an upper limit on exponential backoff growth. */
SecondsDecimal retry_policy_max_backoff{};
float retry_policy_max_backoff{};

/** The backoff will be multiplied by this value after each retry attempt. */
float retry_policy_backoff_multiplier{};
Expand Down
24 changes: 12 additions & 12 deletions exporters/otlp/src/otlp_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1174,46 +1174,46 @@ std::uint32_t GetOtlpDefaultLogsRetryMaxAttempts()
return GetUintEnvVarOrDefault(kSignalEnv, kGenericEnv, 5U);
}

SecondsDecimal GetOtlpDefaultTracesRetryInitialBackoff()
float GetOtlpDefaultTracesRetryInitialBackoff()
{
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_TRACES_RETRY_INITIAL_BACKOFF";
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_INITIAL_BACKOFF";
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0)};
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0);
}

SecondsDecimal GetOtlpDefaultMetricsRetryInitialBackoff()
float GetOtlpDefaultMetricsRetryInitialBackoff()
{
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_METRICS_RETRY_INITIAL_BACKOFF";
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_INITIAL_BACKOFF";
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0)};
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0);
}

SecondsDecimal GetOtlpDefaultLogsRetryInitialBackoff()
float GetOtlpDefaultLogsRetryInitialBackoff()
{
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_LOGS_RETRY_INITIAL_BACKOFF";
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_INITIAL_BACKOFF";
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0)};
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0);
}

SecondsDecimal GetOtlpDefaultTracesRetryMaxBackoff()
float GetOtlpDefaultTracesRetryMaxBackoff()
{
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_TRACES_RETRY_MAX_BACKOFF";
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_MAX_BACKOFF";
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0)};
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0);
}

SecondsDecimal GetOtlpDefaultMetricsRetryMaxBackoff()
float GetOtlpDefaultMetricsRetryMaxBackoff()
{
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_METRICS_RETRY_MAX_BACKOFF";
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_MAX_BACKOFF";
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0)};
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0);
}

SecondsDecimal GetOtlpDefaultLogsRetryMaxBackoff()
float GetOtlpDefaultLogsRetryMaxBackoff()
{
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_LOGS_RETRY_MAX_BACKOFF";
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_MAX_BACKOFF";
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0)};
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0);
}

float GetOtlpDefaultTracesRetryBackoffMultiplier()
Expand Down
11 changes: 4 additions & 7 deletions exporters/otlp/src/otlp_grpc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,8 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
grpc_arguments.SetCompressionAlgorithm(GRPC_COMPRESS_GZIP);
}

if (options.retry_policy_max_attempts > 0U &&
options.retry_policy_initial_backoff > SecondsDecimal::zero() &&
options.retry_policy_max_backoff > SecondsDecimal::zero() &&
options.retry_policy_backoff_multiplier > 0.f)
if (options.retry_policy_max_attempts > 0U && options.retry_policy_initial_backoff > 0.0f &&
options.retry_policy_max_backoff > 0.0f && options.retry_policy_backoff_multiplier > 0.0f)
{
static const auto kServiceConfigJson = opentelemetry::nostd::string_view{R"(
{
Expand Down Expand Up @@ -382,9 +380,8 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
// Prior to C++17, need to explicitly cast away constness from `data()` buffer
std::snprintf(const_cast<decltype(service_config)::value_type *>(service_config.data()),
service_config.size(), kServiceConfigJson.data(),
options.retry_policy_max_attempts, options.retry_policy_initial_backoff.count(),
options.retry_policy_max_backoff.count(),
options.retry_policy_backoff_multiplier);
options.retry_policy_max_attempts, options.retry_policy_initial_backoff,
options.retry_policy_max_backoff, options.retry_policy_backoff_multiplier);

grpc_arguments.SetServiceConfigJSON(service_config);
}
Expand Down
24 changes: 12 additions & 12 deletions exporters/otlp/test/otlp_grpc_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigRetryDefaultValues)
std::unique_ptr<OtlpGrpcExporter> exporter(new OtlpGrpcExporter());
const auto options = GetOptions(exporter);
ASSERT_EQ(options.retry_policy_max_attempts, 5);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 1);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 5);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 1.0);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 5.0);
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 1.5);
}

Expand All @@ -374,8 +374,8 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigRetryValuesFromEnv)
std::unique_ptr<OtlpGrpcExporter> exporter(new OtlpGrpcExporter());
const auto options = GetOptions(exporter);
ASSERT_EQ(options.retry_policy_max_attempts, 123);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 4.5);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 6.7);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 4.5);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 6.7);
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 8.9);

unsetenv("OTEL_EXPORTER_OTLP_TRACES_RETRY_MAX_ATTEMPTS");
Expand All @@ -394,8 +394,8 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigRetryGenericValuesFromEnv)
std::unique_ptr<OtlpGrpcExporter> exporter(new OtlpGrpcExporter());
const auto options = GetOptions(exporter);
ASSERT_EQ(options.retry_policy_max_attempts, 321);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 5.4);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 7.6);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 5.4);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 7.6);
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 9.8);

unsetenv("OTEL_EXPORTER_OTLP_RETRY_MAX_ATTEMPTS");
Expand Down Expand Up @@ -523,16 +523,16 @@ TEST_P(OtlpGrpcExporterRetryIntegrationTests, StatusCodes)
if (is_retry_enabled)
{
opts.retry_policy_max_attempts = 5;
opts.retry_policy_initial_backoff = SecondsDecimal{0.1};
opts.retry_policy_max_backoff = SecondsDecimal{5};
opts.retry_policy_backoff_multiplier = 1;
opts.retry_policy_initial_backoff = 0.1f;
opts.retry_policy_max_backoff = 5.0f;
opts.retry_policy_backoff_multiplier = 1.0f;
}
else
{
opts.retry_policy_max_attempts = 0;
opts.retry_policy_initial_backoff = SecondsDecimal{0};
opts.retry_policy_max_backoff = SecondsDecimal{0};
opts.retry_policy_backoff_multiplier = 0;
opts.retry_policy_initial_backoff = 0.0f;
opts.retry_policy_max_backoff = 0.0f;
opts.retry_policy_backoff_multiplier = 0.0f;
}

auto exporter = otlp::OtlpGrpcExporterFactory::Create(opts);
Expand Down
12 changes: 6 additions & 6 deletions exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ConfigRetryDefaultValues)
std::unique_ptr<OtlpGrpcLogRecordExporter> exporter(new OtlpGrpcLogRecordExporter());
const auto options = GetOptions(exporter);
ASSERT_EQ(options.retry_policy_max_attempts, 5);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 1);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 5);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 1.0);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 5.0);
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 1.5);
}

Expand All @@ -487,8 +487,8 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ConfigRetryValuesFromEnv)
std::unique_ptr<OtlpGrpcLogRecordExporter> exporter(new OtlpGrpcLogRecordExporter());
const auto options = GetOptions(exporter);
ASSERT_EQ(options.retry_policy_max_attempts, 123);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 4.5);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 6.7);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 4.5);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 6.7);
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 8.9);

unsetenv("OTEL_EXPORTER_OTLP_LOGS_RETRY_MAX_ATTEMPTS");
Expand All @@ -507,8 +507,8 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ConfigRetryGenericValuesFromEnv)
std::unique_ptr<OtlpGrpcLogRecordExporter> exporter(new OtlpGrpcLogRecordExporter());
const auto options = GetOptions(exporter);
ASSERT_EQ(options.retry_policy_max_attempts, 321);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 5.4);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 7.6);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 5.4);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 7.6);
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 9.8);

unsetenv("OTEL_EXPORTER_OTLP_RETRY_MAX_ATTEMPTS");
Expand Down
12 changes: 6 additions & 6 deletions exporters/otlp/test/otlp_grpc_metric_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigRetryDefaultValues)
std::unique_ptr<OtlpGrpcMetricExporter> exporter(new OtlpGrpcMetricExporter());
const auto options = GetOptions(exporter);
ASSERT_EQ(options.retry_policy_max_attempts, 5);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 1);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 5);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 1.0);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 5.0);
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 1.5);
}

Expand All @@ -215,8 +215,8 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigRetryValuesFromEnv)
std::unique_ptr<OtlpGrpcMetricExporter> exporter(new OtlpGrpcMetricExporter());
const auto options = GetOptions(exporter);
ASSERT_EQ(options.retry_policy_max_attempts, 123);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 4.5);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 6.7);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 4.5);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 6.7);
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 8.9);

unsetenv("OTEL_EXPORTER_OTLP_METRICS_RETRY_MAX_ATTEMPTS");
Expand All @@ -235,8 +235,8 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigRetryGenericValuesFromEnv)
std::unique_ptr<OtlpGrpcMetricExporter> exporter(new OtlpGrpcMetricExporter());
const auto options = GetOptions(exporter);
ASSERT_EQ(options.retry_policy_max_attempts, 321);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 5.4);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 7.6);
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 5.4);
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 7.6);
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 9.8);

unsetenv("OTEL_EXPORTER_OTLP_RETRY_MAX_ATTEMPTS");
Expand Down

0 comments on commit cb14857

Please sign in to comment.