Added insecure connections counter (#32115)

* Fetch PR 32088 and rebase

* update build file

* update BUILD

* format stats data

* address iwyu error

* Automated change: Fix sanity tests

Co-authored-by: ananda1066 <ananda1066@users.noreply.github.com>
pull/32174/head
Alisha Nanda 2 years ago committed by GitHub
parent aa11978541
commit 2f0734272d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      BUILD
  2. 32
      src/core/lib/debug/stats_data.cc
  3. 7
      src/core/lib/debug/stats_data.h
  4. 2
      src/core/lib/debug/stats_data.yaml
  5. 9
      src/core/lib/security/transport/security_handshaker.cc
  6. 1
      tools/codegen/core/gen_stats_data.py

@ -1631,6 +1631,7 @@ grpc_cc_library(
"handshaker",
"promise",
"ref_counted_ptr",
"stats",
"tsi_base",
"//src/core:activity",
"//src/core:arena",
@ -1654,6 +1655,7 @@ grpc_cc_library(
"//src/core:seq",
"//src/core:slice",
"//src/core:slice_refcount",
"//src/core:stats_data",
"//src/core:status_helper",
"//src/core:try_seq",
"//src/core:unique_type_name",

@ -73,23 +73,15 @@ Histogram_80_10 operator-(const Histogram_80_10& left,
}
const absl::string_view
GlobalStats::counter_name[static_cast<int>(Counter::COUNT)] = {
"client_calls_created",
"server_calls_created",
"client_channels_created",
"client_subchannels_created",
"server_channels_created",
"syscall_write",
"syscall_read",
"tcp_read_alloc_8k",
"tcp_read_alloc_64k",
"http2_settings_writes",
"http2_pings_sent",
"http2_writes_begun",
"http2_transport_stalls",
"http2_stream_stalls",
"cq_pluck_creates",
"cq_next_creates",
"cq_callback_creates",
"client_calls_created", "server_calls_created",
"client_channels_created", "client_subchannels_created",
"server_channels_created", "insecure_connections_created",
"syscall_write", "syscall_read",
"tcp_read_alloc_8k", "tcp_read_alloc_64k",
"http2_settings_writes", "http2_pings_sent",
"http2_writes_begun", "http2_transport_stalls",
"http2_stream_stalls", "cq_pluck_creates",
"cq_next_creates", "cq_callback_creates",
};
const absl::string_view GlobalStats::counter_doc[static_cast<int>(
Counter::COUNT)] = {
@ -98,6 +90,7 @@ const absl::string_view GlobalStats::counter_doc[static_cast<int>(
"Number of client channels created",
"Number of client subchannels created",
"Number of server channels created",
"Number of insecure connections created",
"Number of write syscalls (or equivalent - eg sendmsg) made by this "
"process",
"Number of read syscalls (or equivalent - eg recvmsg) made by this process",
@ -219,6 +212,7 @@ GlobalStats::GlobalStats()
client_channels_created{0},
client_subchannels_created{0},
server_channels_created{0},
insecure_connections_created{0},
syscall_write{0},
syscall_read{0},
tcp_read_alloc_8k{0},
@ -274,6 +268,8 @@ std::unique_ptr<GlobalStats> GlobalStatsCollector::Collect() const {
data.client_subchannels_created.load(std::memory_order_relaxed);
result->server_channels_created +=
data.server_channels_created.load(std::memory_order_relaxed);
result->insecure_connections_created +=
data.insecure_connections_created.load(std::memory_order_relaxed);
result->syscall_write += data.syscall_write.load(std::memory_order_relaxed);
result->syscall_read += data.syscall_read.load(std::memory_order_relaxed);
result->tcp_read_alloc_8k +=
@ -319,6 +315,8 @@ std::unique_ptr<GlobalStats> GlobalStats::Diff(const GlobalStats& other) const {
client_subchannels_created - other.client_subchannels_created;
result->server_channels_created =
server_channels_created - other.server_channels_created;
result->insecure_connections_created =
insecure_connections_created - other.insecure_connections_created;
result->syscall_write = syscall_write - other.syscall_write;
result->syscall_read = syscall_read - other.syscall_read;
result->tcp_read_alloc_8k = tcp_read_alloc_8k - other.tcp_read_alloc_8k;

@ -110,6 +110,7 @@ struct GlobalStats {
kClientChannelsCreated,
kClientSubchannelsCreated,
kServerChannelsCreated,
kInsecureConnectionsCreated,
kSyscallWrite,
kSyscallRead,
kTcpReadAlloc8k,
@ -149,6 +150,7 @@ struct GlobalStats {
uint64_t client_channels_created;
uint64_t client_subchannels_created;
uint64_t server_channels_created;
uint64_t insecure_connections_created;
uint64_t syscall_write;
uint64_t syscall_read;
uint64_t tcp_read_alloc_8k;
@ -198,6 +200,10 @@ class GlobalStatsCollector {
data_.this_cpu().server_channels_created.fetch_add(
1, std::memory_order_relaxed);
}
void IncrementInsecureConnectionsCreated() {
data_.this_cpu().insecure_connections_created.fetch_add(
1, std::memory_order_relaxed);
}
void IncrementSyscallWrite() {
data_.this_cpu().syscall_write.fetch_add(1, std::memory_order_relaxed);
}
@ -270,6 +276,7 @@ class GlobalStatsCollector {
std::atomic<uint64_t> client_channels_created{0};
std::atomic<uint64_t> client_subchannels_created{0};
std::atomic<uint64_t> server_channels_created{0};
std::atomic<uint64_t> insecure_connections_created{0};
std::atomic<uint64_t> syscall_write{0};
std::atomic<uint64_t> syscall_read{0};
std::atomic<uint64_t> tcp_read_alloc_8k{0};

@ -30,6 +30,8 @@
doc: Number of client subchannels created
- counter: server_channels_created
doc: Number of server channels created
- counter: insecure_connections_created
doc: Number of insecure connections created
# tcp
- counter: syscall_write
doc: Number of write syscalls (or equivalent - eg sendmsg) made by this process

@ -44,6 +44,8 @@
#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/channel/channelz.h"
#include "src/core/lib/config/core_configuration.h"
#include "src/core/lib/debug/stats.h"
#include "src/core/lib/debug/stats_data.h"
#include "src/core/lib/gprpp/debug_location.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
#include "src/core/lib/gprpp/status_helper.h"
@ -360,6 +362,13 @@ grpc_error_handle SecurityHandshaker::CheckPeerLocked() {
}
connector_->check_peer(peer, args_->endpoint, args_->args, &auth_context_,
&on_peer_checked_);
grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name(
auth_context_.get(), GRPC_TRANSPORT_SECURITY_LEVEL_PROPERTY_NAME);
const grpc_auth_property* prop = grpc_auth_property_iterator_next(&it);
if (!prop ||
!strcmp(tsi_security_level_to_string(TSI_SECURITY_NONE), prop->value)) {
global_stats().IncrementInsecureConnectionsCreated();
}
return absl::OkStatus();
}

@ -403,7 +403,6 @@ with open('src/core/lib/debug/stats_data.cc', 'w') as C:
print(file=C)
print("#include \"src/core/lib/debug/stats_data.h\"", file=C)
print("#include <stdint.h>", file=C)
print("#include \"absl/memory/memory.h\"", file=C)
print(file=C)
histo_code = []

Loading…
Cancel
Save