Skip to content

Commit 34b1f06

Browse files
committed
[SDK] Implement env var configuration for PeriodicExportingMetricReaderOptions
1 parent 10c5437 commit 34b1f06

File tree

2 files changed

+5
-41
lines changed

2 files changed

+5
-41
lines changed

sdk/include/opentelemetry/sdk/metrics/export/periodic_exporting_metric_reader_options.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <chrono>
77

8-
#include "opentelemetry/nostd/string_view.h"
98
#include "opentelemetry/version.h"
109

1110
OPENTELEMETRY_BEGIN_NAMESPACE
@@ -17,9 +16,6 @@ namespace metrics
1716
constexpr std::chrono::milliseconds kExportIntervalMillis = std::chrono::milliseconds(60000);
1817
constexpr std::chrono::milliseconds kExportTimeOutMillis = std::chrono::milliseconds(30000);
1918

20-
std::chrono::milliseconds GetEnvDuration(nostd::string_view env_var_name,
21-
std::chrono::milliseconds default_value);
22-
2319
/**
2420
* Struct to hold PeriodicExortingMetricReader options.
2521
*/

sdk/test/metrics/periodic_exporting_metric_reader_test.cc

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include <gtest/gtest.h>
55
#include <stddef.h>
66
#include <chrono>
7+
#include <cstdlib>
78
#include <memory>
9+
#include <ratio>
810
#include <thread>
911
#include <utility>
1012
#include <vector>
@@ -18,8 +20,9 @@
1820
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
1921

2022
#if defined(_MSC_VER)
21-
using opentelemetry::common::setenv;
22-
using opentelemetry::common::unsetenv;
23+
# include "opentelemetry/sdk/common/env_variables.h"
24+
using opentelemetry::sdk::common::setenv;
25+
using opentelemetry::sdk::common::unsetenv;
2326
#endif
2427

2528
using namespace opentelemetry;
@@ -114,41 +117,6 @@ TEST(PeriodicExportingMetricReader, Timeout)
114117
reader->Shutdown();
115118
}
116119

117-
TEST(GetEnvDurationTest, Absent)
118-
{
119-
const char *env = "OTEL_TEST";
120-
unsetenv(env);
121-
EXPECT_EQ(GetEnvDuration(env, std::chrono::milliseconds(42)), std::chrono::milliseconds(42));
122-
}
123-
124-
TEST(GetEnvDurationTest, NotSet)
125-
{
126-
const char *env = "OTEL_TEST";
127-
setenv(env, "", 1);
128-
EXPECT_EQ(GetEnvDuration(env, std::chrono::milliseconds(42)), std::chrono::milliseconds(42));
129-
unsetenv(env);
130-
}
131-
132-
TEST(GetEnvDurationTest, Valid)
133-
{
134-
const char *env = "OTEL_TEST";
135-
setenv(env, "1243ms", 1);
136-
EXPECT_EQ(GetEnvDuration(env, std::chrono::milliseconds(42)), std::chrono::milliseconds(1243));
137-
138-
setenv(env, "3s", 1);
139-
EXPECT_EQ(GetEnvDuration(env, std::chrono::milliseconds(42)), std::chrono::milliseconds(3000));
140-
141-
unsetenv(env);
142-
}
143-
144-
TEST(GetEnvDurationTest, Invalid)
145-
{
146-
const char *env = "OTEL_TEST";
147-
setenv(env, "not_a_duration", 1);
148-
EXPECT_EQ(GetEnvDuration(env, std::chrono::milliseconds(42)), std::chrono::milliseconds(42));
149-
unsetenv(env);
150-
}
151-
152120
TEST(PeriodicExportingMetricReaderOptions, UsesEnvVars)
153121
{
154122
const char *env_interval = "OTEL_METRIC_EXPORT_INTERVAL";

0 commit comments

Comments
 (0)