├── .github ├── ISSUE_TEMPLATE │ ├── bug.md │ ├── feature.md │ └── question.md ├── codecov.yml ├── mergeable.yml └── workflows │ ├── codeql-analysis.yml │ ├── coverage.yml │ ├── deps.yml │ ├── lock.yml │ ├── release.yml │ ├── stale.yml │ └── testing.yml ├── AUTHORS ├── CODE-OF-CONDUCT.md ├── CONTRIBUTING.md ├── Documentation ├── anti-patterns.md ├── benchmark.md ├── compression.md ├── concurrency.md ├── encoding.md ├── grpc-auth-support.md ├── grpc-metadata.md ├── keepalive.md ├── log_levels.md ├── proxy.md ├── rpc-errors.md ├── server-reflection-tutorial.md └── versioning.md ├── GOVERNANCE.md ├── LICENSE ├── MAINTAINERS.md ├── Makefile ├── NOTICE.txt ├── README.md ├── SECURITY.md ├── admin ├── admin.go ├── admin_test.go └── test │ ├── admin_test.go │ └── utils.go ├── attributes ├── attributes.go └── attributes_test.go ├── authz ├── audit │ ├── audit_logger.go │ ├── audit_logging_test.go │ └── stdout │ │ ├── stdout_logger.go │ │ └── stdout_logger_test.go ├── grpc_authz_end2end_test.go ├── grpc_authz_server_interceptors.go ├── grpc_authz_server_interceptors_test.go ├── rbac_translator.go └── rbac_translator_test.go ├── backoff.go ├── backoff └── backoff.go ├── balancer ├── balancer.go ├── base │ ├── balancer.go │ ├── balancer_test.go │ └── base.go ├── conn_state_evaluator.go ├── conn_state_evaluator_test.go ├── endpointsharding │ ├── endpointsharding.go │ └── endpointsharding_test.go ├── grpclb │ ├── grpc_lb_v1 │ │ ├── load_balancer.pb.go │ │ └── load_balancer_grpc.pb.go │ ├── grpclb.go │ ├── grpclb_config.go │ ├── grpclb_config_test.go │ ├── grpclb_picker.go │ ├── grpclb_remote_balancer.go │ ├── grpclb_test.go │ ├── grpclb_util.go │ ├── grpclb_util_test.go │ └── state │ │ └── state.go ├── lazy │ ├── lazy.go │ └── lazy_ext_test.go ├── leastrequest │ ├── leastrequest.go │ └── leastrequest_test.go ├── pickfirst │ ├── internal │ │ └── internal.go │ ├── pickfirst.go │ ├── pickfirst_ext_test.go │ ├── pickfirst_test.go │ └── pickfirstleaf │ │ ├── metrics_test.go │ │ ├── pickfirstleaf.go │ │ ├── pickfirstleaf_ext_test.go │ │ └── pickfirstleaf_test.go ├── ringhash │ ├── config.go │ ├── config_test.go │ ├── logging.go │ ├── picker.go │ ├── picker_test.go │ ├── ring.go │ ├── ring_test.go │ ├── ringhash.go │ ├── ringhash_e2e_test.go │ └── ringhash_test.go ├── rls │ ├── balancer.go │ ├── balancer_test.go │ ├── cache.go │ ├── cache_test.go │ ├── child_policy.go │ ├── config.go │ ├── config_test.go │ ├── control_channel.go │ ├── control_channel_test.go │ ├── helpers_test.go │ ├── internal │ │ ├── adaptive │ │ │ ├── adaptive.go │ │ │ ├── adaptive_test.go │ │ │ ├── lookback.go │ │ │ └── lookback_test.go │ │ ├── keys │ │ │ ├── builder.go │ │ │ └── builder_test.go │ │ └── test │ │ │ └── e2e │ │ │ ├── e2e.go │ │ │ ├── rls_child_policy.go │ │ │ └── rls_lb_config.go │ ├── metrics_test.go │ ├── picker.go │ └── picker_test.go ├── roundrobin │ └── roundrobin.go ├── subconn.go ├── weightedroundrobin │ ├── balancer.go │ ├── balancer_test.go │ ├── config.go │ ├── internal │ │ └── internal.go │ ├── logging.go │ ├── metrics_test.go │ └── scheduler.go └── weightedtarget │ ├── logging.go │ ├── weightedaggregator │ └── aggregator.go │ ├── weightedtarget.go │ ├── weightedtarget_config.go │ ├── weightedtarget_config_test.go │ └── weightedtarget_test.go ├── balancer_wrapper.go ├── balancer_wrapper_test.go ├── benchmark ├── benchmain │ └── main.go ├── benchmark.go ├── benchresult │ └── main.go ├── client │ └── main.go ├── flags │ ├── flags.go │ └── flags_test.go ├── latency │ ├── latency.go │ └── latency_test.go ├── primitives │ ├── code_string_test.go │ ├── context_test.go │ ├── primitives_test.go │ ├── safe_config_selector_test.go │ └── syncmap_test.go ├── run_bench.sh ├── server │ └── main.go ├── stats │ ├── curve.go │ ├── histogram.go │ └── stats.go └── worker │ ├── benchmark_client.go │ ├── benchmark_server.go │ └── main.go ├── binarylog ├── binarylog_end2end_test.go ├── grpc_binarylog_v1 │ └── binarylog.pb.go └── sink.go ├── call.go ├── channelz ├── channelz.go ├── grpc_channelz_v1 │ ├── channelz.pb.go │ └── channelz_grpc.pb.go ├── internal │ └── protoconv │ │ ├── channel.go │ │ ├── server.go │ │ ├── socket.go │ │ ├── sockopt_linux.go │ │ ├── sockopt_nonlinux.go │ │ ├── subchannel.go │ │ └── util.go └── service │ ├── service.go │ ├── service_sktopt_test.go │ └── service_test.go ├── clientconn.go ├── clientconn_authority_test.go ├── clientconn_parsed_target_test.go ├── clientconn_test.go ├── cmd └── protoc-gen-go-grpc │ ├── README.md │ ├── go.mod │ ├── go.sum │ ├── grpc.go │ ├── main.go │ ├── protoc-gen-go-grpc_test.sh │ └── unimpl_test.go ├── codec.go ├── codec_test.go ├── codes ├── code_string.go ├── codes.go └── codes_test.go ├── connectivity └── connectivity.go ├── credentials ├── alts │ ├── alts.go │ ├── alts_test.go │ ├── internal │ │ ├── authinfo │ │ │ ├── authinfo.go │ │ │ └── authinfo_test.go │ │ ├── common.go │ │ ├── conn │ │ │ ├── aeadrekey.go │ │ │ ├── aeadrekey_test.go │ │ │ ├── aes128gcm.go │ │ │ ├── aes128gcm_test.go │ │ │ ├── aes128gcmrekey.go │ │ │ ├── aes128gcmrekey_test.go │ │ │ ├── common.go │ │ │ ├── counter.go │ │ │ ├── counter_test.go │ │ │ ├── record.go │ │ │ ├── record_test.go │ │ │ └── utils.go │ │ ├── handshaker │ │ │ ├── handshaker.go │ │ │ ├── handshaker_test.go │ │ │ └── service │ │ │ │ ├── service.go │ │ │ │ └── service_test.go │ │ ├── proto │ │ │ └── grpc_gcp │ │ │ │ ├── altscontext.pb.go │ │ │ │ ├── handshaker.pb.go │ │ │ │ ├── handshaker_grpc.pb.go │ │ │ │ └── transport_security_common.pb.go │ │ └── testutil │ │ │ └── testutil.go │ ├── utils.go │ └── utils_test.go ├── credentials.go ├── credentials_ext_test.go ├── credentials_test.go ├── google │ ├── google.go │ ├── google_test.go │ ├── xds.go │ └── xds_test.go ├── insecure │ └── insecure.go ├── local │ ├── local.go │ └── local_test.go ├── oauth │ ├── oauth.go │ └── oauth_test.go ├── sts │ ├── sts.go │ └── sts_test.go ├── tls.go ├── tls │ └── certprovider │ │ ├── distributor.go │ │ ├── distributor_test.go │ │ ├── pemfile │ │ ├── builder.go │ │ ├── builder_test.go │ │ ├── watcher.go │ │ └── watcher_test.go │ │ ├── provider.go │ │ ├── store.go │ │ └── store_test.go ├── tls_ext_test.go └── xds │ ├── xds.go │ ├── xds_client_test.go │ └── xds_server_test.go ├── default_dial_option_server_option_test.go ├── dialoptions.go ├── doc.go ├── encoding ├── encoding.go ├── encoding_test.go ├── encoding_v2.go ├── gzip │ └── gzip.go └── proto │ ├── proto.go │ ├── proto_benchmark_test.go │ └── proto_test.go ├── examples ├── README.md ├── data │ ├── data.go │ ├── rbac │ │ └── policy.json │ └── x509 │ │ ├── README.md │ │ ├── ca_cert.pem │ │ ├── ca_key.pem │ │ ├── client_ca_cert.pem │ │ ├── client_ca_key.pem │ │ ├── client_cert.pem │ │ ├── client_key.pem │ │ ├── create.sh │ │ ├── openssl.cnf │ │ ├── server_cert.pem │ │ └── server_key.pem ├── examples_test.sh ├── features │ ├── advancedtls │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ ├── creds │ │ │ ├── ca_cert.pem │ │ │ ├── ca_key.pem │ │ │ ├── client_cert.pem │ │ │ ├── client_cert_revoked.pem │ │ │ ├── client_key.pem │ │ │ ├── crl │ │ │ │ └── client_revoked.crl │ │ │ ├── localhost-openssl.cnf │ │ │ ├── openssl-ca.cnf │ │ │ ├── server_cert.pem │ │ │ ├── server_cert_revoked.pem │ │ │ ├── server_key.pem │ │ │ └── server_revoked.crl │ │ ├── generate.sh │ │ ├── localhost-openssl.cnf │ │ ├── openssl-ca.cnf │ │ └── server │ │ │ └── main.go │ ├── authentication │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── authz │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ ├── server │ │ │ └── main.go │ │ └── token │ │ │ └── token.go │ ├── cancellation │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── compression │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── csm_observability │ │ ├── README.md │ │ ├── client │ │ │ ├── Dockerfile │ │ │ └── main.go │ │ └── server │ │ │ ├── Dockerfile │ │ │ └── main.go │ ├── customloadbalancer │ │ ├── README.md │ │ ├── client │ │ │ ├── customroundrobin │ │ │ │ └── customroundrobin.go │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── deadline │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── debugging │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── dualstack │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── encryption │ │ ├── ALTS │ │ │ ├── client │ │ │ │ └── main.go │ │ │ └── server │ │ │ │ └── main.go │ │ ├── README.md │ │ ├── TLS │ │ │ ├── client │ │ │ │ └── main.go │ │ │ └── server │ │ │ │ └── main.go │ │ └── mTLS │ │ │ ├── client │ │ │ └── main.go │ │ │ └── server │ │ │ └── main.go │ ├── error_details │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── error_handling │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── flow_control │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── gracefulstop │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── health │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── interceptor │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── keepalive │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── load_balancing │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── metadata │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── metadata_interceptor │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── multiplex │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── name_resolving │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── observability │ │ ├── README.md │ │ ├── client │ │ │ ├── clientConfig.json │ │ │ └── main.go │ │ └── server │ │ │ ├── main.go │ │ │ └── serverConfig.json │ ├── opentelemetry │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── orca │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── proto │ │ └── echo │ │ │ ├── echo.pb.go │ │ │ ├── echo.proto │ │ │ └── echo_grpc.pb.go │ ├── reflection │ │ ├── README.md │ │ └── server │ │ │ └── main.go │ ├── retry │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── stats_monitoring │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ ├── server │ │ │ └── main.go │ │ └── statshandler │ │ │ └── handler.go │ ├── unix_abstract │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── wait_for_ready │ │ ├── README.md │ │ └── main.go │ └── xds │ │ ├── README.md │ │ ├── client │ │ └── main.go │ │ └── server │ │ └── main.go ├── go.mod ├── go.sum ├── gotutorial.md ├── helloworld │ ├── README.md │ ├── greeter_client │ │ └── main.go │ ├── greeter_server │ │ └── main.go │ └── helloworld │ │ ├── helloworld.pb.go │ │ ├── helloworld.proto │ │ └── helloworld_grpc.pb.go └── route_guide │ ├── README.md │ ├── client │ └── client.go │ ├── routeguide │ ├── route_guide.pb.go │ ├── route_guide.proto │ └── route_guide_grpc.pb.go │ ├── server │ └── server.go │ └── testdata │ └── route_guide_db.json ├── experimental ├── credentials │ ├── credentials_test.go │ ├── internal │ │ ├── spiffe.go │ │ ├── spiffe_test.go │ │ ├── syscallconn.go │ │ └── syscallconn_test.go │ ├── tls.go │ └── tls_ext_test.go ├── experimental.go ├── opentelemetry │ └── trace_options.go ├── shared_buffer_pool_test.go └── stats │ ├── metricregistry.go │ ├── metricregistry_test.go │ └── metrics.go ├── gcp └── observability │ ├── config.go │ ├── exporting.go │ ├── go.mod │ ├── go.sum │ ├── logging.go │ ├── logging_test.go │ ├── observability.go │ ├── observability_test.go │ └── opencensus.go ├── go.mod ├── go.sum ├── grpc_test.go ├── grpclog ├── component.go ├── glogger │ └── glogger.go ├── grpclog.go ├── internal │ ├── grpclog.go │ ├── logger.go │ ├── loggerv2.go │ └── loggerv2_test.go ├── logger.go └── loggerv2.go ├── health ├── client.go ├── client_test.go ├── grpc_health_v1 │ ├── health.pb.go │ └── health_grpc.pb.go ├── logging.go ├── producer.go ├── server.go ├── server_internal_test.go └── server_test.go ├── interceptor.go ├── internal ├── admin │ └── admin.go ├── backoff │ └── backoff.go ├── balancer │ ├── gracefulswitch │ │ ├── config.go │ │ ├── gracefulswitch.go │ │ └── gracefulswitch_test.go │ ├── nop │ │ └── nop.go │ ├── stub │ │ └── stub.go │ └── weight │ │ ├── weight.go │ │ └── weight_test.go ├── balancergroup │ ├── balancergroup.go │ ├── balancergroup_test.go │ └── balancerstateaggregator.go ├── balancerload │ └── load.go ├── binarylog │ ├── binarylog.go │ ├── binarylog_test.go │ ├── binarylog_testutil.go │ ├── env_config.go │ ├── env_config_test.go │ ├── method_logger.go │ ├── method_logger_test.go │ ├── regexp_test.go │ └── sink.go ├── buffer │ ├── unbounded.go │ └── unbounded_test.go ├── cache │ ├── timeoutCache.go │ └── timeoutCache_test.go ├── channelz │ ├── channel.go │ ├── channelmap.go │ ├── funcs.go │ ├── logging.go │ ├── server.go │ ├── socket.go │ ├── subchannel.go │ ├── syscall_linux.go │ ├── syscall_nonlinux.go │ ├── syscall_test.go │ └── trace.go ├── credentials │ ├── credentials.go │ ├── spiffe.go │ ├── spiffe │ │ ├── spiffe.go │ │ └── spiffe_test.go │ ├── spiffe_test.go │ ├── syscallconn.go │ ├── syscallconn_test.go │ ├── util.go │ ├── util_test.go │ └── xds │ │ ├── handshake_info.go │ │ └── handshake_info_test.go ├── envconfig │ ├── envconfig.go │ ├── envconfig_test.go │ ├── observability.go │ └── xds.go ├── experimental.go ├── googlecloud │ ├── googlecloud.go │ ├── googlecloud_test.go │ ├── manufacturer.go │ ├── manufacturer_linux.go │ └── manufacturer_windows.go ├── grpclog │ └── prefix_logger.go ├── grpcsync │ ├── callback_serializer.go │ ├── callback_serializer_test.go │ ├── event.go │ ├── event_test.go │ ├── pubsub.go │ └── pubsub_test.go ├── grpctest │ ├── example_test.go │ ├── grpctest.go │ ├── grpctest_test.go │ ├── tlogger.go │ └── tlogger_test.go ├── grpcutil │ ├── compressor.go │ ├── compressor_test.go │ ├── encode_duration.go │ ├── encode_duration_test.go │ ├── grpcutil.go │ ├── metadata.go │ ├── method.go │ ├── method_test.go │ ├── regex.go │ └── regex_test.go ├── hierarchy │ ├── hierarchy.go │ └── hierarchy_test.go ├── idle │ ├── idle.go │ ├── idle_e2e_test.go │ └── idle_test.go ├── internal.go ├── leakcheck │ ├── leakcheck.go │ ├── leakcheck_enabled.go │ └── leakcheck_test.go ├── metadata │ ├── metadata.go │ └── metadata_test.go ├── pretty │ └── pretty.go ├── profiling │ ├── buffer │ │ ├── buffer.go │ │ └── buffer_test.go │ ├── goid_modified.go │ ├── goid_regular.go │ ├── profiling.go │ └── profiling_test.go ├── proto │ └── grpc_lookup_v1 │ │ ├── rls.pb.go │ │ ├── rls_config.pb.go │ │ └── rls_grpc.pb.go ├── proxyattributes │ ├── proxyattributes.go │ └── proxyattributes_test.go ├── resolver │ ├── config_selector.go │ ├── config_selector_test.go │ ├── delegatingresolver │ │ ├── delegatingresolver.go │ │ ├── delegatingresolver_ext_test.go │ │ └── delegatingresolver_test.go │ ├── dns │ │ ├── dns_resolver.go │ │ ├── dns_resolver_test.go │ │ ├── fake_net_resolver_test.go │ │ └── internal │ │ │ └── internal.go │ ├── passthrough │ │ └── passthrough.go │ └── unix │ │ └── unix.go ├── ringhash │ └── ringhash.go ├── serviceconfig │ ├── duration.go │ ├── duration_test.go │ ├── serviceconfig.go │ └── serviceconfig_test.go ├── stats │ ├── labels.go │ ├── metrics_recorder_list.go │ └── metrics_recorder_list_test.go ├── status │ ├── status.go │ └── status_test.go ├── stubserver │ └── stubserver.go ├── syscall │ ├── syscall_linux.go │ └── syscall_nonlinux.go ├── tcp_keepalive_others.go ├── tcp_keepalive_unix.go ├── tcp_keepalive_windows.go ├── testutils │ ├── balancer.go │ ├── blocking_context_dialer.go │ ├── blocking_context_dialer_test.go │ ├── channel.go │ ├── envconfig.go │ ├── fakegrpclb │ │ └── server.go │ ├── http_client.go │ ├── local_listener.go │ ├── marshal_any.go │ ├── parse_port.go │ ├── parse_url.go │ ├── pickfirst │ │ └── pickfirst.go │ ├── pipe_listener.go │ ├── pipe_listener_test.go │ ├── proxyserver │ │ └── proxyserver.go │ ├── resolver.go │ ├── restartable_listener.go │ ├── rls │ │ └── fake_rls_server.go │ ├── roundrobin │ │ └── roundrobin.go │ ├── state.go │ ├── stats │ │ └── test_metrics_recorder.go │ ├── status_equal.go │ ├── status_equal_test.go │ ├── stubstatshandler.go │ ├── tls_creds.go │ ├── wrappers.go │ ├── wrr.go │ ├── xds │ │ ├── e2e │ │ │ ├── bootstrap.go │ │ │ ├── clientresources.go │ │ │ ├── logging.go │ │ │ ├── server.go │ │ │ └── setup │ │ │ │ └── setup.go │ │ └── fakeserver │ │ │ └── server.go │ └── xds_bootstrap.go ├── transport │ ├── bdp_estimator.go │ ├── client_stream.go │ ├── controlbuf.go │ ├── defaults.go │ ├── flowcontrol.go │ ├── grpchttp2 │ │ ├── errors.go │ │ ├── errors_test.go │ │ ├── framer.go │ │ ├── http2bridge.go │ │ └── http2bridge_test.go │ ├── handler_server.go │ ├── handler_server_test.go │ ├── http2_client.go │ ├── http2_server.go │ ├── http_util.go │ ├── http_util_test.go │ ├── keepalive_test.go │ ├── logging.go │ ├── networktype │ │ └── networktype.go │ ├── proxy.go │ ├── proxy_ext_test.go │ ├── proxy_test.go │ ├── server_stream.go │ ├── transport.go │ └── transport_test.go ├── wrr │ ├── edf.go │ ├── edf_test.go │ ├── random.go │ ├── wrr.go │ └── wrr_test.go └── xds │ ├── bootstrap │ ├── bootstrap.go │ ├── bootstrap_test.go │ ├── logging.go │ ├── template.go │ ├── template_test.go │ └── tlscreds │ │ ├── bundle.go │ │ ├── bundle_ext_test.go │ │ └── bundle_test.go │ ├── matcher │ ├── matcher_header.go │ ├── matcher_header_test.go │ ├── string_matcher.go │ └── string_matcher_test.go │ ├── rbac │ ├── converter.go │ ├── converter_test.go │ ├── matchers.go │ ├── rbac_engine.go │ └── rbac_engine_test.go │ └── xds.go ├── interop ├── alts │ ├── client │ │ └── client.go │ └── server │ │ └── server.go ├── client │ └── client.go ├── fake_grpclb │ └── fake_grpclb.go ├── grpc_testing │ ├── benchmark_service.pb.go │ ├── benchmark_service_grpc.pb.go │ ├── control.pb.go │ ├── core │ │ └── stats.pb.go │ ├── empty.pb.go │ ├── messages.pb.go │ ├── payloads.pb.go │ ├── report_qps_scenario_service.pb.go │ ├── report_qps_scenario_service_grpc.pb.go │ ├── stats.pb.go │ ├── test.pb.go │ ├── test_grpc.pb.go │ ├── worker_service.pb.go │ └── worker_service_grpc.pb.go ├── grpclb_fallback │ └── client_linux.go ├── http2 │ └── negative_http2_client.go ├── interop_test.sh ├── observability │ ├── Dockerfile │ ├── build_docker.sh │ ├── client │ │ └── client.go │ ├── go.mod │ ├── go.sum │ ├── run.sh │ └── server │ │ └── server.go ├── orcalb.go ├── server │ └── server.go ├── soak_tests.go ├── stress │ ├── client │ │ └── main.go │ ├── grpc_testing │ │ ├── metrics.pb.go │ │ ├── metrics.proto │ │ └── metrics_grpc.pb.go │ └── metrics_client │ │ └── main.go ├── test_utils.go ├── xds │ ├── client │ │ ├── Dockerfile │ │ └── client.go │ ├── custom_lb.go │ ├── custom_lb_test.go │ ├── go.mod │ ├── go.sum │ └── server │ │ ├── Dockerfile │ │ └── server.go └── xds_federation │ └── client.go ├── keepalive └── keepalive.go ├── mem ├── buffer_pool.go ├── buffer_pool_test.go ├── buffer_slice.go ├── buffer_slice_test.go ├── buffers.go └── buffers_test.go ├── metadata ├── metadata.go └── metadata_test.go ├── orca ├── call_metrics.go ├── call_metrics_test.go ├── internal │ └── internal.go ├── orca.go ├── orca_test.go ├── producer.go ├── producer_test.go ├── server_metrics.go ├── server_metrics_test.go ├── service.go └── service_test.go ├── peer ├── peer.go └── peer_test.go ├── picker_wrapper.go ├── picker_wrapper_test.go ├── preloader.go ├── producer_ext_test.go ├── profiling ├── cmd │ ├── catapult.go │ ├── flags.go │ ├── local.go │ ├── main.go │ └── remote.go ├── profiling.go ├── proto │ ├── service.pb.go │ ├── service.proto │ └── service_grpc.pb.go └── service │ └── service.go ├── reflection ├── README.md ├── adapt.go ├── grpc_reflection_v1 │ ├── reflection.pb.go │ └── reflection_grpc.pb.go ├── grpc_reflection_v1alpha │ ├── reflection.pb.go │ └── reflection_grpc.pb.go ├── grpc_testing │ ├── proto2.pb.go │ ├── proto2.proto │ ├── proto2_ext.pb.go │ ├── proto2_ext.proto │ ├── proto2_ext2.pb.go │ ├── proto2_ext2.proto │ ├── test.pb.go │ ├── test.proto │ └── test_grpc.pb.go ├── internal │ └── internal.go ├── serverreflection.go └── test │ └── serverreflection_test.go ├── resolver ├── dns │ └── dns_resolver.go ├── manual │ ├── manual.go │ └── manual_test.go ├── map.go ├── map_test.go ├── passthrough │ └── passthrough.go ├── resolver.go ├── resolver_test.go └── ringhash │ └── attr.go ├── resolver_balancer_ext_test.go ├── resolver_test.go ├── resolver_wrapper.go ├── rpc_util.go ├── rpc_util_test.go ├── scripts ├── common.sh ├── gen-deps.sh ├── install-protoc.sh ├── regenerate.sh ├── revive.toml ├── vet-proto.sh └── vet.sh ├── security └── advancedtls │ ├── advancedtls.go │ ├── advancedtls_integration_test.go │ ├── advancedtls_test.go │ ├── crl.go │ ├── crl_provider.go │ ├── crl_provider_test.go │ ├── crl_test.go │ ├── examples │ ├── credential_reloading_from_files │ │ ├── README.md │ │ ├── client │ │ │ └── main.go │ │ └── server │ │ │ └── main.go │ ├── examples_test.sh │ ├── go.mod │ └── go.sum │ ├── go.mod │ ├── go.sum │ ├── internal │ └── testutils │ │ └── testutils.go │ ├── sni.go │ └── testdata │ ├── README.md │ ├── another_client_cert_1.pem │ ├── another_client_key_1.pem │ ├── client_cert_1.pem │ ├── client_cert_2.pem │ ├── client_key_1.pem │ ├── client_key_2.pem │ ├── client_trust_cert_1.pem │ ├── client_trust_cert_2.pem │ ├── client_trust_key_1.pem │ ├── client_trust_key_2.pem │ ├── crl │ ├── 0b35a562.r0 │ ├── 0b35a562.r1 │ ├── 1.crl │ ├── 1ab871c8.r0 │ ├── 2.crl │ ├── 2f11f022.r0 │ ├── 3.crl │ ├── 4.crl │ ├── 5.crl │ ├── 6.crl │ ├── 71eac5a2.r0 │ ├── 7a1799af.r0 │ ├── 8828a7e6.r0 │ ├── README.md │ ├── deee447d.r0 │ ├── provider_client_cert.key │ ├── provider_client_cert.pem │ ├── provider_client_trust_cert.pem │ ├── provider_client_trust_key.pem │ ├── provider_create.sh │ ├── provider_crl.cnf │ ├── provider_crl_empty.pem │ ├── provider_crl_server_revoked.pem │ ├── provider_extensions.conf │ ├── provider_malicious_client_trust_cert.pem │ ├── provider_malicious_client_trust_key.pem │ ├── provider_malicious_crl_empty.pem │ ├── provider_server_cert.key │ ├── provider_server_cert.pem │ ├── provider_server_trust_cert.pem │ ├── provider_server_trust_key.pem │ ├── revokedInt.pem │ ├── revokedLeaf.pem │ └── unrevoked.pem │ ├── localhost-openssl.cnf │ ├── openssl-ca.cnf │ ├── server_cert_1.pem │ ├── server_cert_1.txt │ ├── server_cert_2.pem │ ├── server_cert_2.txt │ ├── server_cert_3.pem │ ├── server_cert_3.txt │ ├── server_cert_localhost_1.pem │ ├── server_key_1.pem │ ├── server_key_2.pem │ ├── server_key_3.pem │ ├── server_key_localhost_1.pem │ ├── server_trust_cert_1.pem │ ├── server_trust_cert_2.pem │ ├── server_trust_key_1.pem │ ├── server_trust_key_2.pem │ └── testdata.go ├── server.go ├── server_ext_test.go ├── server_test.go ├── service_config.go ├── service_config_test.go ├── serviceconfig └── serviceconfig.go ├── stats ├── handlers.go ├── metrics.go ├── opencensus │ ├── client_metrics.go │ ├── e2e_test.go │ ├── go.mod │ ├── go.sum │ ├── opencensus.go │ ├── server_metrics.go │ ├── stats.go │ └── trace.go ├── opentelemetry │ ├── client_metrics.go │ ├── client_tracing.go │ ├── csm │ │ ├── observability.go │ │ ├── observability_test.go │ │ ├── pluginoption.go │ │ └── pluginoption_test.go │ ├── e2e_test.go │ ├── example_test.go │ ├── grpc_trace_bin_propagator.go │ ├── grpc_trace_bin_propagator_test.go │ ├── internal │ │ ├── pluginoption.go │ │ ├── testutils │ │ │ └── testutils.go │ │ └── tracing │ │ │ ├── carrier.go │ │ │ └── carrier_test.go │ ├── metricsregistry_test.go │ ├── opentelemetry.go │ ├── server_metrics.go │ ├── server_tracing.go │ └── trace.go ├── stats.go └── stats_test.go ├── status ├── status.go ├── status_ext_test.go └── status_test.go ├── stream.go ├── stream_interfaces.go ├── stream_test.go ├── tap └── tap.go ├── test ├── authority_test.go ├── balancer_switching_test.go ├── balancer_test.go ├── bufconn │ ├── bufconn.go │ └── bufconn_test.go ├── channelz_linux_test.go ├── channelz_test.go ├── clientconn_state_transition_test.go ├── clientconn_test.go ├── clienttester.go ├── codec_perf │ ├── perf.pb.go │ └── perf.proto ├── compressor_test.go ├── config_selector_test.go ├── context_canceled_test.go ├── control_plane_status_test.go ├── creds_test.go ├── end2end_test.go ├── goaway_test.go ├── gracefulstop_test.go ├── healthcheck_test.go ├── http_header_end2end_test.go ├── insecure_creds_test.go ├── interceptor_test.go ├── invoke_test.go ├── kokoro │ ├── README.md │ ├── psm-csm.cfg │ ├── psm-dualstack.cfg │ ├── psm-interop-build-go.sh │ ├── psm-interop-test-go.sh │ ├── psm-light.cfg │ ├── psm-security.cfg │ ├── xds.cfg │ ├── xds.sh │ ├── xds_k8s_lb.cfg │ ├── xds_url_map.cfg │ ├── xds_v3.cfg │ └── xds_v3.sh ├── local_creds_test.go ├── logging.go ├── metadata_test.go ├── parse_config.go ├── race_test.go ├── rawConnWrapper.go ├── resolver_update_test.go ├── retry_test.go ├── roundrobin_test.go ├── server_test.go ├── servertester.go ├── stats_test.go ├── stream_cleanup_test.go ├── subconn_test.go ├── timeouts.go ├── tools │ ├── go.mod │ ├── go.sum │ ├── tools.go │ └── tools_vet.go ├── transport_test.go └── xds │ ├── xds_client_ack_nack_test.go │ ├── xds_client_affinity_test.go │ ├── xds_client_certificate_providers_test.go │ ├── xds_client_custom_lb_test.go │ ├── xds_client_federation_test.go │ ├── xds_client_ignore_resource_deletion_test.go │ ├── xds_client_integration_test.go │ ├── xds_client_outlier_detection_test.go │ ├── xds_client_priority_locality_test.go │ ├── xds_client_retry_test.go │ ├── xds_rls_clusterspecifier_plugin_test.go │ ├── xds_security_config_nack_test.go │ ├── xds_server_integration_test.go │ ├── xds_server_rbac_test.go │ └── xds_telemetry_labels_test.go ├── testdata ├── README.md ├── ca.pem ├── grpc_testing_not_regenerated │ ├── README.md │ ├── dynamic.go │ ├── dynamic.proto │ ├── simple.proto │ ├── simple_message_v1.go │ ├── testv3.go │ └── testv3.proto ├── server1.key ├── server1.pem ├── spiffe │ ├── README.md │ ├── client_spiffe.pem │ ├── server1_spiffe.pem │ ├── spiffe-openssl.cnf │ ├── spiffe_cert.pem │ ├── spiffe_multi_uri_san_cert.pem │ ├── spiffe_test.json │ ├── spiffebundle.json │ ├── spiffebundle2.json │ ├── spiffebundle_corrupted_cert.json │ ├── spiffebundle_empty_keys.json │ ├── spiffebundle_empty_string_key.json │ ├── spiffebundle_invalid_trustdomain.json │ ├── spiffebundle_malformed.json │ ├── spiffebundle_match_client_spiffe.json │ ├── spiffebundle_wrong_kid.json │ ├── spiffebundle_wrong_kty.json │ ├── spiffebundle_wrong_multi_certs.json │ ├── spiffebundle_wrong_root.json │ ├── spiffebundle_wrong_seq_type.json │ └── spiffebundle_wrong_use.json ├── spiffe_end2end │ ├── README.md │ ├── ca.key │ ├── ca.pem │ ├── client.key │ ├── client_spiffe.pem │ ├── client_spiffebundle.json │ ├── generate.sh │ ├── intermediate.cnf │ ├── intermediate_ca.key │ ├── intermediate_ca.pem │ ├── intermediate_gen.sh │ ├── leaf_and_intermediate_chain.pem │ ├── leaf_signed_by_intermediate.key │ ├── leaf_signed_by_intermediate.pem │ ├── server.key │ ├── server_spiffe.pem │ ├── server_spiffebundle.json │ └── spiffe-openssl.cnf ├── testdata.go └── x509 │ ├── README.md │ ├── client1_cert.pem │ ├── client1_key.pem │ ├── client2_cert.pem │ ├── client2_key.pem │ ├── client_ca_cert.pem │ ├── client_ca_key.pem │ ├── client_with_spiffe_cert.pem │ ├── client_with_spiffe_key.pem │ ├── client_with_spiffe_openssl.cnf │ ├── create.sh │ ├── multiple_uri_cert.pem │ ├── multiple_uri_key.pem │ ├── openssl.cnf │ ├── server1_cert.pem │ ├── server1_key.pem │ ├── server2_cert.pem │ ├── server2_key.pem │ ├── server_ca_cert.pem │ ├── server_ca_key.pem │ ├── spiffe_cert.pem │ └── spiffe_key.pem ├── trace.go ├── trace_notrace.go ├── trace_test.go ├── trace_withtrace.go ├── version.go └── xds ├── bootstrap ├── bootstrap.go ├── bootstrap_test.go └── credentials.go ├── csds ├── csds.go └── csds_e2e_test.go ├── googledirectpath ├── googlec2p.go ├── googlec2p_test.go └── utils.go ├── internal ├── balancer │ ├── balancer.go │ ├── cdsbalancer │ │ ├── aggregate_cluster_test.go │ │ ├── cdsbalancer.go │ │ ├── cdsbalancer_security_test.go │ │ ├── cdsbalancer_test.go │ │ ├── cluster_watcher.go │ │ └── logging.go │ ├── clusterimpl │ │ ├── balancer_test.go │ │ ├── clusterimpl.go │ │ ├── config.go │ │ ├── config_test.go │ │ ├── logging.go │ │ ├── picker.go │ │ └── tests │ │ │ └── balancer_test.go │ ├── clustermanager │ │ ├── balancerstateaggregator.go │ │ ├── clustermanager.go │ │ ├── clustermanager_test.go │ │ ├── config.go │ │ ├── config_test.go │ │ ├── e2e_test │ │ │ └── clustermanager_test.go │ │ └── picker.go │ ├── clusterresolver │ │ ├── clusterresolver.go │ │ ├── clusterresolver_test.go │ │ ├── config.go │ │ ├── config_test.go │ │ ├── configbuilder.go │ │ ├── configbuilder_childname.go │ │ ├── configbuilder_childname_test.go │ │ ├── configbuilder_test.go │ │ ├── e2e_test │ │ │ ├── aggregate_cluster_test.go │ │ │ ├── balancer_test.go │ │ │ └── eds_impl_test.go │ │ ├── logging.go │ │ ├── resource_resolver.go │ │ ├── resource_resolver_dns.go │ │ └── resource_resolver_eds.go │ ├── loadstore │ │ └── load_store_wrapper.go │ ├── outlierdetection │ │ ├── balancer.go │ │ ├── balancer_test.go │ │ ├── callcounter.go │ │ ├── callcounter_test.go │ │ ├── config.go │ │ ├── config_test.go │ │ ├── e2e_test │ │ │ └── outlierdetection_test.go │ │ ├── logging.go │ │ └── subconn_wrapper.go │ ├── priority │ │ ├── balancer.go │ │ ├── balancer_child.go │ │ ├── balancer_priority.go │ │ ├── balancer_test.go │ │ ├── config.go │ │ ├── config_test.go │ │ ├── ignore_resolve_now.go │ │ ├── ignore_resolve_now_test.go │ │ ├── logging.go │ │ ├── utils.go │ │ └── utils_test.go │ └── wrrlocality │ │ ├── balancer.go │ │ ├── balancer_test.go │ │ └── logging.go ├── clients │ ├── config.go │ ├── grpctransport │ │ ├── examples_test.go │ │ ├── grpc_transport.go │ │ ├── grpc_transport_ext_test.go │ │ └── grpc_transport_test.go │ ├── internal │ │ ├── backoff │ │ │ └── backoff.go │ │ ├── buffer │ │ │ ├── unbounded.go │ │ │ └── unbounded_test.go │ │ ├── internal.go │ │ ├── internal_test.go │ │ ├── pretty │ │ │ └── pretty.go │ │ ├── syncutil │ │ │ ├── callback_serializer.go │ │ │ ├── callback_serializer_test.go │ │ │ ├── event.go │ │ │ └── event_test.go │ │ └── testutils │ │ │ ├── channel.go │ │ │ ├── e2e │ │ │ ├── clientresources.go │ │ │ ├── logging.go │ │ │ └── server.go │ │ │ ├── fakeserver │ │ │ └── server.go │ │ │ ├── marshal_any.go │ │ │ ├── restartable_listener.go │ │ │ └── wrappers.go │ ├── lrsclient │ │ ├── internal │ │ │ └── internal.go │ │ ├── load_store.go │ │ ├── load_store_test.go │ │ ├── loadreport_test.go │ │ ├── logging.go │ │ ├── lrs_stream.go │ │ ├── lrsclient.go │ │ └── lrsconfig.go │ ├── transport_builder.go │ └── xdsclient │ │ ├── ads_stream.go │ │ ├── authority.go │ │ ├── channel.go │ │ ├── channel_test.go │ │ ├── clientimpl_watchers.go │ │ ├── helpers_test.go │ │ ├── internal │ │ ├── internal.go │ │ └── xdsresource │ │ │ ├── ads_stream.go │ │ │ ├── errors.go │ │ │ ├── name.go │ │ │ ├── type.go │ │ │ └── version.go │ │ ├── logging.go │ │ ├── metrics │ │ └── metrics.go │ │ ├── resource_type.go │ │ ├── resource_watcher.go │ │ ├── test │ │ ├── ads_stream_ack_nack_test.go │ │ ├── ads_stream_backoff_test.go │ │ ├── ads_stream_flow_control_test.go │ │ ├── ads_stream_restart_test.go │ │ ├── ads_stream_watch_test.go │ │ ├── authority_test.go │ │ ├── dump_test.go │ │ ├── helpers_test.go │ │ ├── lds_watchers_test.go │ │ ├── metrics_test.go │ │ └── misc_watchers_test.go │ │ ├── xdsclient.go │ │ ├── xdsclient_test.go │ │ └── xdsconfig.go ├── clusterspecifier │ ├── cluster_specifier.go │ └── rls │ │ ├── rls.go │ │ └── rls_test.go ├── httpfilter │ ├── fault │ │ ├── fault.go │ │ └── fault_test.go │ ├── httpfilter.go │ ├── rbac │ │ └── rbac.go │ └── router │ │ └── router.go ├── internal.go ├── internal_test.go ├── resolver │ ├── cluster_specifier_plugin_test.go │ ├── helpers_test.go │ ├── internal │ │ └── internal.go │ ├── logging.go │ ├── serviceconfig.go │ ├── serviceconfig_test.go │ ├── watch_service.go │ ├── watch_service_test.go │ ├── xds_resolver.go │ └── xds_resolver_test.go ├── server │ ├── conn_wrapper.go │ ├── listener_wrapper.go │ ├── rds_handler.go │ └── rds_handler_test.go ├── test │ └── e2e │ │ ├── README.md │ │ ├── controlplane.go │ │ ├── e2e.go │ │ ├── e2e_test.go │ │ ├── e2e_utils.go │ │ └── run.sh ├── testutils │ ├── balancer_test.go │ ├── fakeclient │ │ └── client.go │ ├── resource_watcher.go │ └── testutils.go └── xdsclient │ ├── attributes.go │ ├── authority.go │ ├── channel.go │ ├── channel_test.go │ ├── client.go │ ├── client_refcounted_test.go │ ├── client_test.go │ ├── clientimpl.go │ ├── clientimpl_loadreport.go │ ├── clientimpl_watchers.go │ ├── internal │ └── internal.go │ ├── load │ ├── reporter.go │ ├── store.go │ └── store_test.go │ ├── logging.go │ ├── metrics_test.go │ ├── pool.go │ ├── pool │ └── pool_test.go │ ├── requests_counter.go │ ├── requests_counter_test.go │ ├── tests │ ├── ads_stream_ack_nack_test.go │ ├── ads_stream_backoff_test.go │ ├── ads_stream_flow_control_test.go │ ├── ads_stream_restart_test.go │ ├── ads_stream_watch_test.go │ ├── authority_test.go │ ├── cds_watchers_test.go │ ├── client_custom_dialopts_test.go │ ├── dump_test.go │ ├── eds_watchers_test.go │ ├── fallback_test.go │ ├── federation_watchers_test.go │ ├── helpers_test.go │ ├── lds_watchers_test.go │ ├── loadreport_test.go │ ├── misc_watchers_test.go │ ├── rds_watchers_test.go │ └── resource_update_test.go │ ├── transport │ ├── ads │ │ └── ads_stream.go │ ├── grpctransport │ │ ├── grpctransport.go │ │ └── grpctransport_ext_test.go │ ├── lrs │ │ └── lrs_stream.go │ └── transport_interface.go │ ├── xdsclient_test.go │ ├── xdslbregistry │ ├── converter │ │ └── converter.go │ ├── xdslbregistry.go │ └── xdslbregistry_test.go │ └── xdsresource │ ├── cluster_resource_type.go │ ├── endpoints_resource_type.go │ ├── errors.go │ ├── filter_chain.go │ ├── filter_chain_test.go │ ├── listener_resource_type.go │ ├── logging.go │ ├── matcher.go │ ├── matcher_path.go │ ├── matcher_path_test.go │ ├── matcher_test.go │ ├── name.go │ ├── name_test.go │ ├── resource_type.go │ ├── route_config_resource_type.go │ ├── test_utils_test.go │ ├── tests │ └── unmarshal_cds_test.go │ ├── type.go │ ├── type_cds.go │ ├── type_eds.go │ ├── type_lds.go │ ├── type_rds.go │ ├── unmarshal_cds.go │ ├── unmarshal_cds_test.go │ ├── unmarshal_eds.go │ ├── unmarshal_eds_test.go │ ├── unmarshal_lds.go │ ├── unmarshal_lds_test.go │ ├── unmarshal_rds.go │ ├── unmarshal_rds_test.go │ └── version │ └── version.go ├── server.go ├── server_ext_test.go ├── server_options.go ├── server_resource_ext_test.go ├── server_security_ext_test.go ├── server_serving_mode_ext_test.go ├── server_test.go ├── test └── eds_resource_missing_test.go └── xds.go /.github/ISSUE_TEMPLATE/bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Report a non-security bug. For suspected security vulnerabilities or crashes, please use "Report a Security Vulnerability", below. 4 | labels: 'Type: Bug' 5 | 6 | --- 7 | 8 | NOTE: if you are reporting is a potential security vulnerability or a crash, 9 | please follow our CVE process at 10 | https://github.com/grpc/proposal/blob/master/P4-grpc-cve-process.md instead of 11 | filing an issue here. 12 | 13 | Please see the FAQ in our main README.md, then answer the questions below 14 | before submitting your issue. 15 | 16 | ### What version of gRPC are you using? 17 | 18 | ### What version of Go are you using (`go version`)? 19 | 20 | ### What operating system (Linux, Windows, …) and version? 21 | 22 | ### What did you do? 23 | If possible, provide a recipe for reproducing the error. 24 | 25 | ### What did you expect to see? 26 | 27 | ### What did you see instead? 28 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an idea for gRPC-Go 4 | labels: 'Type: Feature' 5 | 6 | --- 7 | 8 | Please see the FAQ in our main README.md before submitting your issue. 9 | 10 | ### Use case(s) - what problem will this feature solve? 11 | 12 | ### Proposed Solution 13 | 14 | ### Alternatives Considered 15 | 16 | ### Additional Context 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: Ask a question about gRPC-Go 4 | labels: 'Type: Question' 5 | 6 | --- 7 | 8 | Please see the FAQ in our main README.md before submitting your issue. 9 | -------------------------------------------------------------------------------- /.github/codecov.yml: -------------------------------------------------------------------------------- 1 | coverage: 2 | status: 3 | project: 4 | default: 5 | informational: true 6 | patch: 7 | default: 8 | informational: true 9 | ignore: 10 | # All 'pb.go's. 11 | - "**/*.pb.go" 12 | # Tests and test related files. 13 | - "**/test" 14 | - "**/testdata" 15 | - "**/testutils" 16 | - "benchmark" 17 | - "interop" 18 | # Other submodules. 19 | - "cmd" 20 | - "examples" 21 | - "gcp" 22 | - "security" 23 | - "stats/opencensus" 24 | comment: 25 | layout: "header, diff, files" 26 | -------------------------------------------------------------------------------- /.github/mergeable.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | mergeable: 3 | - when: pull_request.* 4 | validate: 5 | - do: label 6 | must_include: 7 | regex: '^Type:' 8 | - do: description 9 | must_include: 10 | # Allow: 11 | # RELEASE NOTES: none (case insensitive) 12 | # 13 | # RELEASE NOTES: N/A (case insensitive) 14 | # 15 | # RELEASE NOTES: 16 | # * 17 | regex: '^RELEASE NOTES:\s*([Nn][Oo][Nn][Ee]|[Nn]/[Aa]|\n(\*|-)\s*.+)$' 18 | regex_flag: 'm' 19 | - do: milestone 20 | must_include: 21 | regex: 'Release$' 22 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: "CodeQL" 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | schedule: 7 | - cron: '24 20 * * 3' 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | analyze: 14 | name: Analyze 15 | runs-on: ubuntu-latest 16 | timeout-minutes: 30 17 | 18 | permissions: 19 | security-events: write 20 | pull-requests: read 21 | actions: read 22 | 23 | strategy: 24 | fail-fast: false 25 | 26 | steps: 27 | - name: Checkout repository 28 | uses: actions/checkout@v4 29 | 30 | # Initializes the CodeQL tools for scanning. 31 | - name: Initialize CodeQL 32 | uses: github/codeql-action/init@v2 33 | with: 34 | languages: go 35 | 36 | - name: Perform CodeQL Analysis 37 | uses: github/codeql-action/analyze@v2 38 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | name: codecov 2 | on: [push, pull_request] 3 | 4 | permissions: 5 | contents: read 6 | 7 | jobs: 8 | upload: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Install checkout 12 | uses: actions/checkout@v4 13 | 14 | - name: Install checkout 15 | uses: actions/setup-go@v5 16 | with: 17 | go-version: "stable" 18 | 19 | - name: Run coverage 20 | run: go test -coverprofile=coverage.out -coverpkg=./... ./... 21 | 22 | - name: Run coverage with old pickfirst 23 | run: GRPC_EXPERIMENTAL_ENABLE_NEW_PICK_FIRST=false go test -coverprofile=coverage_old_pickfirst.out -coverpkg=./... ./... 24 | 25 | - name: Upload coverage to Codecov 26 | uses: codecov/codecov-action@v4 27 | with: 28 | token: ${{ secrets.CODECOV_TOKEN }} 29 | fail_ci_if_error: true 30 | -------------------------------------------------------------------------------- /.github/workflows/lock.yml: -------------------------------------------------------------------------------- 1 | name: 'Lock Threads' 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: '22 1 * * *' 7 | 8 | permissions: 9 | contents: read 10 | 11 | jobs: 12 | lock: 13 | runs-on: ubuntu-latest 14 | permissions: 15 | issues: write 16 | pull-requests: write 17 | steps: 18 | - uses: dessant/lock-threads@v5 19 | with: 20 | github-token: ${{ github.token }} 21 | issue-inactive-days: 180 22 | pr-inactive-days: 180 23 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | name: Stale bot 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: "44 */2 * * *" 7 | 8 | permissions: 9 | contents: read 10 | 11 | jobs: 12 | stale: 13 | runs-on: ubuntu-latest 14 | permissions: 15 | issues: write 16 | pull-requests: write 17 | 18 | steps: 19 | - uses: actions/stale@v8 20 | with: 21 | repo-token: ${{ secrets.GITHUB_TOKEN }} 22 | days-before-stale: 6 23 | days-before-close: 7 24 | only-labels: 'Status: Requires Reporter Clarification' 25 | stale-issue-label: 'stale' 26 | stale-pr-label: 'stale' 27 | operations-per-run: 999 28 | stale-issue-message: > 29 | This issue is labeled as requiring an update from the reporter, and no update has been received 30 | after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. 31 | stale-pr-message: > 32 | This PR is labeled as requiring an update from the reporter, and no update has been received 33 | after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. 34 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Google Inc. 2 | -------------------------------------------------------------------------------- /CODE-OF-CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Community Code of Conduct 2 | 3 | gRPC follows the [CNCF Code of Conduct](https://github.com/cncf/foundation/blob/master/code-of-conduct.md). 4 | -------------------------------------------------------------------------------- /Documentation/proxy.md: -------------------------------------------------------------------------------- 1 | # Proxy 2 | 3 | HTTP CONNECT proxies are supported by default in gRPC. The proxy address can be 4 | specified by the environment variables `HTTPS_PROXY` and `NO_PROXY`. (Note that 5 | these environment variables are case insensitive.) 6 | 7 | ## Custom proxy 8 | 9 | Currently, proxy support is implemented in the default dialer. It does one more 10 | handshake (a CONNECT handshake in the case of HTTP CONNECT proxy) on the 11 | connection before giving it to gRPC. 12 | 13 | If the default proxy doesn't work for you, replace the default dialer with your 14 | custom proxy dialer. This can be done using 15 | [`WithContextDialer`](https://pkg.go.dev/google.golang.org/grpc#WithContextDialer). 16 | -------------------------------------------------------------------------------- /Documentation/versioning.md: -------------------------------------------------------------------------------- 1 | # Versioning and Releases 2 | 3 | Note: This document references terminology defined at http://semver.org. 4 | 5 | ## Release Frequency 6 | 7 | Regular MINOR releases of gRPC-Go are performed every six weeks. Patch releases 8 | to the previous two MINOR releases may be performed on demand or if serious 9 | security problems are discovered. 10 | 11 | ## Versioning Policy 12 | 13 | The gRPC-Go versioning policy follows the Semantic Versioning 2.0.0 14 | specification, with the following exceptions: 15 | 16 | - A MINOR version will not _necessarily_ add new functionality. 17 | 18 | - MINOR releases will not break backward compatibility, except in the following 19 | circumstances: 20 | 21 | - An API was marked as EXPERIMENTAL upon its introduction. 22 | - An API was marked as DEPRECATED in the initial MAJOR release. 23 | - An API is inherently flawed and cannot provide correct or secure behavior. 24 | 25 | In these cases, APIs MAY be changed or removed without a MAJOR release. 26 | Otherwise, backward compatibility will be preserved by MINOR releases. 27 | 28 | For an API marked as DEPRECATED, an alternative will be available (if 29 | appropriate) for at least three months prior to its removal. 30 | 31 | ## Release History 32 | 33 | Please see our release history on GitHub: 34 | https://github.com/grpc/grpc-go/releases 35 | -------------------------------------------------------------------------------- /GOVERNANCE.md: -------------------------------------------------------------------------------- 1 | This repository is governed by the gRPC organization's [governance rules](https://github.com/grpc/grpc-community/blob/master/governance.md). 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: vet test testrace 2 | 3 | build: 4 | go build google.golang.org/grpc/... 5 | 6 | clean: 7 | go clean -i google.golang.org/grpc/... 8 | 9 | deps: 10 | GO111MODULE=on go get -d -v google.golang.org/grpc/... 11 | 12 | proto: 13 | @ if ! which protoc > /dev/null; then \ 14 | echo "error: protoc not installed" >&2; \ 15 | exit 1; \ 16 | fi 17 | go generate google.golang.org/grpc/... 18 | 19 | test: 20 | go test -cpu 1,4 -timeout 7m google.golang.org/grpc/... 21 | 22 | testsubmodule: 23 | cd security/advancedtls && go test -cpu 1,4 -timeout 7m google.golang.org/grpc/security/advancedtls/... 24 | cd security/authorization && go test -cpu 1,4 -timeout 7m google.golang.org/grpc/security/authorization/... 25 | 26 | testrace: 27 | go test -race -cpu 1,4 -timeout 7m google.golang.org/grpc/... 28 | 29 | testdeps: 30 | GO111MODULE=on go get -d -v -t google.golang.org/grpc/... 31 | 32 | vet: vetdeps 33 | ./scripts/vet.sh 34 | 35 | vetdeps: 36 | ./scripts/vet.sh -install 37 | 38 | .PHONY: \ 39 | all \ 40 | build \ 41 | clean \ 42 | deps \ 43 | proto \ 44 | test \ 45 | testsubmodule \ 46 | testrace \ 47 | testdeps \ 48 | vet \ 49 | vetdeps 50 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2014 gRPC authors. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | For information on gRPC Security Policy and reporting potential security issues, please see [gRPC CVE Process](https://github.com/grpc/proposal/blob/master/P4-grpc-cve-process.md). 4 | -------------------------------------------------------------------------------- /admin/admin_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package admin_test 20 | 21 | import ( 22 | "testing" 23 | 24 | "google.golang.org/grpc/admin/test" 25 | "google.golang.org/grpc/codes" 26 | ) 27 | 28 | func TestRegisterNoCSDS(t *testing.T) { 29 | test.RunRegisterTests(t, test.ExpectedStatusCodes{ 30 | ChannelzCode: codes.OK, 31 | // CSDS is not registered because xDS isn't imported. 32 | CSDSCode: codes.Unimplemented, 33 | }) 34 | } 35 | -------------------------------------------------------------------------------- /admin/test/admin_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // This file has the same content as admin_test.go, difference is that this is 20 | // in another package, and it imports "xds", so we can test that csds is 21 | // registered when xds is imported. 22 | 23 | package test_test 24 | 25 | import ( 26 | "testing" 27 | 28 | "google.golang.org/grpc/admin/test" 29 | "google.golang.org/grpc/codes" 30 | _ "google.golang.org/grpc/xds" 31 | ) 32 | 33 | func TestRegisterWithCSDS(t *testing.T) { 34 | test.RunRegisterTests(t, test.ExpectedStatusCodes{ 35 | ChannelzCode: codes.OK, 36 | CSDSCode: codes.OK, 37 | }) 38 | } 39 | -------------------------------------------------------------------------------- /balancer/pickfirst/internal/internal.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | // Package internal contains code internal to the pickfirst package. 19 | package internal 20 | 21 | import ( 22 | rand "math/rand/v2" 23 | "time" 24 | ) 25 | 26 | var ( 27 | // RandShuffle pseudo-randomizes the order of addresses. 28 | RandShuffle = rand.Shuffle 29 | // TimeAfterFunc allows mocking the timer for testing connection delay 30 | // related functionality. 31 | TimeAfterFunc = func(d time.Duration, f func()) func() { 32 | timer := time.AfterFunc(d, f) 33 | return func() { timer.Stop() } 34 | } 35 | ) 36 | -------------------------------------------------------------------------------- /balancer/ringhash/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package ringhash 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | const prefix = "[ring-hash-lb %p] " 29 | 30 | var logger = grpclog.Component("xds") 31 | 32 | func prefixLogger(p *ringhashBalancer) *internalgrpclog.PrefixLogger { 33 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) 34 | } 35 | -------------------------------------------------------------------------------- /balancer/rls/internal/test/e2e/e2e.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package e2e contains utilities for end-to-end RouteLookupService tests. 20 | package e2e 21 | -------------------------------------------------------------------------------- /balancer/weightedroundrobin/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2023 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package weightedroundrobin 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | const prefix = "[%p] " 29 | 30 | var logger = grpclog.Component("weighted-round-robin") 31 | 32 | func prefixLogger(p *wrrBalancer) *internalgrpclog.PrefixLogger { 33 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) 34 | } 35 | -------------------------------------------------------------------------------- /balancer/weightedtarget/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package weightedtarget 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | const prefix = "[weighted-target-lb %p] " 29 | 30 | var logger = grpclog.Component("xds") 31 | 32 | func prefixLogger(p *weightedTargetBalancer) *internalgrpclog.PrefixLogger { 33 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) 34 | } 35 | -------------------------------------------------------------------------------- /channelz/channelz.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package channelz exports internals of the channelz implementation as required 20 | // by other gRPC packages. 21 | // 22 | // The implementation of the channelz spec as defined in 23 | // https://github.com/grpc/proposal/blob/master/A14-channelz.md, is provided by 24 | // the `internal/channelz` package. 25 | // 26 | // # Experimental 27 | // 28 | // Notice: All APIs in this package are experimental and may be removed in a 29 | // later release. 30 | package channelz 31 | 32 | import "google.golang.org/grpc/internal/channelz" 33 | 34 | // Identifier is an opaque identifier which uniquely identifies an entity in the 35 | // channelz database. 36 | type Identifier = channelz.Identifier 37 | -------------------------------------------------------------------------------- /channelz/internal/protoconv/sockopt_nonlinux.go: -------------------------------------------------------------------------------- 1 | //go:build !linux 2 | // +build !linux 3 | 4 | /* 5 | * 6 | * Copyright 2018 gRPC authors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | package protoconv 23 | 24 | import ( 25 | channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1" 26 | "google.golang.org/grpc/internal/channelz" 27 | ) 28 | 29 | func sockoptToProto(_ *channelz.SocketOptionData) []*channelzpb.SocketOption { 30 | return nil 31 | } 32 | -------------------------------------------------------------------------------- /channelz/internal/protoconv/util.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2024 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package protoconv supports converting between the internal channelz 20 | // implementation and the protobuf representation of all the entities. 21 | package protoconv 22 | 23 | func strFromPointer(s *string) string { 24 | if s == nil { 25 | return "" 26 | } 27 | return *s 28 | } 29 | -------------------------------------------------------------------------------- /cmd/protoc-gen-go-grpc/README.md: -------------------------------------------------------------------------------- 1 | # protoc-gen-go-grpc 2 | 3 | This tool generates Go language bindings of `service`s in protobuf definition 4 | files for gRPC. For usage information, please see our [quick start 5 | guide](https://grpc.io/docs/languages/go/quickstart/). 6 | 7 | ## Future-proofing services 8 | 9 | By default, to register services using the methods generated by this tool, the 10 | service implementations must embed the corresponding 11 | `UnimplementedServer` for future compatibility. This is a behavior 12 | change from the grpc code generator previously included with `protoc-gen-go`. 13 | To restore this behavior, set the option `require_unimplemented_servers=false`. 14 | E.g.: 15 | 16 | ```sh 17 | protoc --go-grpc_out=. --go-grpc_opt=require_unimplemented_servers=false[,other options...] \ 18 | ``` 19 | 20 | Note that this is not recommended, and the option is only provided to restore 21 | backward compatibility with previously-generated code. 22 | 23 | When embedding the `UnimplementedServer` in a struct that 24 | implements the service, it should be embedded by _value_ instead of as a 25 | _pointer_. If it is embedded as a pointer, it must be assigned to a valid, 26 | non-nil pointer or else unimplemented methods would panic when called. This is 27 | tested at service registration time, and will lead to a panic in 28 | `RegisterServer` if it is not embedded properly. 29 | -------------------------------------------------------------------------------- /cmd/protoc-gen-go-grpc/go.mod: -------------------------------------------------------------------------------- 1 | module google.golang.org/grpc/cmd/protoc-gen-go-grpc 2 | 3 | go 1.23 4 | 5 | require ( 6 | google.golang.org/grpc v1.70.0 7 | google.golang.org/protobuf v1.36.6 8 | ) 9 | 10 | require ( 11 | go.opentelemetry.io/otel v1.34.0 // indirect 12 | go.opentelemetry.io/otel/sdk/metric v1.34.0 // indirect 13 | golang.org/x/net v0.34.0 // indirect 14 | golang.org/x/sys v0.29.0 // indirect 15 | golang.org/x/text v0.21.0 // indirect 16 | google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect 17 | ) 18 | -------------------------------------------------------------------------------- /cmd/protoc-gen-go-grpc/unimpl_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2024 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package main_test 20 | 21 | import ( 22 | "testing" 23 | 24 | "google.golang.org/grpc" 25 | testgrpc "google.golang.org/grpc/interop/grpc_testing" 26 | ) 27 | 28 | type unimplEmbeddedByPointer struct { 29 | *testgrpc.UnimplementedTestServiceServer 30 | } 31 | 32 | type unimplEmbeddedByValue struct { 33 | testgrpc.UnimplementedTestServiceServer 34 | } 35 | 36 | func TestUnimplementedEmbedding(t *testing.T) { 37 | // Embedded by value, this should succeed. 38 | testgrpc.RegisterTestServiceServer(grpc.NewServer(), &unimplEmbeddedByValue{}) 39 | defer func() { 40 | if recover() == nil { 41 | t.Fatalf("Expected panic; received none") 42 | } 43 | }() 44 | 45 | // Embedded by pointer, this should panic. 46 | testgrpc.RegisterTestServiceServer(grpc.NewServer(), &unimplEmbeddedByPointer{}) 47 | } 48 | -------------------------------------------------------------------------------- /codec_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2014 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "testing" 23 | 24 | "google.golang.org/grpc/encoding" 25 | "google.golang.org/grpc/encoding/proto" 26 | ) 27 | 28 | func (s) TestGetCodecForProtoIsNotNil(t *testing.T) { 29 | if encoding.GetCodecV2(proto.Name) == nil { 30 | t.Fatalf("encoding.GetCodec(%q) must not be nil by default", proto.Name) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | //go:generate ./scripts/regenerate.sh 20 | 21 | /* 22 | Package grpc implements an RPC system called gRPC. 23 | 24 | See grpc.io for more information about gRPC. 25 | */ 26 | package grpc // import "google.golang.org/grpc" 27 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | The following examples are provided to help users get started with gRPC-Go. 4 | They are arranged as follows: 5 | 6 | * `helloworld` - a simple example showing a basic client and server 7 | * `routeguide` - a more complicated example showing different types of streaming RPCs 8 | * `features` - a collection of examples, each focused on a single gRPC feature 9 | 10 | `data` is a directory containing data used by the examples, e.g. TLS certificates. 11 | -------------------------------------------------------------------------------- /examples/data/data.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | // Package data provides convenience routines to access files in the data 19 | // directory. 20 | package data 21 | 22 | import ( 23 | "path/filepath" 24 | "runtime" 25 | ) 26 | 27 | // basepath is the root directory of this package. 28 | var basepath string 29 | 30 | func init() { 31 | _, currentFile, _, _ := runtime.Caller(0) 32 | basepath = filepath.Dir(currentFile) 33 | } 34 | 35 | // Path returns the absolute path the given relative file or directory path, 36 | // relative to the google.golang.org/grpc/examples/data directory in the 37 | // user's GOPATH. If rel is already absolute, it is returned unmodified. 38 | func Path(rel string) string { 39 | if filepath.IsAbs(rel) { 40 | return rel 41 | } 42 | 43 | return filepath.Join(basepath, rel) 44 | } 45 | -------------------------------------------------------------------------------- /examples/data/rbac/policy.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "authz", 3 | "allow_rules": [ 4 | { 5 | "name": "allow_UnaryEcho", 6 | "request": { 7 | "paths": ["/grpc.examples.echo.Echo/UnaryEcho"], 8 | "headers": [ 9 | { 10 | "key": "UNARY_ECHO:RW", 11 | "values": ["true"] 12 | } 13 | ] 14 | } 15 | }, 16 | { 17 | "name": "allow_BidirectionalStreamingEcho", 18 | "request": { 19 | "paths": ["/grpc.examples.echo.Echo/BidirectionalStreamingEcho"], 20 | "headers": [ 21 | { 22 | "key": "STREAM_ECHO:RW", 23 | "values": ["true"] 24 | } 25 | ] 26 | } 27 | } 28 | ], 29 | "deny_rules": [] 30 | } 31 | -------------------------------------------------------------------------------- /examples/data/x509/README.md: -------------------------------------------------------------------------------- 1 | This directory contains x509 certificates and associated private keys used in 2 | examples. 3 | 4 | How were these test certs/keys generated ? 5 | ------------------------------------------ 6 | Run `./create.sh` 7 | -------------------------------------------------------------------------------- /examples/data/x509/openssl.cnf: -------------------------------------------------------------------------------- 1 | [req] 2 | distinguished_name = req_distinguished_name 3 | attributes = req_attributes 4 | 5 | [req_distinguished_name] 6 | 7 | [req_attributes] 8 | 9 | [test_ca] 10 | basicConstraints = critical,CA:TRUE 11 | subjectKeyIdentifier = hash 12 | authorityKeyIdentifier = keyid:always,issuer:always 13 | keyUsage = critical,keyCertSign 14 | 15 | [test_server] 16 | basicConstraints = critical,CA:FALSE 17 | subjectKeyIdentifier = hash 18 | keyUsage = critical,digitalSignature,keyEncipherment,keyAgreement 19 | subjectAltName = @server_alt_names 20 | 21 | [server_alt_names] 22 | DNS.1 = *.test.example.com 23 | 24 | [test_client] 25 | basicConstraints = critical,CA:FALSE 26 | subjectKeyIdentifier = hash 27 | keyUsage = critical,nonRepudiation,digitalSignature,keyEncipherment 28 | extendedKeyUsage = critical,clientAuth 29 | -------------------------------------------------------------------------------- /examples/features/advancedtls/README.md: -------------------------------------------------------------------------------- 1 | # gRPC Advanced Security Examples 2 | This repo contains example code for different security configurations for grpc-go using `advancedtls`. 3 | 4 | The servers run a basic echo server with the following setups: 5 | * Port 8885: A server with a good certificate using certificate providers and crl providers. 6 | * Port 8884: A server with a revoked certificate using certificate providers and crl providers. 7 | * Port 8883: A server running using InsecureCredentials. 8 | 9 | The clients are designed to call these servers with varying configurations of credentials and revocation configurations. 10 | * mTLS with certificate providers and CRLs 11 | * mTLS with custom verification 12 | * mTLS with credentials from credentials.NewTLS (directly using the tls.Config) 13 | * Insecure Credentials 14 | 15 | ## Building and Running 16 | ``` 17 | # Run the server 18 | $ go run server/main.go -credentials_directory $(pwd)/creds 19 | # Run the clients from the `grpc-go/examples/features/advancedtls` directory 20 | $ go run client/main.go -credentials_directory $(pwd)/creds 21 | ``` 22 | 23 | Stop the servers with ctrl-c or by killing the process. 24 | 25 | ## Developer Note - Generate the credentials used in the examples 26 | The credentials used for these examples were generated by running the `examples/features/advancedtls/generate.sh` script. 27 | 28 | If the credentials need to be re-generated, run `./generate.sh` from `/path/to/grpc-go/examples/features/advancedtls` to re-create the `creds` directory containing the certificates and CRLs needed for these examples. 29 | -------------------------------------------------------------------------------- /examples/features/advancedtls/creds/crl/client_revoked.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIDOzCCASMCAQEwDQYJKoZIhvcNAQELBQAwgaExCzAJBgNVBAYTAlVTMRAwDgYD 3 | VQQIDAdHZW9yZ2lhMRAwDgYDVQQHDAdBdGxhbnRhMRAwDgYDVQQKDAdUZXN0IENB 4 | MRwwGgYDVQQLDBNUZXN0IENBIE9yZ2FuemF0aW9uMR0wGwYDVQQDDBRUZXN0IENB 5 | IE9yZ2FuaXphdGlvbjEfMB0GCSqGSIb3DQEJARYQdGVzdEBleGFtcGxlLmNvbRcN 6 | MjQwODA4MTgwNjIyWhcNMjQwOTA3MTgwNjIyWjAoMBICAQIXDTI0MDgwODE4MDYy 7 | MVowEgIBBBcNMjQwODA4MTgwNjIyWqAjMCEwHwYDVR0jBBgwFoAUUHbDXGsS4ZIP 8 | KPjyQ6aAwpzoVtYwDQYJKoZIhvcNAQELBQADggIBAArFuFeXXCWCCNLy8qk0UG5r 9 | CljVMSWrOPTy3eyQH+pSbzdwA5PYW2i5BOBcr6ULKW5aamFjhYMviqroFXrib7yU 10 | hNhiK8FtH9cl2O7pbdFGBdjqHoGOSOWXG++0LU+Hhh5kTr/iZrgkYvB3RHycofC1 11 | 85nY01t//fGZZJ3e8hBwf8sNdR4L7vQ2WJtbzj8mj6mU4K//UkTiqZv2yGlbDXmh 12 | p0HDdu9/nBFLrLE35N/0m/1R4pW7AXm3R6WBiqxY8KdA4Us9tC9+qvtsWwEe/klN 13 | 5E9FLcARMTl9kwJLNJZpVoe6tyt/S4WXs4nh+XEpiD5uZgbMh0N0jwaCMWyz3wo6 14 | tLkMmg+4mXEViAKQZTGVU2fTVaBH1C6A4ugB7IcFG1gXVw2DnF6I1XQB9+EcPbpb 15 | 6ZTBo1msSR0Bzr0sUOdCiKhSc60DTjeNjcLhNT4k06cVvzQcyb2KePG+NnA/Tfbz 16 | yMuDcx62T2BTL1X2aVMUSLY3mwWnqyFdHbEQOoKH084Nrhizq7H2YwdoL992UTuH 17 | PzjyEqJN3hIePthlHl2g9fGh9dIJtxu6didm2M4WoHKeCfpWPH8fc37zhX8QYpqj 18 | U9vDvc2F567lRpAGwyqKZti+2xg2L2K/qBSGvKdtf5hPsOvVlEnWC4mTbjo19aUn 19 | YvLKT6e3D16ao5jVKITj 20 | -----END X509 CRL----- 21 | -------------------------------------------------------------------------------- /examples/features/advancedtls/creds/localhost-openssl.cnf: -------------------------------------------------------------------------------- 1 | [req] 2 | distinguished_name = req_distinguished_name 3 | req_extensions = v3_req 4 | 5 | [req_distinguished_name] 6 | countryName = Country Name (2 letter code) 7 | countryName_default = US 8 | stateOrProvinceName = State or Province Name (full name) 9 | stateOrProvinceName_default = Georgia 10 | localityName = Locality Name (eg, city) 11 | localityName_default = Atlanta 12 | organizationName = Organization Name (eg, company) 13 | organizationName_default = Test Department 14 | commonName = Common Name (eg, YOUR name) 15 | commonName_max = 64 16 | 17 | [v3_req] 18 | basicConstraints = CA:FALSE 19 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment 20 | subjectAltName = @alt_names 21 | 22 | [alt_names] 23 | DNS.1 = localhost 24 | IP.1 = 0.0.0.0 25 | -------------------------------------------------------------------------------- /examples/features/advancedtls/creds/server_revoked.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIDJzCCAQ8CAQEwDQYJKoZIhvcNAQELBQAwgaExCzAJBgNVBAYTAlVTMRAwDgYD 3 | VQQIDAdHZW9yZ2lhMRAwDgYDVQQHDAdBdGxhbnRhMRAwDgYDVQQKDAdUZXN0IENB 4 | MRwwGgYDVQQLDBNUZXN0IENBIE9yZ2FuemF0aW9uMR0wGwYDVQQDDBRUZXN0IENB 5 | IE9yZ2FuaXphdGlvbjEfMB0GCSqGSIb3DQEJARYQdGVzdEBleGFtcGxlLmNvbRcN 6 | MjQwODA4MTgwNjIxWhcNMjQwOTA3MTgwNjIxWjAUMBICAQIXDTI0MDgwODE4MDYy 7 | MVqgIzAhMB8GA1UdIwQYMBaAFFB2w1xrEuGSDyj48kOmgMKc6FbWMA0GCSqGSIb3 8 | DQEBCwUAA4ICAQAvc4fK9H6OnUrtIzBls7ctVnmg4Up8NLWS9BWM9Ncw4MxLEXwM 9 | 4iD2Tgg5Yq51iE5pDNet5shae3l/kDNWigPixhpfiT8xwxnrOA3BUtD3affc0Nem 10 | kS9Heq99jqvRdDF2nlEoiJesElxlSrwaljpev2SDzX/qnP5iRsBEuRS7Dr+83rcf 11 | ysYt0Hd84MCaSJ2iITF7Kg7Zg7R+HV0O++k+ZXCuJkDDo8TGa+Kr87WtFsER1+SX 12 | rtIgZEmikF/rEiKOHYV7QSujn8bzSsKzW2S/8/xygQnZ39vk5OPKKokPMUqesMPE 13 | 8hUwGjCnDDijj6WGyP54FHKcH61P6R5a1EsjNfTUli9J7BNSHjb7AqPFRMCz6Ihj 14 | GUidGqCz4mpxkUpOwGJZWyefeWlKCdoBqDHlRtf8EjdE9BClOacJeVx2dmXd7k5r 15 | y6grIFfNjHYJmVa8+o2YCV80wY9XFtRUsGpEwHFTrtAjec+y2gtILKpsv5aqyvOa 16 | +nffFdMAR05Dx4MeFJSKYQGk64hPmgrRK+MGc224JPmQDi9uMwDKo+jB1TkCgwvR 17 | ZTF0VpPWBfhkB6x2haYyq2whf6zHfR+jMA0npUA8vHSUIiQrgWbvwsCc3nFGt4nz 18 | WjEZ7Q8Sw9CBfcvXrSV+WQdJF6kHgwaiI56x7DvdEAoDxuDLbmb+D/5gIg== 19 | -----END X509 CRL----- 20 | -------------------------------------------------------------------------------- /examples/features/advancedtls/localhost-openssl.cnf: -------------------------------------------------------------------------------- 1 | [req] 2 | distinguished_name = req_distinguished_name 3 | req_extensions = v3_req 4 | 5 | [req_distinguished_name] 6 | countryName = Country Name (2 letter code) 7 | countryName_default = US 8 | stateOrProvinceName = State or Province Name (full name) 9 | stateOrProvinceName_default = Georgia 10 | localityName = Locality Name (eg, city) 11 | localityName_default = Atlanta 12 | organizationName = Organization Name (eg, company) 13 | organizationName_default = Test Department 14 | commonName = Common Name (eg, YOUR name) 15 | commonName_max = 64 16 | 17 | [v3_req] 18 | basicConstraints = CA:FALSE 19 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment 20 | subjectAltName = @alt_names 21 | 22 | [alt_names] 23 | DNS.1 = localhost 24 | IP.1 = 0.0.0.0 25 | -------------------------------------------------------------------------------- /examples/features/cancellation/README.md: -------------------------------------------------------------------------------- 1 | # Cancellation 2 | 3 | This example shows how clients can cancel in-flight RPCs by canceling the 4 | context passed to the RPC call. The client will receive a status with code 5 | `Canceled` and the service handler's context will be canceled. 6 | 7 | ``` 8 | go run server/main.go 9 | ``` 10 | 11 | ``` 12 | go run client/main.go 13 | ``` 14 | -------------------------------------------------------------------------------- /examples/features/compression/README.md: -------------------------------------------------------------------------------- 1 | # Compression 2 | 3 | This example shows how clients can specify compression options when performing 4 | RPCs, and how to install support for compressors on the server. For more 5 | information, please see [our detailed 6 | documentation](../../../Documentation/compression.md). 7 | 8 | ``` 9 | go run server/main.go 10 | ``` 11 | 12 | ``` 13 | go run client/main.go 14 | ``` 15 | -------------------------------------------------------------------------------- /examples/features/csm_observability/README.md: -------------------------------------------------------------------------------- 1 | # CSM Observability 2 | 3 | This examples shows how to configure CSM Observability for gRPC client and 4 | server applications (configured once per binary), and shows what type of 5 | telemetry data it can produce for certain RPCs with additional CSM Labels. The 6 | gRPC Client accepts configuration from an xDS Control plane as the default 7 | address that it connects to is "xds:///helloworld:50051", but this can be 8 | overridden with the command line flag --server_addr. This can be plugged into 9 | the steps outlined in the CSM Observability User Guide. 10 | 11 | ## Try it (locally if overwritten xDS Address) 12 | 13 | ``` 14 | go run server/main.go 15 | ``` 16 | 17 | ``` 18 | go run client/main.go 19 | ``` 20 | 21 | Curl to the port where Prometheus exporter is outputting metrics data: 22 | ``` 23 | curl localhost:9464/metrics 24 | ``` 25 | 26 | # Building 27 | From the grpc-go directory: 28 | 29 | Client: 30 | docker build -t -f examples/features/csm_observability/client/Dockerfile . 31 | 32 | Server: 33 | docker build -t -f examples/features/csm_observability/server/Dockerfile . 34 | 35 | Note that this example will not work by default, as the client uses an xDS 36 | Scheme and thus needs xDS Resources to connect to the server. Deploy the built 37 | client and server containers within Cloud Service Mesh in order for this example 38 | to work, or overwrite target to point to :. 39 | -------------------------------------------------------------------------------- /examples/features/csm_observability/client/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2024 gRPC authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Dockerfile for building the example client. To build the image, run the 16 | # following command from grpc-go directory: 17 | # docker build -t -f examples/features/csm_observability/client/Dockerfile . 18 | FROM golang:1.23-alpine as build 19 | 20 | RUN apk --no-cache add curl 21 | 22 | # Make a grpc-go directory and copy the repo into it. 23 | WORKDIR /go/src/grpc-go 24 | COPY . . 25 | 26 | # Build a static binary without cgo so that we can copy just the binary in the 27 | # final image, and can get rid of the Go compiler and gRPC-Go dependencies. 28 | RUN cd examples/features/csm_observability/client && go build -tags osusergo,netgo . 29 | 30 | FROM alpine 31 | RUN apk --no-cache add curl 32 | COPY --from=build /go/src/grpc-go/examples/features/csm_observability/client/client . 33 | ENV GRPC_GO_LOG_VERBOSITY_LEVEL=99 34 | ENV GRPC_GO_LOG_SEVERITY_LEVEL="info" 35 | ENTRYPOINT ["./client"] 36 | -------------------------------------------------------------------------------- /examples/features/csm_observability/server/Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2024 gRPC authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # Dockerfile for building the example server. To build the image, run the 16 | # following command from grpc-go directory: 17 | # docker build -t -f examples/features/csm_observability/server/Dockerfile . 18 | 19 | FROM golang:1.23-alpine as build 20 | RUN apk --no-cache add curl 21 | # Make a grpc-go directory and copy the repo into it. 22 | WORKDIR /go/src/grpc-go 23 | COPY . . 24 | 25 | # Build a static binary without cgo so that we can copy just the binary in the 26 | # final image, and can get rid of the Go compiler and gRPC-Go dependencies. 27 | RUN cd examples/features/csm_observability/server && go build -tags osusergo,netgo . 28 | 29 | FROM alpine 30 | RUN apk --no-cache add curl 31 | COPY --from=build /go/src/grpc-go/examples/features/csm_observability/server/server . 32 | ENV GRPC_GO_LOG_VERBOSITY_LEVEL=99 33 | ENV GRPC_GO_LOG_SEVERITY_LEVEL="info" 34 | ENTRYPOINT ["./server"] 35 | -------------------------------------------------------------------------------- /examples/features/debugging/README.md: -------------------------------------------------------------------------------- 1 | # Debugging 2 | 3 | Currently, grpc provides two major tools to help user debug issues, which are logging and channelz. 4 | 5 | ## Logs 6 | gRPC has put substantial logging instruments on critical paths of gRPC to help users debug issues. 7 | The [Log Levels](https://github.com/grpc/grpc-go/blob/master/Documentation/log_levels.md) doc describes 8 | what each log level means in the gRPC context. 9 | 10 | To turn on the logs for debugging, run the code with the following environment variable: 11 | `GRPC_GO_LOG_VERBOSITY_LEVEL=99 GRPC_GO_LOG_SEVERITY_LEVEL=info`. 12 | 13 | ## Channelz 14 | We also provide a runtime debugging tool, Channelz, to help users with live debugging. 15 | 16 | See the channelz blog post here ([link](https://grpc.io/blog/a-short-introduction-to-channelz/)) for 17 | details about how to use channelz service to debug live program. 18 | 19 | ## Try it 20 | The example is able to showcase how logging and channelz can help with debugging. See the channelz 21 | blog post linked above for full explanation. 22 | 23 | ``` 24 | go run server/main.go 25 | ``` 26 | 27 | ``` 28 | go run client/main.go 29 | ``` 30 | -------------------------------------------------------------------------------- /examples/features/dualstack/README.md: -------------------------------------------------------------------------------- 1 | # Dualstack 2 | 3 | The dualstack example uses a custom name resolver that provides both IPv4 and 4 | IPv6 localhost endpoints for each of 3 server instances. The client will first 5 | use the default name resolver and load balancers which will only connect to the 6 | first server. It will then use the custom name resolver with round robin to 7 | connect to each of the servers in turn. The 3 instances of the server will bind 8 | respectively to: both IPv4 and IPv6, IPv4 only, and IPv6 only. 9 | 10 | Three servers are serving on the following loopback addresses: 11 | 12 | 1. `[::]:50052`: Listening on both IPv4 and IPv6 loopback addresses. 13 | 1. `127.0.0.1:50050`: Listening only on the IPv4 loopback address. 14 | 1. `[::1]:50051`: Listening only on the IPv6 loopback address. 15 | 16 | The server response will include its serving port and address type (IPv4, IPv6 17 | or both). So the server on "127.0.0.1:50050" will reply to the RPC with the 18 | following message: `Greeting:Hello request:1 from server<50052> type: IPv4 19 | only)`. 20 | 21 | ## Try it 22 | 23 | ```sh 24 | go run server/main.go 25 | ``` 26 | 27 | ```sh 28 | go run client/main.go 29 | ``` 30 | -------------------------------------------------------------------------------- /examples/features/error_details/README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | This example demonstrates the use of status details in grpc errors. 4 | 5 | # Run the sample code 6 | 7 | Run the server: 8 | 9 | ```sh 10 | $ go run ./server/main.go 11 | ``` 12 | Then run the client in another terminal: 13 | 14 | ```sh 15 | $ go run ./client/main.go 16 | ``` 17 | 18 | It should succeed and print the greeting it received from the server. 19 | Then run the client again: 20 | 21 | ```sh 22 | $ go run ./client/main.go 23 | ``` 24 | 25 | This time, it should fail by printing error status details that it received from the server. 26 | -------------------------------------------------------------------------------- /examples/features/error_handling/README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | This example demonstrates basic RPC error handling in gRPC. 4 | 5 | # Run the sample code 6 | 7 | Run the server, which returns an error if the RPC request's `Name` field is 8 | empty. 9 | 10 | ```sh 11 | $ go run ./server/main.go 12 | ``` 13 | 14 | Then run the client in another terminal, which does two requests: one with an 15 | empty Name field and one with it populated with the current username provided by 16 | os/user. 17 | 18 | ```sh 19 | $ go run ./client/main.go 20 | ``` 21 | 22 | It should print the status codes it received from the server. 23 | -------------------------------------------------------------------------------- /examples/features/keepalive/README.md: -------------------------------------------------------------------------------- 1 | # Keepalive 2 | 3 | This example illustrates how to set up client-side keepalive pings and 4 | server-side keepalive ping enforcement and connection idleness settings. For 5 | more details on these settings, see the [full 6 | documentation](https://github.com/grpc/grpc-go/tree/master/Documentation/keepalive.md). 7 | 8 | 9 | ``` 10 | go run server/main.go 11 | ``` 12 | 13 | ``` 14 | GODEBUG=http2debug=2 go run client/main.go 15 | ``` 16 | -------------------------------------------------------------------------------- /examples/features/metadata/README.md: -------------------------------------------------------------------------------- 1 | # Metadata example 2 | 3 | This example shows how to set and read metadata in RPC headers and trailers. 4 | Please see 5 | [grpc-metadata.md](https://github.com/grpc/grpc-go/blob/master/Documentation/grpc-metadata.md) 6 | for more information. 7 | 8 | ## Start the server 9 | 10 | ``` 11 | go run server/main.go 12 | ``` 13 | 14 | ## Run the client 15 | 16 | ``` 17 | go run client/main.go 18 | ``` 19 | -------------------------------------------------------------------------------- /examples/features/multiplex/README.md: -------------------------------------------------------------------------------- 1 | # Multiplex 2 | 3 | A `grpc.ClientConn` can be shared by two stubs and two services can share a 4 | `grpc.Server`. This example illustrates how to perform both types of sharing. 5 | 6 | ``` 7 | go run server/main.go 8 | ``` 9 | 10 | ``` 11 | go run client/main.go 12 | ``` 13 | -------------------------------------------------------------------------------- /examples/features/name_resolving/README.md: -------------------------------------------------------------------------------- 1 | # Name resolving 2 | 3 | This examples shows how `ClientConn` can pick different name resolvers. 4 | 5 | ## What is a name resolver 6 | 7 | A name resolver can be seen as a `map[service-name][]backend-ip`. It takes a 8 | service name, and returns a list of IPs of the backends. A common used name 9 | resolver is DNS. 10 | 11 | In this example, a resolver is created to resolve `resolver.example.grpc.io` to 12 | `localhost:50051`. 13 | 14 | ## Try it 15 | 16 | ``` 17 | go run server/main.go 18 | ``` 19 | 20 | ``` 21 | go run client/main.go 22 | ``` 23 | 24 | ## Explanation 25 | 26 | The echo server is serving on ":50051". Two clients are created, one is dialing 27 | to `passthrough:///localhost:50051`, while the other is dialing to 28 | `example:///resolver.example.grpc.io`. Both of them can connect the server. 29 | 30 | Name resolver is picked based on the `scheme` in the target string. See 31 | https://github.com/grpc/grpc/blob/master/doc/naming.md for the target syntax. 32 | 33 | The first client picks the `passthrough` resolver, which takes the input, and 34 | use it as the backend addresses. 35 | 36 | The second is connecting to service name `resolver.example.grpc.io`. Without a 37 | proper name resolver, this would fail. In the example it picks the `example` 38 | resolver that we installed. The `example` resolver can handle 39 | `resolver.example.grpc.io` correctly by returning the backend address. So even 40 | though the backend IP is not set when ClientConn is created, the connection will 41 | be created to the correct backend. 42 | -------------------------------------------------------------------------------- /examples/features/observability/README.md: -------------------------------------------------------------------------------- 1 | This example is the Hello World example instrumented for logs, metrics, and tracing. 2 | 3 | Please refer to Microservices Observability user guide for setup. 4 | -------------------------------------------------------------------------------- /examples/features/observability/client/clientConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "cloud_monitoring": {}, 3 | "cloud_trace": { 4 | "sampling_rate": 1.0 5 | }, 6 | "cloud_logging": { 7 | "client_rpc_events": [{ 8 | "methods": ["*"] 9 | }], 10 | "server_rpc_events": [{ 11 | "methods": ["*"] 12 | }] 13 | }, 14 | "labels": { 15 | "environment" : "example-client" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/features/observability/server/serverConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "cloud_monitoring": {}, 3 | "cloud_trace": { 4 | "sampling_rate": 1.0 5 | }, 6 | "cloud_logging": { 7 | "client_rpc_events": [{ 8 | "methods": ["*"] 9 | }], 10 | "server_rpc_events": [{ 11 | "methods": ["*"] 12 | }] 13 | }, 14 | "labels": { 15 | "environment" : "example-server" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/features/opentelemetry/README.md: -------------------------------------------------------------------------------- 1 | # OpenTelemetry 2 | 3 | This example shows how to configure OpenTelemetry on a client and server, and 4 | shows what type of telemetry data it can produce for certain RPCs. 5 | 6 | ## Try it 7 | 8 | ``` 9 | go run server/main.go 10 | ``` 11 | 12 | ``` 13 | go run client/main.go 14 | ``` 15 | 16 | ``` 17 | curl localhost:9464/metrics 18 | curl localhost:9465/metrics 19 | ``` 20 | 21 | ## Explanation 22 | 23 | The client continuously makes RPCs to a server. The client and server both 24 | expose a prometheus exporter to listen and provide metrics. This defaults to 25 | :9464 for the server and :9465 for the client. The client and server are also 26 | configured to output traces directly to their standard output streams using 27 | `stdouttrace`. 28 | 29 | OpenTelemetry is configured on both the client and the server, and exports to 30 | the Prometheus exporter. The exporter exposes metrics on the Prometheus ports 31 | described above. OpenTelemetry exports traces using the `stdouttrace` exporter, 32 | which prints structured trace data to the console output of both the client and 33 | server. Each RPC call produces trace information that captures the execution 34 | flow and timing of operations. 35 | 36 | Curling to the exposed Prometheus ports outputs the metrics recorded on the 37 | client and server. 38 | -------------------------------------------------------------------------------- /examples/features/reflection/README.md: -------------------------------------------------------------------------------- 1 | # Reflection 2 | 3 | This example shows how reflection can be registered on a gRPC server. 4 | 5 | See 6 | https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md 7 | for a tutorial. 8 | 9 | 10 | # Try it 11 | 12 | ```go 13 | go run server/main.go 14 | ``` 15 | 16 | There are multiple existing reflection clients. 17 | 18 | To use `gRPC CLI`, follow 19 | https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md#grpc-cli. 20 | 21 | To use `grpcurl`, see https://github.com/fullstorydev/grpcurl. 22 | -------------------------------------------------------------------------------- /examples/features/unix_abstract/README.md: -------------------------------------------------------------------------------- 1 | # Unix abstract sockets 2 | 3 | This examples shows how to start a gRPC server listening on a unix abstract 4 | socket and how to get a gRPC client to connect to it. 5 | 6 | ## What is a unix abstract socket 7 | 8 | An abstract socket address is distinguished from a regular unix socket by the 9 | fact that the first byte of the address is a null byte ('\0'). The address has 10 | no connection with filesystem path names. 11 | 12 | ## Try it 13 | 14 | ``` 15 | go run server/main.go 16 | ``` 17 | 18 | ``` 19 | go run client/main.go 20 | ``` 21 | 22 | ## Explanation 23 | 24 | The gRPC server in this example listens on an address starting with a null byte 25 | and the network is `unix`. The client uses the `unix-abstract` scheme with the 26 | endpoint set to the abstract unix socket address without the null byte. The 27 | `unix` resolver takes care of adding the null byte on the client. See 28 | https://github.com/grpc/grpc/blob/master/doc/naming.md for the more details. 29 | 30 | -------------------------------------------------------------------------------- /examples/features/wait_for_ready/README.md: -------------------------------------------------------------------------------- 1 | # Wait for ready example 2 | 3 | This example shows how to enable "wait for ready" in RPC calls. 4 | 5 | This code starts a server with a 2 seconds delay. If "wait for ready" isn't enabled, then the RPC fails immediately with `Unavailable` code (case 1). If "wait for ready" is enabled, then the RPC waits for the server. If context dies before the server is available, then it fails with `DeadlineExceeded` (case 3). Otherwise it succeeds (case 2). 6 | 7 | ## Run the example 8 | 9 | ``` 10 | go run main.go 11 | ``` 12 | -------------------------------------------------------------------------------- /examples/features/xds/README.md: -------------------------------------------------------------------------------- 1 | # gRPC xDS example 2 | 3 | xDS is the protocol initially used by Envoy, that is evolving into a universal 4 | data plane API for service mesh. 5 | 6 | The xDS example is a Hello World client/server capable of being configured with 7 | the XDS management protocol. Out-of-the-box it behaves the same as [our other 8 | hello world 9 | example](https://github.com/grpc/grpc-go/tree/master/examples/helloworld). The 10 | server replies with responses including its hostname. 11 | 12 | ## xDS environment setup 13 | 14 | This example doesn't include instructions to setup xDS environment. Please refer 15 | to documentation specific for your xDS management server. Examples will be added 16 | later. 17 | 18 | The client also needs a bootstrap file. See [gRFC 19 | A27](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md#xdsclient-and-bootstrap-file) 20 | for the bootstrap format. 21 | 22 | ## The client 23 | 24 | The client application needs to import the xDS package to install the resolver and balancers: 25 | 26 | ```go 27 | _ "google.golang.org/grpc/xds" // To install the xds resolvers and balancers. 28 | ``` 29 | 30 | Then, use `xds` target scheme for the ClientConn. 31 | 32 | ``` 33 | $ export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json 34 | $ go run client/main.go "xDS world" xds:///target_service 35 | ``` 36 | -------------------------------------------------------------------------------- /examples/helloworld/README.md: -------------------------------------------------------------------------------- 1 | # gRPC Hello World 2 | 3 | Follow these setup to run the [quick start][] example: 4 | 5 | 1. Get the code: 6 | 7 | ```console 8 | $ go get google.golang.org/grpc/examples/helloworld/greeter_client 9 | $ go get google.golang.org/grpc/examples/helloworld/greeter_server 10 | ``` 11 | 12 | 2. Run the server: 13 | 14 | ```console 15 | $ $(go env GOPATH)/bin/greeter_server & 16 | ``` 17 | 18 | 3. Run the client: 19 | 20 | ```console 21 | $ $(go env GOPATH)/bin/greeter_client 22 | Greeting: Hello world 23 | ``` 24 | 25 | For more details (including instructions for making a small change to the 26 | example code) or if you're having trouble running this example, see [Quick 27 | Start][]. 28 | 29 | [quick start]: https://grpc.io/docs/languages/go/quickstart 30 | -------------------------------------------------------------------------------- /examples/helloworld/helloworld/helloworld.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | option go_package = "google.golang.org/grpc/examples/helloworld/helloworld"; 18 | option java_multiple_files = true; 19 | option java_package = "io.grpc.examples.helloworld"; 20 | option java_outer_classname = "HelloWorldProto"; 21 | 22 | package helloworld; 23 | 24 | // The greeting service definition. 25 | service Greeter { 26 | // Sends a greeting 27 | rpc SayHello (HelloRequest) returns (HelloReply) {} 28 | } 29 | 30 | // The request message containing the user's name. 31 | message HelloRequest { 32 | string name = 1; 33 | } 34 | 35 | // The response message containing the greetings 36 | message HelloReply { 37 | string message = 1; 38 | } 39 | -------------------------------------------------------------------------------- /examples/route_guide/README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | The route guide server and client demonstrate how to use grpc go libraries to 3 | perform unary, client streaming, server streaming and full duplex RPCs. 4 | 5 | Please refer to [gRPC Basics: Go](https://grpc.io/docs/tutorials/basic/go.html) for more information. 6 | 7 | See the definition of the route guide service in `routeguide/route_guide.proto`. 8 | 9 | # Run the sample code 10 | To compile and run the server, assuming you are in the root of the `route_guide` 11 | folder, i.e., `.../examples/route_guide/`, simply: 12 | 13 | ```sh 14 | $ go run server/server.go 15 | ``` 16 | 17 | Likewise, to run the client: 18 | 19 | ```sh 20 | $ go run client/client.go 21 | ``` 22 | 23 | # Optional command line flags 24 | The server and client both take optional command line flags. For example, the 25 | client and server run without TLS by default. To enable TLS: 26 | 27 | ```sh 28 | $ go run server/server.go -tls=true 29 | ``` 30 | 31 | and 32 | 33 | ```sh 34 | $ go run client/client.go -tls=true 35 | ``` 36 | -------------------------------------------------------------------------------- /experimental/opentelemetry/trace_options.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Package opentelemetry is EXPERIMENTAL and will be moved to stats/opentelemetry 18 | // package in a later release. 19 | package opentelemetry 20 | 21 | import ( 22 | "go.opentelemetry.io/otel/propagation" 23 | "go.opentelemetry.io/otel/trace" 24 | ) 25 | 26 | // TraceOptions contains the tracing settings for OpenTelemetry instrumentation. 27 | type TraceOptions struct { 28 | // TracerProvider is the OpenTelemetry tracer which is required to 29 | // record traces/trace spans for instrumentation. If unset, tracing 30 | // will not be recorded. 31 | TracerProvider trace.TracerProvider 32 | 33 | // TextMapPropagator propagates span context through text map carrier. 34 | // If unset, tracing will not be recorded. 35 | TextMapPropagator propagation.TextMapPropagator 36 | } 37 | -------------------------------------------------------------------------------- /grpc_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "testing" 23 | 24 | "google.golang.org/grpc/internal/grpctest" 25 | ) 26 | 27 | type s struct { 28 | grpctest.Tester 29 | } 30 | 31 | func Test(t *testing.T) { 32 | grpctest.RunSubTests(t, s{}) 33 | } 34 | -------------------------------------------------------------------------------- /grpclog/internal/grpclog.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2024 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package internal contains functionality internal to the grpclog package. 20 | package internal 21 | 22 | // LoggerV2Impl is the logger used for the non-depth log functions. 23 | var LoggerV2Impl LoggerV2 24 | 25 | // DepthLoggerV2Impl is the logger used for the depth log functions. 26 | var DepthLoggerV2Impl DepthLoggerV2 27 | -------------------------------------------------------------------------------- /grpclog/logger.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2015 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpclog 20 | 21 | import "google.golang.org/grpc/grpclog/internal" 22 | 23 | // Logger mimics golang's standard Logger as an interface. 24 | // 25 | // Deprecated: use LoggerV2. 26 | type Logger internal.Logger 27 | 28 | // SetLogger sets the logger that is used in grpc. Call only from 29 | // init() functions. 30 | // 31 | // Deprecated: use SetLoggerV2. 32 | func SetLogger(l Logger) { 33 | internal.LoggerV2Impl = &internal.LoggerWrapper{Logger: l} 34 | } 35 | -------------------------------------------------------------------------------- /health/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package health 20 | 21 | import "google.golang.org/grpc/grpclog" 22 | 23 | var logger = grpclog.Component("health_service") 24 | -------------------------------------------------------------------------------- /health/server_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package health_test 20 | 21 | import ( 22 | "testing" 23 | 24 | "google.golang.org/grpc" 25 | "google.golang.org/grpc/health" 26 | healthgrpc "google.golang.org/grpc/health/grpc_health_v1" 27 | "google.golang.org/grpc/internal/grpctest" 28 | ) 29 | 30 | type s struct { 31 | grpctest.Tester 32 | } 33 | 34 | func Test(t *testing.T) { 35 | grpctest.RunSubTests(t, s{}) 36 | } 37 | 38 | // Make sure the service implementation complies with the proto definition. 39 | func (s) TestRegister(t *testing.T) { 40 | s := grpc.NewServer() 41 | healthgrpc.RegisterHealthServer(s, health.NewServer()) 42 | s.Stop() 43 | } 44 | -------------------------------------------------------------------------------- /internal/balancergroup/balancerstateaggregator.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package balancergroup 20 | 21 | import ( 22 | "google.golang.org/grpc/balancer" 23 | ) 24 | 25 | // BalancerStateAggregator aggregates sub-picker and connectivity states into a 26 | // state. 27 | // 28 | // It takes care of merging sub-picker into one picker. The picking config is 29 | // passed directly from the parent to the aggregator implementation (instead 30 | // via balancer group). 31 | type BalancerStateAggregator interface { 32 | // UpdateState updates the state of the id. 33 | // 34 | // It's up to the implementation whether this will trigger an update to the 35 | // parent ClientConn. 36 | UpdateState(id string, state balancer.State) 37 | } 38 | -------------------------------------------------------------------------------- /internal/balancerload/load.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Package balancerload defines APIs to parse server loads in trailers. The 18 | // parsed loads are sent to balancers in DoneInfo. 19 | package balancerload 20 | 21 | import ( 22 | "google.golang.org/grpc/metadata" 23 | ) 24 | 25 | // Parser converts loads from metadata into a concrete type. 26 | type Parser interface { 27 | // Parse parses loads from metadata. 28 | Parse(md metadata.MD) any 29 | } 30 | 31 | var parser Parser 32 | 33 | // SetParser sets the load parser. 34 | // 35 | // Not mutex-protected, should be called before any gRPC functions. 36 | func SetParser(lr Parser) { 37 | parser = lr 38 | } 39 | 40 | // Parse calls parser.Read(). 41 | func Parse(md metadata.MD) any { 42 | if parser == nil { 43 | return nil 44 | } 45 | return parser.Parse(md) 46 | } 47 | -------------------------------------------------------------------------------- /internal/channelz/syscall_nonlinux.go: -------------------------------------------------------------------------------- 1 | //go:build !linux 2 | 3 | /* 4 | * 5 | * Copyright 2018 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package channelz 22 | 23 | import ( 24 | "sync" 25 | ) 26 | 27 | var once sync.Once 28 | 29 | // SocketOptionData defines the struct to hold socket option data, and related 30 | // getter function to obtain info from fd. 31 | // Windows OS doesn't support Socket Option 32 | type SocketOptionData struct { 33 | } 34 | 35 | // Getsockopt defines the function to get socket options requested by channelz. 36 | // It is to be passed to syscall.RawConn.Control(). 37 | // Windows OS doesn't support Socket Option 38 | func (s *SocketOptionData) Getsockopt(uintptr) { 39 | once.Do(func() { 40 | logger.Warning("Channelz: socket options are not supported on non-linux environments") 41 | }) 42 | } 43 | 44 | // GetSocketOption gets the socket option info of the conn. 45 | func GetSocketOption(any) *SocketOptionData { 46 | return nil 47 | } 48 | -------------------------------------------------------------------------------- /internal/credentials/credentials.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package credentials 18 | 19 | import ( 20 | "context" 21 | ) 22 | 23 | // clientHandshakeInfoKey is a struct used as the key to store 24 | // ClientHandshakeInfo in a context. 25 | type clientHandshakeInfoKey struct{} 26 | 27 | // ClientHandshakeInfoFromContext extracts the ClientHandshakeInfo from ctx. 28 | func ClientHandshakeInfoFromContext(ctx context.Context) any { 29 | return ctx.Value(clientHandshakeInfoKey{}) 30 | } 31 | 32 | // NewClientHandshakeInfoContext creates a context with chi. 33 | func NewClientHandshakeInfoContext(ctx context.Context, chi any) context.Context { 34 | return context.WithValue(ctx, clientHandshakeInfoKey{}, chi) 35 | } 36 | -------------------------------------------------------------------------------- /internal/credentials/util.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package credentials 20 | 21 | import ( 22 | "crypto/tls" 23 | ) 24 | 25 | const alpnProtoStrH2 = "h2" 26 | 27 | // AppendH2ToNextProtos appends h2 to next protos. 28 | func AppendH2ToNextProtos(ps []string) []string { 29 | for _, p := range ps { 30 | if p == alpnProtoStrH2 { 31 | return ps 32 | } 33 | } 34 | ret := make([]string, 0, len(ps)+1) 35 | ret = append(ret, ps...) 36 | return append(ret, alpnProtoStrH2) 37 | } 38 | 39 | // CloneTLSConfig returns a shallow clone of the exported 40 | // fields of cfg, ignoring the unexported sync.Once, which 41 | // contains a mutex and must not be copied. 42 | // 43 | // If cfg is nil, a new zero tls.Config is returned. 44 | // 45 | // TODO: inline this function if possible. 46 | func CloneTLSConfig(cfg *tls.Config) *tls.Config { 47 | if cfg == nil { 48 | return &tls.Config{} 49 | } 50 | 51 | return cfg.Clone() 52 | } 53 | -------------------------------------------------------------------------------- /internal/experimental.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2023 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package internal 19 | 20 | var ( 21 | // WithBufferPool is implemented by the grpc package and returns a dial 22 | // option to configure a shared buffer pool for a grpc.ClientConn. 23 | WithBufferPool any // func (grpc.SharedBufferPool) grpc.DialOption 24 | 25 | // BufferPool is implemented by the grpc package and returns a server 26 | // option to configure a shared buffer pool for a grpc.Server. 27 | BufferPool any // func (grpc.SharedBufferPool) grpc.ServerOption 28 | ) 29 | -------------------------------------------------------------------------------- /internal/googlecloud/manufacturer.go: -------------------------------------------------------------------------------- 1 | //go:build !(linux || windows) 2 | // +build !linux,!windows 3 | 4 | /* 5 | * 6 | * Copyright 2022 gRPC authors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | package googlecloud 23 | 24 | func manufacturer() ([]byte, error) { 25 | return nil, nil 26 | } 27 | -------------------------------------------------------------------------------- /internal/googlecloud/manufacturer_linux.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2022 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package googlecloud 20 | 21 | import "os" 22 | 23 | const linuxProductNameFile = "/sys/class/dmi/id/product_name" 24 | 25 | func manufacturer() ([]byte, error) { 26 | return os.ReadFile(linuxProductNameFile) 27 | } 28 | -------------------------------------------------------------------------------- /internal/grpctest/grpctest_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpctest 20 | 21 | import ( 22 | "reflect" 23 | "testing" 24 | ) 25 | 26 | type tRunST struct { 27 | setup, test, teardown bool 28 | } 29 | 30 | func (t *tRunST) Setup(*testing.T) { 31 | t.setup = true 32 | } 33 | func (t *tRunST) TestSubTest(*testing.T) { 34 | t.test = true 35 | } 36 | func (t *tRunST) Teardown(*testing.T) { 37 | t.teardown = true 38 | } 39 | 40 | func TestRunSubTests(t *testing.T) { 41 | x := &tRunST{} 42 | RunSubTests(t, x) 43 | if want := (&tRunST{setup: true, test: true, teardown: true}); !reflect.DeepEqual(x, want) { 44 | t.Fatalf("x = %v; want all fields true", x) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /internal/grpcutil/compressor.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2022 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpcutil 20 | 21 | import ( 22 | "strings" 23 | ) 24 | 25 | // RegisteredCompressorNames holds names of the registered compressors. 26 | var RegisteredCompressorNames []string 27 | 28 | // IsCompressorNameRegistered returns true when name is available in registry. 29 | func IsCompressorNameRegistered(name string) bool { 30 | for _, compressor := range RegisteredCompressorNames { 31 | if compressor == name { 32 | return true 33 | } 34 | } 35 | return false 36 | } 37 | 38 | // RegisteredCompressors returns a string of registered compressor names 39 | // separated by comma. 40 | func RegisteredCompressors() string { 41 | return strings.Join(RegisteredCompressorNames, ",") 42 | } 43 | -------------------------------------------------------------------------------- /internal/grpcutil/compressor_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2022 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpcutil 20 | 21 | import ( 22 | "testing" 23 | ) 24 | 25 | func TestRegisteredCompressors(t *testing.T) { 26 | defer func(c []string) { RegisteredCompressorNames = c }(RegisteredCompressorNames) 27 | RegisteredCompressorNames = []string{"gzip", "snappy"} 28 | if got, want := RegisteredCompressors(), "gzip,snappy"; got != want { 29 | t.Fatalf("Unexpected compressors got:%s, want:%s", got, want) 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /internal/grpcutil/encode_duration_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpcutil 20 | 21 | import ( 22 | "testing" 23 | "time" 24 | ) 25 | 26 | func TestEncodeDuration(t *testing.T) { 27 | for _, test := range []struct { 28 | in string 29 | out string 30 | }{ 31 | {"12345678ns", "12345678n"}, 32 | {"123456789ns", "123457u"}, 33 | {"12345678us", "12345678u"}, 34 | {"123456789us", "123457m"}, 35 | {"12345678ms", "12345678m"}, 36 | {"123456789ms", "123457S"}, 37 | {"12345678s", "12345678S"}, 38 | {"123456789s", "2057614M"}, 39 | {"12345678m", "12345678M"}, 40 | {"123456789m", "2057614H"}, 41 | } { 42 | d, err := time.ParseDuration(test.in) 43 | if err != nil { 44 | t.Fatalf("failed to parse duration string %s: %v", test.in, err) 45 | } 46 | out := EncodeDuration(d) 47 | if out != test.out { 48 | t.Fatalf("timeoutEncode(%s) = %s, want %s", test.in, out, test.out) 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /internal/grpcutil/grpcutil.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package grpcutil provides utility functions used across the gRPC codebase. 20 | package grpcutil 21 | -------------------------------------------------------------------------------- /internal/grpcutil/metadata.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpcutil 20 | 21 | import ( 22 | "context" 23 | 24 | "google.golang.org/grpc/metadata" 25 | ) 26 | 27 | type mdExtraKey struct{} 28 | 29 | // WithExtraMetadata creates a new context with incoming md attached. 30 | func WithExtraMetadata(ctx context.Context, md metadata.MD) context.Context { 31 | return context.WithValue(ctx, mdExtraKey{}, md) 32 | } 33 | 34 | // ExtraMetadata returns the incoming metadata in ctx if it exists. The 35 | // returned MD should not be modified. Writing to it may cause races. 36 | // Modification should be made to copies of the returned MD. 37 | func ExtraMetadata(ctx context.Context) (md metadata.MD, ok bool) { 38 | md, ok = ctx.Value(mdExtraKey{}).(metadata.MD) 39 | return 40 | } 41 | -------------------------------------------------------------------------------- /internal/grpcutil/regex.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpcutil 20 | 21 | import "regexp" 22 | 23 | // FullMatchWithRegex returns whether the full text matches the regex provided. 24 | func FullMatchWithRegex(re *regexp.Regexp, text string) bool { 25 | if len(text) == 0 { 26 | return re.MatchString(text) 27 | } 28 | re.Longest() 29 | rem := re.FindString(text) 30 | return len(rem) == len(text) 31 | } 32 | -------------------------------------------------------------------------------- /internal/leakcheck/leakcheck_enabled.go: -------------------------------------------------------------------------------- 1 | //go:build checkbuffers 2 | 3 | /* 4 | * 5 | * Copyright 2017 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package leakcheck 22 | 23 | func init() { 24 | failTestsOnLeakedBuffers = true 25 | } 26 | -------------------------------------------------------------------------------- /internal/profiling/goid_regular.go: -------------------------------------------------------------------------------- 1 | //go:build !grpcgoid 2 | // +build !grpcgoid 3 | 4 | /* 5 | * 6 | * Copyright 2019 gRPC authors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | package profiling 23 | 24 | // This dummy function always returns 0. In some modified dev environments, 25 | // this may be replaced with a call to a function in a modified Go runtime that 26 | // retrieves the goroutine ID efficiently. See goid_modified.go for a different 27 | // version of goId that requires a grpcgoid build tag to compile. 28 | func goid() int64 { 29 | return 0 30 | } 31 | -------------------------------------------------------------------------------- /internal/stats/labels.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2024 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package stats provides internal stats related functionality. 20 | package stats 21 | 22 | import "context" 23 | 24 | // Labels are the labels for metrics. 25 | type Labels struct { 26 | // TelemetryLabels are the telemetry labels to record. 27 | TelemetryLabels map[string]string 28 | } 29 | 30 | type labelsKey struct{} 31 | 32 | // GetLabels returns the Labels stored in the context, or nil if there is one. 33 | func GetLabels(ctx context.Context) *Labels { 34 | labels, _ := ctx.Value(labelsKey{}).(*Labels) 35 | return labels 36 | } 37 | 38 | // SetLabels sets the Labels in the context. 39 | func SetLabels(ctx context.Context, labels *Labels) context.Context { 40 | // could also append 41 | return context.WithValue(ctx, labelsKey{}, labels) 42 | } 43 | -------------------------------------------------------------------------------- /internal/status/status_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2025 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package status_test 20 | 21 | import ( 22 | "testing" 23 | 24 | "google.golang.org/grpc/codes" 25 | "google.golang.org/grpc/internal/status" 26 | ) 27 | 28 | func TestRawStatusProto(t *testing.T) { 29 | spb := status.RawStatusProto(nil) 30 | if spb != nil { 31 | t.Errorf("RawStatusProto(nil) = %v; must return nil", spb) 32 | } 33 | s := status.New(codes.Internal, "test internal error") 34 | spb1 := status.RawStatusProto(s) 35 | spb2 := status.RawStatusProto(s) 36 | // spb1 and spb2 should be the same pointer: no copies 37 | if spb1 != spb2 { 38 | t.Errorf("RawStatusProto(s)=%p then %p; must return the same pointer", spb1, spb2) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /internal/tcp_keepalive_others.go: -------------------------------------------------------------------------------- 1 | //go:build !unix && !windows 2 | 3 | /* 4 | * Copyright 2023 gRPC authors. 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | 20 | package internal 21 | 22 | import ( 23 | "net" 24 | ) 25 | 26 | // NetDialerWithTCPKeepalive returns a vanilla net.Dialer on non-unix platforms. 27 | func NetDialerWithTCPKeepalive() *net.Dialer { 28 | return &net.Dialer{} 29 | } 30 | -------------------------------------------------------------------------------- /internal/testutils/envconfig.go: -------------------------------------------------------------------------------- 1 | package testutils 2 | 3 | /* 4 | * 5 | * Copyright 2025 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | */ 19 | 20 | import ( 21 | "testing" 22 | ) 23 | 24 | // SetEnvConfig sets the value of the given variable to the specified value, 25 | // taking care of restoring the original value after the test completes. 26 | func SetEnvConfig[T any](t *testing.T, variable *T, value T) { 27 | t.Helper() 28 | old := *variable 29 | t.Cleanup(func() { 30 | *variable = old 31 | }) 32 | *variable = value 33 | } 34 | -------------------------------------------------------------------------------- /internal/testutils/local_listener.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package testutils 20 | 21 | import "net" 22 | 23 | // LocalTCPListener returns a net.Listener listening on local address and port. 24 | func LocalTCPListener() (net.Listener, error) { 25 | return net.Listen("tcp", "localhost:0") 26 | } 27 | -------------------------------------------------------------------------------- /internal/testutils/marshal_any.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package testutils 19 | 20 | import ( 21 | "testing" 22 | 23 | "google.golang.org/protobuf/proto" 24 | "google.golang.org/protobuf/types/known/anypb" 25 | ) 26 | 27 | // MarshalAny is a convenience function to marshal protobuf messages into any 28 | // protos. function will fail the test with a fatal error if the marshaling fails. 29 | func MarshalAny(t *testing.T, m proto.Message) *anypb.Any { 30 | t.Helper() 31 | 32 | a, err := anypb.New(m) 33 | if err != nil { 34 | t.Fatalf("Failed to marshal proto %+v into an Any: %v", m, err) 35 | } 36 | return a 37 | } 38 | -------------------------------------------------------------------------------- /internal/testutils/parse_port.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2023 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package testutils 19 | 20 | import ( 21 | "net" 22 | "strconv" 23 | "testing" 24 | ) 25 | 26 | // ParsePort returns the port from the given address string, as a unit32. 27 | func ParsePort(t *testing.T, addr string) uint32 { 28 | t.Helper() 29 | 30 | _, p, err := net.SplitHostPort(addr) 31 | if err != nil { 32 | t.Fatalf("Invalid serving address: %v", err) 33 | } 34 | port, err := strconv.ParseUint(p, 10, 32) 35 | if err != nil { 36 | t.Fatalf("Invalid serving port: %v", err) 37 | } 38 | return uint32(port) 39 | } 40 | -------------------------------------------------------------------------------- /internal/testutils/parse_url.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2023 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package testutils 20 | 21 | import ( 22 | "fmt" 23 | "net/url" 24 | ) 25 | 26 | // MustParseURL attempts to parse the provided target using url.Parse() 27 | // and panics if parsing fails. 28 | func MustParseURL(target string) *url.URL { 29 | u, err := url.Parse(target) 30 | if err != nil { 31 | panic(fmt.Sprintf("Error parsing target(%s): %v", target, err)) 32 | } 33 | return u 34 | } 35 | -------------------------------------------------------------------------------- /internal/testutils/status_equal.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2019 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package testutils 20 | 21 | import ( 22 | "google.golang.org/grpc/status" 23 | "google.golang.org/protobuf/proto" 24 | ) 25 | 26 | // StatusErrEqual returns true iff both err1 and err2 wrap status.Status errors 27 | // and their underlying status protos are equal. 28 | func StatusErrEqual(err1, err2 error) bool { 29 | status1, ok := status.FromError(err1) 30 | if !ok { 31 | return false 32 | } 33 | status2, ok := status.FromError(err2) 34 | if !ok { 35 | return false 36 | } 37 | return proto.Equal(status1.Proto(), status2.Proto()) 38 | } 39 | -------------------------------------------------------------------------------- /internal/testutils/xds/e2e/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2022 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package e2e 20 | 21 | // serverLogger implements the Logger interface defined at 22 | // envoyproxy/go-control-plane/pkg/log. This is passed to the Snapshot cache. 23 | type serverLogger struct { 24 | logger interface { 25 | Logf(format string, args ...any) 26 | } 27 | } 28 | 29 | func (l serverLogger) Debugf(format string, args ...any) { 30 | l.logger.Logf(format, args...) 31 | } 32 | func (l serverLogger) Infof(format string, args ...any) { 33 | l.logger.Logf(format, args...) 34 | } 35 | func (l serverLogger) Warnf(format string, args ...any) { 36 | l.logger.Logf(format, args...) 37 | } 38 | func (l serverLogger) Errorf(format string, args ...any) { 39 | l.logger.Logf(format, args...) 40 | } 41 | -------------------------------------------------------------------------------- /internal/transport/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2023 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package transport 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | var logger = grpclog.Component("transport") 29 | 30 | func prefixLoggerForServerTransport(p *http2Server) *internalgrpclog.PrefixLogger { 31 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf("[server-transport %p] ", p)) 32 | } 33 | 34 | func prefixLoggerForServerHandlerTransport(p *serverHandlerTransport) *internalgrpclog.PrefixLogger { 35 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf("[server-handler-transport %p] ", p)) 36 | } 37 | 38 | func prefixLoggerForClientTransport(p *http2Client) *internalgrpclog.PrefixLogger { 39 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf("[client-transport %p] ", p)) 40 | } 41 | -------------------------------------------------------------------------------- /internal/wrr/edf_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package wrr 18 | 19 | import ( 20 | "testing" 21 | ) 22 | 23 | func (s) TestEDFOnEndpointsWithSameWeight(t *testing.T) { 24 | wrr := NewEDF() 25 | wrr.Add("1", 1) 26 | wrr.Add("2", 1) 27 | wrr.Add("3", 1) 28 | expected := []string{"1", "2", "3", "1", "2", "3", "1", "2", "3", "1", "2", "3"} 29 | for i := 0; i < len(expected); i++ { 30 | item := wrr.Next().(string) 31 | if item != expected[i] { 32 | t.Errorf("wrr Next=%s, want=%s", item, expected[i]) 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /internal/wrr/wrr.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2019 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | // Package wrr contains the interface and common implementations of wrr 19 | // algorithms. 20 | package wrr 21 | 22 | // WRR defines an interface that implements weighted round robin. 23 | type WRR interface { 24 | // Add adds an item with weight to the WRR set. Add must be only called 25 | // before any calls to Next. 26 | Add(item any, weight int64) 27 | // Next returns the next picked item. 28 | // 29 | // Next needs to be thread safe. Add may not be called after any call to 30 | // Next. 31 | Next() any 32 | } 33 | -------------------------------------------------------------------------------- /internal/xds/bootstrap/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package bootstrap 20 | 21 | import ( 22 | "google.golang.org/grpc/grpclog" 23 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 24 | ) 25 | 26 | const prefix = "[xds-bootstrap] " 27 | 28 | var logger = internalgrpclog.NewPrefixLogger(grpclog.Component("xds"), prefix) 29 | -------------------------------------------------------------------------------- /interop/observability/build_docker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2022 gRPC authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -ex 17 | cd "$(dirname "$0")"/../.. 18 | 19 | # Environment Variables: 20 | # 21 | # TAG_NAME: the docker image tag name 22 | # 23 | 24 | echo Building ${TAG_NAME} 25 | 26 | docker build --no-cache -t ${TAG_NAME} -f ./interop/observability/Dockerfile . 27 | -------------------------------------------------------------------------------- /interop/observability/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2022 gRPC authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -ex 17 | cd "$(dirname "$0")"/../.. 18 | 19 | if [ "$1" = "server" ] ; then 20 | /grpc-go/interop/observability/server/server "${@:2}" 21 | 22 | elif [ "$1" = "client" ] ; then 23 | /grpc-go/interop/observability/client/client "${@:2}" 24 | 25 | else 26 | echo "Invalid action: $1. Usage:" 27 | echo " $ .../run.sh [server|client] --server_host= --server_port= ..." 28 | exit 1 29 | fi 30 | -------------------------------------------------------------------------------- /profiling/cmd/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2019 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Binary cmd is a command-line tool for profiling management. It retrieves and 20 | // processes data from the profiling service. 21 | package main 22 | 23 | import ( 24 | "os" 25 | 26 | "google.golang.org/grpc/grpclog" 27 | ppb "google.golang.org/grpc/profiling/proto" 28 | ) 29 | 30 | var logger = grpclog.Component("profiling") 31 | 32 | type snapshot struct { 33 | StreamStats []*ppb.Stat 34 | } 35 | 36 | func main() { 37 | if err := parseArgs(); err != nil { 38 | logger.Errorf("error parsing flags: %v", err) 39 | os.Exit(1) 40 | } 41 | 42 | if *flagAddress != "" { 43 | if err := remoteCommand(); err != nil { 44 | logger.Errorf("error: %v", err) 45 | os.Exit(1) 46 | } 47 | } else { 48 | if err := localCommand(); err != nil { 49 | logger.Errorf("error: %v", err) 50 | os.Exit(1) 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /profiling/profiling.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2019 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package profiling exposes methods to manage profiling within gRPC. 20 | // 21 | // # Experimental 22 | // 23 | // Notice: This package is EXPERIMENTAL and may be changed or removed in a 24 | // later release. 25 | package profiling 26 | 27 | import ( 28 | internal "google.golang.org/grpc/internal/profiling" 29 | ) 30 | 31 | // Enable turns profiling on and off. This operation is safe for concurrent 32 | // access from different goroutines. 33 | // 34 | // Note that this is the only operation that's accessible through the publicly 35 | // exposed profiling package. Everything else (such as retrieving stats) must 36 | // be done through the profiling service. This is allowed so that users can use 37 | // heuristics to turn profiling on and off automatically. 38 | func Enable(enabled bool) { 39 | internal.Enable(enabled) 40 | } 41 | -------------------------------------------------------------------------------- /reflection/README.md: -------------------------------------------------------------------------------- 1 | # Reflection 2 | 3 | Package reflection implements server reflection service. 4 | 5 | The service implemented is defined in: https://github.com/grpc/grpc/blob/master/src/proto/grpc/reflection/v1/reflection.proto. 6 | 7 | To register server reflection on a gRPC server: 8 | ```go 9 | import "google.golang.org/grpc/reflection" 10 | 11 | s := grpc.NewServer() 12 | pb.RegisterYourOwnServer(s, &server{}) 13 | 14 | // Register reflection service on gRPC server. 15 | reflection.Register(s) 16 | 17 | s.Serve(lis) 18 | ``` 19 | -------------------------------------------------------------------------------- /reflection/grpc_testing/proto2.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2017 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto2"; 16 | 17 | option go_package = "google.golang.org/grpc/reflection/grpc_testing"; 18 | 19 | package grpc.testing; 20 | 21 | message ToBeExtended { 22 | required int32 foo = 1; 23 | extensions 10 to 30; 24 | } 25 | -------------------------------------------------------------------------------- /reflection/grpc_testing/proto2_ext.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2017 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto2"; 16 | 17 | option go_package = "google.golang.org/grpc/reflection/grpc_testing"; 18 | 19 | package grpc.testing; 20 | 21 | import "reflection/grpc_testing/proto2.proto"; 22 | import "reflection/grpc_testing/test.proto"; 23 | 24 | extend ToBeExtended { 25 | optional int32 foo = 13; 26 | optional Extension bar = 17; 27 | optional SearchRequest baz = 19; 28 | } 29 | 30 | message Extension { 31 | optional int32 whatzit = 1; 32 | } 33 | -------------------------------------------------------------------------------- /reflection/grpc_testing/proto2_ext2.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2017 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto2"; 16 | 17 | option go_package = "google.golang.org/grpc/reflection/grpc_testing"; 18 | 19 | package grpc.testing; 20 | 21 | import "reflection/grpc_testing/proto2.proto"; 22 | 23 | extend ToBeExtended { 24 | optional string frob = 23; 25 | optional AnotherExtension nitz = 29; 26 | } 27 | 28 | message AnotherExtension { 29 | optional int32 whatchamacallit = 1; 30 | } 31 | -------------------------------------------------------------------------------- /reflection/grpc_testing/test.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2017 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | option go_package = "google.golang.org/grpc/reflection/grpc_testing"; 18 | 19 | package grpc.testing; 20 | 21 | message SearchResponse { 22 | message Result { 23 | string url = 1; 24 | string title = 2; 25 | repeated string snippets = 3; 26 | } 27 | repeated Result results = 1; 28 | } 29 | 30 | message SearchRequest { 31 | string query = 1; 32 | } 33 | 34 | service SearchService { 35 | rpc Search(SearchRequest) returns (SearchResponse); 36 | rpc StreamingSearch(stream SearchRequest) returns (stream SearchResponse); 37 | } 38 | -------------------------------------------------------------------------------- /resolver/passthrough/passthrough.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2017 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package passthrough implements a pass-through resolver. It sends the target 20 | // name without scheme back to gRPC as resolved address. 21 | // 22 | // Deprecated: this package is imported by grpc and should not need to be 23 | // imported directly by users. 24 | package passthrough 25 | 26 | import _ "google.golang.org/grpc/internal/resolver/passthrough" // import for side effects after package was moved 27 | -------------------------------------------------------------------------------- /scripts/common.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | fail_on_output() { 4 | tee /dev/stderr | not read 5 | } 6 | 7 | # not makes sure the command passed to it does not exit with a return code of 0. 8 | not() { 9 | # This is required instead of the earlier (! $COMMAND) because subshells and 10 | # pipefail don't work the same on Darwin as in Linux. 11 | ! "$@" 12 | } 13 | 14 | # noret_grep will return 0 if zero or more lines were selected, and >1 if an 15 | # error occurred. Suppresses grep's return code of 1 when there are no matches 16 | # (for eg, empty file). 17 | noret_grep() { 18 | grep "$@" || [[ $? == 1 ]] 19 | } 20 | 21 | die() { 22 | echo "$@" >&2 23 | exit 1 24 | } 25 | -------------------------------------------------------------------------------- /scripts/gen-deps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e # Exit on error 4 | set -o pipefail # Fail a pipe if any sub-command fails. 5 | 6 | source "$(dirname $0)/common.sh" 7 | 8 | if [[ "$#" -ne 1 || ! -d "$1" ]]; then 9 | echo "Specify a valid output directory as the first parameter." 10 | exit 1 11 | fi 12 | 13 | SCRIPTS_DIR="$(dirname "$0")" 14 | OUTPUT_DIR="$1" 15 | 16 | cd "${SCRIPTS_DIR}/.." 17 | 18 | git ls-files -- '*.go' | grep -v '\(^\|/\)\(internal\|examples\|benchmark\|interop\|test\|testdata\)\(/\|$\)' | xargs dirname | sort -u | while read d; do 19 | pushd "$d" > /dev/null 20 | pkg="$(echo "$d" | sed 's;\.;grpc;' | sed 's;/;_;g')" 21 | go list -deps . | sort | noret_grep -v 'google.golang.org/grpc' >| "${OUTPUT_DIR}/$pkg" 22 | popd > /dev/null 23 | done 24 | -------------------------------------------------------------------------------- /scripts/revive.toml: -------------------------------------------------------------------------------- 1 | # Enabled rules 2 | [rule.blank-imports] 3 | 4 | [rule.context-as-argument] 5 | 6 | [rule.context-keys-type] 7 | 8 | [rule.dot-imports] 9 | 10 | [rule.errorf] 11 | 12 | [rule.error-return] 13 | 14 | [rule.error-strings] 15 | 16 | [rule.error-naming] 17 | 18 | [rule.exported] 19 | 20 | [rule.increment-decrement] 21 | 22 | [rule.indent-error-flow] 23 | arguments = ["preserveScope"] 24 | 25 | [rule.package-comments] 26 | 27 | [rule.range] 28 | 29 | [rule.receiver-naming] 30 | 31 | [rule.superfluous-else] 32 | arguments = ["preserveScope"] 33 | 34 | [rule.time-naming] 35 | 36 | [rule.unexported-return] 37 | 38 | [rule.unnecessary-stmt] 39 | 40 | [rule.unreachable-code] 41 | 42 | [rule.unused-parameter] 43 | 44 | [rule.use-any] 45 | 46 | [rule.useless-break] 47 | 48 | [rule.var-declaration] 49 | 50 | [rule.var-naming] 51 | 52 | # Disabled rules 53 | [rule.empty-block] # Disabled to allow intentional no-op blocks (e.g., channel draining). 54 | Disabled = true 55 | 56 | [rule.import-shadowing] # Disabled to allow intentional reuse of variable names that are the same as package imports. 57 | Disabled = true 58 | 59 | [rule.redefines-builtin-id] # Disabled to allow intentional reuse of variable names that are the same as built-in functions. 60 | Disabled = true 61 | -------------------------------------------------------------------------------- /scripts/vet-proto.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex # Exit on error; debugging enabled. 4 | set -o pipefail # Fail a pipe if any sub-command fails. 5 | 6 | # - Source them sweet sweet helpers. 7 | source "$(dirname $0)/common.sh" 8 | 9 | # - Check to make sure it's safe to modify the user's git repo. 10 | git status --porcelain | fail_on_output 11 | 12 | # - Undo any edits made by this script. 13 | cleanup() { 14 | git reset --hard HEAD 15 | } 16 | trap cleanup EXIT 17 | 18 | # - Installs protoc into your ${GOBIN} directory, if requested. 19 | # ($GOBIN might not be the best place for the protoc binary, but is at least 20 | # consistent with the place where all binaries installed by scripts in this repo 21 | # go.) 22 | if [[ "$1" = "-install" ]]; then 23 | if [[ "${GITHUB_ACTIONS}" = "true" ]]; then 24 | source ./scripts/install-protoc.sh "/home/runner/go" 25 | else 26 | die "run protoc installer https://github.com/grpc/grpc-go/blob/master/scripts/install-protoc.sh" 27 | fi 28 | echo SUCCESS 29 | exit 0 30 | elif [[ "$#" -ne 0 ]]; then 31 | die "Unknown argument(s): $*" 32 | fi 33 | 34 | for MOD_FILE in $(find . -name 'go.mod'); do 35 | MOD_DIR=$(dirname ${MOD_FILE}) 36 | pushd ${MOD_DIR} 37 | go generate ./... 38 | popd 39 | done 40 | 41 | # - Check that generated proto files are up to date. 42 | git status --porcelain 2>&1 | fail_on_output || \ 43 | (git status; git --no-pager diff; exit 1) 44 | 45 | echo SUCCESS 46 | exit 0 47 | -------------------------------------------------------------------------------- /security/advancedtls/examples/credential_reloading_from_files/README.md: -------------------------------------------------------------------------------- 1 | # Credential Reloading From Files 2 | 3 | Credential reloading is a feature supported in the advancedtls library. 4 | A very common way to achieve this is to reload from files. 5 | 6 | This example demonstrates how to set the reloading fields in advancedtls API. 7 | Basically, a set of file system locations holding the credential data need to be specified. 8 | Once the credential data needs to be updated, users just change the credential data in the file system, and gRPC will pick up the changes automatically. 9 | 10 | A couple of things to note: 11 | 1. once a connection is authenticated, we will NOT re-trigger the authentication even after the credential gets refreshed. 12 | 2. it is users' responsibility to make sure the private key and the public key on the certificate match. If they don't match, gRPC will 13 | ignore the update and use the old credentials. If this mismatch happens at the first time, all connections will hang until the correct 14 | credentials are pushed or context timeout. 15 | 16 | ## Try it 17 | In directory `security/advancedtls/examples`: 18 | 19 | ``` 20 | go run server/main.go 21 | ``` 22 | 23 | ``` 24 | go run client/main.go 25 | ``` 26 | -------------------------------------------------------------------------------- /security/advancedtls/examples/go.mod: -------------------------------------------------------------------------------- 1 | module google.golang.org/grpc/security/advancedtls/examples 2 | 3 | go 1.23.0 4 | 5 | require ( 6 | google.golang.org/grpc v1.72.1 7 | google.golang.org/grpc/examples v0.0.0-20250403095317-51d6a43ec597 8 | google.golang.org/grpc/security/advancedtls v1.0.0 9 | ) 10 | 11 | require ( 12 | github.com/go-jose/go-jose/v4 v4.0.5 // indirect 13 | github.com/spiffe/go-spiffe/v2 v2.5.0 // indirect 14 | github.com/zeebo/errs v1.4.0 // indirect 15 | golang.org/x/crypto v0.38.0 // indirect 16 | golang.org/x/net v0.40.0 // indirect 17 | golang.org/x/sys v0.33.0 // indirect 18 | golang.org/x/text v0.25.0 // indirect 19 | google.golang.org/genproto/googleapis/rpc v0.0.0-20250512202823-5a2f75b736a9 // indirect 20 | google.golang.org/protobuf v1.36.6 // indirect 21 | ) 22 | 23 | replace google.golang.org/grpc => ../../.. 24 | 25 | replace google.golang.org/grpc/examples => ../../../examples 26 | 27 | replace google.golang.org/grpc/security/advancedtls => ../ 28 | -------------------------------------------------------------------------------- /security/advancedtls/go.mod: -------------------------------------------------------------------------------- 1 | module google.golang.org/grpc/security/advancedtls 2 | 3 | go 1.23.0 4 | 5 | require ( 6 | github.com/google/go-cmp v0.7.0 7 | golang.org/x/crypto v0.38.0 8 | google.golang.org/grpc v1.72.1 9 | google.golang.org/grpc/examples v0.0.0-20250403095317-51d6a43ec597 10 | ) 11 | 12 | require ( 13 | github.com/go-jose/go-jose/v4 v4.0.5 // indirect 14 | github.com/spiffe/go-spiffe/v2 v2.5.0 // indirect 15 | github.com/zeebo/errs v1.4.0 // indirect 16 | golang.org/x/net v0.40.0 // indirect 17 | golang.org/x/sys v0.33.0 // indirect 18 | golang.org/x/text v0.25.0 // indirect 19 | google.golang.org/genproto/googleapis/rpc v0.0.0-20250512202823-5a2f75b736a9 // indirect 20 | google.golang.org/protobuf v1.36.6 // indirect 21 | ) 22 | 23 | replace google.golang.org/grpc => ../../ 24 | 25 | replace google.golang.org/grpc/examples => ../../examples 26 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/0b35a562.r0: -------------------------------------------------------------------------------- 1 | 5.crl -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/0b35a562.r1: -------------------------------------------------------------------------------- 1 | 1.crl -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/1.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIBYDCCAQYCAQEwCgYIKoZIzj0EAwIwgaUxCzAJBgNVBAYTAlVTMRMwEQYDVQQI 3 | EwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpH 4 | b29nbGUgTExDMSYwEQYDVQQLEwpQcm9kdWN0aW9uMBEGA1UECxMKY2FtcHVzLXNs 5 | bjEsMCoGA1UEAxMjUm9vdCBDQSAoMjAyMS0wMi0wMlQwNzozMDozNi0wODowMCkX 6 | DTIxMDIwMjE1MzAzNloXDTIxMDIwOTE1MzAzNlqgLzAtMB8GA1UdIwQYMBaAFPQN 7 | tnCIBcG4ReQgoVi0kPgTROseMAoGA1UdFAQDAgEAMAoGCCqGSM49BAMCA0gAMEUC 8 | IQDB9WEPBPHEo5xjCv8CT9okockJJnkLDOus6FypVLqj5QIgYw9/PYLwb41/Uc+4 9 | LLTAsfdDWh7xBJmqvVQglMoJOEc= 10 | -----END X509 CRL----- 11 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/1ab871c8.r0: -------------------------------------------------------------------------------- 1 | 2.crl -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/2.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIBYDCCAQYCAQEwCgYIKoZIzj0EAwIwgaUxCzAJBgNVBAYTAlVTMRMwEQYDVQQI 3 | EwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpH 4 | b29nbGUgTExDMSYwEQYDVQQLEwpQcm9kdWN0aW9uMBEGA1UECxMKY2FtcHVzLXNs 5 | bjEsMCoGA1UEAxMjbm9kZSBDQSAoMjAyMS0wMi0wMlQwNzozMDozNi0wODowMCkX 6 | DTIxMDIwMjE1MzAzNloXDTIxMDIwOTE1MzAzNlqgLzAtMB8GA1UdIwQYMBaAFBjo 7 | V5Jnk/gp1k7fmWwkvTk/cF/IMAoGA1UdFAQDAgEAMAoGCCqGSM49BAMCA0gAMEUC 8 | IQDgjA1Vj/pNFtNRL0vFEdapmFoArHM2+rn4IiP8jYLsCAIgAj2KEHbbtJ3zl5XP 9 | WVW6ZyW7r3wIX+Bt3vLJWPrQtf8= 10 | -----END X509 CRL----- 11 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/2f11f022.r0: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIHnMFICAQEwDQYJKoZIhvcNAQEMBQAwDDEKMAgGAioDDAI6KRcNMDkxMTEwMjMw 3 | MDAwWhcNMDkxMTExMDAwMDAwWqASMBAwDgYDVR0jBAcwBYADAQIDMA0GCSqGSIb3 4 | DQEBDAUAA4GBAMl2sjOjtOQ+OCsRyjM0IvqTn7lmdGJMvpYAym367JBamJPCbYrL 5 | MifCjCA1ra7gG0MweZbpm4SG2YLakwi1/B+XhApQ5VVv5SwDn6Yy5zr9ePLEF7Iy 6 | sP86e9s5XfOusLTW+Spre8q1vi7pJrRvUxhJGuUuLoM6Uhvh65ViilDJ 7 | -----END X509 CRL----- 8 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/3.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIBiDCCAS8CAQEwCgYIKoZIzj0EAwIwgaUxCzAJBgNVBAYTAlVTMRMwEQYDVQQI 3 | EwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpH 4 | b29nbGUgTExDMSYwEQYDVQQLEwpQcm9kdWN0aW9uMBEGA1UECxMKY2FtcHVzLXNs 5 | bjEsMCoGA1UEAxMjUm9vdCBDQSAoMjAyMS0wMi0wMlQwNzozMTo1NC0wODowMCkX 6 | DTIxMDIwMjE1MzE1NFoXDTIxMDIwOTE1MzE1NFowJzAlAhQAroEYW855BRqTrlov 7 | 5cBCGvkutxcNMjEwMjAyMTUzMTU0WqAvMC0wHwYDVR0jBBgwFoAUeq/TQ959KbWk 8 | /um08jSTXogXpWUwCgYDVR0UBAMCAQEwCgYIKoZIzj0EAwIDRwAwRAIgaSOIhJDg 9 | wOLYlbXkmxW0cqy/AfOUNYbz5D/8/FfvhosCICftg7Vzlu0Nh83jikyjy+wtkiJt 10 | ZYNvGFQ3Sp2L3A9e 11 | -----END X509 CRL----- 12 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/4.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIBYDCCAQYCAQEwCgYIKoZIzj0EAwIwgaUxCzAJBgNVBAYTAlVTMRMwEQYDVQQI 3 | EwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpH 4 | b29nbGUgTExDMSYwEQYDVQQLEwpQcm9kdWN0aW9uMBEGA1UECxMKY2FtcHVzLXNs 5 | bjEsMCoGA1UEAxMjbm9kZSBDQSAoMjAyMS0wMi0wMlQwNzozMTo1NC0wODowMCkX 6 | DTIxMDIwMjE1MzE1NFoXDTIxMDIwOTE1MzE1NFqgLzAtMB8GA1UdIwQYMBaAFIVn 7 | 8tIFgZpIdhomgYJ2c5ULLzpSMAoGA1UdFAQDAgEAMAoGCCqGSM49BAMCA0gAMEUC 8 | ICupTvOqgAyRa1nn7+Pe/1vvlJPAQ8gUfTQsQ6XX3v6oAiEA08B2PsK6aTEwzjry 9 | pXqhlUNZFzgaXrVVQuEJbyJ1qoU= 10 | -----END X509 CRL----- 11 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/5.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIBXzCCAQYCAQEwCgYIKoZIzj0EAwIwgaUxCzAJBgNVBAYTAlVTMRMwEQYDVQQI 3 | EwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpH 4 | b29nbGUgTExDMSYwEQYDVQQLEwpQcm9kdWN0aW9uMBEGA1UECxMKY2FtcHVzLXNs 5 | bjEsMCoGA1UEAxMjUm9vdCBDQSAoMjAyMS0wMi0wMlQwNzozMjo1Ny0wODowMCkX 6 | DTIxMDIwMjE1MzI1N1oXDTIxMDIwOTE1MzI1N1qgLzAtMB8GA1UdIwQYMBaAFN+g 7 | xTAtSTlb5Qqvrbp4rZtsaNzqMAoGA1UdFAQDAgEAMAoGCCqGSM49BAMCA0cAMEQC 8 | IHrRKjieY7w7gxvpkJAdszPZBlaSSp/c9wILutBTy7SyAiAwhaHfgas89iRfaBs2 9 | EhGIeK39A+kSzqu6qEQBHpK36g== 10 | -----END X509 CRL----- 11 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/6.crl: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIBiDCCAS8CAQEwCgYIKoZIzj0EAwIwgaUxCzAJBgNVBAYTAlVTMRMwEQYDVQQI 3 | EwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRMwEQYDVQQKEwpH 4 | b29nbGUgTExDMSYwEQYDVQQLEwpQcm9kdWN0aW9uMBEGA1UECxMKY2FtcHVzLXNs 5 | bjEsMCoGA1UEAxMjbm9kZSBDQSAoMjAyMS0wMi0wMlQwNzozMjo1Ny0wODowMCkX 6 | DTIxMDIwMjE1MzI1N1oXDTIxMDIwOTE1MzI1N1owJzAlAhQAxSe/pGmyvzN7mxm5 7 | 6ZJTYUXYuhcNMjEwMjAyMTUzMjU3WqAvMC0wHwYDVR0jBBgwFoAUpZ30UJXB4lI9 8 | j2SzodCtRFckrRcwCgYDVR0UBAMCAQEwCgYIKoZIzj0EAwIDRwAwRAIgRg3u7t3b 9 | oyV5FhMuGGzWnfIwnKclpT8imnp8tEN253sCIFUY7DjiDohwu4Zup3bWs1OaZ3q3 10 | cm+j0H/oe8zzCAgp 11 | -----END X509 CRL----- 12 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/71eac5a2.r0: -------------------------------------------------------------------------------- 1 | 4.crl -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/7a1799af.r0: -------------------------------------------------------------------------------- 1 | 3.crl -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/8828a7e6.r0: -------------------------------------------------------------------------------- 1 | 6.crl -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/deee447d.r0: -------------------------------------------------------------------------------- 1 | 5.crl -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/provider_crl.cnf: -------------------------------------------------------------------------------- 1 | [ ca ] 2 | default_ca = my_ca 3 | 4 | [ my_ca ] 5 | default_md = sha256 6 | database = provider_index.txt 7 | crlnumber = provider_crlnumber.txt 8 | default_crl_days = 30 9 | default_crl_hours = 1 10 | crl_extensions = crl_ext 11 | 12 | [crl_ext] 13 | # Authority Key Identifier extension 14 | authorityKeyIdentifier=keyid:always,issuer:always 15 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/provider_crl_empty.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIDMTCCARkCAQEwDQYJKoZIhvcNAQELBQAwSzELMAkGA1UEBhMCVVMxCzAJBgNV 3 | BAgMAkNBMQwwCgYDVQQHDANTVkwxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMg 4 | UHR5IEx0ZBcNMjUwMjExMDg1NDU4WhcNMjUwMzEzMDk1NDU4WqCBmTCBljCBhgYD 5 | VR0jBH8wfYAUjEyoZ1F7uhn+Mi48fDhTmb33MrahT6RNMEsxCzAJBgNVBAYTAlVT 6 | MQswCQYDVQQIDAJDQTEMMAoGA1UEBwwDU1ZMMSEwHwYDVQQKDBhJbnRlcm5ldCBX 7 | aWRnaXRzIFB0eSBMdGSCFBGWbavM3d+CR0dTuomppifCsPSuMAsGA1UdFAQEAgIQ 8 | ADANBgkqhkiG9w0BAQsFAAOCAgEACpuG5h2y13sA7liSDt3c/OSj/U8mmuVGRcl7 9 | hi/6ltsJSO3djnoHr+E6Grd4MvUBGTiGinwXgdxXa1TIYzikSNEMy4rzqF+cK2Na 10 | H0Loc/i7mwZ3wBBCHxmDPZx5vnEjOv957hHNe+5y4CIBsDZJbAdHExSTjKlKSsYG 11 | HYUZllsePYw5d/hThqXu0+lHk9eMJ+ljdvjVCzRmxjIKpaDAt+Kp/aj+FI9H0TNl 12 | 1i8tQl4H++Pe+DJTF5b4/EVUB2oyyagcCwXgxjDAWEzXjKftQS7fVpPcDhgvT4+U 13 | NwKcAYbMrg6m63ZF4yBy7q5PIDYyXXMW8c8fJPxsbec9BISIKQWVTTfx3wDYc7HF 14 | J57cGkHw+ijQmulQMTr37pnn6R0nTEpmbHEIUdj4QzDmVGx1FuAtLVYTVkzkQpGj 15 | k9Xj32eGAFYTTYUVaG8ehI0RoraWIl2UEbvoIYZAVO38qq1ueNkPNzeaGova4YUC 16 | vlry7NfFRJ7djOfCmOM9CP4XxFPzs0mfG8knY3K1eKGzRgslYI48K7xMKAS4h4YR 17 | feN8jQG6XHuuozsduBDWY2DygIK5Ol9GMXmr14V/jmn9U+dzj1j76ySB+3loDxT4 18 | W7tIWLOEQmr1+3C61aR0TMeVYwhQOSJRTs1AoXQPzOUsUZCy7LR8Sj/k5b0y+I2w 19 | oMXFbVU= 20 | -----END X509 CRL----- 21 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/provider_crl_server_revoked.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIDWjCCAUICAQEwDQYJKoZIhvcNAQELBQAwSzELMAkGA1UEBhMCVVMxCzAJBgNV 3 | BAgMAkNBMQwwCgYDVQQHDANTVkwxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMg 4 | UHR5IEx0ZBcNMjUwMjExMDg1NDU4WhcNMjUwMzEzMDk1NDU4WjAnMCUCFHOSrtXu 5 | CvESLVKM2mcrNGCS3XBDFw0yNTAyMTEwODU0NThaoIGZMIGWMIGGBgNVHSMEfzB9 6 | gBSMTKhnUXu6Gf4yLjx8OFOZvfcytqFPpE0wSzELMAkGA1UEBhMCVVMxCzAJBgNV 7 | BAgMAkNBMQwwCgYDVQQHDANTVkwxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMg 8 | UHR5IEx0ZIIUEZZtq8zd34JHR1O6iammJ8Kw9K4wCwYDVR0UBAQCAhABMA0GCSqG 9 | SIb3DQEBCwUAA4ICAQBo39YSzt53/RrX1acgfvCfqlB9f2Pir+JbmaE4dmQCC9Km 10 | abdKLNxAQ2E8HPJMrOEpF+KGOm+6ugCkmr5c9NHFpMk+/BW2+LgtI7Xs481Eg16B 11 | gzrDX/AU9UvsA7p+7hT7lldCZGyya4v5iLVD0uRllvku7wkYF7vyhtWuKxnJaDWs 12 | noCfvbHuVi3srSdfQjWhCsARpi9eoDrry0iXUE+FiQeF6Iit5sHW/XQzMfYNLYxp 13 | W1PqIp/dlVAFjPmXrU9eOv9eofwsCuDFFQMuN+33K3zGI/gNnw08X6xoarG/m1Rp 14 | Vfsf3eBeBvHwlPsketshg8jyPXuY7Jtg2niizHJgK2AUFgepozfztuVP7FFFvOXB 15 | YLZA9xwO3kNiPjZGc60HiyQexOCVwC2DtnN62bOsJa6daA9CUNHjpoKLrkF0TdgI 16 | RTJcEPPLsbHBhqXFBAKAf8mLEQIkVpkqb1XNf3LCjnRFXrM847KhLIP54PtniRpZ 17 | UJRSIYNGhrHr9qGMlJXzKZuhqKUAMSG5Cw3tZMOxFroFrT0eOXN5pncj1McRuL2F 18 | 2bt6g18EfpQVqGFrYbs+2UHzTuvEkvH3wlMk5FojlDerq74GLrk026AF48Tykedo 19 | gJc5qxrPS9nFd7iiPUO7o2nCozGaKyuMQq5kylaIGDib1KDE8DoShmC4zc6onA== 20 | -----END X509 CRL----- 21 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/provider_extensions.conf: -------------------------------------------------------------------------------- 1 | [extensions] 2 | subjectKeyIdentifier = hash 3 | authorityKeyIdentifier = keyid,issuer 4 | basicConstraints = CA:FALSE 5 | keyUsage = digitalSignature, keyEncipherment 6 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/crl/provider_malicious_crl_empty.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN X509 CRL----- 2 | MIIDWjCCAUICAQEwDQYJKoZIhvcNAQELBQAwSzELMAkGA1UEBhMCVVMxCzAJBgNV 3 | BAgMAkNBMQwwCgYDVQQHDANTVkwxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMg 4 | UHR5IEx0ZBcNMjUwMjExMDg1NDU5WhcNMjUwMzEzMDk1NDU5WjAnMCUCFHOSrtXu 5 | CvESLVKM2mcrNGCS3XBDFw0yNTAyMTEwODU0NThaoIGZMIGWMIGGBgNVHSMEfzB9 6 | gBSMTKhnUXu6Gf4yLjx8OFOZvfcytqFPpE0wSzELMAkGA1UEBhMCVVMxCzAJBgNV 7 | BAgMAkNBMQwwCgYDVQQHDANTVkwxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMg 8 | UHR5IEx0ZIIUJAaDEkZf8jEXmqlzlxRAIOQvt1owCwYDVR0UBAQCAhACMA0GCSqG 9 | SIb3DQEBCwUAA4ICAQBYfdS07RS5kS8pRpb2r+TX3yPqVbNK9BzUhzu+mAi0IJPw 10 | wOVUt4mErf7fZ/uagmG3AeS9lDl7SrRcD7LcTR+5L8UiukX2sntrqkvOnaticwwg 11 | x5yCFFuepXfnVSH2xcvlQYU0dHdpb4aTE2jzLc04/3MgBXSsqBUsu3QS46x+NNLt 12 | FHtbpEVG5Jl4lZkO2R1krNw09cYiUYMp+oV78imaarNjsGKE8Y7rPXB5lFwAbm0H 13 | XblogLVlYIo6AMF28hnCovntEEtOjLHHdMxRyOH/cFWE/YqXuuAxHwM2PBPt55wf 14 | gbpJDOXgMhwcK8O5jA6N8RfF6RAxnhsMRSTfMRfNtRUXKAM/t9pa4kz/8/wcSZPC 15 | tnZRIe0ggDnWNoAtnguoMfwDqnTL1TUnRavFMSmaEgUiTro1x85owqqsOUlrG+4G 16 | F6IH7hpWv86vXdYq8WsQdo01M0WylQa41fB+D4amDnUwMsiLsoaGMqoOAQlbwebh 17 | Lx5locMdPoYeJQxrF1mh8RNXrbkiye5LuCFU97mwtsRwPfJULQ5fuUZm6oDNQEH7 18 | 5GRiAgoKMn4J7nSqyIfXtkFZ2D1BgkN5pwvrPZNH4ExPgJQcHS1DtosZLmn4EvIF 19 | 3uIE6eiIkdqZLupmdAUfuNAAXP39TNpqHj/X8RMB4UpC9Tx2VSK9KJI15/szNA== 20 | -----END X509 CRL----- 21 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/localhost-openssl.cnf: -------------------------------------------------------------------------------- 1 | [req] 2 | distinguished_name = req_distinguished_name 3 | req_extensions = v3_req 4 | 5 | [req_distinguished_name] 6 | countryName = Country Name (2 letter code) 7 | countryName_default = US 8 | stateOrProvinceName = State or Province Name (full name) 9 | stateOrProvinceName_default = Illinois 10 | localityName = Locality Name (eg, city) 11 | localityName_default = Chicago 12 | organizationName = Organization Name (eg, company) 13 | organizationName_default = Example, Co. 14 | commonName = Common Name (eg, YOUR name) 15 | commonName_max = 64 16 | 17 | [v3_req] 18 | basicConstraints = CA:FALSE 19 | keyUsage = nonRepudiation, digitalSignature, keyEncipherment 20 | subjectAltName = @alt_names 21 | 22 | [alt_names] 23 | DNS.1 = localhost 24 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/server_cert_3.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDyTCCArGgAwIBAgIUeoNdEiqhXVkpcYsmHaKiVS5W/tQwDQYJKoZIhvcNAQEL 3 | BQAwPjELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMREwDwYDVQQHDAhTYW4gSm9z 4 | ZTEPMA0GA1UECgwGR29vZ2xlMB4XDTIwMDcxNjE2NTMxOVoXDTQwMDcxMTE2NTMx 5 | OVowgZMxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTERMA8GA1UEBwwIU2FuIEpv 6 | c2UxEjAQBgNVBAoMCUVuZCBQb2ludDEOMAwGA1UECwwFSW5mcmExIjAgBgkqhkiG 7 | 9w0BCQEWE2NpbmR5eHVlQGdvb2dsZS5jb20xHDAaBgNVBAMME2Zvby5iYXIuc2Vy 8 | dmVyMy5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDcIyJEt3ZA 9 | xPn7H5f/IwXS8NcoAXWP8L6rWndcg+EWayx7W+wmUsFKGSFGzrFPPCFmKO8MrQqp 10 | 8LSAxHAVtOC6Uw+INWJJw9BRlx2nvV7hfbqu3OnPkPVkN/siUQCqnEKJQHliNT9X 11 | Dl4/Mav75uQSWb3Vfi3KtG7mzPFNNbbe4yfHyGbC4e9RtKkGimDSJ413s3m4+scD 12 | vtpCcCXj9XXZNdCwD1CL3kNdmOdhgfkDBP+AMLBFKZKqpCo6m0s4JJTiej13dc27 13 | wTrnkFm1CP77SV+kQlWg5DAcVXYJkN9FqNqExqIPS/SxMk7H+3qSQACbttQK9UmC 14 | n3qR3pGbwqzNAgMBAAGjaTBnMB8GA1UdIwQYMBaAFG4bi8k0dOd7jSpPQQ6YUDAU 15 | ARaxMAkGA1UdEwQCMAAwCwYDVR0PBAQDAgTwMCwGA1UdEQQlMCOCCmdvb2dsZS5j 16 | b22CCWFwcGxlLmNvbYIKYW1hem9uLmNvbTANBgkqhkiG9w0BAQsFAAOCAQEAn5aW 17 | HEHNTDmcgC25oEtCj+IkoAslgFze4ZqkSz0HCzx76vj3AfMmIEvqB0W74wKqeZgm 18 | V0D7I0xHkM3ILH4RjoCotpol3nLooIPFflA6Z1ILTRZl8mE5kfBSHzKdPS0egOf6 19 | kgrNYgJjBEtGNsmq8RKxAHVVAPgH88di0JnQDN5LcV9ZBKTQM2R7EM6a8eWD/Jsi 20 | uujbNtdNERssSBV+Oil93MbsEcOT1RSKKxAiVvkHkR+45GRB889xBnqelcDVqcMK 21 | Vcdp6X7aD5/Bu/4fq9AZlcHSEQDixNtjp/pQR0B5FsCGrb5OAz0B2t9jykDiIyj4 22 | 4lxhQz8ykXf7ue0/ag== 23 | -----END CERTIFICATE----- 24 | -------------------------------------------------------------------------------- /security/advancedtls/testdata/testdata.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | // Package testdata contains functionality to find data files in tests. 19 | package testdata 20 | 21 | import ( 22 | "path/filepath" 23 | "runtime" 24 | ) 25 | 26 | // basepath is the root directory of this package. 27 | var basepath string 28 | 29 | func init() { 30 | _, currentFile, _, _ := runtime.Caller(0) 31 | basepath = filepath.Dir(currentFile) 32 | } 33 | 34 | // Path returns the absolute path the given relative file or directory path, 35 | // relative to the google.golang.org/grpc/testdata directory in the user's GOPATH. 36 | // If rel is already absolute, it is returned unmodified. 37 | func Path(rel string) string { 38 | if filepath.IsAbs(rel) { 39 | return rel 40 | } 41 | 42 | return filepath.Join(basepath, rel) 43 | } 44 | -------------------------------------------------------------------------------- /serviceconfig/serviceconfig.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2019 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package serviceconfig defines types and methods for operating on gRPC 20 | // service configs. 21 | // 22 | // # Experimental 23 | // 24 | // Notice: This package is EXPERIMENTAL and may be changed or removed in a 25 | // later release. 26 | package serviceconfig 27 | 28 | // Config represents an opaque data structure holding a service config. 29 | type Config interface { 30 | isServiceConfig() 31 | } 32 | 33 | // LoadBalancingConfig represents an opaque data structure holding a load 34 | // balancing config. 35 | type LoadBalancingConfig interface { 36 | isLoadBalancingConfig() 37 | } 38 | 39 | // ParseResult contains a service config or an error. Exactly one must be 40 | // non-nil. 41 | type ParseResult struct { 42 | Config Config 43 | Err error 44 | } 45 | -------------------------------------------------------------------------------- /stats/opencensus/go.mod: -------------------------------------------------------------------------------- 1 | module google.golang.org/grpc/stats/opencensus 2 | 3 | go 1.23.0 4 | 5 | require ( 6 | github.com/google/go-cmp v0.7.0 7 | go.opencensus.io v0.24.0 8 | google.golang.org/grpc v1.72.1 9 | ) 10 | 11 | require ( 12 | github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect 13 | golang.org/x/net v0.40.0 // indirect 14 | golang.org/x/sys v0.33.0 // indirect 15 | golang.org/x/text v0.25.0 // indirect 16 | google.golang.org/genproto/googleapis/rpc v0.0.0-20250512202823-5a2f75b736a9 // indirect 17 | google.golang.org/protobuf v1.36.6 // indirect 18 | ) 19 | 20 | replace google.golang.org/grpc => ../.. 21 | -------------------------------------------------------------------------------- /test/codec_perf/perf.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2017 gRPC authors. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Messages used for performance tests that may not reference grpc directly for 16 | // reasons of import cycles. 17 | syntax = "proto3"; 18 | 19 | option go_package = "google.golang.org/grpc/test/codec_perf"; 20 | 21 | package codec.perf; 22 | 23 | // Buffer is a message that contains a body of bytes that is used to exercise 24 | // encoding and decoding overheads. 25 | message Buffer { 26 | bytes body = 1; 27 | } 28 | -------------------------------------------------------------------------------- /test/kokoro/README.md: -------------------------------------------------------------------------------- 1 | The scripts in this directory are intended to be run by Kokoro CI jobs. 2 | -------------------------------------------------------------------------------- /test/kokoro/psm-csm.cfg: -------------------------------------------------------------------------------- 1 | # Config file for internal CI 2 | 3 | # Location of the continuous shell script in repository. 4 | build_file: "grpc-go/test/kokoro/psm-interop-test-go.sh" 5 | timeout_mins: 120 6 | 7 | action { 8 | define_artifacts { 9 | regex: "artifacts/**/*sponge_log.xml" 10 | regex: "artifacts/**/*.log" 11 | strip_prefix: "artifacts" 12 | } 13 | } 14 | env_vars { 15 | key: "PSM_TEST_SUITE" 16 | value: "csm" 17 | } 18 | -------------------------------------------------------------------------------- /test/kokoro/psm-dualstack.cfg: -------------------------------------------------------------------------------- 1 | # Config file for internal CI 2 | 3 | # Location of the continuous shell script in repository. 4 | build_file: "grpc-go/test/kokoro/psm-interop-test-go.sh" 5 | timeout_mins: 360 6 | 7 | action { 8 | define_artifacts { 9 | regex: "artifacts/**/*sponge_log.xml" 10 | regex: "artifacts/**/*.log" 11 | strip_prefix: "artifacts" 12 | } 13 | } 14 | env_vars { 15 | key: "PSM_TEST_SUITE" 16 | value: "dualstack" 17 | } 18 | -------------------------------------------------------------------------------- /test/kokoro/psm-interop-build-go.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright 2024 gRPC authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | set -eo pipefail 16 | 17 | ####################################### 18 | # Builds test app Docker images and pushes them to GCR. 19 | # Called from psm_interop_kokoro_lib.sh. 20 | # 21 | # Globals: 22 | # SRC_DIR: Absolute path to the source repo on Kokoro VM 23 | # SERVER_IMAGE_NAME: Test server Docker image name 24 | # CLIENT_IMAGE_NAME: Test client Docker image name 25 | # GIT_COMMIT: SHA-1 of git commit being built 26 | # DOCKER_REGISTRY: Docker registry to push to 27 | # Outputs: 28 | # Writes the output of docker image build stdout, stderr 29 | ####################################### 30 | psm::lang::build_docker_images() { 31 | local client_dockerfile="interop/xds/client/Dockerfile" 32 | local server_dockerfile="interop/xds/server/Dockerfile" 33 | psm::build::docker_images_generic "${client_dockerfile}" "${server_dockerfile}" 34 | } 35 | -------------------------------------------------------------------------------- /test/kokoro/psm-light.cfg: -------------------------------------------------------------------------------- 1 | # Config file for internal CI 2 | 3 | # Location of the continuous shell script in repository. 4 | build_file: "grpc-go/test/kokoro/psm-interop-test-go.sh" 5 | timeout_mins: 30 6 | 7 | action { 8 | define_artifacts { 9 | regex: "artifacts/**/*sponge_log.xml" 10 | regex: "artifacts/**/*.log" 11 | strip_prefix: "artifacts" 12 | } 13 | } 14 | env_vars { 15 | key: "PSM_TEST_SUITE" 16 | value: "light" 17 | } 18 | -------------------------------------------------------------------------------- /test/kokoro/psm-security.cfg: -------------------------------------------------------------------------------- 1 | # Config file for internal CI 2 | 3 | # Location of the continuous shell script in repository. 4 | build_file: "grpc-go/test/kokoro/psm-interop-test-go.sh" 5 | timeout_mins: 240 6 | 7 | action { 8 | define_artifacts { 9 | regex: "artifacts/**/*sponge_log.xml" 10 | regex: "artifacts/**/*.log" 11 | strip_prefix: "artifacts" 12 | } 13 | } 14 | env_vars { 15 | key: "PSM_TEST_SUITE" 16 | value: "security" 17 | } 18 | -------------------------------------------------------------------------------- /test/kokoro/xds.cfg: -------------------------------------------------------------------------------- 1 | # Config file for internal CI 2 | 3 | # Location of the continuous shell script in repository. 4 | build_file: "grpc-go/test/kokoro/xds.sh" 5 | timeout_mins: 360 6 | action { 7 | define_artifacts { 8 | regex: "**/*sponge_log.*" 9 | regex: "github/grpc/reports/**" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/kokoro/xds_k8s_lb.cfg: -------------------------------------------------------------------------------- 1 | # Config file for internal CI 2 | 3 | # Location of the continuous shell script in repository. 4 | build_file: "grpc-go/test/kokoro/psm-interop-test-go.sh" 5 | timeout_mins: 300 6 | 7 | action { 8 | define_artifacts { 9 | regex: "artifacts/**/*sponge_log.xml" 10 | regex: "artifacts/**/*.log" 11 | strip_prefix: "artifacts" 12 | } 13 | } 14 | env_vars { 15 | key: "PSM_TEST_SUITE" 16 | value: "lb" 17 | } 18 | -------------------------------------------------------------------------------- /test/kokoro/xds_url_map.cfg: -------------------------------------------------------------------------------- 1 | # Config file for internal CI 2 | 3 | # Location of the continuous shell script in repository. 4 | build_file: "grpc-go/test/kokoro/psm-interop-test-go.sh" 5 | timeout_mins: 60 6 | 7 | action { 8 | define_artifacts { 9 | regex: "artifacts/**/*sponge_log.xml" 10 | regex: "artifacts/**/*.log" 11 | strip_prefix: "artifacts" 12 | } 13 | } 14 | env_vars { 15 | key: "PSM_TEST_SUITE" 16 | value: "url_map" 17 | } 18 | -------------------------------------------------------------------------------- /test/kokoro/xds_v3.cfg: -------------------------------------------------------------------------------- 1 | # Config file for internal CI 2 | 3 | # Location of the continuous shell script in repository. 4 | build_file: "grpc-go/test/kokoro/xds_v3.sh" 5 | timeout_mins: 360 6 | action { 7 | define_artifacts { 8 | regex: "**/*sponge_log.*" 9 | regex: "github/grpc/reports/**" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/kokoro/xds_v3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | XDS_V3_OPT="--xds_v3_support" `dirname $0`/xds.sh 4 | -------------------------------------------------------------------------------- /test/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package test 20 | 21 | import "google.golang.org/grpc/grpclog" 22 | 23 | var logger = grpclog.Component("testing") 24 | -------------------------------------------------------------------------------- /test/parse_config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2022 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package test 20 | 21 | import ( 22 | "testing" 23 | 24 | "google.golang.org/grpc/resolver/manual" 25 | "google.golang.org/grpc/serviceconfig" 26 | ) 27 | 28 | // parseServiceConfig is a test helper which uses the manual resolver to parse 29 | // the given service config. It calls t.Fatal() if service config parsing fails. 30 | func parseServiceConfig(t *testing.T, r *manual.Resolver, sc string) *serviceconfig.ParseResult { 31 | t.Helper() 32 | 33 | scpr := r.CC().ParseServiceConfig(sc) 34 | if scpr.Err != nil { 35 | t.Fatalf("Failed to parse service config %q: %v", sc, scpr.Err) 36 | } 37 | return scpr 38 | } 39 | -------------------------------------------------------------------------------- /test/race_test.go: -------------------------------------------------------------------------------- 1 | //go:build race 2 | // +build race 3 | 4 | /* 5 | * Copyright 2016 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package test 22 | 23 | func init() { 24 | raceMode = true 25 | } 26 | -------------------------------------------------------------------------------- /test/timeouts.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package test 20 | 21 | import "time" 22 | 23 | const ( 24 | // Default timeout for tests in this package. 25 | defaultTestTimeout = 10 * time.Second 26 | // Default short timeout, to be used when waiting for events which are not 27 | // expected to happen. 28 | defaultTestShortTimeout = 100 * time.Millisecond 29 | ) 30 | -------------------------------------------------------------------------------- /test/tools/go.mod: -------------------------------------------------------------------------------- 1 | module google.golang.org/grpc/test/tools 2 | 3 | go 1.23.0 4 | 5 | require ( 6 | github.com/client9/misspell v0.3.4 7 | github.com/mgechev/revive v1.8.0 8 | golang.org/x/tools v0.33.0 9 | google.golang.org/protobuf v1.36.6 10 | honnef.co/go/tools v0.6.1 11 | ) 12 | 13 | require ( 14 | github.com/BurntSushi/toml v1.5.0 // indirect 15 | github.com/chavacava/garif v0.1.0 // indirect 16 | github.com/fatih/color v1.18.0 // indirect 17 | github.com/fatih/structtag v1.2.0 // indirect 18 | github.com/hashicorp/go-version v1.7.0 // indirect 19 | github.com/mattn/go-colorable v0.1.14 // indirect 20 | github.com/mattn/go-isatty v0.0.20 // indirect 21 | github.com/mattn/go-runewidth v0.0.16 // indirect 22 | github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517 // indirect 23 | github.com/olekukonko/tablewriter v0.0.5 // indirect 24 | github.com/rivo/uniseg v0.4.7 // indirect 25 | github.com/spf13/afero v1.14.0 // indirect 26 | golang.org/x/exp/typeparams v0.0.0-20250506013437-ce4c2cf36ca6 // indirect 27 | golang.org/x/mod v0.24.0 // indirect 28 | golang.org/x/sync v0.14.0 // indirect 29 | golang.org/x/sys v0.33.0 // indirect 30 | golang.org/x/text v0.25.0 // indirect 31 | ) 32 | -------------------------------------------------------------------------------- /test/tools/tools.go: -------------------------------------------------------------------------------- 1 | //go:build tools 2 | // +build tools 3 | 4 | /* 5 | * 6 | * Copyright 2018 gRPC authors. 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | * 20 | */ 21 | 22 | // This file is not intended to be compiled. Because some of these imports are 23 | // not actual go packages, we use a build constraint at the top of this file to 24 | // prevent tools from inspecting the imports. 25 | 26 | package tools 27 | 28 | import ( 29 | _ "github.com/client9/misspell/cmd/misspell" 30 | _ "github.com/mgechev/revive" 31 | _ "golang.org/x/tools/cmd/goimports" 32 | _ "google.golang.org/protobuf/cmd/protoc-gen-go" 33 | _ "honnef.co/go/tools/cmd/staticcheck" 34 | ) 35 | -------------------------------------------------------------------------------- /test/tools/tools_vet.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package tools is used to pin specific versions of external tools in this 20 | // module's go.mod that gRPC uses for internal testing. 21 | package tools 22 | -------------------------------------------------------------------------------- /testdata/README.md: -------------------------------------------------------------------------------- 1 | This directory contains x509 certificates used in cloud-to-prod interop tests. 2 | For tests within gRPC-Go repo, please use the files in testdata/x509 3 | directory. 4 | -------------------------------------------------------------------------------- /testdata/ca.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDWjCCAkKgAwIBAgIUWrP0VvHcy+LP6UuYNtiL9gBhD5owDQYJKoZIhvcNAQEL 3 | BQAwVjELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM 4 | GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEPMA0GA1UEAwwGdGVzdGNhMB4XDTIw 5 | MDMxNzE4NTk1MVoXDTMwMDMxNTE4NTk1MVowVjELMAkGA1UEBhMCQVUxEzARBgNV 6 | BAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0 7 | ZDEPMA0GA1UEAwwGdGVzdGNhMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKC 8 | AQEAsGL0oXflF0LzoM+Bh+qUU9yhqzw2w8OOX5mu/iNCyUOBrqaHi7mGHx73GD01 9 | diNzCzvlcQqdNIH6NQSL7DTpBjca66jYT9u73vZe2MDrr1nVbuLvfu9850cdxiUO 10 | Inv5xf8+sTHG0C+a+VAvMhsLiRjsq+lXKRJyk5zkbbsETybqpxoJ+K7CoSy3yc/k 11 | QIY3TipwEtwkKP4hzyo6KiGd/DPexie4nBUInN3bS1BUeNZ5zeaIC2eg3bkeeW7c 12 | qT55b+Yen6CxY0TEkzBK6AKt/WUialKMgT0wbTxRZO7kUCH3Sq6e/wXeFdJ+HvdV 13 | LPlAg5TnMaNpRdQih/8nRFpsdwIDAQABoyAwHjAMBgNVHRMEBTADAQH/MA4GA1Ud 14 | DwEB/wQEAwICBDANBgkqhkiG9w0BAQsFAAOCAQEAkTrKZjBrJXHps/HrjNCFPb5a 15 | THuGPCSsepe1wkKdSp1h4HGRpLoCgcLysCJ5hZhRpHkRihhef+rFHEe60UePQO3S 16 | CVTtdJB4CYWpcNyXOdqefrbJW5QNljxgi6Fhvs7JJkBqdXIkWXtFk2eRgOIP2Eo9 17 | /OHQHlYnwZFrk6sp4wPyR+A95S0toZBcyDVz7u+hOW0pGK3wviOe9lvRgj/H3Pwt 18 | bewb0l+MhRig0/DVHamyVxrDRbqInU1/GTNCwcZkXKYFWSf92U+kIcTth24Q1gcw 19 | eZiLl5FfrWokUNytFElXob0V0a5/kbhiLc3yWmvWqHTpqCALbVyF+rKJo2f5Kw== 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /testdata/grpc_testing_not_regenerated/README.md: -------------------------------------------------------------------------------- 1 | `testv3.go` was generated with an older version of codegen, to test reflection 2 | behavior with `grpc.SupportPackageIsVersion3`. DO NOT REGENERATE! 3 | 4 | `testv3.go` was then manually edited to replace `"golang.org/x/net/context"` 5 | with `"context"`. 6 | 7 | `dynamic.go` was generated with a newer protoc and manually edited to remove 8 | everything except the descriptor bytes var, which is renamed and exported. 9 | 10 | `simple_message_v1.go` was generated using protoc-gen-go v1.3.5 which doesn't 11 | support the MesssageV2 API. As a result the generated code implements only the 12 | old MessageV1 API. 13 | -------------------------------------------------------------------------------- /testdata/grpc_testing_not_regenerated/dynamic.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | syntax = "proto3"; 19 | 20 | package grpc.testing; 21 | 22 | option go_package = "google.golang.org/grpc/testdata/grpc_testing_not_regenerated"; 23 | 24 | message DynamicRes {} 25 | 26 | message DynamicReq {} 27 | 28 | // DynamicService is used to test reflection on dynamically constructed protocol 29 | // buffer messages. 30 | service DynamicService { 31 | // DynamicMessage1 is a test RPC for dynamically constructed protobufs. 32 | rpc DynamicMessage1(DynamicReq) returns (DynamicRes); 33 | } 34 | -------------------------------------------------------------------------------- /testdata/grpc_testing_not_regenerated/simple.proto: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2024 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | syntax = "proto3"; 19 | 20 | package grpc.testdata.grpc_testing_not_regenerated; 21 | 22 | option go_package = "google.golang.org/grpc/testdata/grpc_testing_not_regenerated"; 23 | 24 | // SimpleMessage is used to hold string data. 25 | message SimpleMessage { 26 | string data = 1; 27 | } 28 | -------------------------------------------------------------------------------- /testdata/server1.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDtDCCApygAwIBAgIUbJfTREJ6k6/+oInWhV1O1j3ZT0IwDQYJKoZIhvcNAQEL 3 | BQAwVjELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM 4 | GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEPMA0GA1UEAwwGdGVzdGNhMB4XDTIw 5 | MDMxODAzMTA0MloXDTMwMDMxNjAzMTA0MlowZTELMAkGA1UEBhMCVVMxETAPBgNV 6 | BAgMCElsbGlub2lzMRAwDgYDVQQHDAdDaGljYWdvMRUwEwYDVQQKDAxFeGFtcGxl 7 | LCBDby4xGjAYBgNVBAMMESoudGVzdC5nb29nbGUuY29tMIIBIjANBgkqhkiG9w0B 8 | AQEFAAOCAQ8AMIIBCgKCAQEA5xOONxJJ8b8Qauvob5/7dPYZfIcd+uhAWL2ZlTPz 9 | Qvu4oF0QI4iYgP5iGgry9zEtCM+YQS8UhiAlPlqa6ANxgiBSEyMHH/xE8lo/+caY 10 | GeACqy640Jpl/JocFGo3xd1L8DCawjlaj6eu7T7T/tpAV2qq13b5710eNRbCAfFe 11 | 8yALiGQemx0IYhlZXNbIGWLBNhBhvVjJh7UvOqpADk4xtl8o5j0xgMIRg6WJGK6c 12 | 6ffSIg4eP1XmovNYZ9LLEJG68tF0Q/yIN43B4dt1oq4jzSdCbG4F1EiykT2TmwPV 13 | YDi8tml6DfOCDGnit8svnMEmBv/fcPd31GSbXjF8M+KGGQIDAQABo2swaTAJBgNV 14 | HRMEAjAAMAsGA1UdDwQEAwIF4DBPBgNVHREESDBGghAqLnRlc3QuZ29vZ2xlLmZy 15 | ghh3YXRlcnpvb2kudGVzdC5nb29nbGUuYmWCEioudGVzdC55b3V0dWJlLmNvbYcE 16 | wKgBAzANBgkqhkiG9w0BAQsFAAOCAQEAS8hDQA8PSgipgAml7Q3/djwQ644ghWQv 17 | C2Kb+r30RCY1EyKNhnQnIIh/OUbBZvh0M0iYsy6xqXgfDhCB93AA6j0i5cS8fkhH 18 | Jl4RK0tSkGQ3YNY4NzXwQP/vmUgfkw8VBAZ4Y4GKxppdATjffIW+srbAmdDruIRM 19 | wPeikgOoRrXf0LA1fi4TqxARzeRwenQpayNfGHTvVF9aJkl8HoaMunTAdG5pIVcr 20 | 9GKi/gEMpXUJbbVv3U5frX1Wo4CFo+rZWJ/LyCMeb0jciNLxSdMwj/E/ZuExlyeZ 21 | gc9ctPjSMvgSyXEKv6Vwobleeg88V2ZgzenziORoWj4KszG/lbQZvg== 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /testdata/spiffe/spiffe-openssl.cnf: -------------------------------------------------------------------------------- 1 | [spiffe_client] 2 | subjectAltName = @alt_names 3 | 4 | [spiffe_client_multi] 5 | subjectAltName = @alt_names_multi 6 | 7 | [spiffe_server_e2e] 8 | subjectAltName = @alt_names_server_e2e 9 | 10 | [spiffe_client_e2e] 11 | subjectAltName = @alt_names_client_e2e 12 | 13 | [alt_names] 14 | URI = spiffe://foo.bar.com/client/workload/1 15 | 16 | [alt_names_multi] 17 | URI.1 = spiffe://foo.bar.com/client/workload/1 18 | URI.2 = spiffe://foo.bar.com/client/workload/2 19 | 20 | [alt_names_server_e2e] 21 | DNS.1 = *.test.google.fr 22 | DNS.2 = waterzooi.test.google.be 23 | DNS.3 = *.test.youtube.com 24 | IP.1 = "192.168.1.3" 25 | URI = spiffe://example.com/workload/9eebccd2 26 | 27 | [alt_names_client_e2e] 28 | URI = spiffe://foo.bar.com/9eebccd2-12bf-40a6-b262-65fe0487d453 29 | -------------------------------------------------------------------------------- /testdata/spiffe/spiffebundle_empty_keys.json: -------------------------------------------------------------------------------- 1 | { 2 | "trust_domains": { 3 | "": { 4 | "spiffe_sequence": 12035488, 5 | "keys": [ 6 | ] 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /testdata/spiffe/spiffebundle_malformed.json: -------------------------------------------------------------------------------- 1 | [ 2 | "test.google.com", 3 | "test.google.com.au" 4 | ] 5 | -------------------------------------------------------------------------------- /testdata/spiffe_end2end/generate.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Generate client/server self signed CAs and certs. 4 | openssl req -x509 -newkey rsa:4096 -keyout ca.key -out ca.pem -days 365 -nodes -subj "/C=US/ST=VA/O=Internet Widgits Pty Ltd/CN=foo.bar.hoo.ca.com" 5 | 6 | # The SPIFFE related extensions are listed in spiffe-openssl.cnf config. Both 7 | # client_spiffe.pem and server_spiffe.pem are generated in the same way with 8 | # original client.pem and server.pem but with using that config. Here are the 9 | # exact commands (we pass "-subj" as argument in this case): 10 | openssl genrsa -out client.key.rsa 2048 11 | openssl pkcs8 -topk8 -in client.key.rsa -out client.key -nocrypt 12 | openssl req -new -key client.key -out spiffe-cert.csr \ 13 | -subj /C=US/ST=CA/L=SVL/O=gRPC/CN=testclient/ \ 14 | -config spiffe-openssl.cnf -reqexts spiffe_client_e2e 15 | openssl x509 -req -CA ca.pem -CAkey ca.key -CAcreateserial \ 16 | -in spiffe-cert.csr -out client_spiffe.pem -extensions spiffe_client_e2e \ 17 | -extfile spiffe-openssl.cnf -days 3650 -sha256 18 | 19 | openssl genrsa -out server.key.rsa 2048 20 | openssl pkcs8 -topk8 -in server.key.rsa -out server.key -nocrypt 21 | openssl req -new -key server.key -out spiffe-cert.csr \ 22 | -subj "/C=US/ST=CA/L=SVL/O=gRPC/CN=*.test.google.com/" \ 23 | -config spiffe-openssl.cnf -reqexts spiffe_server_e2e 24 | openssl x509 -req -CA ca.pem -CAkey ca.key -CAcreateserial \ 25 | -in spiffe-cert.csr -out server_spiffe.pem -extensions spiffe_server_e2e \ 26 | -extfile spiffe-openssl.cnf -days 3650 -sha256 27 | 28 | rm *.rsa 29 | rm *.csr 30 | rm *.srl 31 | -------------------------------------------------------------------------------- /testdata/spiffe_end2end/intermediate.cnf: -------------------------------------------------------------------------------- 1 | [ca] 2 | default_ca = CA_intermediate 3 | 4 | [CA_intermediate] 5 | dir = . 6 | certs = $dir/certs 7 | crl_dir = $dir/crl 8 | new_certs_dir = $dir/newcerts 9 | database = $dir/index.txt 10 | serial = $dir/serial 11 | RANDFILE = $dir/private/.rand 12 | private_key = $dir/intermediate_ca.key 13 | certificate = $dir/intermediate_ca.pem 14 | crl = $dir/intermediate.crl 15 | 16 | # For certificate revocation lists. 17 | crlnumber = $dir/crlnumber 18 | crl = $dir/crl/intermediate.crl 19 | crl_extensions = crl_ext 20 | default_crl_days = 3650 21 | 22 | default_md = sha256 23 | 24 | [req] 25 | distinguished_name = req_distinguished_name 26 | req_extensions = v3_req 27 | prompt = no 28 | 29 | [req_distinguished_name] 30 | CN = intermediatecert.example.com 31 | 32 | [crl_ext] 33 | authorityKeyIdentifier=keyid:always 34 | 35 | [v3_req] 36 | keyUsage = critical, digitalSignature, keyEncipherment, keyCertSign, cRLSign 37 | extendedKeyUsage = clientAuth, serverAuth 38 | basicConstraints = critical, CA:true 39 | -------------------------------------------------------------------------------- /testdata/spiffe_end2end/leaf_signed_by_intermediate.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDvjCCAqagAwIBAgIUSuuNuIcMCQ1UZrOtCL689eeZx9EwDQYJKoZIhvcNAQEL 3 | BQAwJzElMCMGA1UEAwwcaW50ZXJtZWRpYXRlY2VydC5leGFtcGxlLmNvbTAeFw0y 4 | NTAzMTgxNjE4NTFaFw0zNTAzMTYxNjE4NTFaMEwxCzAJBgNVBAYTAlVTMQswCQYD 5 | VQQIDAJDQTEMMAoGA1UEBwwDU1ZMMQ0wCwYDVQQKDARnUlBDMRMwEQYDVQQDDAp0 6 | ZXN0c2VydmVyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAue2BY6B4 7 | JNz5SnYr0b4IUsXfpSxqXzpx3CymRzNiPL+ZYERQd+5PPbwyj/K0ZUPNcdGtgj0i 8 | jCSpKl6fGNx11vY/Z5BS7DN9Z6Fqf8/sBr5BIko33UafdqB/s1avrIzFNRD1n6Fu 9 | X1EwlQpXwjiTMLswuf6X6mJVJ2VhA/xtyO4S6fTeK2jUlFn4MYHVczJBDTiMCUPX 10 | 1Z/9SXkcwZbQTbRaWvd6c0OEWZKSWxSzWG6d4qOmq9C0Tse39cmjuDpeBvtiGik4 11 | pYrTmmswiQ8lgLbOY1/YGjvOD+qlxXkX9Y/cYjdygrQoY7mqnjMcUFvWK/OW0XCB 12 | CJ1jeSflrYUd4QIDAQABo4G8MIG5MHcGA1UdEQRwMG6CECoudGVzdC5nb29nbGUu 13 | ZnKCGHdhdGVyem9vaS50ZXN0Lmdvb2dsZS5iZYISKi50ZXN0LnlvdXR1YmUuY29t 14 | hwTAqAEDhiZzcGlmZmU6Ly9leGFtcGxlLmNvbS93b3JrbG9hZC85ZWViY2NkMjAd 15 | BgNVHQ4EFgQUsMpVfuYdrW5+i5mFW/hCaOZiKKcwHwYDVR0jBBgwFoAU6M3fe56O 16 | 8P6gCUGcTRcEmKusnVYwDQYJKoZIhvcNAQELBQADggEBABReEQ2cIaZv5wZKOjFS 17 | 5b5QfpkbR29JTQQxrkiqdXcnonX+Q/dCH+tnzUp9LCCIsVjp6is4pdKTvPNg1ZPT 18 | WB0KEFpVG9LAOmfcgu9pwIsKUCS384PeVhffMKXsKWfgfRGP1E7XeEIdSgpwPKzK 19 | Defa7kwTG276xre/36WOAu9RZ32s0ltXyvHtTi0pfaGuOmryX+XeHtVpxQSjhdDB 20 | tpLvolS+7cRsvKNKIL5X/789IKbdShMgpwPDDe6Z3riBjGPBydnA40IofRc8y3jL 21 | 0TKiBiKYOz8nj6DLAiVPqQ2vo5NzihNoqgu/HpkhSG26OAJq2NDYurMsT+Myiuq4 22 | YkE= 23 | -----END CERTIFICATE----- 24 | -------------------------------------------------------------------------------- /testdata/spiffe_end2end/spiffe-openssl.cnf: -------------------------------------------------------------------------------- 1 | [spiffe_client] 2 | subjectAltName = @alt_names 3 | 4 | [spiffe_client_multi] 5 | subjectAltName = @alt_names_multi 6 | 7 | [spiffe_server_e2e] 8 | subjectAltName = @alt_names_server_e2e 9 | 10 | [spiffe_client_e2e] 11 | subjectAltName = @alt_names_client_e2e 12 | 13 | [alt_names] 14 | URI = spiffe://foo.bar.com/client/workload/1 15 | 16 | [alt_names_multi] 17 | URI.1 = spiffe://foo.bar.com/client/workload/1 18 | URI.2 = spiffe://foo.bar.com/client/workload/2 19 | 20 | [alt_names_server_e2e] 21 | DNS.1 = *.test.google.fr 22 | DNS.2 = waterzooi.test.google.be 23 | DNS.3 = *.test.youtube.com 24 | IP.1 = "192.168.1.3" 25 | URI = spiffe://example.com/workload/9eebccd2 26 | 27 | [alt_names_client_e2e] 28 | URI = spiffe://foo.bar.com/9eebccd2-12bf-40a6-b262-65fe0487d453 29 | -------------------------------------------------------------------------------- /testdata/testdata.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package testdata 19 | 20 | import ( 21 | "path/filepath" 22 | "runtime" 23 | ) 24 | 25 | // basepath is the root directory of this package. 26 | var basepath string 27 | 28 | func init() { 29 | _, currentFile, _, _ := runtime.Caller(0) 30 | basepath = filepath.Dir(currentFile) 31 | } 32 | 33 | // Path returns the absolute path the given relative file or directory path, 34 | // relative to the google.golang.org/grpc/testdata directory in the user's GOPATH. 35 | // If rel is already absolute, it is returned unmodified. 36 | func Path(rel string) string { 37 | if filepath.IsAbs(rel) { 38 | return rel 39 | } 40 | 41 | return filepath.Join(basepath, rel) 42 | } 43 | -------------------------------------------------------------------------------- /testdata/x509/README.md: -------------------------------------------------------------------------------- 1 | This directory contains x509 certificates and associated private keys used in 2 | gRPC-Go tests. 3 | 4 | How were these test certs/keys generated ? 5 | ------------------------------------------ 6 | Run `./create.sh` 7 | -------------------------------------------------------------------------------- /testdata/x509/client_with_spiffe_openssl.cnf: -------------------------------------------------------------------------------- 1 | [req] 2 | distinguished_name = req_distinguished_name 3 | attributes = req_attributes 4 | 5 | [req_distinguished_name] 6 | 7 | [req_attributes] 8 | 9 | [test_client] 10 | basicConstraints = critical,CA:FALSE 11 | subjectKeyIdentifier = hash 12 | keyUsage = critical,nonRepudiation,digitalSignature,keyEncipherment 13 | extendedKeyUsage = critical,clientAuth 14 | subjectAltName = @alt_names 15 | 16 | [alt_names] 17 | URI = spiffe://foo.bar.com/client/workload/1 18 | -------------------------------------------------------------------------------- /testdata/x509/openssl.cnf: -------------------------------------------------------------------------------- 1 | [req] 2 | distinguished_name = req_distinguished_name 3 | attributes = req_attributes 4 | 5 | [req_distinguished_name] 6 | 7 | [req_attributes] 8 | 9 | [test_ca] 10 | basicConstraints = critical,CA:TRUE 11 | subjectKeyIdentifier = hash 12 | authorityKeyIdentifier = keyid:always,issuer:always 13 | keyUsage = critical,keyCertSign 14 | 15 | [test_server] 16 | basicConstraints = critical,CA:FALSE 17 | subjectKeyIdentifier = hash 18 | keyUsage = critical,digitalSignature,keyEncipherment,keyAgreement 19 | subjectAltName = @server_alt_names 20 | 21 | [server_alt_names] 22 | DNS.1 = *.test.example.com 23 | 24 | [test_client] 25 | basicConstraints = critical,CA:FALSE 26 | subjectKeyIdentifier = hash 27 | keyUsage = critical,nonRepudiation,digitalSignature,keyEncipherment 28 | extendedKeyUsage = critical,clientAuth 29 | -------------------------------------------------------------------------------- /trace_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2019 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | import ( 22 | "testing" 23 | ) 24 | 25 | func (s) TestMethodFamily(t *testing.T) { 26 | cases := []struct { 27 | desc string 28 | method string 29 | wantMethodFamily string 30 | }{ 31 | { 32 | desc: "No leading slash", 33 | method: "pkg.service/method", 34 | wantMethodFamily: "pkg.service", 35 | }, 36 | { 37 | desc: "Leading slash", 38 | method: "/pkg.service/method", 39 | wantMethodFamily: "pkg.service", 40 | }, 41 | } 42 | 43 | for _, ut := range cases { 44 | t.Run(ut.desc, func(t *testing.T) { 45 | if got := methodFamily(ut.method); got != ut.wantMethodFamily { 46 | t.Fatalf("methodFamily(%s) = %s, want %s", ut.method, got, ut.wantMethodFamily) 47 | } 48 | }) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /trace_withtrace.go: -------------------------------------------------------------------------------- 1 | //go:build !grpcnotrace 2 | 3 | /* 4 | * 5 | * Copyright 2024 gRPC authors. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * 19 | */ 20 | 21 | package grpc 22 | 23 | import ( 24 | "context" 25 | 26 | t "golang.org/x/net/trace" 27 | ) 28 | 29 | func newTrace(family, title string) traceLog { 30 | return t.New(family, title) 31 | } 32 | 33 | func newTraceContext(ctx context.Context, tr traceLog) context.Context { 34 | return t.NewContext(ctx, tr) 35 | } 36 | 37 | func newTraceEventLog(family, title string) traceEventLog { 38 | return t.NewEventLog(family, title) 39 | } 40 | -------------------------------------------------------------------------------- /version.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2018 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package grpc 20 | 21 | // Version is the current grpc version. 22 | const Version = "1.74.0-dev" 23 | -------------------------------------------------------------------------------- /xds/internal/balancer/cdsbalancer/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package cdsbalancer 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | const prefix = "[cds-lb %p] " 29 | 30 | var logger = grpclog.Component("xds") 31 | 32 | func prefixLogger(p *cdsBalancer) *internalgrpclog.PrefixLogger { 33 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) 34 | } 35 | -------------------------------------------------------------------------------- /xds/internal/balancer/clusterimpl/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package clusterimpl 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | const prefix = "[xds-cluster-impl-lb %p] " 29 | 30 | var logger = grpclog.Component("xds") 31 | 32 | func prefixLogger(p *clusterImplBalancer) *internalgrpclog.PrefixLogger { 33 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) 34 | } 35 | -------------------------------------------------------------------------------- /xds/internal/balancer/clustermanager/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package clustermanager 20 | 21 | import ( 22 | "encoding/json" 23 | 24 | internalserviceconfig "google.golang.org/grpc/internal/serviceconfig" 25 | "google.golang.org/grpc/serviceconfig" 26 | ) 27 | 28 | type childConfig struct { 29 | // ChildPolicy is the child policy and it's config. 30 | ChildPolicy *internalserviceconfig.BalancerConfig 31 | } 32 | 33 | // lbConfig is the balancer config for xds routing policy. 34 | type lbConfig struct { 35 | serviceconfig.LoadBalancingConfig 36 | Children map[string]childConfig 37 | } 38 | 39 | func parseConfig(c json.RawMessage) (*lbConfig, error) { 40 | cfg := &lbConfig{} 41 | if err := json.Unmarshal(c, cfg); err != nil { 42 | return nil, err 43 | } 44 | 45 | return cfg, nil 46 | } 47 | -------------------------------------------------------------------------------- /xds/internal/balancer/clusterresolver/clusterresolver_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2019 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package clusterresolver 20 | 21 | import ( 22 | "testing" 23 | "time" 24 | 25 | "google.golang.org/grpc/internal/grpctest" 26 | ) 27 | 28 | const ( 29 | defaultTestTimeout = 5 * time.Second 30 | defaultTestShortTimeout = 10 * time.Millisecond 31 | testEDSService = "test-eds-service-name" 32 | testClusterName = "test-cluster-name" 33 | testClusterName2 = "google_cfe_some-name" 34 | testBalancerNameFooBar = "foo.bar" 35 | ) 36 | 37 | type s struct { 38 | grpctest.Tester 39 | } 40 | 41 | func Test(t *testing.T) { 42 | grpctest.RunSubTests(t, s{}) 43 | } 44 | -------------------------------------------------------------------------------- /xds/internal/balancer/clusterresolver/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package clusterresolver 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | const prefix = "[xds-cluster-resolver-lb %p] " 29 | 30 | var logger = grpclog.Component("xds") 31 | 32 | func prefixLogger(p *clusterResolverBalancer) *internalgrpclog.PrefixLogger { 33 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) 34 | } 35 | -------------------------------------------------------------------------------- /xds/internal/balancer/outlierdetection/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2022 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package outlierdetection 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | const prefix = "[outlier-detection-lb %p] " 29 | 30 | var logger = grpclog.Component("xds") 31 | 32 | func prefixLogger(p *outlierDetectionBalancer) *internalgrpclog.PrefixLogger { 33 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) 34 | } 35 | -------------------------------------------------------------------------------- /xds/internal/balancer/priority/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package priority 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | const prefix = "[priority-lb %p] " 29 | 30 | var logger = grpclog.Component("xds") 31 | 32 | func prefixLogger(p *priorityBalancer) *internalgrpclog.PrefixLogger { 33 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) 34 | } 35 | -------------------------------------------------------------------------------- /xds/internal/balancer/priority/utils.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package priority 20 | 21 | func equalStringSlice(a, b []string) bool { 22 | if len(a) != len(b) { 23 | return false 24 | } 25 | for i := range a { 26 | if a[i] != b[i] { 27 | return false 28 | } 29 | } 30 | return true 31 | } 32 | -------------------------------------------------------------------------------- /xds/internal/balancer/wrrlocality/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2023 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package wrrlocality 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | const prefix = "[wrrlocality-lb %p] " 29 | 30 | var logger = grpclog.Component("xds") 31 | 32 | func prefixLogger(p *wrrLocalityBalancer) *internalgrpclog.PrefixLogger { 33 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) 34 | } 35 | -------------------------------------------------------------------------------- /xds/internal/clients/internal/testutils/e2e/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2022 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package e2e 20 | 21 | // serverLogger implements the Logger interface defined at 22 | // envoyproxy/go-control-plane/pkg/log. This is passed to the Snapshot cache. 23 | type serverLogger struct { 24 | logger interface { 25 | Logf(format string, args ...any) 26 | } 27 | } 28 | 29 | func (l serverLogger) Debugf(format string, args ...any) { 30 | l.logger.Logf(format, args...) 31 | } 32 | func (l serverLogger) Infof(format string, args ...any) { 33 | l.logger.Logf(format, args...) 34 | } 35 | func (l serverLogger) Warnf(format string, args ...any) { 36 | l.logger.Logf(format, args...) 37 | } 38 | func (l serverLogger) Errorf(format string, args ...any) { 39 | l.logger.Logf(format, args...) 40 | } 41 | -------------------------------------------------------------------------------- /xds/internal/clients/internal/testutils/marshal_any.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package testutils 19 | 20 | import ( 21 | "testing" 22 | 23 | "google.golang.org/protobuf/proto" 24 | "google.golang.org/protobuf/types/known/anypb" 25 | ) 26 | 27 | // MarshalAny is a convenience function to marshal protobuf messages into any 28 | // protos. function will fail the test with a fatal error if the marshaling fails. 29 | func MarshalAny(t *testing.T, m proto.Message) *anypb.Any { 30 | t.Helper() 31 | 32 | a, err := anypb.New(m) 33 | if err != nil { 34 | t.Fatalf("Failed to marshal proto %+v into an Any: %v", m, err) 35 | } 36 | return a 37 | } 38 | -------------------------------------------------------------------------------- /xds/internal/clients/lrsclient/internal/internal.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2025 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | // Package internal contains functionality internal to the lrsclient package. 19 | package internal 20 | 21 | import "time" 22 | 23 | var ( 24 | // TimeNow is used to get the current time. It can be overridden in tests. 25 | TimeNow func() time.Time 26 | ) 27 | -------------------------------------------------------------------------------- /xds/internal/clients/lrsclient/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2025 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package lrsclient 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | var logger = grpclog.Component("xds") 29 | 30 | func prefixLogger(c *LRSClient) *internalgrpclog.PrefixLogger { 31 | return internalgrpclog.NewPrefixLogger(logger, clientPrefix(c)) 32 | } 33 | 34 | func clientPrefix(c *LRSClient) string { 35 | return fmt.Sprintf("[lrs-client %p] ", c) 36 | } 37 | -------------------------------------------------------------------------------- /xds/internal/clients/lrsclient/lrsconfig.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2025 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package lrsclient 20 | 21 | import ( 22 | "google.golang.org/grpc/xds/internal/clients" 23 | ) 24 | 25 | // Config is used to configure an LRS client. After one has been passed to the 26 | // LRS client's New function, no part of it may modified. A Config may be 27 | // reused; the lrsclient package will also not modify it. 28 | type Config struct { 29 | // Node is the identity of the client application reporting load to the 30 | // LRS server. 31 | Node clients.Node 32 | 33 | // TransportBuilder is used to connect to the LRS server. 34 | TransportBuilder clients.TransportBuilder 35 | } 36 | -------------------------------------------------------------------------------- /xds/internal/clients/xdsclient/internal/internal.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2025 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | // Package internal contains functionality internal to the xdsclient package. 19 | package internal 20 | 21 | import "time" 22 | 23 | var ( 24 | // WatchExpiryTimeout is the watch expiry timeout for xDS client. It can be 25 | // overridden by tests to change the default watch expiry timeout. 26 | WatchExpiryTimeout time.Duration 27 | 28 | // StreamBackoff is the stream backoff for xDS client. It can be overridden 29 | // by tests to change the default backoff strategy. 30 | StreamBackoff func(int) time.Duration 31 | 32 | // ResourceWatchStateForTesting gets the watch state for the resource 33 | // identified by the given resource type and resource name. Returns a 34 | // non-nil error if there is no such resource being watched. 35 | ResourceWatchStateForTesting any // func(*xdsclient.XDSClient, xdsclient.ResourceType, string) error 36 | ) 37 | -------------------------------------------------------------------------------- /xds/internal/clients/xdsclient/internal/xdsresource/version.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2025 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package xdsresource defines constants to distinguish between supported xDS 20 | // API versions. 21 | package xdsresource 22 | 23 | // Resource URLs. We need to be able to accept either version of the resource 24 | // regardless of the version of the transport protocol in use. 25 | const ( 26 | googleapiPrefix = "type.googleapis.com/" 27 | 28 | V3ListenerURL = googleapiPrefix + "envoy.config.listener.v3.Listener" 29 | V3HTTPConnManagerURL = googleapiPrefix + "envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager" 30 | ) 31 | -------------------------------------------------------------------------------- /xds/internal/clients/xdsclient/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2025 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package xdsclient 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | var logger = grpclog.Component("xds") 29 | 30 | func prefixLogger(p *XDSClient) *internalgrpclog.PrefixLogger { 31 | return internalgrpclog.NewPrefixLogger(logger, clientPrefix(p)) 32 | } 33 | 34 | func clientPrefix(p *XDSClient) string { 35 | return fmt.Sprintf("[xds-client %p] ", p) 36 | } 37 | -------------------------------------------------------------------------------- /xds/internal/clients/xdsclient/metrics/metrics.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2025 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package metrics defines all metrics that can be produced by an xDS client. 20 | // All calls to the MetricsRecorder by the xDS client will contain a struct 21 | // from this package passed by pointer. 22 | package metrics 23 | 24 | // ResourceUpdateValid is a metric to report a valid resource update from 25 | // the xDS management server for a given resource type. 26 | type ResourceUpdateValid struct { 27 | ServerURI string 28 | ResourceType string 29 | } 30 | 31 | // ResourceUpdateInvalid is a metric to report an invalid resource update 32 | // from the xDS management server for a given resource type. 33 | type ResourceUpdateInvalid struct { 34 | ServerURI string 35 | ResourceType string 36 | } 37 | 38 | // ServerFailure is a metric to report a server failure of the xDS 39 | // management server. 40 | type ServerFailure struct { 41 | ServerURI string 42 | } 43 | -------------------------------------------------------------------------------- /xds/internal/resolver/internal/internal.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2023 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | // Package internal contains functionality internal to the xDS resolver. 20 | package internal 21 | 22 | // The following variables are overridden in tests. 23 | var ( 24 | // NewWRR is the function used to create a new weighted round robin 25 | // implementation. 26 | NewWRR any // func() wrr.WRR 27 | 28 | // NewXDSClient is the function used to create a new xDS client. 29 | NewXDSClient any // func(string, estats.MetricsRecorder) (xdsclient.XDSClient, func(), error) 30 | ) 31 | -------------------------------------------------------------------------------- /xds/internal/resolver/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package resolver 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | const prefix = "[xds-resolver %p] " 29 | 30 | var logger = grpclog.Component("xds") 31 | 32 | func prefixLogger(p *xdsResolver) *internalgrpclog.PrefixLogger { 33 | return internalgrpclog.NewPrefixLogger(logger, fmt.Sprintf(prefix, p)) 34 | } 35 | -------------------------------------------------------------------------------- /xds/internal/test/e2e/README.md: -------------------------------------------------------------------------------- 1 | Build client and server binaries. 2 | 3 | ```sh 4 | go build -o ./binaries/client ../../../../interop/xds/client/ 5 | go build -o ./binaries/server ../../../../interop/xds/server/ 6 | ``` 7 | 8 | Run the test 9 | 10 | ```sh 11 | go test . -v 12 | ``` 13 | 14 | The client/server paths are flags 15 | 16 | ```sh 17 | go test . -v -client=$HOME/grpc-java/interop-testing/build/install/grpc-interop-testing/bin/xds-test-client 18 | ``` 19 | Note that grpc logs are only turned on for Go. 20 | -------------------------------------------------------------------------------- /xds/internal/test/e2e/controlplane.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package e2e 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/google/uuid" 24 | "google.golang.org/grpc/internal/testutils/xds/e2e" 25 | ) 26 | 27 | type controlPlane struct { 28 | server *e2e.ManagementServer 29 | nodeID string 30 | bootstrapContent string 31 | } 32 | 33 | func newControlPlane(t *testing.T) (*controlPlane, error) { 34 | // Spin up an xDS management server on a local port. 35 | server := e2e.StartManagementServer(t, e2e.ManagementServerOptions{}) 36 | 37 | nodeID := uuid.New().String() 38 | bootstrapContents := e2e.DefaultBootstrapContents(t, nodeID, server.Address) 39 | 40 | return &controlPlane{ 41 | server: server, 42 | nodeID: nodeID, 43 | bootstrapContent: string(bootstrapContents), 44 | }, nil 45 | } 46 | -------------------------------------------------------------------------------- /xds/internal/test/e2e/e2e_utils.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2021 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package e2e 19 | 20 | import ( 21 | "testing" 22 | 23 | "github.com/google/go-cmp/cmp" 24 | channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1" 25 | ) 26 | 27 | func verifySubConnStates(t *testing.T, scs []*channelzpb.Subchannel, want map[channelzpb.ChannelConnectivityState_State]int) { 28 | t.Helper() 29 | var scStatsCount = map[channelzpb.ChannelConnectivityState_State]int{} 30 | for _, sc := range scs { 31 | scStatsCount[sc.Data.State.State]++ 32 | } 33 | if diff := cmp.Diff(scStatsCount, want); diff != "" { 34 | t.Fatalf("got unexpected number of subchannels in state Ready, %v, scs: %v", diff, scs) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /xds/internal/test/e2e/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir binaries 4 | go build -o ./binaries/client ../../../../interop/xds/client/ 5 | go build -o ./binaries/server ../../../../interop/xds/server/ 6 | go test . 7 | -------------------------------------------------------------------------------- /xds/internal/xdsclient/attributes.go: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 gRPC authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | */ 17 | 18 | package xdsclient 19 | 20 | import "google.golang.org/grpc/resolver" 21 | 22 | type clientKeyType string 23 | 24 | const clientKey = clientKeyType("grpc.xds.internal.client.Client") 25 | 26 | // FromResolverState returns the Client from state, or nil if not present. 27 | func FromResolverState(state resolver.State) XDSClient { 28 | cs, _ := state.Attributes.Value(clientKey).(XDSClient) 29 | return cs 30 | } 31 | 32 | // SetClient sets c in state and returns the new state. 33 | func SetClient(state resolver.State, c XDSClient) resolver.State { 34 | state.Attributes = state.Attributes.WithValue(clientKey, c) 35 | return state 36 | } 37 | -------------------------------------------------------------------------------- /xds/internal/xdsclient/client_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2019 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package xdsclient 20 | 21 | import ( 22 | "testing" 23 | "time" 24 | 25 | "google.golang.org/grpc/internal/grpctest" 26 | ) 27 | 28 | type s struct { 29 | grpctest.Tester 30 | } 31 | 32 | func Test(t *testing.T) { 33 | grpctest.RunSubTests(t, s{}) 34 | } 35 | 36 | const ( 37 | defaultTestWatchExpiryTimeout = 100 * time.Millisecond 38 | defaultTestTimeout = 5 * time.Second 39 | defaultTestShortTimeout = 10 * time.Millisecond // For events expected to *not* happen. 40 | ) 41 | -------------------------------------------------------------------------------- /xds/internal/xdsclient/internal/internal.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2024 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | // Package internal contains functionality internal to the xdsclient package. 19 | package internal 20 | 21 | // The following vars can be overridden by tests. 22 | var ( 23 | // GRPCNewClient returns a new gRPC Client. 24 | GRPCNewClient any // func(string, ...grpc.DialOption) (*grpc.ClientConn, error) 25 | 26 | // NewADSStream returns a new ADS stream. 27 | NewADSStream any // func(context.Context, *grpc.ClientConn) (v3adsgrpc.AggregatedDiscoveryService_StreamAggregatedResourcesClient, error) 28 | 29 | // ResourceWatchStateForTesting gets the watch state for the resource 30 | // identified by the given resource type and resource name. Returns a 31 | // non-nil error if there is no such resource being watched. 32 | ResourceWatchStateForTesting any // func(xdsclient.XDSClient, xdsresource.Type, string) error 33 | ) 34 | -------------------------------------------------------------------------------- /xds/internal/xdsclient/load/reporter.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package load 20 | 21 | // PerClusterReporter wraps the methods from the loadStore that are used here. 22 | type PerClusterReporter interface { 23 | CallStarted(locality string) 24 | CallFinished(locality string, err error) 25 | CallServerLoad(locality, name string, val float64) 26 | CallDropped(category string) 27 | } 28 | -------------------------------------------------------------------------------- /xds/internal/xdsclient/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package xdsclient 20 | 21 | import ( 22 | "fmt" 23 | 24 | "google.golang.org/grpc/grpclog" 25 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 26 | ) 27 | 28 | var logger = grpclog.Component("xds") 29 | 30 | func prefixLogger(p *clientImpl) *internalgrpclog.PrefixLogger { 31 | return internalgrpclog.NewPrefixLogger(logger, clientPrefix(p)) 32 | } 33 | 34 | func clientPrefix(p *clientImpl) string { 35 | return fmt.Sprintf("[xds-client %p] ", p) 36 | } 37 | -------------------------------------------------------------------------------- /xds/internal/xdsclient/xdsclient_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package xdsclient_test 20 | 21 | import ( 22 | "testing" 23 | 24 | "google.golang.org/grpc/internal/grpctest" 25 | ) 26 | 27 | type s struct { 28 | grpctest.Tester 29 | } 30 | 31 | func Test(t *testing.T) { 32 | grpctest.RunSubTests(t, s{}) 33 | } 34 | -------------------------------------------------------------------------------- /xds/internal/xdsclient/xdsresource/logging.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2023 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * 17 | */ 18 | 19 | package xdsresource 20 | 21 | import ( 22 | "google.golang.org/grpc/grpclog" 23 | internalgrpclog "google.golang.org/grpc/internal/grpclog" 24 | ) 25 | 26 | const prefix = "[xds-resource] " 27 | 28 | var logger = internalgrpclog.NewPrefixLogger(grpclog.Component("xds"), prefix) 29 | -------------------------------------------------------------------------------- /xds/internal/xdsclient/xdsresource/test_utils_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * Copyright 2020 gRPC authors. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package xdsresource 19 | 20 | import ( 21 | "testing" 22 | "time" 23 | 24 | "github.com/google/go-cmp/cmp" 25 | "github.com/google/go-cmp/cmp/cmpopts" 26 | "google.golang.org/grpc/internal/grpctest" 27 | "google.golang.org/protobuf/testing/protocmp" 28 | ) 29 | 30 | type s struct { 31 | grpctest.Tester 32 | } 33 | 34 | func Test(t *testing.T) { 35 | grpctest.RunSubTests(t, s{}) 36 | } 37 | 38 | var ( 39 | cmpOpts = cmp.Options{ 40 | cmpopts.EquateEmpty(), 41 | cmp.FilterValues(func(_, _ error) bool { return true }, cmpopts.EquateErrors()), 42 | cmp.Comparer(func(_, _ time.Time) bool { return true }), 43 | protocmp.Transform(), 44 | } 45 | ) 46 | --------------------------------------------------------------------------------