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: http2: Unify telemetry maps #31154

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/network/ebpf/c/protocols/http2/decoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,17 @@ static __always_inline void pktbuf_skip_preface(pktbuf_t pkt) {

// Returns the telemetry pointer from the relevant map.
static __always_inline void* get_telemetry(pktbuf_t pkt) {
const __u32 zero = 0;
const __u32 plaintext_ey = 0;
const __u32 tls_key = 1;

pktbuf_map_lookup_option_t map_lookup_telemetry_array[] = {
[PKTBUF_SKB] = {
.map = &http2_telemetry,
.key = (void*)&zero,
.key = (void*)&plaintext_ey,
},
[PKTBUF_TLS] = {
.map = &tls_http2_telemetry,
.key = (void*)&zero,
.map = &http2_telemetry,
.key = (void*)&tls_key,
},
};
return pktbuf_map_lookup(pkt, map_lookup_telemetry_array);
Expand Down
9 changes: 3 additions & 6 deletions pkg/network/ebpf/c/protocols/http2/maps-defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@ BPF_PERCPU_ARRAY_MAP(http2_scratch_buffer, http2_event_t, 1)
/* Allocating a ctx on the heap, in order to save the ctx between the current stream. */
BPF_PERCPU_ARRAY_MAP(http2_ctx_heap, http2_ctx_t, 1)

/* This map is used for telemetry in kernelspace
* only key 0 is used
* value is a http2 telemetry object
*/
BPF_ARRAY_MAP(http2_telemetry, http2_telemetry_t, 1)
BPF_ARRAY_MAP(tls_http2_telemetry, http2_telemetry_t, 1)
// This map is used to gather telemetry data from the eBPF programs. Key 0 is used for plaintext traffic,
// and key 1 is used for encrypted traffic.
BPF_ARRAY_MAP(http2_telemetry, http2_telemetry_t, 2)

#endif
19 changes: 6 additions & 13 deletions pkg/network/protocols/http2/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ const (
eosParserTailCall = "socket__http2_eos_parser"
eventStream = "http2"

// TelemetryMap is the name of the map used to retrieve plaintext metrics from the kernel
// TelemetryMap is the name of the map that collects telemetry for plaintext and TLS encrypted HTTP/2 traffic.
TelemetryMap = "http2_telemetry"
// TLSTelemetryMap is the name of the map used to retrieve metrics from the eBPF probes for TLS
TLSTelemetryMap = "tls_http2_telemetry"

tlsFirstFrameTailCall = "uprobe__http2_tls_handle_first_frame"
tlsFilterTailCall = "uprobe__http2_tls_filter"
Expand Down Expand Up @@ -316,13 +314,8 @@ func (p *Protocol) updateKernelTelemetry(mgr *manager.Manager) {
return
}

tlsMap, err := protocols.GetMap(mgr, TLSTelemetryMap)
if err != nil {
log.Warn(err)
return
}

var zero uint32
plaintextKey := uint32(0)
tlsKey := uint32(1)
http2Telemetry := &HTTP2Telemetry{}
ticker := time.NewTicker(30 * time.Second)

Expand All @@ -332,14 +325,14 @@ func (p *Protocol) updateKernelTelemetry(mgr *manager.Manager) {
for {
select {
case <-ticker.C:
if err := mp.Lookup(unsafe.Pointer(&zero), unsafe.Pointer(http2Telemetry)); err != nil {
if err := mp.Lookup(unsafe.Pointer(&plaintextKey), unsafe.Pointer(http2Telemetry)); err != nil {
log.Errorf("unable to lookup %q map: %s", TelemetryMap, err)
return
}
p.http2Telemetry.update(http2Telemetry, false)

if err := tlsMap.Lookup(unsafe.Pointer(&zero), unsafe.Pointer(http2Telemetry)); err != nil {
log.Errorf("unable to lookup %q map: %s", TLSTelemetryMap, err)
if err := mp.Lookup(unsafe.Pointer(&tlsKey), unsafe.Pointer(http2Telemetry)); err != nil {
log.Errorf("unable to lookup %q map: %s", TelemetryMap, err)
return
}
p.http2Telemetry.update(http2Telemetry, true)
Expand Down
6 changes: 3 additions & 3 deletions pkg/network/usm/usm_http2_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1924,19 +1924,19 @@ func dialHTTP2Server(t *testing.T) net.Conn {
// getHTTP2KernelTelemetry returns the HTTP2 kernel telemetry
func getHTTP2KernelTelemetry(monitor *Monitor, isTLS bool) (*usmhttp2.HTTP2Telemetry, error) {
http2Telemetry := &usmhttp2.HTTP2Telemetry{}
var zero uint32

mapName := usmhttp2.TelemetryMap
key := uint32(0)
if isTLS {
mapName = usmhttp2.TLSTelemetryMap
key = uint32(1)
}

mp, _, err := monitor.ebpfProgram.GetMap(mapName)
if err != nil {
return nil, fmt.Errorf("unable to get %q map: %s", mapName, err)
}

if err := mp.Lookup(unsafe.Pointer(&zero), unsafe.Pointer(http2Telemetry)); err != nil {
if err := mp.Lookup(unsafe.Pointer(&key), unsafe.Pointer(http2Telemetry)); err != nil {
return nil, fmt.Errorf("unable to lookup %q map: %s", mapName, err)
}
return http2Telemetry, nil
Expand Down
Loading