@ -33,7 +33,6 @@
# include <grpc/support/sync.h>
# include <grpc/support/sync.h>
# include <grpcpp/impl/grpc_library.h>
# include <grpcpp/impl/grpc_library.h>
# include "src/core/ext/gcp/metadata_query.h"
# include "src/core/lib/debug/trace.h"
# include "src/core/lib/debug/trace.h"
# include "src/core/lib/event_engine/default_event_engine.h"
# include "src/core/lib/event_engine/default_event_engine.h"
# include "src/core/lib/gprpp/crash.h"
# include "src/core/lib/gprpp/crash.h"
@ -49,6 +48,7 @@
# include "src/core/lib/iomgr/polling_entity.h"
# include "src/core/lib/iomgr/polling_entity.h"
# include "src/core/lib/iomgr/pollset.h"
# include "src/core/lib/iomgr/pollset.h"
# include "src/core/lib/slice/slice.h"
# include "src/core/lib/slice/slice.h"
# include "src/core/util/gcp_metadata_query.h"
namespace grpc {
namespace grpc {
namespace internal {
namespace internal {
@ -202,18 +202,18 @@ class EnvironmentAutoDetectHelper
resource_ . labels . emplace ( " namespace_name " , GetNamespaceName ( ) ) ;
resource_ . labels . emplace ( " namespace_name " , GetNamespaceName ( ) ) ;
resource_ . labels . emplace ( " pod_name " , GetPodName ( ) ) ;
resource_ . labels . emplace ( " pod_name " , GetPodName ( ) ) ;
resource_ . labels . emplace ( " container_name " , GetContainerName ( ) ) ;
resource_ . labels . emplace ( " container_name " , GetContainerName ( ) ) ;
attributes_to_fetch_ . emplace ( grpc_core : : MetadataQuery : : kZoneAttribute ,
attributes_to_fetch_ . emplace ( grpc_core : : Gcp MetadataQuery: : kZoneAttribute ,
" location " ) ;
" location " ) ;
attributes_to_fetch_ . emplace (
attributes_to_fetch_ . emplace (
grpc_core : : MetadataQuery : : kClusterNameAttribute , " cluster_name " ) ;
grpc_core : : Gcp MetadataQuery: : kClusterNameAttribute , " cluster_name " ) ;
}
}
// Cloud Functions
// Cloud Functions
else if ( grpc_core : : GetEnv ( " FUNCTION_NAME " ) . has_value ( ) | |
else if ( grpc_core : : GetEnv ( " FUNCTION_NAME " ) . has_value ( ) | |
grpc_core : : GetEnv ( " FUNCTION_TARGET " ) . has_value ( ) ) {
grpc_core : : GetEnv ( " FUNCTION_TARGET " ) . has_value ( ) ) {
resource_ . resource_type = " cloud_function " ;
resource_ . resource_type = " cloud_function " ;
resource_ . labels . emplace ( " function_name " , GetFunctionName ( ) ) ;
resource_ . labels . emplace ( " function_name " , GetFunctionName ( ) ) ;
attributes_to_fetch_ . emplace ( grpc_core : : MetadataQuery : : kRegionAttribute ,
attributes_to_fetch_ . emplace (
" region " ) ;
grpc_core : : GcpMetadataQuery : : kRegionAttribute , " region " ) ;
}
}
// Cloud Run
// Cloud Run
else if ( grpc_core : : GetEnv ( " K_CONFIGURATION " ) . has_value ( ) ) {
else if ( grpc_core : : GetEnv ( " K_CONFIGURATION " ) . has_value ( ) ) {
@ -221,15 +221,15 @@ class EnvironmentAutoDetectHelper
resource_ . labels . emplace ( " revision_name " , GetRevisionName ( ) ) ;
resource_ . labels . emplace ( " revision_name " , GetRevisionName ( ) ) ;
resource_ . labels . emplace ( " service_name " , GetServiceName ( ) ) ;
resource_ . labels . emplace ( " service_name " , GetServiceName ( ) ) ;
resource_ . labels . emplace ( " configuration_name " , GetConfiguratioName ( ) ) ;
resource_ . labels . emplace ( " configuration_name " , GetConfiguratioName ( ) ) ;
attributes_to_fetch_ . emplace ( grpc_core : : MetadataQuery : : kRegionAttribute ,
attributes_to_fetch_ . emplace (
" location " ) ;
grpc_core : : GcpMetadataQuery : : kRegionAttribute , " location " ) ;
}
}
// App Engine
// App Engine
else if ( grpc_core : : GetEnv ( " GAE_SERVICE " ) . has_value ( ) ) {
else if ( grpc_core : : GetEnv ( " GAE_SERVICE " ) . has_value ( ) ) {
resource_ . resource_type = " gae_app " ;
resource_ . resource_type = " gae_app " ;
resource_ . labels . emplace ( " module_id " , GetModuleId ( ) ) ;
resource_ . labels . emplace ( " module_id " , GetModuleId ( ) ) ;
resource_ . labels . emplace ( " version_id " , GetVersionId ( ) ) ;
resource_ . labels . emplace ( " version_id " , GetVersionId ( ) ) ;
attributes_to_fetch_ . emplace ( grpc_core : : MetadataQuery : : kZoneAttribute ,
attributes_to_fetch_ . emplace ( grpc_core : : Gcp MetadataQuery: : kZoneAttribute ,
" zone " ) ;
" zone " ) ;
}
}
// Assume GCE
// Assume GCE
@ -237,8 +237,8 @@ class EnvironmentAutoDetectHelper
assuming_gce_ = true ;
assuming_gce_ = true ;
resource_ . resource_type = " gce_instance " ;
resource_ . resource_type = " gce_instance " ;
attributes_to_fetch_ . emplace (
attributes_to_fetch_ . emplace (
grpc_core : : MetadataQuery : : kInstanceIdAttribute , " instance_id " ) ;
grpc_core : : Gcp MetadataQuery: : kInstanceIdAttribute , " instance_id " ) ;
attributes_to_fetch_ . emplace ( grpc_core : : MetadataQuery : : kZoneAttribute ,
attributes_to_fetch_ . emplace ( grpc_core : : Gcp MetadataQuery: : kZoneAttribute ,
" zone " ) ;
" zone " ) ;
}
}
FetchMetadataServerAttributesAsynchronouslyLocked ( ) ;
FetchMetadataServerAttributesAsynchronouslyLocked ( ) ;
@ -248,7 +248,7 @@ class EnvironmentAutoDetectHelper
ABSL_EXCLUSIVE_LOCKS_REQUIRED ( mu_ ) {
ABSL_EXCLUSIVE_LOCKS_REQUIRED ( mu_ ) {
CHECK ( ! attributes_to_fetch_ . empty ( ) ) ;
CHECK ( ! attributes_to_fetch_ . empty ( ) ) ;
for ( auto & element : attributes_to_fetch_ ) {
for ( auto & element : attributes_to_fetch_ ) {
queries_ . push_back ( grpc_core : : MakeOrphanable < grpc_core : : MetadataQuery > (
queries_ . push_back ( grpc_core : : MakeOrphanable < grpc_core : : Gcp MetadataQuery> (
element . first , & pollent_ ,
element . first , & pollent_ ,
[ this ] ( std : : string attribute , absl : : StatusOr < std : : string > result ) {
[ this ] ( std : : string attribute , absl : : StatusOr < std : : string > result ) {
if ( GRPC_TRACE_FLAG_ENABLED ( grpc_environment_autodetect_trace ) ) {
if ( GRPC_TRACE_FLAG_ENABLED ( grpc_environment_autodetect_trace ) ) {
@ -317,7 +317,7 @@ class EnvironmentAutoDetectHelper
absl : : flat_hash_map < std : : string /* metadata_server_attribute */ ,
absl : : flat_hash_map < std : : string /* metadata_server_attribute */ ,
std : : string /* resource_attribute */ >
std : : string /* resource_attribute */ >
attributes_to_fetch_ ABSL_GUARDED_BY ( mu_ ) ;
attributes_to_fetch_ ABSL_GUARDED_BY ( mu_ ) ;
std : : vector < grpc_core : : OrphanablePtr < grpc_core : : MetadataQuery > > queries_
std : : vector < grpc_core : : OrphanablePtr < grpc_core : : Gcp MetadataQuery> > queries_
ABSL_GUARDED_BY ( mu_ ) ;
ABSL_GUARDED_BY ( mu_ ) ;
EnvironmentAutoDetect : : ResourceType resource_ ABSL_GUARDED_BY ( mu_ ) ;
EnvironmentAutoDetect : : ResourceType resource_ ABSL_GUARDED_BY ( mu_ ) ;
// This would be true if we are assuming the resource to be GCE. In this case,
// This would be true if we are assuming the resource to be GCE. In this case,