Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[usm] system-probe, add Postgres message counters to the eBPF module #31104

Merged
merged 15 commits into from
Dec 9, 2024

Conversation

yuri-lipnesh
Copy link
Contributor

What does this PR do?

Adds Postgres message counters to the eBPF module of the system-probe

Motivation

PostgreSQL communication is done via a continuous stream of messages. This code gathers statistics on the number of Postgres messages processed by eBPF, providing valuable telemetry that enables optimization of eBPF buffer sizes for handling Postgres messages in the agent and system-probe processes.

Describe how to test/QA your changes

Passed unit tests for Postgres monitoring on local VM.
This branch will be tested on staging environment before merge.

Possible Drawbacks / Trade-offs

The complexity of an eBPF program will increase.

Additional Notes

@yuri-lipnesh yuri-lipnesh added changelog/no-changelog component/system-probe team/usm The USM team qa/done QA done before merge and regressions are covered by tests labels Nov 14, 2024
@yuri-lipnesh yuri-lipnesh requested a review from a team as a code owner November 14, 2024 22:18
@github-actions github-actions bot added the medium review PR review might take time label Nov 14, 2024
@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Nov 14, 2024

Test changes on VM

Use this command from test-infra-definitions to manually test this PR changes on a VM:

inv aws.create-vm --pipeline-id=50607237 --os-family=ubuntu

Note: This applies to commit 3e8d162

@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Nov 14, 2024

eBPF complexity changes

Summary result: ❔ - needs attention

  • Highest complexity change (%): +27.25%
  • Highest complexity change (abs.): +986 instructions
  • Programs that were above the 85.0% limit of instructions and are now below: 0
  • Programs that were below the 85.0% limit of instructions and are now above: 0
usm details

usm [programs with changes]

Program Avg. complexity Distro with highest complexity Distro with lowest complexity
uprobe__postgres_tls_handle_response 🔴 4799.0 (+611.8, +14.61%) amazon_5.4/arm64: 🔴 5049.0 (+851.0, +20.27%) ubuntu_18.04/arm64: 🟢 3815.0 (-356.0, -8.54%)

usm [programs without changes]

Program Avg. complexity Distro with highest complexity Distro with lowest complexity
socket__postgres_process_parse_message ⚪ 35878.0 (+0.0, +0.00%) fedora_38/arm64: ⚪ 59525.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 18994.0 (+0.0, +0.00%)
socket__protocol_dispatcher ⚪ 1650.7 (+0.0, +0.00%) fedora_38/arm64: ⚪ 1746.0 (+0.0, +0.00%) centos_8/arm64: ⚪ 1543.0 (+0.0, +0.00%)
socket__protocol_dispatcher_kafka ⚪ 38624.0 (+0.0, +0.00%) centos_8/arm64: ⚪ 48093.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 19686.0 (+0.0, +0.00%)
socket__redis_process ⚪ 2.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2.0 (+0.0, +0.00%)
tracepoint__net__netif_receive_skb ⚪ 16.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 16.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 16.0 (+0.0, +0.00%)
uprobe__BIO_new_socket ⚪ 23.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 23.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 23.0 (+0.0, +0.00%)
uprobe__SSL_connect ⚪ 23.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 23.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 23.0 (+0.0, +0.00%)
uprobe__SSL_do_handshake ⚪ 23.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 23.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 23.0 (+0.0, +0.00%)
uprobe__SSL_read ⚪ 98.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 98.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 98.0 (+0.0, +0.00%)
uprobe__SSL_read_ex ⚪ 85.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 85.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 85.0 (+0.0, +0.00%)
uprobe__SSL_set_bio ⚪ 46.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 46.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 46.0 (+0.0, +0.00%)
uprobe__SSL_set_fd ⚪ 31.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 31.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 31.0 (+0.0, +0.00%)
uprobe__SSL_shutdown ⚪ 352.0 (+0.0, +0.00%) centos_8/arm64: ⚪ 363.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 333.0 (+0.0, +0.00%)
uprobe__SSL_write ⚪ 28.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 28.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 28.0 (+0.0, +0.00%)
uprobe__SSL_write_ex ⚪ 22.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 22.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 22.0 (+0.0, +0.00%)
uprobe__crypto_tls_Conn_Close ⚪ 1137.2 (+0.0, +0.00%) centos_8/arm64: ⚪ 1265.0 (+0.0, +0.00%) amazon_5.4/x86_64: ⚪ 1009.0 (+0.0, +0.00%)
uprobe__crypto_tls_Conn_Read ⚪ 773.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 860.0 (+0.0, +0.00%) amazon_5.4/x86_64: ⚪ 686.0 (+0.0, +0.00%)
uprobe__crypto_tls_Conn_Read__return ⚪ 5377.2 (+0.0, +0.00%) fedora_38/arm64: ⚪ 8266.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 3245.0 (+0.0, +0.00%)
uprobe__crypto_tls_Conn_Write ⚪ 1315.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 1807.0 (+0.0, +0.00%) amazon_5.4/x86_64: ⚪ 823.0 (+0.0, +0.00%)
uprobe__crypto_tls_Conn_Write__return ⚪ 6434.3 (+0.0, +0.00%) fedora_38/x86_64: ⚪ 10094.0 (+0.0, +0.00%) amazon_5.4/x86_64: ⚪ 3335.0 (+0.0, +0.00%)
uprobe__gnutls_bye ⚪ 352.0 (+0.0, +0.00%) centos_8/arm64: ⚪ 363.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 333.0 (+0.0, +0.00%)
uprobe__gnutls_deinit ⚪ 352.0 (+0.0, +0.00%) centos_8/arm64: ⚪ 363.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 333.0 (+0.0, +0.00%)
uprobe__gnutls_handshake ⚪ 23.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 23.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 23.0 (+0.0, +0.00%)
uprobe__gnutls_record_recv ⚪ 25.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 25.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 25.0 (+0.0, +0.00%)
uprobe__gnutls_record_send ⚪ 28.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 28.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 28.0 (+0.0, +0.00%)
uprobe__gnutls_transport_set_int2 ⚪ 31.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 31.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 31.0 (+0.0, +0.00%)
uprobe__gnutls_transport_set_ptr ⚪ 31.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 31.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 31.0 (+0.0, +0.00%)
uprobe__gnutls_transport_set_ptr2 ⚪ 31.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 31.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 31.0 (+0.0, +0.00%)
uprobe__http2_dynamic_table_cleaner ⚪ 3964.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 3964.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 3964.0 (+0.0, +0.00%)
uprobe__http2_tls_eos_parser ⚪ 182422.7 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 182451.0 (+0.0, +0.00%) centos_8/arm64: ⚪ 182366.0 (+0.0, +0.00%)
uprobe__http2_tls_filter ⚪ 68112.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 68460.0 (+0.0, +0.00%) centos_8/arm64: ⚪ 67938.0 (+0.0, +0.00%)
uprobe__http2_tls_handle_first_frame ⚪ 979.0 (+0.0, +0.00%) centos_8/arm64: ⚪ 1195.0 (+0.0, +0.00%) debian_10/arm64: ⚪ 797.0 (+0.0, +0.00%)
uprobe__http2_tls_headers_parser ⚪ 637767.0 (+0.0, +0.00%) fedora_38/arm64: ⚪ 637767.0 (+0.0, +0.00%) fedora_38/arm64: ⚪ 637767.0 (+0.0, +0.00%)
uprobe__http2_tls_termination ⚪ 100.2 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 105.0 (+0.0, +0.00%) debian_10/arm64: ⚪ 93.0 (+0.0, +0.00%)
uprobe__http_process ⚪ 2777.8 (+0.0, +0.00%) debian_10/arm64: ⚪ 5143.0 (+0.0, +0.00%) ubuntu_18.04/arm64: ⚪ 2050.0 (+0.0, +0.00%)
uprobe__http_termination ⚪ 288.6 (+0.0, +0.00%) debian_10/arm64: ⚪ 291.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 287.0 (+0.0, +0.00%)
uprobe__kafka_tls_fetch_response_partition_parser_v0 ⚪ 5338.6 (+0.0, +0.00%) centos_8/arm64: ⚪ 5569.0 (+0.0, +0.00%) debian_10/arm64: ⚪ 4934.0 (+0.0, +0.00%)
uprobe__kafka_tls_fetch_response_partition_parser_v12 ⚪ 6582.4 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 6713.0 (+0.0, +0.00%) debian_10/arm64: ⚪ 6305.0 (+0.0, +0.00%)
uprobe__kafka_tls_fetch_response_record_batch_parser_v0 ⚪ 6795.6 (+0.0, +0.00%) centos_8/arm64: ⚪ 6833.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 6666.0 (+0.0, +0.00%)
uprobe__kafka_tls_fetch_response_record_batch_parser_v12 ⚪ 6795.6 (+0.0, +0.00%) centos_8/arm64: ⚪ 6833.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 6666.0 (+0.0, +0.00%)
uprobe__kafka_tls_filter ⚪ 19916.0 (+0.0, +0.00%) centos_8/arm64: ⚪ 29149.0 (+0.0, +0.00%) ubuntu_18.04/arm64: ⚪ 10488.0 (+0.0, +0.00%)
uprobe__kafka_tls_produce_response_partition_parser_v0 ⚪ 1436.6 (+0.0, +0.00%) centos_8/arm64: ⚪ 1563.0 (+0.0, +0.00%) debian_10/arm64: ⚪ 1218.0 (+0.0, +0.00%)
uprobe__kafka_tls_produce_response_partition_parser_v9 ⚪ 1825.8 (+0.0, +0.00%) debian_10/arm64: ⚪ 2241.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 1476.0 (+0.0, +0.00%)
uprobe__kafka_tls_termination ⚪ 43.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 43.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 43.0 (+0.0, +0.00%)
uprobe__postgres_tls_handle ⚪ 195.2 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 199.0 (+0.0, +0.00%) debian_10/arm64: ⚪ 189.0 (+0.0, +0.00%)
uprobe__postgres_tls_process_parse_message ⚪ 3067.4 (+0.0, +0.00%) ubuntu_18.04/arm64: ⚪ 3327.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2895.0 (+0.0, +0.00%)
uprobe__postgres_tls_termination ⚪ 43.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 43.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 43.0 (+0.0, +0.00%)
uprobe__redis_tls_process ⚪ 2.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2.0 (+0.0, +0.00%)
uprobe__redis_tls_termination ⚪ 2.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2.0 (+0.0, +0.00%)
uprobe__tls_protocol_dispatcher_kafka ⚪ 6136.8 (+0.0, +0.00%) fedora_38/arm64: ⚪ 9305.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 4747.0 (+0.0, +0.00%)
uretprobe__BIO_new_socket ⚪ 44.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 44.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 44.0 (+0.0, +0.00%)
uretprobe__SSL_connect ⚪ 9.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 9.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 9.0 (+0.0, +0.00%)
uretprobe__SSL_do_handshake ⚪ 9.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 9.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 9.0 (+0.0, +0.00%)
uretprobe__SSL_read ⚪ 5626.3 (+0.0, +0.00%) fedora_38/arm64: ⚪ 9080.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2633.0 (+0.0, +0.00%)
uretprobe__SSL_read_ex ⚪ 7004.7 (+0.0, +0.00%) fedora_38/arm64: ⚪ 9184.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2722.0 (+0.0, +0.00%)
uretprobe__SSL_write ⚪ 2941.3 (+0.0, +0.00%) fedora_38/arm64: ⚪ 3180.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2750.0 (+0.0, +0.00%)
uretprobe__SSL_write_ex ⚪ 6612.3 (+0.0, +0.00%) fedora_38/arm64: ⚪ 9569.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2820.0 (+0.0, +0.00%)
uretprobe__gnutls_handshake ⚪ 9.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 9.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 9.0 (+0.0, +0.00%)
uretprobe__gnutls_record_recv ⚪ 5201.3 (+0.0, +0.00%) fedora_38/arm64: ⚪ 7470.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2733.0 (+0.0, +0.00%)
uretprobe__gnutls_record_send ⚪ 4185.3 (+0.0, +0.00%) centos_8/arm64: ⚪ 4921.0 (+0.0, +0.00%) amazon_5.4/arm64: ⚪ 2728.0 (+0.0, +0.00%)

This report was generated based on the complexity data for the current branch yuri_USMON-1124_ebpf_postgres_msg_counts (pipeline 50607237, commit 3e8d162) and the base branch main (commit c5069b5). Objects without changes are not reported. Contact #ebpf-platform if you have any questions/feedback.

Table complexity legend: 🔵 - new; ⚪ - unchanged; 🟢 - reduced; 🔴 - increased

Copy link

cit-pr-commenter bot commented Nov 14, 2024

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: 61efc18c-3245-4f87-80bf-080ad43aca1c

Baseline: c5069b5
Comparison: 3e8d162
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
tcp_syslog_to_blackhole ingress throughput +0.88 [+0.83, +0.94] 1 Logs
file_to_blackhole_500ms_latency egress throughput +0.11 [-0.66, +0.88] 1 Logs
quality_gate_idle memory utilization +0.10 [+0.05, +0.14] 1 Logs bounds checks dashboard
uds_dogstatsd_to_api_cpu % cpu utilization +0.08 [-0.63, +0.80] 1 Logs
file_to_blackhole_0ms_latency egress throughput +0.03 [-0.83, +0.89] 1 Logs
file_to_blackhole_100ms_latency egress throughput +0.02 [-0.68, +0.73] 1 Logs
file_to_blackhole_1000ms_latency_linear_load egress throughput +0.02 [-0.44, +0.48] 1 Logs
uds_dogstatsd_to_api ingress throughput +0.01 [-0.12, +0.14] 1 Logs
file_to_blackhole_300ms_latency egress throughput +0.01 [-0.62, +0.64] 1 Logs
file_to_blackhole_0ms_latency_http2 egress throughput +0.01 [-0.86, +0.87] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput +0.00 [-0.01, +0.01] 1 Logs
file_to_blackhole_0ms_latency_http1 egress throughput -0.02 [-0.93, +0.88] 1 Logs
quality_gate_logs % cpu utilization -0.05 [-2.97, +2.87] 1 Logs
otel_to_otel_logs ingress throughput -0.21 [-0.87, +0.44] 1 Logs
quality_gate_idle_all_features memory utilization -0.54 [-0.65, -0.42] 1 Logs bounds checks dashboard
file_tree memory utilization -0.54 [-0.66, -0.42] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.77 [-1.55, +0.01] 1 Logs

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed links
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_0ms_latency_http1 lost_bytes 10/10
file_to_blackhole_0ms_latency_http1 memory_usage 10/10
file_to_blackhole_0ms_latency_http2 lost_bytes 10/10
file_to_blackhole_0ms_latency_http2 memory_usage 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency_linear_load memory_usage 10/10
file_to_blackhole_100ms_latency lost_bytes 10/10
file_to_blackhole_100ms_latency memory_usage 10/10
file_to_blackhole_300ms_latency lost_bytes 10/10
file_to_blackhole_300ms_latency memory_usage 10/10
file_to_blackhole_500ms_latency lost_bytes 10/10
file_to_blackhole_500ms_latency memory_usage 10/10
quality_gate_idle memory_usage 10/10 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 bounds checks dashboard
quality_gate_logs lost_bytes 10/10
quality_gate_logs memory_usage 10/10

Explanation

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

Passed. All Quality Gates passed.

  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check lost_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.

@yuri-lipnesh yuri-lipnesh force-pushed the yuri_USMON-1124_ebpf_postgres_msg_counts branch from 0cd106b to aed60c2 Compare November 15, 2024 18:42
pkg/network/ebpf/c/protocols/postgres/decoding-maps.h Outdated Show resolved Hide resolved
pkg/network/ebpf/c/protocols/postgres/decoding.h Outdated Show resolved Hide resolved
pkg/network/ebpf/c/protocols/postgres/types.h Outdated Show resolved Hide resolved
pkg/network/ebpf/c/protocols/postgres/types.h Outdated Show resolved Hide resolved
pkg/network/ebpf/c/protocols/postgres/types.h Outdated Show resolved Hide resolved
pkg/network/usm/postgres_monitor_test.go Outdated Show resolved Hide resolved
Comment on lines 213 to 215
if (iteration_value->iteration >= POSTGRES_MAX_TAIL_CALLS_FOR_MAX_MESSAGES) {
return 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you remove this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I do not count iterations, I count total processed messages

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following why you removed the check, it is still a valid check, you might just need to modify the condition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've restored exit condition

pkg/network/ebpf/c/protocols/postgres/decoding.h Outdated Show resolved Hide resolved
pkg/network/ebpf/c/protocols/postgres/decoding.h Outdated Show resolved Hide resolved
@github-actions github-actions bot added long review PR is complex, plan time to review it and removed medium review PR review might take time labels Nov 17, 2024
@yuri-lipnesh yuri-lipnesh force-pushed the yuri_USMON-1124_ebpf_postgres_msg_counts branch from 50ecc18 to d9c8ef6 Compare November 19, 2024 19:58
@yuri-lipnesh yuri-lipnesh force-pushed the yuri_USMON-1124_ebpf_postgres_msg_counts branch from d9c8ef6 to 2044662 Compare November 21, 2024 18:18
Comment on lines 274 to 276
__u8 bucket_idx = ((__u8)(iteration_value->total_msg_count - PG_KERNEL_MSG_COUNT_FIRST_BUCKET) / PG_KERNEL_MSG_COUNT_BUCKET_SIZE) + 1;
bucket_idx = (bucket_idx >= PG_KERNEL_MSG_COUNT_NUM_BUCKETS) ? (PG_KERNEL_MSG_COUNT_NUM_BUCKETS - 1) : bucket_idx;
__sync_fetch_and_add(&pg_msg_counts->msg_count_buckets[bucket_idx], 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you copy it from http2?
IIRC, in http2 we have a single function to handle all scenarios, I do recommend taking the same function and use it here
it will simplify the readability, and remove the if-else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced 'if's with ternary operator like http2 does

@yuri-lipnesh yuri-lipnesh requested a review from guyarb November 22, 2024 23:51
Comment on lines 32 to 44
// Reads a message header from the given context.
// Returns the result of the read: successfully read header, end of packet reached, or fragmented message detected.
static __always_inline postgres_read_result_t read_message_header(pktbuf_t pkt, struct pg_message_header* header) {
u32 data_off = pktbuf_data_offset(pkt);
u32 data_end = pktbuf_data_end(pkt);
// Ensuring that the header is in the buffer.
if (data_off + sizeof(struct pg_message_header) > data_end) {
return false;
}
pktbuf_load_bytes(pkt, data_off, header, sizeof(struct pg_message_header));
// Converting the header to host byte order.
header->message_len = bpf_ntohl(header->message_len);
return true;

if (data_off + sizeof(struct pg_message_header) <= data_end) {
// header fits within the buffer boundaries.
pktbuf_load_bytes(pkt, data_off, header, sizeof(struct pg_message_header));
// Converting the header to host byte order.
header->message_len = bpf_ntohl(header->message_len);

return READ_OK;
}
if (data_off == data_end) {
return READ_END;
}
// the offset is outside the packet boundaries
return READ_FRAGMENTED;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reporting READ_OK, READ_END and READ_FRAGMENTED does not bring any value to the PR.
Eventually, you're only checking if the result was READ_OK or not which is equivalent for the previous version of a boolean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I increase counter pg_msg_counts->fragmented_packets when READ_FRAGMENTED and stop iterating tail calls when READ_END

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're using it only once, and we can get the same outcome without modifying that internal function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've restored previous read_message_header() function

@yuri-lipnesh yuri-lipnesh requested a review from guyarb December 2, 2024 12:38
Comment on lines 197 to 198
kernelTel.reachedMaxMessages = libtelemetry.NewTLSAwareCounter(metricGroup, "messages_count_max_messages")
kernelTel.fragmentedPackets = libtelemetry.NewTLSAwareCounter(metricGroup, "messages_count_fragmented_packets")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the metric name is confusing. Please find a clear name for the purpose

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed names

kernelTel.fragmentedPackets = libtelemetry.NewTLSAwareCounter(metricGroup, "messages_count_fragmented_packets")

for i := range kernelTel.msgCountBuckets {
kernelTel.msgCountBuckets[i] = libtelemetry.NewTLSAwareCounter(metricGroup, "messages_count_bucket_"+(strconv.Itoa(i+1)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant parenthesis

Suggested change
kernelTel.msgCountBuckets[i] = libtelemetry.NewTLSAwareCounter(metricGroup, "messages_count_bucket_"+(strconv.Itoa(i+1)))
kernelTel.msgCountBuckets[i] = libtelemetry.NewTLSAwareCounter(metricGroup, "messages_count_bucket_"+strconv.Itoa(i+1))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return kernelTel
}

// update the Postgres message counter store with new counters from the kernel, return immediately if nothing to add.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// update the Postgres message counter store with new counters from the kernel, return immediately if nothing to add.
// update the postgres message counter store with new counters from the kernel, return immediately if nothing to add.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 220 to 221
s := t.metricGroup.Summary()
log.Debugf("postgres kernel telemetry, isTLS=%t, summary: %s", isTLS, s)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be wrapped with ShouldLog. No need to generate the summary if the log level is above debug level

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added ShouldLog condition

Comment on lines 42 to 43
typedef enum
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
typedef enum
{
typedef enum {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed this enum in recent commit

Comment on lines 274 to 275
// save messages counter in bucket.
__u8 bucket_idx = iteration_value->total_msg_count;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bucket index (0-5) is initialized with total_msg_count?
Please use a variable with indicative name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You copied the code from http2, but ignored the documentation we have there.
The code is not clear for the average reader and that's why we put the extensive documentation.

Also, it is better to move it into an helper function to make the code more readable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created separate function update_msg_count_telemetry() to update telemetry buckets

Comment on lines 32 to 44
// Reads a message header from the given context.
// Returns the result of the read: successfully read header, end of packet reached, or fragmented message detected.
static __always_inline postgres_read_result_t read_message_header(pktbuf_t pkt, struct pg_message_header* header) {
u32 data_off = pktbuf_data_offset(pkt);
u32 data_end = pktbuf_data_end(pkt);
// Ensuring that the header is in the buffer.
if (data_off + sizeof(struct pg_message_header) > data_end) {
return false;
}
pktbuf_load_bytes(pkt, data_off, header, sizeof(struct pg_message_header));
// Converting the header to host byte order.
header->message_len = bpf_ntohl(header->message_len);
return true;

if (data_off + sizeof(struct pg_message_header) <= data_end) {
// header fits within the buffer boundaries.
pktbuf_load_bytes(pkt, data_off, header, sizeof(struct pg_message_header));
// Converting the header to host byte order.
header->message_len = bpf_ntohl(header->message_len);

return READ_OK;
}
if (data_off == data_end) {
return READ_END;
}
// the offset is outside the packet boundaries
return READ_FRAGMENTED;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're using it only once, and we can get the same outcome without modifying that internal function.

utils.WaitForProgramsToBeTraced(t, consts.USMModuleName, GoTLSAttacherName, os.Getpid(), utils.ManualTracingFallbackEnabled)
}
pgClient := setupPGClient(t, serverAddress, isTLS)
defer func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use t.Cleanup

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@yuri-lipnesh yuri-lipnesh force-pushed the yuri_USMON-1124_ebpf_postgres_msg_counts branch from d30ba7e to 5be261a Compare December 2, 2024 18:53
@yuri-lipnesh yuri-lipnesh requested a review from guyarb December 2, 2024 20:58
@yuri-lipnesh yuri-lipnesh requested a review from guyarb December 5, 2024 19:02
@agent-platform-auto-pr
Copy link
Contributor

Package size comparison

Comparison with ancestor c5069b54c0645677da73fcaf0765bbf6c898c8e1

Diff per package
package diff status size ancestor threshold
datadog-agent-amd64-deb -0.10MB 1270.86MB 1270.96MB 140.00MB
datadog-iot-agent-amd64-deb 0.00MB 113.20MB 113.20MB 10.00MB
datadog-dogstatsd-amd64-deb 0.00MB 78.32MB 78.32MB 10.00MB
datadog-heroku-agent-amd64-deb 0.00MB 526.45MB 526.45MB 70.00MB
datadog-agent-x86_64-rpm -0.10MB 1280.09MB 1280.20MB 140.00MB
datadog-agent-x86_64-suse -0.10MB 1280.09MB 1280.20MB 140.00MB
datadog-iot-agent-x86_64-rpm 0.00MB 113.26MB 113.26MB 10.00MB
datadog-iot-agent-x86_64-suse 0.00MB 113.26MB 113.26MB 10.00MB
datadog-dogstatsd-x86_64-rpm 0.00MB 78.40MB 78.40MB 10.00MB
datadog-dogstatsd-x86_64-suse 0.00MB 78.40MB 78.40MB 10.00MB
datadog-agent-arm64-deb -0.10MB 1005.03MB 1005.13MB 140.00MB
datadog-iot-agent-arm64-deb 0.00MB 108.67MB 108.67MB 10.00MB
datadog-dogstatsd-arm64-deb 0.00MB 55.59MB 55.59MB 10.00MB
datadog-agent-aarch64-rpm -0.10MB 1014.25MB 1014.35MB 140.00MB
datadog-iot-agent-aarch64-rpm 0.00MB 108.74MB 108.74MB 10.00MB

Decision

✅ Passed

@yuri-lipnesh
Copy link
Contributor Author

/merge

@dd-devflow
Copy link

dd-devflow bot commented Dec 9, 2024

Devflow running: /merge

View all feedbacks in Devflow UI.


2024-12-09 22:24:22 UTC ℹ️ MergeQueue: pull request added to the queue

The median merge time in main is 24m.

@dd-mergequeue dd-mergequeue bot merged commit 0744b78 into main Dec 9, 2024
300 checks passed
@dd-mergequeue dd-mergequeue bot deleted the yuri_USMON-1124_ebpf_postgres_msg_counts branch December 9, 2024 22:46
@github-actions github-actions bot added this to the 7.62.0 milestone Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog component/system-probe long review PR is complex, plan time to review it qa/done QA done before merge and regressions are covered by tests team/usm The USM team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants