Skip to content

Commit cb14857

Browse files
committed
No real need for decimal seconds in otlp grpc exporter
1 parent 7d422cd commit cb14857

File tree

7 files changed

+48
-53
lines changed

7 files changed

+48
-53
lines changed

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_environment.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ namespace exporter
1818
namespace otlp
1919
{
2020

21-
using SecondsDecimal = std::chrono::duration<float, std::ratio<1>>;
22-
2321
inline std::string GetOtlpDefaultUserAgent()
2422
{
2523
return "OTel-OTLP-Exporter-Cpp/" OPENTELEMETRY_SDK_VERSION;
@@ -158,13 +156,13 @@ std::uint32_t GetOtlpDefaultTracesRetryMaxAttempts();
158156
std::uint32_t GetOtlpDefaultMetricsRetryMaxAttempts();
159157
std::uint32_t GetOtlpDefaultLogsRetryMaxAttempts();
160158

161-
SecondsDecimal GetOtlpDefaultTracesRetryInitialBackoff();
162-
SecondsDecimal GetOtlpDefaultMetricsRetryInitialBackoff();
163-
SecondsDecimal GetOtlpDefaultLogsRetryInitialBackoff();
159+
float GetOtlpDefaultTracesRetryInitialBackoff();
160+
float GetOtlpDefaultMetricsRetryInitialBackoff();
161+
float GetOtlpDefaultLogsRetryInitialBackoff();
164162

165-
SecondsDecimal GetOtlpDefaultTracesRetryMaxBackoff();
166-
SecondsDecimal GetOtlpDefaultMetricsRetryMaxBackoff();
167-
SecondsDecimal GetOtlpDefaultLogsRetryMaxBackoff();
163+
float GetOtlpDefaultTracesRetryMaxBackoff();
164+
float GetOtlpDefaultMetricsRetryMaxBackoff();
165+
float GetOtlpDefaultLogsRetryMaxBackoff();
168166

169167
float GetOtlpDefaultTracesRetryBackoffMultiplier();
170168
float GetOtlpDefaultMetricsRetryBackoffMultiplier();

exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_client_options.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ struct OtlpGrpcClientOptions
6767
std::uint32_t retry_policy_max_attempts{};
6868

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

7272
/** The maximum backoff places an upper limit on exponential backoff growth. */
73-
SecondsDecimal retry_policy_max_backoff{};
73+
float retry_policy_max_backoff{};
7474

7575
/** The backoff will be multiplied by this value after each retry attempt. */
7676
float retry_policy_backoff_multiplier{};

exporters/otlp/src/otlp_environment.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,46 +1174,46 @@ std::uint32_t GetOtlpDefaultLogsRetryMaxAttempts()
11741174
return GetUintEnvVarOrDefault(kSignalEnv, kGenericEnv, 5U);
11751175
}
11761176

1177-
SecondsDecimal GetOtlpDefaultTracesRetryInitialBackoff()
1177+
float GetOtlpDefaultTracesRetryInitialBackoff()
11781178
{
11791179
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_TRACES_RETRY_INITIAL_BACKOFF";
11801180
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_INITIAL_BACKOFF";
1181-
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0)};
1181+
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0);
11821182
}
11831183

1184-
SecondsDecimal GetOtlpDefaultMetricsRetryInitialBackoff()
1184+
float GetOtlpDefaultMetricsRetryInitialBackoff()
11851185
{
11861186
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_METRICS_RETRY_INITIAL_BACKOFF";
11871187
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_INITIAL_BACKOFF";
1188-
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0)};
1188+
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0);
11891189
}
11901190

1191-
SecondsDecimal GetOtlpDefaultLogsRetryInitialBackoff()
1191+
float GetOtlpDefaultLogsRetryInitialBackoff()
11921192
{
11931193
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_LOGS_RETRY_INITIAL_BACKOFF";
11941194
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_INITIAL_BACKOFF";
1195-
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0)};
1195+
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 1.0);
11961196
}
11971197

1198-
SecondsDecimal GetOtlpDefaultTracesRetryMaxBackoff()
1198+
float GetOtlpDefaultTracesRetryMaxBackoff()
11991199
{
12001200
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_TRACES_RETRY_MAX_BACKOFF";
12011201
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_MAX_BACKOFF";
1202-
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0)};
1202+
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0);
12031203
}
12041204

1205-
SecondsDecimal GetOtlpDefaultMetricsRetryMaxBackoff()
1205+
float GetOtlpDefaultMetricsRetryMaxBackoff()
12061206
{
12071207
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_METRICS_RETRY_MAX_BACKOFF";
12081208
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_MAX_BACKOFF";
1209-
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0)};
1209+
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0);
12101210
}
12111211

1212-
SecondsDecimal GetOtlpDefaultLogsRetryMaxBackoff()
1212+
float GetOtlpDefaultLogsRetryMaxBackoff()
12131213
{
12141214
constexpr char kSignalEnv[] = "OTEL_EXPORTER_OTLP_LOGS_RETRY_MAX_BACKOFF";
12151215
constexpr char kGenericEnv[] = "OTEL_EXPORTER_OTLP_RETRY_MAX_BACKOFF";
1216-
return SecondsDecimal{GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0)};
1216+
return GetFloatEnvVarOrDefault(kSignalEnv, kGenericEnv, 5.0);
12171217
}
12181218

12191219
float GetOtlpDefaultTracesRetryBackoffMultiplier()

exporters/otlp/src/otlp_grpc_client.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,8 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
349349
grpc_arguments.SetCompressionAlgorithm(GRPC_COMPRESS_GZIP);
350350
}
351351

352-
if (options.retry_policy_max_attempts > 0U &&
353-
options.retry_policy_initial_backoff > SecondsDecimal::zero() &&
354-
options.retry_policy_max_backoff > SecondsDecimal::zero() &&
355-
options.retry_policy_backoff_multiplier > 0.f)
352+
if (options.retry_policy_max_attempts > 0U && options.retry_policy_initial_backoff > 0.0f &&
353+
options.retry_policy_max_backoff > 0.0f && options.retry_policy_backoff_multiplier > 0.0f)
356354
{
357355
static const auto kServiceConfigJson = opentelemetry::nostd::string_view{R"(
358356
{
@@ -382,9 +380,8 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
382380
// Prior to C++17, need to explicitly cast away constness from `data()` buffer
383381
std::snprintf(const_cast<decltype(service_config)::value_type *>(service_config.data()),
384382
service_config.size(), kServiceConfigJson.data(),
385-
options.retry_policy_max_attempts, options.retry_policy_initial_backoff.count(),
386-
options.retry_policy_max_backoff.count(),
387-
options.retry_policy_backoff_multiplier);
383+
options.retry_policy_max_attempts, options.retry_policy_initial_backoff,
384+
options.retry_policy_max_backoff, options.retry_policy_backoff_multiplier);
388385

389386
grpc_arguments.SetServiceConfigJSON(service_config);
390387
}

exporters/otlp/test/otlp_grpc_exporter_test.cc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ TEST_F(OtlpGrpcExporterTestPeer, ConfigRetryDefaultValues)
359359
std::unique_ptr<OtlpGrpcExporter> exporter(new OtlpGrpcExporter());
360360
const auto options = GetOptions(exporter);
361361
ASSERT_EQ(options.retry_policy_max_attempts, 5);
362-
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 1);
363-
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 5);
362+
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 1.0);
363+
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 5.0);
364364
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 1.5);
365365
}
366366

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

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

401401
unsetenv("OTEL_EXPORTER_OTLP_RETRY_MAX_ATTEMPTS");
@@ -523,16 +523,16 @@ TEST_P(OtlpGrpcExporterRetryIntegrationTests, StatusCodes)
523523
if (is_retry_enabled)
524524
{
525525
opts.retry_policy_max_attempts = 5;
526-
opts.retry_policy_initial_backoff = SecondsDecimal{0.1};
527-
opts.retry_policy_max_backoff = SecondsDecimal{5};
528-
opts.retry_policy_backoff_multiplier = 1;
526+
opts.retry_policy_initial_backoff = 0.1f;
527+
opts.retry_policy_max_backoff = 5.0f;
528+
opts.retry_policy_backoff_multiplier = 1.0f;
529529
}
530530
else
531531
{
532532
opts.retry_policy_max_attempts = 0;
533-
opts.retry_policy_initial_backoff = SecondsDecimal{0};
534-
opts.retry_policy_max_backoff = SecondsDecimal{0};
535-
opts.retry_policy_backoff_multiplier = 0;
533+
opts.retry_policy_initial_backoff = 0.0f;
534+
opts.retry_policy_max_backoff = 0.0f;
535+
opts.retry_policy_backoff_multiplier = 0.0f;
536536
}
537537

538538
auto exporter = otlp::OtlpGrpcExporterFactory::Create(opts);

exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,8 @@ TEST_F(OtlpGrpcLogRecordExporterTestPeer, ConfigRetryDefaultValues)
472472
std::unique_ptr<OtlpGrpcLogRecordExporter> exporter(new OtlpGrpcLogRecordExporter());
473473
const auto options = GetOptions(exporter);
474474
ASSERT_EQ(options.retry_policy_max_attempts, 5);
475-
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 1);
476-
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 5);
475+
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 1.0);
476+
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 5.0);
477477
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 1.5);
478478
}
479479

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

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

514514
unsetenv("OTEL_EXPORTER_OTLP_RETRY_MAX_ATTEMPTS");

exporters/otlp/test/otlp_grpc_metric_exporter_test.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ TEST_F(OtlpGrpcMetricExporterTestPeer, ConfigRetryDefaultValues)
200200
std::unique_ptr<OtlpGrpcMetricExporter> exporter(new OtlpGrpcMetricExporter());
201201
const auto options = GetOptions(exporter);
202202
ASSERT_EQ(options.retry_policy_max_attempts, 5);
203-
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff.count(), 1);
204-
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff.count(), 5);
203+
ASSERT_FLOAT_EQ(options.retry_policy_initial_backoff, 1.0);
204+
ASSERT_FLOAT_EQ(options.retry_policy_max_backoff, 5.0);
205205
ASSERT_FLOAT_EQ(options.retry_policy_backoff_multiplier, 1.5);
206206
}
207207

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

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

242242
unsetenv("OTEL_EXPORTER_OTLP_RETRY_MAX_ATTEMPTS");

0 commit comments

Comments
 (0)