|
15 | 15 | #ifdef GOOGLE_CLOUD_CPP_STORAGE_WITH_OTEL_METRICS |
16 | 16 |
|
17 | 17 | #include "google/cloud/storage/internal/grpc/metrics_exporter_impl.h" |
| 18 | +#include "google/cloud/opentelemetry/internal/monitoring_exporter.h" |
18 | 19 | #include "google/cloud/opentelemetry/monitoring_exporter.h" |
19 | 20 | #include "google/cloud/storage/grpc_plugin.h" |
20 | 21 | #include "google/cloud/storage/internal/grpc/default_options.h" |
@@ -156,6 +157,64 @@ TEST(GrpcMetricsExporter, ReaderOptionsAreSetFromConfig) { |
156 | 157 | std::chrono::milliseconds(expected_timeout)); |
157 | 158 | } |
158 | 159 |
|
| 160 | +TEST(MakeMeterProviderConfigTest, NoExcludedLabels) { |
| 161 | + auto resource = opentelemetry::sdk::resource::Resource::Create( |
| 162 | + {{"service.name", "test-service"}, {"service.version", "1.0.0"}}); |
| 163 | + |
| 164 | + Options options; |
| 165 | + options.set<storage_experimental::EnableGrpcMetricsOption>(true); |
| 166 | + options.set<storage::ProjectIdOption>("test-project"); |
| 167 | + |
| 168 | + auto config = MakeMeterProviderConfig(resource, options); |
| 169 | + |
| 170 | + ASSERT_TRUE(config.has_value()); |
| 171 | + EXPECT_FALSE(config->exporter_options |
| 172 | + .has<otel_internal::ResourceFilterDataFnOption>()); |
| 173 | +} |
| 174 | + |
| 175 | +TEST(MakeMeterProviderConfigTest, WithExcludedLabels) { |
| 176 | + auto resource = opentelemetry::sdk::resource::Resource::Create( |
| 177 | + {{"service.name", "test-service"}, {"service.version", "1.0.0"}}); |
| 178 | + |
| 179 | + std::set<std::string> excluded_labels{"service_name", "service_version"}; |
| 180 | + Options options; |
| 181 | + options.set<storage_experimental::EnableGrpcMetricsOption>(true); |
| 182 | + options.set<storage::ProjectIdOption>("test-project"); |
| 183 | + options.set<storage_experimental::GrpcMetricsExcludedLabelsOption>( |
| 184 | + excluded_labels); |
| 185 | + |
| 186 | + auto config = MakeMeterProviderConfig(resource, options); |
| 187 | + |
| 188 | + ASSERT_TRUE(config.has_value()); |
| 189 | + EXPECT_TRUE(config->exporter_options |
| 190 | + .has<otel_internal::ResourceFilterDataFnOption>()); |
| 191 | + |
| 192 | + auto actual_excluded = |
| 193 | + config->exporter_options.get<otel_internal::ResourceFilterDataFnOption>(); |
| 194 | + EXPECT_EQ(excluded_labels, actual_excluded); |
| 195 | +} |
| 196 | + |
| 197 | +TEST(MakeMeterProviderConfigTest, EmptyExcludedLabels) { |
| 198 | + auto resource = opentelemetry::sdk::resource::Resource::Create( |
| 199 | + {{"service.name", "test-service"}}); |
| 200 | + |
| 201 | + Options options; |
| 202 | + options.set<storage_experimental::EnableGrpcMetricsOption>(true); |
| 203 | + options.set<storage::ProjectIdOption>("test-project"); |
| 204 | + options.set<storage_experimental::GrpcMetricsExcludedLabelsOption>( |
| 205 | + std::set<std::string>{}); |
| 206 | + |
| 207 | + auto config = MakeMeterProviderConfig(resource, options); |
| 208 | + |
| 209 | + ASSERT_TRUE(config.has_value()); |
| 210 | + EXPECT_TRUE(config->exporter_options |
| 211 | + .has<otel_internal::ResourceFilterDataFnOption>()); |
| 212 | + |
| 213 | + auto actual_excluded = |
| 214 | + config->exporter_options.get<otel_internal::ResourceFilterDataFnOption>(); |
| 215 | + EXPECT_TRUE(actual_excluded.empty()); |
| 216 | +} |
| 217 | + |
159 | 218 | } // namespace |
160 | 219 | GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END |
161 | 220 | } // namespace storage_internal |
|
0 commit comments