[reorg] move ext/gcp/metadata_query.* -> util/gcp_metadata_query.* (#36789)

Also rename the class from `MetadataQuery` to `GcpMetadataQuery`.

Closes #36789

COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/36789 from markdroth:reorg_gcp_metadata_query d2b84f46be
PiperOrigin-RevId: 639256546
pull/36558/head^2
Mark D. Roth 6 months ago committed by Copybara-Service
parent 05af32503c
commit e4daabc8bc
  1. 2
      CMakeLists.txt
  2. 2
      Makefile
  3. 4
      Package.swift
  4. 4
      build_autogenerated.yaml
  5. 3
      config.m4
  6. 3
      config.w32
  7. 4
      gRPC-C++.podspec
  8. 6
      gRPC-Core.podspec
  9. 4
      grpc.gemspec
  10. 2
      grpc.gyp
  11. 4
      package.xml
  12. 4
      src/core/BUILD
  13. 14
      src/core/resolver/google_c2p/google_c2p_resolver.cc
  14. 35
      src/core/util/gcp_metadata_query.cc
  15. 18
      src/core/util/gcp_metadata_query.h
  16. 24
      src/cpp/ext/gcp/environment_autodetect.cc
  17. 2
      src/python/grpcio/grpc_core_dependencies.py
  18. 4
      tools/doxygen/Doxyfile.c++.internal
  19. 4
      tools/doxygen/Doxyfile.core.internal

2
CMakeLists.txt generated

@ -1872,7 +1872,6 @@ add_library(grpc
src/core/ext/filters/rbac/rbac_service_config_parser.cc
src/core/ext/filters/stateful_session/stateful_session_filter.cc
src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc
src/core/ext/gcp/metadata_query.cc
src/core/ext/transport/chttp2/alpn/alpn.cc
src/core/ext/transport/chttp2/client/chttp2_connector.cc
src/core/ext/transport/chttp2/server/chttp2_server.cc
@ -2603,6 +2602,7 @@ add_library(grpc
src/core/tsi/ssl_transport_security_utils.cc
src/core/tsi/transport_security.cc
src/core/tsi/transport_security_grpc.cc
src/core/util/gcp_metadata_query.cc
src/core/util/http_client/format_request.cc
src/core/util/http_client/httpcli.cc
src/core/util/http_client/httpcli_security_connector.cc

2
Makefile generated

@ -703,7 +703,6 @@ LIBGRPC_SRC = \
src/core/ext/filters/rbac/rbac_service_config_parser.cc \
src/core/ext/filters/stateful_session/stateful_session_filter.cc \
src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc \
src/core/ext/gcp/metadata_query.cc \
src/core/ext/transport/chttp2/alpn/alpn.cc \
src/core/ext/transport/chttp2/client/chttp2_connector.cc \
src/core/ext/transport/chttp2/server/chttp2_server.cc \
@ -1456,6 +1455,7 @@ LIBGRPC_SRC = \
src/core/util/alloc.cc \
src/core/util/android/log.cc \
src/core/util/atm.cc \
src/core/util/gcp_metadata_query.cc \
src/core/util/http_client/format_request.cc \
src/core/util/http_client/httpcli.cc \
src/core/util/http_client/httpcli_security_connector.cc \

4
Package.swift generated

@ -193,8 +193,6 @@ let package = Package(
"src/core/ext/filters/stateful_session/stateful_session_filter.h",
"src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc",
"src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h",
"src/core/ext/gcp/metadata_query.cc",
"src/core/ext/gcp/metadata_query.h",
"src/core/ext/transport/chttp2/alpn/alpn.cc",
"src/core/ext/transport/chttp2/alpn/alpn.h",
"src/core/ext/transport/chttp2/client/chttp2_connector.cc",
@ -1914,6 +1912,8 @@ let package = Package(
"src/core/util/alloc.h",
"src/core/util/android/log.cc",
"src/core/util/atm.cc",
"src/core/util/gcp_metadata_query.cc",
"src/core/util/gcp_metadata_query.h",
"src/core/util/http_client/format_request.cc",
"src/core/util/http_client/format_request.h",
"src/core/util/http_client/httpcli.cc",

@ -261,7 +261,6 @@ libs:
- src/core/ext/filters/rbac/rbac_service_config_parser.h
- src/core/ext/filters/stateful_session/stateful_session_filter.h
- src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h
- src/core/ext/gcp/metadata_query.h
- src/core/ext/transport/chttp2/alpn/alpn.h
- src/core/ext/transport/chttp2/client/chttp2_connector.h
- src/core/ext/transport/chttp2/server/chttp2_server.h
@ -1205,6 +1204,7 @@ libs:
- src/core/tsi/transport_security.h
- src/core/tsi/transport_security_grpc.h
- src/core/tsi/transport_security_interface.h
- src/core/util/gcp_metadata_query.h
- src/core/util/http_client/format_request.h
- src/core/util/http_client/httpcli.h
- src/core/util/http_client/httpcli_ssl_credentials.h
@ -1287,7 +1287,6 @@ libs:
- src/core/ext/filters/rbac/rbac_service_config_parser.cc
- src/core/ext/filters/stateful_session/stateful_session_filter.cc
- src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc
- src/core/ext/gcp/metadata_query.cc
- src/core/ext/transport/chttp2/alpn/alpn.cc
- src/core/ext/transport/chttp2/client/chttp2_connector.cc
- src/core/ext/transport/chttp2/server/chttp2_server.cc
@ -2018,6 +2017,7 @@ libs:
- src/core/tsi/ssl_transport_security_utils.cc
- src/core/tsi/transport_security.cc
- src/core/tsi/transport_security_grpc.cc
- src/core/util/gcp_metadata_query.cc
- src/core/util/http_client/format_request.cc
- src/core/util/http_client/httpcli.cc
- src/core/util/http_client/httpcli_security_connector.cc

3
config.m4 generated

@ -78,7 +78,6 @@ if test "$PHP_GRPC" != "no"; then
src/core/ext/filters/rbac/rbac_service_config_parser.cc \
src/core/ext/filters/stateful_session/stateful_session_filter.cc \
src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc \
src/core/ext/gcp/metadata_query.cc \
src/core/ext/transport/chttp2/alpn/alpn.cc \
src/core/ext/transport/chttp2/client/chttp2_connector.cc \
src/core/ext/transport/chttp2/server/chttp2_server.cc \
@ -831,6 +830,7 @@ if test "$PHP_GRPC" != "no"; then
src/core/util/alloc.cc \
src/core/util/android/log.cc \
src/core/util/atm.cc \
src/core/util/gcp_metadata_query.cc \
src/core/util/http_client/format_request.cc \
src/core/util/http_client/httpcli.cc \
src/core/util/http_client/httpcli_security_connector.cc \
@ -1402,7 +1402,6 @@ if test "$PHP_GRPC" != "no"; then
PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/filters/message_size)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/filters/rbac)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/filters/stateful_session)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/gcp)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/transport/chttp2/alpn)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/transport/chttp2/client)
PHP_ADD_BUILD_DIR($ext_builddir/src/core/ext/transport/chttp2/server)

3
config.w32 generated

@ -43,7 +43,6 @@ if (PHP_GRPC != "no") {
"src\\core\\ext\\filters\\rbac\\rbac_service_config_parser.cc " +
"src\\core\\ext\\filters\\stateful_session\\stateful_session_filter.cc " +
"src\\core\\ext\\filters\\stateful_session\\stateful_session_service_config_parser.cc " +
"src\\core\\ext\\gcp\\metadata_query.cc " +
"src\\core\\ext\\transport\\chttp2\\alpn\\alpn.cc " +
"src\\core\\ext\\transport\\chttp2\\client\\chttp2_connector.cc " +
"src\\core\\ext\\transport\\chttp2\\server\\chttp2_server.cc " +
@ -796,6 +795,7 @@ if (PHP_GRPC != "no") {
"src\\core\\util\\alloc.cc " +
"src\\core\\util\\android\\log.cc " +
"src\\core\\util\\atm.cc " +
"src\\core\\util\\gcp_metadata_query.cc " +
"src\\core\\util\\http_client\\format_request.cc " +
"src\\core\\util\\http_client\\httpcli.cc " +
"src\\core\\util\\http_client\\httpcli_security_connector.cc " +
@ -1396,7 +1396,6 @@ if (PHP_GRPC != "no") {
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\filters\\message_size");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\filters\\rbac");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\filters\\stateful_session");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\gcp");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\transport");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\transport\\chttp2");
FSO.CreateFolder(base_dir+"\\ext\\grpc\\src\\core\\ext\\transport\\chttp2\\alpn");

4
gRPC-C++.podspec generated

@ -302,7 +302,6 @@ Pod::Spec.new do |s|
'src/core/ext/filters/rbac/rbac_service_config_parser.h',
'src/core/ext/filters/stateful_session/stateful_session_filter.h',
'src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h',
'src/core/ext/gcp/metadata_query.h',
'src/core/ext/transport/binder/client/binder_connector.cc',
'src/core/ext/transport/binder/client/binder_connector.h',
'src/core/ext/transport/binder/client/channel_create.cc',
@ -1304,6 +1303,7 @@ Pod::Spec.new do |s|
'src/core/tsi/transport_security_grpc.h',
'src/core/tsi/transport_security_interface.h',
'src/core/util/alloc.h',
'src/core/util/gcp_metadata_query.h',
'src/core/util/http_client/format_request.h',
'src/core/util/http_client/httpcli.h',
'src/core/util/http_client/httpcli_ssl_credentials.h',
@ -1594,7 +1594,6 @@ Pod::Spec.new do |s|
'src/core/ext/filters/rbac/rbac_service_config_parser.h',
'src/core/ext/filters/stateful_session/stateful_session_filter.h',
'src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h',
'src/core/ext/gcp/metadata_query.h',
'src/core/ext/transport/binder/client/binder_connector.h',
'src/core/ext/transport/binder/client/channel_create_impl.h',
'src/core/ext/transport/binder/client/connection_id_generator.h',
@ -2578,6 +2577,7 @@ Pod::Spec.new do |s|
'src/core/tsi/transport_security_grpc.h',
'src/core/tsi/transport_security_interface.h',
'src/core/util/alloc.h',
'src/core/util/gcp_metadata_query.h',
'src/core/util/http_client/format_request.h',
'src/core/util/http_client/httpcli.h',
'src/core/util/http_client/httpcli_ssl_credentials.h',

6
gRPC-Core.podspec generated

@ -312,8 +312,6 @@ Pod::Spec.new do |s|
'src/core/ext/filters/stateful_session/stateful_session_filter.h',
'src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc',
'src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h',
'src/core/ext/gcp/metadata_query.cc',
'src/core/ext/gcp/metadata_query.h',
'src/core/ext/transport/chttp2/alpn/alpn.cc',
'src/core/ext/transport/chttp2/alpn/alpn.h',
'src/core/ext/transport/chttp2/client/chttp2_connector.cc',
@ -2029,6 +2027,8 @@ Pod::Spec.new do |s|
'src/core/util/alloc.h',
'src/core/util/android/log.cc',
'src/core/util/atm.cc',
'src/core/util/gcp_metadata_query.cc',
'src/core/util/gcp_metadata_query.h',
'src/core/util/http_client/format_request.cc',
'src/core/util/http_client/format_request.h',
'src/core/util/http_client/httpcli.cc',
@ -2396,7 +2396,6 @@ Pod::Spec.new do |s|
'src/core/ext/filters/rbac/rbac_service_config_parser.h',
'src/core/ext/filters/stateful_session/stateful_session_filter.h',
'src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h',
'src/core/ext/gcp/metadata_query.h',
'src/core/ext/transport/chttp2/alpn/alpn.h',
'src/core/ext/transport/chttp2/client/chttp2_connector.h',
'src/core/ext/transport/chttp2/server/chttp2_server.h',
@ -3360,6 +3359,7 @@ Pod::Spec.new do |s|
'src/core/tsi/transport_security_grpc.h',
'src/core/tsi/transport_security_interface.h',
'src/core/util/alloc.h',
'src/core/util/gcp_metadata_query.h',
'src/core/util/http_client/format_request.h',
'src/core/util/http_client/httpcli.h',
'src/core/util/http_client/httpcli_ssl_credentials.h',

4
grpc.gemspec generated

@ -199,8 +199,6 @@ Gem::Specification.new do |s|
s.files += %w( src/core/ext/filters/stateful_session/stateful_session_filter.h )
s.files += %w( src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc )
s.files += %w( src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h )
s.files += %w( src/core/ext/gcp/metadata_query.cc )
s.files += %w( src/core/ext/gcp/metadata_query.h )
s.files += %w( src/core/ext/transport/chttp2/alpn/alpn.cc )
s.files += %w( src/core/ext/transport/chttp2/alpn/alpn.h )
s.files += %w( src/core/ext/transport/chttp2/client/chttp2_connector.cc )
@ -1916,6 +1914,8 @@ Gem::Specification.new do |s|
s.files += %w( src/core/util/alloc.h )
s.files += %w( src/core/util/android/log.cc )
s.files += %w( src/core/util/atm.cc )
s.files += %w( src/core/util/gcp_metadata_query.cc )
s.files += %w( src/core/util/gcp_metadata_query.h )
s.files += %w( src/core/util/http_client/format_request.cc )
s.files += %w( src/core/util/http_client/format_request.h )
s.files += %w( src/core/util/http_client/httpcli.cc )

@ -312,7 +312,7 @@
'src/core/ext/filters/server_config_selector/server_config_selector_filter.cc',
'src/core/ext/filters/stateful_session/stateful_session_filter.cc',
'src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc',
'src/core/ext/gcp/metadata_query.cc',
'src/core/util/gcp_metadata_query.cc',
'src/core/ext/transport/chttp2/alpn/alpn.cc',
'src/core/ext/transport/chttp2/client/chttp2_connector.cc',
'src/core/ext/transport/chttp2/server/chttp2_server.cc',

4
package.xml generated

@ -181,8 +181,6 @@
<file baseinstalldir="/" name="src/core/ext/filters/stateful_session/stateful_session_filter.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc" role="src" />
<file baseinstalldir="/" name="src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/gcp/metadata_query.cc" role="src" />
<file baseinstalldir="/" name="src/core/ext/gcp/metadata_query.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/transport/chttp2/alpn/alpn.cc" role="src" />
<file baseinstalldir="/" name="src/core/ext/transport/chttp2/alpn/alpn.h" role="src" />
<file baseinstalldir="/" name="src/core/ext/transport/chttp2/client/chttp2_connector.cc" role="src" />
@ -1898,6 +1896,8 @@
<file baseinstalldir="/" name="src/core/util/alloc.h" role="src" />
<file baseinstalldir="/" name="src/core/util/android/log.cc" role="src" />
<file baseinstalldir="/" name="src/core/util/atm.cc" role="src" />
<file baseinstalldir="/" name="src/core/util/gcp_metadata_query.cc" role="src" />
<file baseinstalldir="/" name="src/core/util/gcp_metadata_query.h" role="src" />
<file baseinstalldir="/" name="src/core/util/http_client/format_request.cc" role="src" />
<file baseinstalldir="/" name="src/core/util/http_client/format_request.h" role="src" />
<file baseinstalldir="/" name="src/core/util/http_client/httpcli.cc" role="src" />

@ -7199,10 +7199,10 @@ grpc_cc_library(
grpc_cc_library(
name = "gcp_metadata_query",
srcs = [
"ext/gcp/metadata_query.cc",
"util/gcp_metadata_query.cc",
],
hdrs = [
"ext/gcp/metadata_query.h",
"util/gcp_metadata_query.h",
],
external_deps = [
"absl/functional:any_invocable",

@ -33,7 +33,6 @@
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include "src/core/ext/gcp/metadata_query.h"
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/gprpp/debug_location.h"
@ -49,6 +48,7 @@
#include "src/core/resolver/resolver.h"
#include "src/core/resolver/resolver_factory.h"
#include "src/core/resolver/resolver_registry.h"
#include "src/core/util/gcp_metadata_query.h"
#include "src/core/util/json/json.h"
#include "src/core/util/json/json_writer.h"
#include "src/core/xds/grpc/xds_client_grpc.h"
@ -82,10 +82,10 @@ class GoogleCloud2ProdResolver final : public Resolver {
std::string metadata_server_name_ = "metadata.google.internal.";
bool shutdown_ = false;
OrphanablePtr<MetadataQuery> zone_query_;
OrphanablePtr<GcpMetadataQuery> zone_query_;
absl::optional<std::string> zone_;
OrphanablePtr<MetadataQuery> ipv6_query_;
OrphanablePtr<GcpMetadataQuery> ipv6_query_;
absl::optional<bool> supports_ipv6_;
};
@ -152,8 +152,8 @@ void GoogleCloud2ProdResolver::StartLocked() {
return;
}
// Using xDS. Start metadata server queries.
zone_query_ = MakeOrphanable<MetadataQuery>(
metadata_server_name_, std::string(MetadataQuery::kZoneAttribute),
zone_query_ = MakeOrphanable<GcpMetadataQuery>(
metadata_server_name_, std::string(GcpMetadataQuery::kZoneAttribute),
&pollent_,
[resolver = RefAsSubclass<GoogleCloud2ProdResolver>()](
std::string /* attribute */,
@ -166,8 +166,8 @@ void GoogleCloud2ProdResolver::StartLocked() {
DEBUG_LOCATION);
},
Duration::Seconds(10));
ipv6_query_ = MakeOrphanable<MetadataQuery>(
metadata_server_name_, std::string(MetadataQuery::kIPv6Attribute),
ipv6_query_ = MakeOrphanable<GcpMetadataQuery>(
metadata_server_name_, std::string(GcpMetadataQuery::kIPv6Attribute),
&pollent_,
[resolver = RefAsSubclass<GoogleCloud2ProdResolver>()](
std::string /* attribute */,

@ -16,7 +16,9 @@
//
//
#include "src/core/ext/gcp/metadata_query.h"
#include <grpc/support/port_platform.h>
#include "src/core/util/gcp_metadata_query.h"
#include <string.h>
@ -34,7 +36,6 @@
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/log.h>
#include <grpc/support/port_platform.h>
#include "src/core/lib/debug/trace.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
@ -47,29 +48,29 @@ namespace grpc_core {
TraceFlag grpc_metadata_query_trace(false, "metadata_query");
constexpr const char MetadataQuery::kZoneAttribute[];
constexpr const char MetadataQuery::kClusterNameAttribute[];
constexpr const char MetadataQuery::kRegionAttribute[];
constexpr const char MetadataQuery::kInstanceIdAttribute[];
constexpr const char MetadataQuery::kIPv6Attribute[];
constexpr const char GcpMetadataQuery::kZoneAttribute[];
constexpr const char GcpMetadataQuery::kClusterNameAttribute[];
constexpr const char GcpMetadataQuery::kRegionAttribute[];
constexpr const char GcpMetadataQuery::kInstanceIdAttribute[];
constexpr const char GcpMetadataQuery::kIPv6Attribute[];
MetadataQuery::MetadataQuery(
GcpMetadataQuery::GcpMetadataQuery(
std::string attribute, grpc_polling_entity* pollent,
absl::AnyInvocable<void(std::string /* attribute */,
absl::StatusOr<std::string> /* result */)>
callback,
Duration timeout)
: MetadataQuery("metadata.google.internal.", std::move(attribute), pollent,
std::move(callback), timeout) {}
: GcpMetadataQuery("metadata.google.internal.", std::move(attribute),
pollent, std::move(callback), timeout) {}
MetadataQuery::MetadataQuery(
GcpMetadataQuery::GcpMetadataQuery(
std::string metadata_server_name, std::string attribute,
grpc_polling_entity* pollent,
absl::AnyInvocable<void(std::string /* attribute */,
absl::StatusOr<std::string> /* result */)>
callback,
Duration timeout)
: InternallyRefCounted<MetadataQuery>(nullptr, 2),
: InternallyRefCounted<GcpMetadataQuery>(nullptr, 2),
attribute_(std::move(attribute)),
callback_(std::move(callback)) {
GRPC_CLOSURE_INIT(&on_done_, OnDone, this, nullptr);
@ -90,15 +91,17 @@ MetadataQuery::MetadataQuery(
http_request_->Start();
}
MetadataQuery::~MetadataQuery() { grpc_http_response_destroy(&response_); }
GcpMetadataQuery::~GcpMetadataQuery() {
grpc_http_response_destroy(&response_);
}
void MetadataQuery::Orphan() {
void GcpMetadataQuery::Orphan() {
http_request_.reset();
Unref();
}
void MetadataQuery::OnDone(void* arg, grpc_error_handle error) {
auto* self = static_cast<MetadataQuery*>(arg);
void GcpMetadataQuery::OnDone(void* arg, grpc_error_handle error) {
auto* self = static_cast<GcpMetadataQuery*>(arg);
if (GRPC_TRACE_FLAG_ENABLED(grpc_metadata_query_trace)) {
gpr_log(GPR_INFO, "MetadataServer Query for %s: HTTP status: %d, error: %s",
self->attribute_.c_str(), self->response_.status,

@ -14,16 +14,16 @@
// limitations under the License.
//
#ifndef GRPC_SRC_CORE_EXT_GCP_METADATA_QUERY_H
#define GRPC_SRC_CORE_EXT_GCP_METADATA_QUERY_H
#ifndef GRPC_SRC_CORE_UTIL_GCP_METADATA_QUERY_H
#define GRPC_SRC_CORE_UTIL_GCP_METADATA_QUERY_H
#include <grpc/support/port_platform.h>
#include <string>
#include "absl/functional/any_invocable.h"
#include "absl/status/statusor.h"
#include <grpc/support/port_platform.h>
#include "src/core/lib/gprpp/orphanable.h"
#include "src/core/lib/gprpp/time.h"
#include "src/core/lib/iomgr/closure.h"
@ -36,7 +36,7 @@ namespace grpc_core {
// Fetches the value of an attribute from the MetadataServer on a GCP
// environment.
class MetadataQuery : public InternallyRefCounted<MetadataQuery> {
class GcpMetadataQuery : public InternallyRefCounted<GcpMetadataQuery> {
public:
static constexpr const char kZoneAttribute[] =
"/computeMetadata/v1/instance/zone";
@ -49,7 +49,7 @@ class MetadataQuery : public InternallyRefCounted<MetadataQuery> {
static constexpr const char kIPv6Attribute[] =
"/computeMetadata/v1/instance/network-interfaces/0/ipv6s";
MetadataQuery(
GcpMetadataQuery(
std::string attribute, grpc_polling_entity* pollent,
absl::AnyInvocable<void(std::string /* attribute */,
absl::StatusOr<std::string> /* result */)>
@ -58,7 +58,7 @@ class MetadataQuery : public InternallyRefCounted<MetadataQuery> {
// Alternative ctor allows overriding the metadata server address, mainly
// to inject fakes in tests
MetadataQuery(
GcpMetadataQuery(
std::string metadata_server_name, std::string attribute,
grpc_polling_entity* pollent,
absl::AnyInvocable<void(std::string /* attribute */,
@ -66,7 +66,7 @@ class MetadataQuery : public InternallyRefCounted<MetadataQuery> {
callback,
Duration timeout);
~MetadataQuery() override;
~GcpMetadataQuery() override;
void Orphan() override;
@ -84,4 +84,4 @@ class MetadataQuery : public InternallyRefCounted<MetadataQuery> {
} // namespace grpc_core
#endif // GRPC_SRC_CORE_EXT_GCP_METADATA_QUERY_H
#endif // GRPC_SRC_CORE_UTIL_GCP_METADATA_QUERY_H

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

@ -52,7 +52,6 @@ CORE_SOURCE_FILES = [
'src/core/ext/filters/rbac/rbac_service_config_parser.cc',
'src/core/ext/filters/stateful_session/stateful_session_filter.cc',
'src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc',
'src/core/ext/gcp/metadata_query.cc',
'src/core/ext/transport/chttp2/alpn/alpn.cc',
'src/core/ext/transport/chttp2/client/chttp2_connector.cc',
'src/core/ext/transport/chttp2/server/chttp2_server.cc',
@ -805,6 +804,7 @@ CORE_SOURCE_FILES = [
'src/core/util/alloc.cc',
'src/core/util/android/log.cc',
'src/core/util/atm.cc',
'src/core/util/gcp_metadata_query.cc',
'src/core/util/http_client/format_request.cc',
'src/core/util/http_client/httpcli.cc',
'src/core/util/http_client/httpcli_security_connector.cc',

@ -1160,8 +1160,6 @@ src/core/ext/filters/stateful_session/stateful_session_filter.cc \
src/core/ext/filters/stateful_session/stateful_session_filter.h \
src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc \
src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h \
src/core/ext/gcp/metadata_query.cc \
src/core/ext/gcp/metadata_query.h \
src/core/ext/transport/binder/client/binder_connector.cc \
src/core/ext/transport/binder/client/binder_connector.h \
src/core/ext/transport/binder/client/channel_create.cc \
@ -2915,6 +2913,8 @@ src/core/util/alloc.cc \
src/core/util/alloc.h \
src/core/util/android/log.cc \
src/core/util/atm.cc \
src/core/util/gcp_metadata_query.cc \
src/core/util/gcp_metadata_query.h \
src/core/util/http_client/format_request.cc \
src/core/util/http_client/format_request.h \
src/core/util/http_client/httpcli.cc \

@ -964,8 +964,6 @@ src/core/ext/filters/stateful_session/stateful_session_filter.cc \
src/core/ext/filters/stateful_session/stateful_session_filter.h \
src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc \
src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h \
src/core/ext/gcp/metadata_query.cc \
src/core/ext/gcp/metadata_query.h \
src/core/ext/transport/README.md \
src/core/ext/transport/binder/README.md \
src/core/ext/transport/chttp2/README.md \
@ -2697,6 +2695,8 @@ src/core/util/alloc.cc \
src/core/util/alloc.h \
src/core/util/android/log.cc \
src/core/util/atm.cc \
src/core/util/gcp_metadata_query.cc \
src/core/util/gcp_metadata_query.h \
src/core/util/http_client/format_request.cc \
src/core/util/http_client/format_request.h \
src/core/util/http_client/httpcli.cc \

Loading…
Cancel
Save