grpc 1.75.0.pre1 → 1.76.0.pre1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +18 -5
- data/include/grpc/credentials.h +21 -5
- data/src/core/call/call_filters.cc +4 -4
- data/src/core/call/call_filters.h +36 -36
- data/src/core/call/call_spine.h +27 -27
- data/src/core/call/client_call.cc +6 -5
- data/src/core/call/filter_fusion.h +5 -5
- data/src/core/call/metadata_batch.h +3 -3
- data/src/core/call/security_context.cc +1 -1
- data/src/core/call/server_call.cc +4 -4
- data/src/core/call/server_call.h +1 -1
- data/src/core/channelz/channelz.cc +12 -18
- data/src/core/channelz/channelz.h +32 -16
- data/src/core/channelz/channelz_registry.h +11 -0
- data/src/core/channelz/property_list.cc +18 -0
- data/src/core/channelz/property_list.h +10 -1
- data/src/core/channelz/text_encode.cc +66 -0
- data/src/core/channelz/text_encode.h +29 -0
- data/src/core/channelz/v2tov1/convert.cc +11 -0
- data/src/core/channelz/v2tov1/legacy_api.cc +15 -8
- data/src/core/channelz/ztrace_collector.h +247 -86
- data/src/core/client_channel/backup_poller.cc +5 -6
- data/src/core/client_channel/client_channel.cc +20 -13
- data/src/core/client_channel/client_channel_filter.cc +53 -45
- data/src/core/client_channel/client_channel_filter.h +2 -2
- data/src/core/client_channel/client_channel_internal.h +3 -4
- data/src/core/client_channel/config_selector.h +3 -3
- data/src/core/client_channel/dynamic_filters.cc +3 -3
- data/src/core/client_channel/global_subchannel_pool.cc +0 -37
- data/src/core/client_channel/global_subchannel_pool.h +0 -27
- data/src/core/client_channel/load_balanced_call_destination.cc +7 -7
- data/src/core/client_channel/local_subchannel_pool.cc +4 -4
- data/src/core/client_channel/retry_filter.h +3 -3
- data/src/core/client_channel/retry_filter_legacy_call_data.cc +5 -5
- data/src/core/client_channel/subchannel.cc +8 -8
- data/src/core/client_channel/subchannel_stream_client.cc +4 -4
- data/src/core/config/config_vars.cc +30 -1
- data/src/core/config/config_vars.h +21 -0
- data/src/core/config/core_configuration.cc +5 -5
- data/src/core/config/core_configuration.h +7 -7
- data/src/core/config/load_config.cc +12 -0
- data/src/core/config/load_config.h +2 -0
- data/src/core/credentials/call/call_credentials.h +2 -2
- data/src/core/credentials/call/call_creds_util.cc +4 -3
- data/src/core/credentials/call/composite/composite_call_credentials.cc +4 -4
- data/src/core/credentials/call/external/aws_external_account_credentials.cc +3 -3
- data/src/core/credentials/call/external/external_account_credentials.cc +1 -1
- data/src/core/credentials/call/external/url_external_account_credentials.cc +1 -1
- data/src/core/credentials/call/iam/iam_credentials.cc +4 -4
- data/src/core/credentials/call/jwt/json_token.cc +3 -3
- data/src/core/credentials/call/jwt/jwt_credentials.cc +2 -2
- data/src/core/credentials/call/jwt/jwt_verifier.cc +14 -13
- data/src/core/credentials/call/oauth2/oauth2_credentials.cc +20 -12
- data/src/core/credentials/call/plugin/plugin_credentials.cc +2 -2
- data/src/core/credentials/transport/alts/alts_credentials.cc +4 -4
- data/src/core/credentials/transport/alts/alts_security_connector.cc +14 -12
- data/src/core/credentials/transport/alts/grpc_alts_credentials_client_options.cc +22 -2
- data/src/core/credentials/transport/alts/grpc_alts_credentials_options.cc +10 -1
- data/src/core/credentials/transport/alts/grpc_alts_credentials_options.h +31 -0
- data/src/core/credentials/transport/alts/grpc_alts_credentials_server_options.cc +8 -3
- data/src/core/credentials/transport/composite/composite_channel_credentials.cc +5 -5
- data/src/core/credentials/transport/fake/fake_security_connector.cc +2 -2
- data/src/core/credentials/transport/google_default/google_default_credentials.cc +78 -28
- data/src/core/credentials/transport/insecure/insecure_security_connector.cc +3 -3
- data/src/core/credentials/transport/local/local_security_connector.cc +8 -8
- data/src/core/credentials/transport/security_connector.cc +5 -5
- data/src/core/credentials/transport/ssl/ssl_credentials.cc +12 -12
- data/src/core/credentials/transport/ssl/ssl_credentials.h +2 -2
- data/src/core/credentials/transport/ssl/ssl_security_connector.cc +3 -3
- data/src/core/credentials/transport/tls/certificate_provider_registry.cc +2 -2
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +24 -24
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +5 -5
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +2 -2
- data/src/core/credentials/transport/tls/grpc_tls_certificate_verifier.cc +2 -2
- data/src/core/credentials/transport/tls/grpc_tls_certificate_verifier.h +2 -2
- data/src/core/credentials/transport/tls/grpc_tls_credentials_options.cc +17 -17
- data/src/core/credentials/transport/tls/ssl_utils.cc +14 -9
- data/src/core/credentials/transport/tls/tls_credentials.cc +2 -2
- data/src/core/credentials/transport/tls/tls_security_connector.cc +11 -11
- data/src/core/credentials/transport/transport_credentials.cc +2 -2
- data/src/core/credentials/transport/transport_credentials.h +2 -2
- data/src/core/credentials/transport/xds/xds_credentials.cc +5 -5
- data/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc +2 -0
- data/src/core/ext/filters/gcp_authentication/gcp_authentication_filter.cc +1 -1
- data/src/core/ext/filters/http/message_compress/compression_filter.cc +8 -8
- data/src/core/ext/filters/http/message_compress/compression_filter.h +3 -3
- data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +7 -7
- data/src/core/ext/transport/chttp2/alpn/alpn.cc +2 -2
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +10 -9
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +10 -7
- data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +5 -5
- data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +6 -6
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +96 -88
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/flow_control.h +12 -7
- data/src/core/ext/transport/chttp2/transport/flow_control_manager.h +60 -0
- data/src/core/ext/transport/chttp2/transport/frame.cc +32 -10
- data/src/core/ext/transport/chttp2/transport/frame.h +16 -2
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +4 -4
- data/src/core/ext/transport/chttp2/transport/frame_ping.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/header_assembler.h +28 -12
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +4 -2
- data/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc +8 -8
- data/src/core/ext/transport/chttp2/transport/hpack_parse_result.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/hpack_parse_result.h +2 -2
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +27 -27
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +2 -3
- data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +4 -4
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +543 -366
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +198 -277
- data/src/core/ext/transport/chttp2/transport/http2_settings_manager.cc +3 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings_manager.h +11 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings_promises.h +179 -0
- data/src/core/ext/transport/chttp2/transport/http2_transport.cc +51 -23
- data/src/core/ext/transport/chttp2/transport/http2_transport.h +13 -6
- data/src/core/ext/transport/chttp2/transport/http2_ztrace_collector.h +115 -71
- data/src/core/ext/transport/chttp2/transport/internal.h +6 -14
- data/src/core/ext/transport/chttp2/transport/message_assembler.h +7 -7
- data/src/core/ext/transport/chttp2/transport/parsing.cc +17 -15
- data/src/core/ext/transport/chttp2/transport/ping_callbacks.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/ping_promise.cc +62 -26
- data/src/core/ext/transport/chttp2/transport/ping_promise.h +58 -22
- data/src/core/ext/transport/chttp2/transport/stream.h +207 -0
- data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +328 -187
- data/src/core/ext/transport/chttp2/transport/stream_lists.cc +7 -7
- data/src/core/ext/transport/chttp2/transport/transport_common.cc +17 -1
- data/src/core/ext/transport/chttp2/transport/transport_common.h +52 -0
- data/src/core/ext/transport/chttp2/transport/varint.h +2 -2
- data/src/core/ext/transport/chttp2/transport/writable_streams.h +181 -79
- data/src/core/ext/transport/chttp2/transport/write_size_policy.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/writing.cc +3 -3
- data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
- data/src/core/ext/transport/inproc/legacy_inproc_transport.cc +3 -3
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/service.upb.h +740 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/service.upb_minitable.c +218 -0
- data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/service.upb_minitable.h +46 -0
- data/src/core/ext/upb-gen/src/proto/grpc/gcp/handshaker.upb.h +87 -55
- data/src/core/ext/upb-gen/src/proto/grpc/gcp/handshaker.upb_minitable.c +23 -21
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/channelz.upbdefs.c +80 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/channelz.upbdefs.h +47 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/service.upbdefs.c +129 -0
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/service.upbdefs.h +72 -0
- data/src/core/filter/auth/server_auth_filter.cc +2 -2
- data/src/core/handshaker/handshaker.cc +3 -3
- data/src/core/handshaker/http_connect/http_proxy_mapper.cc +2 -2
- data/src/core/handshaker/security/legacy_secure_endpoint.cc +2 -2
- data/src/core/handshaker/security/pipelined_secure_endpoint.cc +31 -8
- data/src/core/handshaker/security/secure_endpoint.cc +16 -6
- data/src/core/handshaker/security/security_handshaker.cc +3 -3
- data/src/core/handshaker/tcp_connect/tcp_connect_handshaker.cc +2 -2
- data/src/core/lib/channel/channel_stack.cc +8 -5
- data/src/core/lib/channel/channel_stack.h +3 -0
- data/src/core/lib/channel/channel_stack_builder_impl.cc +1 -0
- data/src/core/lib/channel/connected_channel.cc +2 -2
- data/src/core/lib/channel/promise_based_filter.cc +69 -64
- data/src/core/lib/channel/promise_based_filter.h +16 -15
- data/src/core/lib/compression/compression_internal.cc +2 -2
- data/src/core/lib/compression/message_compress.cc +7 -7
- data/src/core/lib/event_engine/ares_resolver.cc +22 -20
- data/src/core/lib/event_engine/cf_engine/cf_engine.cc +2 -2
- data/src/core/lib/event_engine/cf_engine/dns_service_resolver.cc +2 -2
- data/src/core/lib/event_engine/cf_engine/dns_service_resolver.h +2 -2
- data/src/core/lib/event_engine/extensions/channelz.h +2 -2
- data/src/core/lib/event_engine/extensions/supports_fd.h +5 -5
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +8 -8
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +10 -10
- data/src/core/lib/event_engine/posix_engine/lockfree_event.cc +2 -2
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +23 -22
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +11 -11
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +168 -170
- data/src/core/lib/event_engine/posix_engine/posix_engine.h +33 -54
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +4 -3
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +5 -5
- data/src/core/lib/event_engine/posix_engine/posix_interface.h +1 -1
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +1 -1
- data/src/core/lib/event_engine/posix_engine/timer_manager.cc +3 -3
- data/src/core/lib/event_engine/resolved_address.cc +3 -3
- data/src/core/lib/event_engine/shim.cc +8 -11
- data/src/core/lib/event_engine/shim.h +2 -1
- data/src/core/lib/event_engine/slice.cc +2 -2
- data/src/core/lib/event_engine/tcp_socket_utils.cc +11 -11
- data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +7 -7
- data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +31 -31
- data/src/core/lib/event_engine/windows/iocp.cc +10 -10
- data/src/core/lib/event_engine/windows/win_socket.cc +6 -6
- data/src/core/lib/event_engine/windows/windows_endpoint.cc +11 -11
- data/src/core/lib/event_engine/windows/windows_engine.cc +16 -14
- data/src/core/lib/event_engine/windows/windows_listener.cc +7 -7
- data/src/core/lib/experiments/experiments.cc +105 -18
- data/src/core/lib/experiments/experiments.h +43 -11
- data/src/core/lib/iomgr/call_combiner.cc +3 -3
- data/src/core/lib/iomgr/endpoint_cfstream.cc +6 -6
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +5 -5
- data/src/core/lib/iomgr/endpoint_pair_windows.cc +15 -14
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +15 -15
- data/src/core/lib/iomgr/ev_poll_posix.cc +11 -11
- data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +5 -4
- data/src/core/lib/iomgr/event_engine_shims/endpoint.h +1 -1
- data/src/core/lib/iomgr/iocp_windows.cc +8 -8
- data/src/core/lib/iomgr/iomgr_windows.cc +3 -3
- data/src/core/lib/iomgr/lockfree_event.cc +2 -2
- data/src/core/lib/iomgr/polling_entity.cc +3 -3
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +2 -2
- data/src/core/lib/iomgr/socket_windows.cc +4 -4
- data/src/core/lib/iomgr/tcp_client_posix.cc +4 -4
- data/src/core/lib/iomgr/tcp_client_windows.cc +4 -4
- data/src/core/lib/iomgr/tcp_posix.cc +42 -42
- data/src/core/lib/iomgr/tcp_server.cc +5 -0
- data/src/core/lib/iomgr/tcp_server.h +7 -0
- data/src/core/lib/iomgr/tcp_server_posix.cc +47 -27
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +5 -5
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +2 -2
- data/src/core/lib/iomgr/tcp_server_windows.cc +68 -29
- data/src/core/lib/iomgr/tcp_windows.cc +7 -7
- data/src/core/lib/iomgr/timer_generic.cc +2 -2
- data/src/core/lib/iomgr/timer_manager.cc +2 -2
- data/src/core/lib/iomgr/unix_sockets_posix.cc +2 -2
- data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +2 -2
- data/src/core/lib/promise/activity.cc +2 -2
- data/src/core/lib/promise/activity.h +6 -6
- data/src/core/lib/promise/context.h +2 -2
- data/src/core/lib/promise/detail/join_state.h +9 -9
- data/src/core/lib/promise/detail/seq_state.h +13 -13
- data/src/core/lib/promise/detail/status.h +2 -2
- data/src/core/lib/promise/for_each.h +5 -5
- data/src/core/lib/promise/interceptor_list.h +2 -2
- data/src/core/lib/promise/latch.h +7 -7
- data/src/core/lib/promise/mpsc.cc +26 -26
- data/src/core/lib/promise/mpsc.h +2 -2
- data/src/core/lib/promise/observable.h +4 -4
- data/src/core/lib/promise/party.cc +32 -25
- data/src/core/lib/promise/party.h +16 -19
- data/src/core/lib/promise/pipe.h +15 -15
- data/src/core/lib/promise/poll.h +5 -4
- data/src/core/lib/promise/promise.h +0 -2
- data/src/core/lib/promise/sleep.cc +3 -1
- data/src/core/lib/promise/status_flag.h +7 -7
- data/src/core/lib/promise/try_join.h +2 -2
- data/src/core/lib/promise/try_seq.h +2 -2
- data/src/core/lib/resource_quota/arena.h +15 -2
- data/src/core/lib/resource_quota/connection_quota.cc +9 -7
- data/src/core/lib/resource_quota/memory_quota.cc +45 -24
- data/src/core/lib/resource_quota/memory_quota.h +48 -16
- data/src/core/lib/resource_quota/telemetry.h +54 -0
- data/src/core/lib/resource_quota/thread_quota.cc +2 -2
- data/src/core/lib/resource_tracker/resource_tracker.cc +33 -0
- data/src/core/lib/resource_tracker/resource_tracker.h +46 -0
- data/src/core/lib/security/authorization/audit_logging.cc +5 -5
- data/src/core/lib/security/authorization/grpc_authorization_engine.cc +2 -2
- data/src/core/lib/security/authorization/stdout_logger.cc +3 -3
- data/src/core/lib/surface/byte_buffer_reader.cc +2 -2
- data/src/core/lib/surface/call.cc +16 -14
- data/src/core/lib/surface/call.h +1 -1
- data/src/core/lib/surface/call_utils.cc +2 -2
- data/src/core/lib/surface/call_utils.h +2 -2
- data/src/core/lib/surface/channel.cc +4 -4
- data/src/core/lib/surface/channel_create.cc +10 -6
- data/src/core/lib/surface/channel_init.cc +80 -23
- data/src/core/lib/surface/channel_init.h +26 -11
- data/src/core/lib/surface/completion_queue.cc +17 -16
- data/src/core/lib/surface/completion_queue_factory.cc +7 -7
- data/src/core/lib/surface/connection_context.h +45 -2
- data/src/core/lib/surface/filter_stack_call.cc +12 -23
- data/src/core/lib/surface/filter_stack_call.h +3 -4
- data/src/core/lib/surface/legacy_channel.cc +7 -7
- data/src/core/lib/surface/validate_metadata.h +2 -2
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/bdp_estimator.cc +2 -2
- data/src/core/lib/transport/bdp_estimator.h +3 -3
- data/src/core/lib/transport/promise_endpoint.cc +3 -3
- data/src/core/lib/transport/promise_endpoint.h +8 -8
- data/src/core/lib/transport/timeout_encoding.cc +4 -4
- data/src/core/load_balancing/child_policy_handler.cc +4 -4
- data/src/core/load_balancing/endpoint_list.cc +2 -2
- data/src/core/load_balancing/grpclb/grpclb.cc +24 -24
- data/src/core/load_balancing/health_check_client.cc +4 -4
- data/src/core/load_balancing/health_check_client_internal.h +2 -2
- data/src/core/load_balancing/lb_policy_registry.cc +2 -2
- data/src/core/load_balancing/oob_backend_metric.cc +4 -4
- data/src/core/load_balancing/oob_backend_metric_internal.h +2 -2
- data/src/core/load_balancing/outlier_detection/outlier_detection.cc +2 -2
- data/src/core/load_balancing/pick_first/pick_first.cc +14 -14
- data/src/core/load_balancing/priority/priority.cc +23 -24
- data/src/core/load_balancing/ring_hash/ring_hash.cc +3 -3
- data/src/core/load_balancing/rls/rls.cc +13 -13
- data/src/core/load_balancing/round_robin/round_robin.cc +9 -9
- data/src/core/load_balancing/weighted_round_robin/static_stride_scheduler.cc +3 -3
- data/src/core/load_balancing/weighted_round_robin/weighted_round_robin.cc +33 -26
- data/src/core/load_balancing/weighted_target/weighted_target.cc +5 -5
- data/src/core/load_balancing/xds/cds.cc +76 -32
- data/src/core/load_balancing/xds/xds_cluster_impl.cc +3 -3
- data/src/core/load_balancing/xds/xds_override_host.cc +4 -4
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +2 -2
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +33 -33
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +10 -10
- data/src/core/resolver/dns/dns_resolver_plugin.cc +6 -3
- data/src/core/resolver/dns/event_engine/event_engine_client_channel_resolver.cc +2 -2
- data/src/core/resolver/endpoint_addresses.cc +3 -3
- data/src/core/resolver/endpoint_addresses.h +3 -0
- data/src/core/resolver/fake/fake_resolver.cc +2 -2
- data/src/core/resolver/google_c2p/google_c2p_resolver.cc +41 -54
- data/src/core/resolver/polling_resolver.cc +3 -3
- data/src/core/resolver/resolver_registry.cc +5 -4
- data/src/core/resolver/xds/xds_dependency_manager.cc +5 -5
- data/src/core/resolver/xds/xds_resolver.cc +9 -9
- data/src/core/server/server.cc +38 -38
- data/src/core/server/server_call_tracer_filter.h +4 -4
- data/src/core/server/server_config_selector_filter.cc +2 -2
- data/src/core/server/xds_server_config_fetcher.cc +9 -8
- data/src/core/service_config/service_config_impl.h +2 -2
- data/src/core/telemetry/call_tracer.cc +39 -49
- data/src/core/telemetry/call_tracer.h +199 -22
- data/src/core/telemetry/histogram.h +205 -0
- data/src/core/telemetry/instrument.cc +719 -0
- data/src/core/telemetry/instrument.h +932 -0
- data/src/core/telemetry/metrics.cc +13 -5
- data/src/core/telemetry/metrics.h +3 -1
- data/src/core/telemetry/stats_data.cc +0 -19
- data/src/core/telemetry/stats_data.h +0 -19
- data/src/core/transport/auth_context.cc +2 -2
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +78 -45
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +1 -0
- data/src/core/tsi/alts/handshaker/alts_shared_resource.cc +3 -3
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +39 -31
- data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +3 -3
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc +3 -3
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_record_protocol_common.cc +7 -7
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
- data/src/core/tsi/fake_transport_security.cc +4 -4
- data/src/core/tsi/ssl/key_logging/ssl_key_logging.cc +4 -4
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +9 -9
- data/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc +3 -3
- data/src/core/tsi/ssl_transport_security.cc +26 -25
- data/src/core/tsi/ssl_transport_security_utils.cc +9 -9
- data/src/core/util/chunked_vector.h +4 -4
- data/src/core/util/event_log.cc +2 -2
- data/src/core/util/gcp_metadata_query.cc +2 -2
- data/src/core/util/grpc_check.cc +22 -0
- data/src/core/util/grpc_check.h +103 -0
- data/src/core/util/http_client/httpcli.cc +3 -3
- data/src/core/util/http_client/parser.cc +4 -4
- data/src/core/util/latent_see.h +7 -4
- data/src/core/util/lru_cache.h +4 -4
- data/src/core/util/memory_usage.h +16 -0
- data/src/core/util/posix/directory_reader.cc +3 -2
- data/src/core/util/posix/sync.cc +24 -24
- data/src/core/util/postmortem_emit.cc +52 -0
- data/src/core/util/postmortem_emit.h +30 -0
- data/src/core/util/ref_counted_ptr.h +5 -0
- data/src/core/util/trie_lookup.h +170 -0
- data/src/core/util/unique_ptr_with_bitset.h +5 -5
- data/src/core/xds/grpc/xds_bootstrap_grpc.h +6 -1
- data/src/core/xds/grpc/xds_certificate_provider.cc +3 -3
- data/src/core/xds/grpc/xds_client_grpc.cc +34 -15
- data/src/core/xds/grpc/xds_client_grpc.h +4 -1
- data/src/core/xds/grpc/xds_cluster_parser.cc +2 -2
- data/src/core/xds/grpc/xds_cluster_specifier_plugin.cc +2 -2
- data/src/core/xds/grpc/xds_endpoint_parser.cc +2 -2
- data/src/core/xds/grpc/xds_http_filter_registry.cc +4 -3
- data/src/core/xds/grpc/xds_listener_parser.cc +3 -3
- data/src/core/xds/grpc/xds_matcher.cc +277 -0
- data/src/core/xds/grpc/xds_matcher.h +432 -0
- data/src/core/xds/grpc/xds_matcher_action.cc +47 -0
- data/src/core/xds/grpc/xds_matcher_action.h +48 -0
- data/src/core/xds/grpc/xds_matcher_context.cc +29 -0
- data/src/core/xds/grpc/xds_matcher_context.h +46 -0
- data/src/core/xds/grpc/xds_matcher_input.cc +79 -0
- data/src/core/xds/grpc/xds_matcher_input.h +105 -0
- data/src/core/xds/grpc/xds_matcher_parse.cc +356 -0
- data/src/core/xds/grpc/xds_matcher_parse.h +39 -0
- data/src/core/xds/grpc/xds_metadata.cc +4 -3
- data/src/core/xds/grpc/xds_route_config_parser.cc +6 -6
- data/src/core/xds/grpc/xds_routing.cc +3 -3
- data/src/core/xds/grpc/xds_transport_grpc.cc +10 -10
- data/src/core/xds/xds_client/lrs_client.cc +6 -6
- data/src/core/xds/xds_client/xds_client.cc +9 -9
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +2 -2
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/abseil-cpp/absl/container/internal/node_slot_policy.h +95 -0
- data/third_party/abseil-cpp/absl/container/node_hash_map.h +687 -0
- metadata +37 -2
@@ -0,0 +1,719 @@
|
|
1
|
+
// Copyright 2025 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
|
+
#include "src/core/telemetry/instrument.h"
|
16
|
+
|
17
|
+
#include <grpc/support/port_platform.h>
|
18
|
+
|
19
|
+
#include <atomic>
|
20
|
+
#include <cstddef>
|
21
|
+
#include <cstdint>
|
22
|
+
#include <memory>
|
23
|
+
#include <string>
|
24
|
+
#include <tuple>
|
25
|
+
#include <utility>
|
26
|
+
#include <vector>
|
27
|
+
|
28
|
+
#include "absl/container/flat_hash_map.h"
|
29
|
+
#include "absl/log/log.h"
|
30
|
+
#include "absl/strings/str_join.h"
|
31
|
+
#include "absl/strings/string_view.h"
|
32
|
+
#include "absl/types/span.h"
|
33
|
+
#include "src/core/util/grpc_check.h"
|
34
|
+
|
35
|
+
namespace grpc_core {
|
36
|
+
|
37
|
+
namespace {
|
38
|
+
struct Hook {
|
39
|
+
HistogramCollectionHook hook;
|
40
|
+
Hook* next;
|
41
|
+
};
|
42
|
+
|
43
|
+
std::atomic<Hook*> hooks = nullptr;
|
44
|
+
} // namespace
|
45
|
+
|
46
|
+
void RegisterHistogramCollectionHook(HistogramCollectionHook hook) {
|
47
|
+
Hook* new_hook =
|
48
|
+
new Hook{std::move(hook), hooks.load(std::memory_order_acquire)};
|
49
|
+
while (!hooks.compare_exchange_weak(new_hook->next, new_hook,
|
50
|
+
std::memory_order_acq_rel)) {
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
namespace instrument_detail {
|
55
|
+
|
56
|
+
void CallHistogramCollectionHooks(
|
57
|
+
const InstrumentMetadata::Description* instrument,
|
58
|
+
absl::Span<const std::string> labels, int64_t value) {
|
59
|
+
Hook* hook = hooks.load(std::memory_order_acquire);
|
60
|
+
while (GPR_UNLIKELY(hook != nullptr)) {
|
61
|
+
hook->hook(instrument, labels, value);
|
62
|
+
hook = hook->next;
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
} // namespace instrument_detail
|
67
|
+
|
68
|
+
CollectionScope::CollectionScope(
|
69
|
+
std::vector<std::unique_ptr<instrument_detail::StorageSet>> storage_sets)
|
70
|
+
: storage_sets_(std::move(storage_sets)) {}
|
71
|
+
|
72
|
+
size_t CollectionScope::TestOnlyCountStorageHeld() const {
|
73
|
+
size_t count = 0;
|
74
|
+
for (const auto& set : storage_sets_) {
|
75
|
+
count += set->TestOnlyCountStorageHeld();
|
76
|
+
}
|
77
|
+
return count;
|
78
|
+
}
|
79
|
+
|
80
|
+
std::vector<instrument_detail::StorageSet*> CollectionScope::GetStorageSets() {
|
81
|
+
std::vector<instrument_detail::StorageSet*> result;
|
82
|
+
result.reserve(storage_sets_.size());
|
83
|
+
for (const auto& storage_set : storage_sets_) {
|
84
|
+
result.push_back(storage_set.get());
|
85
|
+
}
|
86
|
+
return result;
|
87
|
+
}
|
88
|
+
|
89
|
+
std::unique_ptr<CollectionScope>
|
90
|
+
instrument_detail::QueryableDomain::CreateCollectionScope() {
|
91
|
+
std::vector<std::unique_ptr<instrument_detail::StorageSet>> storage_sets;
|
92
|
+
for (auto* domain = last_; domain != nullptr; domain = domain->prev_) {
|
93
|
+
storage_sets.push_back(domain->CreateStorageSet());
|
94
|
+
}
|
95
|
+
return std::make_unique<CollectionScope>(std::move(storage_sets));
|
96
|
+
}
|
97
|
+
|
98
|
+
////////////////////////////////////////////////////////////////////////////////
|
99
|
+
// InstrumentMetadata
|
100
|
+
|
101
|
+
void InstrumentMetadata::ForEachInstrument(
|
102
|
+
absl::FunctionRef<void(const InstrumentMetadata::Description*)> fn) {
|
103
|
+
instrument_detail::QueryableDomain::ForEachInstrument(fn);
|
104
|
+
}
|
105
|
+
|
106
|
+
/////////////////////////////////////////////////////////////////////////////////
|
107
|
+
// GaugeStorage
|
108
|
+
|
109
|
+
namespace instrument_detail {
|
110
|
+
|
111
|
+
GaugeStorage::GaugeStorage(QueryableDomain* domain)
|
112
|
+
: double_gauges_(domain->allocated_double_gauge_slots()),
|
113
|
+
int_gauges_(domain->allocated_int_gauge_slots()),
|
114
|
+
uint_gauges_(domain->allocated_uint_gauge_slots()) {}
|
115
|
+
|
116
|
+
} // namespace instrument_detail
|
117
|
+
|
118
|
+
////////////////////////////////////////////////////////////////////////////////
|
119
|
+
// StorageSet
|
120
|
+
|
121
|
+
namespace instrument_detail {
|
122
|
+
|
123
|
+
StorageSet::StorageSet(QueryableDomain* domain, size_t map_shards_size)
|
124
|
+
: domain_(domain),
|
125
|
+
map_shards_(std::make_unique<MapShard[]>(map_shards_size)),
|
126
|
+
map_shards_size_(map_shards_size) {
|
127
|
+
domain_->RegisterStorageSet(this);
|
128
|
+
}
|
129
|
+
|
130
|
+
StorageSet::~StorageSet() { domain_->UnregisterStorageSet(this); }
|
131
|
+
|
132
|
+
void StorageSet::ExportMetrics(
|
133
|
+
MetricsSink& sink,
|
134
|
+
absl::Span<const InstrumentMetadata::Description* const> metrics) {
|
135
|
+
for (size_t i = 0; i < map_shards_size_; ++i) {
|
136
|
+
MutexLock lock(&map_shards_[i].mu);
|
137
|
+
map_shards_[i].storage_map.ForEach([&](const auto& label,
|
138
|
+
const auto& weak_storage) {
|
139
|
+
// It's safe to use `get()` here because the `StorageSet` itself
|
140
|
+
// holds a weak reference, guaranteeing the object's memory is
|
141
|
+
// alive. We can't get a strong ref if the object is orphaned, but
|
142
|
+
// we still need to read its final metric values.
|
143
|
+
DomainStorage* storage = weak_storage.get();
|
144
|
+
GaugeStorage gauge_storage(storage->domain());
|
145
|
+
storage->FillGaugeStorage(gauge_storage);
|
146
|
+
for (const auto* metric : metrics) {
|
147
|
+
Match(
|
148
|
+
metric->shape,
|
149
|
+
[metric, &sink, storage, &label](InstrumentMetadata::CounterShape) {
|
150
|
+
sink.Counter(label, metric->name,
|
151
|
+
storage->SumCounter(metric->offset));
|
152
|
+
},
|
153
|
+
[metric, &sink, storage,
|
154
|
+
&label](InstrumentMetadata::HistogramShape bounds) {
|
155
|
+
std::vector<uint64_t> counts(bounds.size());
|
156
|
+
for (size_t i = 0; i < bounds.size(); ++i) {
|
157
|
+
counts[i] = storage->SumCounter(metric->offset + i);
|
158
|
+
}
|
159
|
+
sink.Histogram(label, metric->name, bounds, counts);
|
160
|
+
},
|
161
|
+
[metric, &sink, &gauge_storage,
|
162
|
+
&label](InstrumentMetadata::DoubleGaugeShape) {
|
163
|
+
if (auto value = gauge_storage.GetDouble(metric->offset);
|
164
|
+
value.has_value()) {
|
165
|
+
sink.DoubleGauge(label, metric->name, *value);
|
166
|
+
}
|
167
|
+
},
|
168
|
+
[metric, &sink, &gauge_storage,
|
169
|
+
&label](InstrumentMetadata::IntGaugeShape) {
|
170
|
+
if (auto value = gauge_storage.GetInt(metric->offset);
|
171
|
+
value.has_value()) {
|
172
|
+
sink.IntGauge(label, metric->name, *value);
|
173
|
+
}
|
174
|
+
},
|
175
|
+
[metric, &sink, &gauge_storage,
|
176
|
+
&label](InstrumentMetadata::UintGaugeShape) {
|
177
|
+
if (auto value = gauge_storage.GetUint(metric->offset);
|
178
|
+
value.has_value()) {
|
179
|
+
sink.UintGauge(label, metric->name, *value);
|
180
|
+
}
|
181
|
+
});
|
182
|
+
}
|
183
|
+
});
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
size_t StorageSet::TestOnlyCountStorageHeld() const {
|
188
|
+
size_t count = 0;
|
189
|
+
for (size_t i = 0; i < map_shards_size_; ++i) {
|
190
|
+
MutexLock lock(&map_shards_[i].mu);
|
191
|
+
map_shards_[i].storage_map.ForEach([&](const auto&, const auto& weak) {
|
192
|
+
count += weak->RefIfNonZero() != nullptr;
|
193
|
+
});
|
194
|
+
}
|
195
|
+
return count;
|
196
|
+
}
|
197
|
+
|
198
|
+
void StorageSet::AddStorage(WeakRefCountedPtr<DomainStorage> storage) {
|
199
|
+
size_t shard;
|
200
|
+
auto label = storage->label();
|
201
|
+
if (map_shards_size_ == 1) {
|
202
|
+
shard = 0;
|
203
|
+
} else {
|
204
|
+
GRPC_CHECK(!label.empty());
|
205
|
+
shard = absl::HashOf(label[0], this) % map_shards_size_;
|
206
|
+
}
|
207
|
+
MapShard& map_shard = map_shards_[shard];
|
208
|
+
MutexLock lock(&map_shard.mu);
|
209
|
+
map_shard.storage_map = map_shard.storage_map.Add(label, std::move(storage));
|
210
|
+
}
|
211
|
+
|
212
|
+
} // namespace instrument_detail
|
213
|
+
|
214
|
+
////////////////////////////////////////////////////////////////////////////////
|
215
|
+
// MetricsQuery
|
216
|
+
|
217
|
+
MetricsQuery& MetricsQuery::WithLabelEq(absl::string_view label,
|
218
|
+
std::string value) {
|
219
|
+
label_eqs_.emplace(label, std::move(value));
|
220
|
+
return *this;
|
221
|
+
}
|
222
|
+
|
223
|
+
MetricsQuery& MetricsQuery::CollapseLabels(
|
224
|
+
absl::Span<const std::string> labels) {
|
225
|
+
for (const auto& label : labels) {
|
226
|
+
collapsed_labels_.insert(label);
|
227
|
+
}
|
228
|
+
return *this;
|
229
|
+
}
|
230
|
+
|
231
|
+
MetricsQuery& MetricsQuery::OnlyMetrics(absl::Span<const std::string> metrics) {
|
232
|
+
only_metrics_.emplace(metrics.begin(), metrics.end());
|
233
|
+
return *this;
|
234
|
+
}
|
235
|
+
|
236
|
+
void MetricsQuery::Run(std::unique_ptr<CollectionScope> scope,
|
237
|
+
MetricsSink& sink) const {
|
238
|
+
GRPC_CHECK_NE(scope.get(), nullptr);
|
239
|
+
auto selected_metrics = this->selected_metrics();
|
240
|
+
absl::flat_hash_map<instrument_detail::QueryableDomain*,
|
241
|
+
std::vector<const InstrumentMetadata::Description*>>
|
242
|
+
metrics_by_domain;
|
243
|
+
if (selected_metrics.has_value()) {
|
244
|
+
for (const auto& metric : *selected_metrics) {
|
245
|
+
const auto* desc = instrument_detail::InstrumentIndex::Get().Find(metric);
|
246
|
+
if (desc == nullptr) continue;
|
247
|
+
metrics_by_domain[desc->domain].push_back(desc);
|
248
|
+
}
|
249
|
+
} else {
|
250
|
+
instrument_detail::QueryableDomain::ForEachInstrument(
|
251
|
+
[&](const InstrumentMetadata::Description* desc) {
|
252
|
+
metrics_by_domain[desc->domain].push_back(desc);
|
253
|
+
});
|
254
|
+
}
|
255
|
+
for (auto* storage_set : scope->GetStorageSets()) {
|
256
|
+
instrument_detail::QueryableDomain* domain = storage_set->domain();
|
257
|
+
if (domain == nullptr) continue;
|
258
|
+
auto it = metrics_by_domain.find(domain);
|
259
|
+
if (it == metrics_by_domain.end()) continue;
|
260
|
+
this->Apply(
|
261
|
+
domain->label_names(),
|
262
|
+
[&](MetricsSink& sink) {
|
263
|
+
storage_set->ExportMetrics(sink, it->second);
|
264
|
+
},
|
265
|
+
sink);
|
266
|
+
}
|
267
|
+
}
|
268
|
+
|
269
|
+
void MetricsQuery::Apply(absl::Span<const std::string> label_names,
|
270
|
+
absl::FunctionRef<void(MetricsSink&)> fn,
|
271
|
+
MetricsSink& sink) const {
|
272
|
+
if (collapsed_labels_.empty()) {
|
273
|
+
ApplyLabelChecks(label_names, fn, sink);
|
274
|
+
return;
|
275
|
+
}
|
276
|
+
std::vector<size_t> include_labels;
|
277
|
+
for (size_t i = 0; i < label_names.size(); ++i) {
|
278
|
+
if (!collapsed_labels_.contains(label_names[i])) {
|
279
|
+
include_labels.push_back(i);
|
280
|
+
}
|
281
|
+
}
|
282
|
+
if (include_labels.size() == label_names.size()) {
|
283
|
+
ApplyLabelChecks(label_names, fn, sink);
|
284
|
+
return;
|
285
|
+
}
|
286
|
+
class Filter final : public MetricsSink {
|
287
|
+
public:
|
288
|
+
explicit Filter(absl::Span<const size_t> include_labels)
|
289
|
+
: include_labels_(include_labels) {}
|
290
|
+
|
291
|
+
void Counter(absl::Span<const std::string> label, absl::string_view name,
|
292
|
+
uint64_t value) override {
|
293
|
+
uint64_counters_[ConstructKey(label, name)] += value;
|
294
|
+
}
|
295
|
+
|
296
|
+
void Histogram(absl::Span<const std::string> label, absl::string_view name,
|
297
|
+
HistogramBuckets bounds,
|
298
|
+
absl::Span<const uint64_t> counts) override {
|
299
|
+
GRPC_CHECK_EQ(counts.size(), bounds.size());
|
300
|
+
auto it = histograms_.find(ConstructKey(label, name));
|
301
|
+
if (it == histograms_.end()) {
|
302
|
+
histograms_.emplace(std::piecewise_construct,
|
303
|
+
std::tuple(ConstructKey(label, name)),
|
304
|
+
std::tuple(bounds, counts));
|
305
|
+
} else {
|
306
|
+
if (it->second.bounds != bounds) {
|
307
|
+
LOG(FATAL) << "Histogram bounds mismatch for metric '" << name
|
308
|
+
<< "': {" << absl::StrJoin(it->second.bounds, ",")
|
309
|
+
<< "} vs {" << absl::StrJoin(bounds, ",") << "}";
|
310
|
+
}
|
311
|
+
for (size_t i = 0; i < counts.size(); ++i) {
|
312
|
+
it->second.counts[i] += counts[i];
|
313
|
+
}
|
314
|
+
}
|
315
|
+
}
|
316
|
+
|
317
|
+
void DoubleGauge(absl::Span<const std::string>, absl::string_view,
|
318
|
+
double) override {
|
319
|
+
// Not aggregatable
|
320
|
+
}
|
321
|
+
void IntGauge(absl::Span<const std::string>, absl::string_view,
|
322
|
+
int64_t) override {
|
323
|
+
// Not aggregatable
|
324
|
+
}
|
325
|
+
void UintGauge(absl::Span<const std::string>, absl::string_view,
|
326
|
+
uint64_t) override {
|
327
|
+
// Not aggregatable
|
328
|
+
}
|
329
|
+
|
330
|
+
void Publish(MetricsSink& sink) const {
|
331
|
+
for (const auto& [key, value] : uint64_counters_) {
|
332
|
+
sink.Counter(std::get<0>(key), std::get<1>(key), value);
|
333
|
+
}
|
334
|
+
for (const auto& [key, value] : histograms_) {
|
335
|
+
sink.Histogram(std::get<0>(key), std::get<1>(key), value.bounds,
|
336
|
+
value.counts);
|
337
|
+
}
|
338
|
+
}
|
339
|
+
|
340
|
+
private:
|
341
|
+
std::tuple<std::vector<std::string>, absl::string_view> ConstructKey(
|
342
|
+
absl::Span<const std::string> label, absl::string_view name) const {
|
343
|
+
std::vector<std::string> key;
|
344
|
+
key.reserve(include_labels_.size());
|
345
|
+
for (auto i : include_labels_) {
|
346
|
+
key.push_back(label[i]);
|
347
|
+
}
|
348
|
+
return std::tuple(std::move(key), name);
|
349
|
+
}
|
350
|
+
|
351
|
+
absl::Span<const size_t> include_labels_;
|
352
|
+
absl::flat_hash_map<std::tuple<std::vector<std::string>, absl::string_view>,
|
353
|
+
uint64_t>
|
354
|
+
uint64_counters_;
|
355
|
+
struct HistogramValue {
|
356
|
+
HistogramValue(HistogramBuckets bounds, absl::Span<const uint64_t> counts)
|
357
|
+
: bounds(bounds), counts(counts.begin(), counts.end()) {}
|
358
|
+
HistogramBuckets bounds;
|
359
|
+
std::vector<uint64_t> counts;
|
360
|
+
};
|
361
|
+
absl::flat_hash_map<std::tuple<std::vector<std::string>, absl::string_view>,
|
362
|
+
HistogramValue>
|
363
|
+
histograms_;
|
364
|
+
};
|
365
|
+
Filter filter(include_labels);
|
366
|
+
ApplyLabelChecks(label_names, fn, filter);
|
367
|
+
filter.Publish(sink);
|
368
|
+
}
|
369
|
+
|
370
|
+
void MetricsQuery::ApplyLabelChecks(absl::Span<const std::string> label_names,
|
371
|
+
absl::FunctionRef<void(MetricsSink&)> fn,
|
372
|
+
MetricsSink& sink) const {
|
373
|
+
if (label_eqs_.empty()) {
|
374
|
+
fn(sink);
|
375
|
+
return;
|
376
|
+
}
|
377
|
+
struct LabelEq {
|
378
|
+
size_t offset;
|
379
|
+
absl::string_view value;
|
380
|
+
};
|
381
|
+
std::vector<LabelEq> label_eqs;
|
382
|
+
for (size_t i = 0; i < label_names.size(); ++i) {
|
383
|
+
const auto& label = label_names[i];
|
384
|
+
auto it = label_eqs_.find(label);
|
385
|
+
if (it != label_eqs_.end()) label_eqs.push_back({i, it->second});
|
386
|
+
}
|
387
|
+
// If there are labels to match, but this domain doesn't have all the labels
|
388
|
+
// requested, skip it - it can never match all!
|
389
|
+
if (label_eqs.size() < label_eqs_.size()) return;
|
390
|
+
class Filter final : public MetricsSink {
|
391
|
+
public:
|
392
|
+
explicit Filter(MetricsSink& sink,
|
393
|
+
absl::Span<const LabelEq> inclusion_checks)
|
394
|
+
: inclusion_checks_(inclusion_checks), sink_(sink) {}
|
395
|
+
|
396
|
+
void Counter(absl::Span<const std::string> label, absl::string_view name,
|
397
|
+
uint64_t value) override {
|
398
|
+
if (!Matches(label)) return;
|
399
|
+
sink_.Counter(label, name, value);
|
400
|
+
}
|
401
|
+
|
402
|
+
void Histogram(absl::Span<const std::string> label, absl::string_view name,
|
403
|
+
HistogramBuckets bounds,
|
404
|
+
absl::Span<const uint64_t> counts) override {
|
405
|
+
if (!Matches(label)) return;
|
406
|
+
sink_.Histogram(label, name, bounds, counts);
|
407
|
+
}
|
408
|
+
|
409
|
+
void DoubleGauge(absl::Span<const std::string> label,
|
410
|
+
absl::string_view name, double value) override {
|
411
|
+
if (!Matches(label)) return;
|
412
|
+
sink_.DoubleGauge(label, name, value);
|
413
|
+
}
|
414
|
+
void IntGauge(absl::Span<const std::string> label, absl::string_view name,
|
415
|
+
int64_t value) override {
|
416
|
+
if (!Matches(label)) return;
|
417
|
+
sink_.IntGauge(label, name, value);
|
418
|
+
}
|
419
|
+
void UintGauge(absl::Span<const std::string> label, absl::string_view name,
|
420
|
+
uint64_t value) override {
|
421
|
+
if (!Matches(label)) return;
|
422
|
+
sink_.UintGauge(label, name, value);
|
423
|
+
}
|
424
|
+
|
425
|
+
private:
|
426
|
+
bool Matches(absl::Span<const std::string> label) const {
|
427
|
+
for (const auto& check : inclusion_checks_) {
|
428
|
+
if (label[check.offset] != check.value) return false;
|
429
|
+
}
|
430
|
+
return true;
|
431
|
+
}
|
432
|
+
|
433
|
+
absl::Span<const LabelEq> inclusion_checks_;
|
434
|
+
MetricsSink& sink_;
|
435
|
+
};
|
436
|
+
Filter filter(sink, label_eqs);
|
437
|
+
fn(filter);
|
438
|
+
}
|
439
|
+
|
440
|
+
namespace instrument_detail {
|
441
|
+
|
442
|
+
////////////////////////////////////////////////////////////////////////////////
|
443
|
+
// InstrumentIndex
|
444
|
+
|
445
|
+
const InstrumentMetadata::Description* InstrumentIndex::Register(
|
446
|
+
QueryableDomain* domain, uint64_t offset, absl::string_view name,
|
447
|
+
absl::string_view description, absl::string_view unit,
|
448
|
+
InstrumentMetadata::Shape shape) {
|
449
|
+
auto it = metrics_.emplace(
|
450
|
+
name, InstrumentMetadata::Description{domain, offset, name, description,
|
451
|
+
unit, shape});
|
452
|
+
if (!it.second) {
|
453
|
+
// If this is firing one of two things is true:
|
454
|
+
// 1. We have code in gRPC that's registering two different metrics with the
|
455
|
+
// same name. gRPC should fix this.
|
456
|
+
// 2. gRPC static initialization is executing twice. This is an unsupported
|
457
|
+
// use of the gRPC library and the application owner should fix it.
|
458
|
+
LOG(ERROR) << "Metric with name '" << name
|
459
|
+
<< "' registered more than once. Ignoring later registration.";
|
460
|
+
}
|
461
|
+
return &it.first->second;
|
462
|
+
}
|
463
|
+
|
464
|
+
const InstrumentMetadata::Description* InstrumentIndex::Find(
|
465
|
+
absl::string_view name) const {
|
466
|
+
auto it = metrics_.find(name);
|
467
|
+
if (it == metrics_.end()) {
|
468
|
+
return nullptr;
|
469
|
+
}
|
470
|
+
return &it->second;
|
471
|
+
}
|
472
|
+
|
473
|
+
////////////////////////////////////////////////////////////////////////////////
|
474
|
+
// DomainStorage
|
475
|
+
|
476
|
+
DomainStorage::DomainStorage(QueryableDomain* domain,
|
477
|
+
std::vector<std::string> label)
|
478
|
+
: domain_(domain), label_(std::move(label)) {}
|
479
|
+
|
480
|
+
void DomainStorage::Orphaned() { domain_->DomainStorageOrphaned(this); }
|
481
|
+
|
482
|
+
////////////////////////////////////////////////////////////////////////////////
|
483
|
+
// QueryableDomain
|
484
|
+
|
485
|
+
void QueryableDomain::Constructed() {
|
486
|
+
GRPC_CHECK_EQ(prev_, nullptr);
|
487
|
+
prev_ = last_;
|
488
|
+
last_ = this;
|
489
|
+
}
|
490
|
+
|
491
|
+
void QueryableDomain::ForEachInstrument(
|
492
|
+
absl::FunctionRef<void(const InstrumentMetadata::Description*)> fn) {
|
493
|
+
for (auto* domain = last_; domain != nullptr; domain = domain->prev_) {
|
494
|
+
for (const auto* metric : domain->metrics_) {
|
495
|
+
fn(metric);
|
496
|
+
}
|
497
|
+
}
|
498
|
+
}
|
499
|
+
|
500
|
+
size_t QueryableDomain::TestOnlyCountStorageHeld() const {
|
501
|
+
size_t count = 0;
|
502
|
+
for (size_t i = 0; i < map_shards_size_; ++i) {
|
503
|
+
MutexLock lock(&map_shards_[i].mu);
|
504
|
+
map_shards_[i].storage_map.ForEach(
|
505
|
+
[&count](const auto&, const auto&) { count++; });
|
506
|
+
}
|
507
|
+
return count;
|
508
|
+
}
|
509
|
+
|
510
|
+
void QueryableDomain::DomainStorageOrphaned(DomainStorage* storage) {
|
511
|
+
auto label = storage->label();
|
512
|
+
auto& map_shard = GetMapShard(label);
|
513
|
+
MutexLock lock(&map_shard.mu);
|
514
|
+
auto* found_storage = map_shard.storage_map.Lookup(label);
|
515
|
+
if (found_storage == nullptr) return;
|
516
|
+
if (found_storage->get() != storage) return;
|
517
|
+
map_shard.storage_map = map_shard.storage_map.Remove(label);
|
518
|
+
}
|
519
|
+
|
520
|
+
QueryableDomain::MapShard& QueryableDomain::GetMapShard(
|
521
|
+
absl::Span<const std::string> label) {
|
522
|
+
size_t shard;
|
523
|
+
if (map_shards_size_ == 1) {
|
524
|
+
shard = 0;
|
525
|
+
} else {
|
526
|
+
GRPC_CHECK(!label.empty());
|
527
|
+
// Use the first label to shard, all labels to index.
|
528
|
+
shard = absl::HashOf(label[0], this) % map_shards_size_;
|
529
|
+
}
|
530
|
+
return map_shards_[shard];
|
531
|
+
}
|
532
|
+
|
533
|
+
std::unique_ptr<StorageSet> QueryableDomain::CreateStorageSet() {
|
534
|
+
return std::make_unique<StorageSet>(this, map_shards_size_);
|
535
|
+
}
|
536
|
+
|
537
|
+
void QueryableDomain::RegisterStorageSet(StorageSet* storage_set) {
|
538
|
+
// Now register the new set.
|
539
|
+
std::vector<RefCountedPtr<DomainStorage>> added_storage;
|
540
|
+
MutexLock lock(&active_storage_sets_mu_);
|
541
|
+
active_storage_sets_.push_back(storage_set);
|
542
|
+
for (size_t i = 0; i < map_shards_size_; ++i) {
|
543
|
+
MutexLock lock(&map_shards_[i].mu);
|
544
|
+
map_shards_[i].storage_map.ForEach(
|
545
|
+
[&](const auto&, const auto& weak_storage) {
|
546
|
+
// Only add storage that is not already orphaned.
|
547
|
+
if (auto storage = weak_storage->RefIfNonZero(); storage != nullptr) {
|
548
|
+
added_storage.emplace_back(storage);
|
549
|
+
storage_set->AddStorage(weak_storage);
|
550
|
+
}
|
551
|
+
});
|
552
|
+
}
|
553
|
+
}
|
554
|
+
|
555
|
+
void QueryableDomain::UnregisterStorageSet(StorageSet* storage_set) {
|
556
|
+
MutexLock lock(&active_storage_sets_mu_);
|
557
|
+
active_storage_sets_.erase(
|
558
|
+
std::remove(active_storage_sets_.begin(), active_storage_sets_.end(),
|
559
|
+
storage_set),
|
560
|
+
active_storage_sets_.end());
|
561
|
+
}
|
562
|
+
|
563
|
+
void QueryableDomain::TestOnlyReset() {
|
564
|
+
map_shards_ = std::make_unique<MapShard[]>(map_shards_size_);
|
565
|
+
MutexLock lock(&active_storage_sets_mu_);
|
566
|
+
active_storage_sets_.clear();
|
567
|
+
}
|
568
|
+
|
569
|
+
const InstrumentMetadata::Description* QueryableDomain::AllocateCounter(
|
570
|
+
absl::string_view name, absl::string_view description,
|
571
|
+
absl::string_view unit) {
|
572
|
+
const size_t offset = allocated_counter_slots_++;
|
573
|
+
auto* desc =
|
574
|
+
InstrumentIndex::Get().Register(this, offset, name, description, unit,
|
575
|
+
InstrumentMetadata::CounterShape{});
|
576
|
+
metrics_.push_back(desc);
|
577
|
+
return desc;
|
578
|
+
}
|
579
|
+
|
580
|
+
const InstrumentMetadata::Description* QueryableDomain::AllocateHistogram(
|
581
|
+
absl::string_view name, absl::string_view description,
|
582
|
+
absl::string_view unit, HistogramBuckets bounds) {
|
583
|
+
const size_t offset = AllocateCounterSlots(bounds.size());
|
584
|
+
auto* desc = InstrumentIndex::Get().Register(this, offset, name, description,
|
585
|
+
unit, bounds);
|
586
|
+
metrics_.push_back(desc);
|
587
|
+
return desc;
|
588
|
+
}
|
589
|
+
|
590
|
+
const InstrumentMetadata::Description* QueryableDomain::AllocateDoubleGauge(
|
591
|
+
absl::string_view name, absl::string_view description,
|
592
|
+
absl::string_view unit) {
|
593
|
+
const size_t offset = allocated_double_gauge_slots_++;
|
594
|
+
auto* desc =
|
595
|
+
InstrumentIndex::Get().Register(this, offset, name, description, unit,
|
596
|
+
InstrumentMetadata::DoubleGaugeShape{});
|
597
|
+
metrics_.push_back(desc);
|
598
|
+
return desc;
|
599
|
+
}
|
600
|
+
|
601
|
+
const InstrumentMetadata::Description* QueryableDomain::AllocateIntGauge(
|
602
|
+
absl::string_view name, absl::string_view description,
|
603
|
+
absl::string_view unit) {
|
604
|
+
const size_t offset = allocated_int_gauge_slots_++;
|
605
|
+
auto* desc =
|
606
|
+
InstrumentIndex::Get().Register(this, offset, name, description, unit,
|
607
|
+
InstrumentMetadata::IntGaugeShape{});
|
608
|
+
metrics_.push_back(desc);
|
609
|
+
return desc;
|
610
|
+
}
|
611
|
+
|
612
|
+
const InstrumentMetadata::Description* QueryableDomain::AllocateUintGauge(
|
613
|
+
absl::string_view name, absl::string_view description,
|
614
|
+
absl::string_view unit) {
|
615
|
+
const size_t offset = allocated_uint_gauge_slots_++;
|
616
|
+
auto* desc =
|
617
|
+
InstrumentIndex::Get().Register(this, offset, name, description, unit,
|
618
|
+
InstrumentMetadata::UintGaugeShape{});
|
619
|
+
metrics_.push_back(desc);
|
620
|
+
return desc;
|
621
|
+
}
|
622
|
+
|
623
|
+
void QueryableDomain::TestOnlyResetAll() {
|
624
|
+
for (auto* domain = last_; domain != nullptr; domain = domain->prev_) {
|
625
|
+
domain->TestOnlyReset();
|
626
|
+
}
|
627
|
+
}
|
628
|
+
|
629
|
+
RefCountedPtr<DomainStorage> QueryableDomain::GetDomainStorage(
|
630
|
+
std::vector<std::string> label) {
|
631
|
+
MapShard& map_shard = GetMapShard(label);
|
632
|
+
// First try to get an existing storage.
|
633
|
+
map_shard.mu.Lock();
|
634
|
+
auto storage_map = map_shard.storage_map;
|
635
|
+
map_shard.mu.Unlock();
|
636
|
+
// With an AVL we can search outside the lock.
|
637
|
+
auto* weak_storage = storage_map.Lookup(label);
|
638
|
+
if (weak_storage != nullptr) {
|
639
|
+
// Found a weak pointer, try to upgrade it to a strong pointer.
|
640
|
+
RefCountedPtr<DomainStorage> strong_storage =
|
641
|
+
(*weak_storage)->RefIfNonZero();
|
642
|
+
if (strong_storage != nullptr) {
|
643
|
+
// Upgrade successful, return the strong pointer.
|
644
|
+
return strong_storage;
|
645
|
+
}
|
646
|
+
}
|
647
|
+
// No hit, or the storage is orphaned: now we lock and search again.
|
648
|
+
RefCountedPtr<DomainStorage> new_storage;
|
649
|
+
{
|
650
|
+
MutexLock lock(&map_shard.mu);
|
651
|
+
storage_map = map_shard.storage_map;
|
652
|
+
// We must look up the storage map again, as it may have been created
|
653
|
+
// by another thread while we were not holding the lock.
|
654
|
+
weak_storage = storage_map.Lookup(label);
|
655
|
+
if (weak_storage != nullptr) {
|
656
|
+
// Found a weak pointer, try to upgrade it to a strong pointer.
|
657
|
+
RefCountedPtr<DomainStorage> strong_storage =
|
658
|
+
(*weak_storage)->RefIfNonZero();
|
659
|
+
if (strong_storage != nullptr) {
|
660
|
+
// Upgrade successful, return the strong pointer.
|
661
|
+
return strong_storage;
|
662
|
+
}
|
663
|
+
}
|
664
|
+
// Still no hit or orphaned: with the lock held we allocate a new storage
|
665
|
+
// and insert it into the map.
|
666
|
+
new_storage = CreateDomainStorage(std::move(label));
|
667
|
+
auto new_weak_storage = new_storage->WeakRef();
|
668
|
+
map_shard.storage_map =
|
669
|
+
map_shard.storage_map.Add(new_weak_storage->label(), new_weak_storage);
|
670
|
+
}
|
671
|
+
// Add to active storage sets
|
672
|
+
MutexLock lock(&active_storage_sets_mu_);
|
673
|
+
for (auto* storage_set : active_storage_sets_) {
|
674
|
+
storage_set->AddStorage(new_storage->WeakRef());
|
675
|
+
}
|
676
|
+
return new_storage;
|
677
|
+
}
|
678
|
+
|
679
|
+
} // namespace instrument_detail
|
680
|
+
|
681
|
+
void TestOnlyResetInstruments() {
|
682
|
+
Hook* hook = hooks.load(std::memory_order_acquire);
|
683
|
+
while (hook != nullptr) {
|
684
|
+
Hook* next = hook->next;
|
685
|
+
delete hook;
|
686
|
+
hook = next;
|
687
|
+
}
|
688
|
+
hooks.store(nullptr, std::memory_order_release);
|
689
|
+
instrument_detail::QueryableDomain::TestOnlyResetAll();
|
690
|
+
}
|
691
|
+
|
692
|
+
LowContentionBackend::LowContentionBackend(size_t size)
|
693
|
+
: counters_(new std::atomic<uint64_t>[size]) {
|
694
|
+
for (size_t i = 0; i < size; ++i) {
|
695
|
+
counters_[i].store(0, std::memory_order_relaxed);
|
696
|
+
}
|
697
|
+
}
|
698
|
+
|
699
|
+
uint64_t LowContentionBackend::Sum(size_t index) {
|
700
|
+
return counters_[index].load(std::memory_order_relaxed);
|
701
|
+
}
|
702
|
+
|
703
|
+
HighContentionBackend::HighContentionBackend(size_t size) {
|
704
|
+
for (auto& shard : counters_) {
|
705
|
+
shard = std::make_unique<std::atomic<uint64_t>[]>(size);
|
706
|
+
for (size_t i = 0; i < size; ++i) {
|
707
|
+
shard[i].store(0, std::memory_order_relaxed);
|
708
|
+
}
|
709
|
+
}
|
710
|
+
}
|
711
|
+
|
712
|
+
uint64_t HighContentionBackend::Sum(size_t index) {
|
713
|
+
uint64_t sum = 0;
|
714
|
+
for (auto& shard : counters_) {
|
715
|
+
sum += shard[index].load(std::memory_order_relaxed);
|
716
|
+
}
|
717
|
+
return sum;
|
718
|
+
}
|
719
|
+
} // namespace grpc_core
|