kmesh-net / kmesh

High Performance ServiceMesh Data Plane Based on Programmable Kernel
https://kmesh.net
Apache License 2.0
362 stars 46 forks source link

Kmesh eBPF log user space dumping #388

Closed nlgwcy closed 2 weeks ago

nlgwcy commented 1 month ago

What would you like to be added: Kmesh logs governance process information via BPF_LOG. Logs are expected to be dumped to the user space:

  1. Log information should be dumped to user space via ringbuf.
  2. In user space, the log information should be obtained through epoll and formatted for printing.

reference: https://github.com/anakryiko/bpf-ringbuf-examples/blob/main/src/ringbuf-output.bpf.c

Why is this needed: The current API has the following issues:

  1. Logs are recorded in memory through trace_pipe and can be viewed using bpftool prog tracelog, limited space.
  2. Format parameters such as "%pI4h" are supported latter than v5.13 kernel version, not yet supported in 5.10 (such as openEuler 22.03 SP3),
  3. Only three parameters are supported.
bfforever commented 1 month ago

/assign

hzxuzhonghu commented 1 month ago

Logs are recorded in memory through trace_pipe and can be viewed using bpftool prog tracelog, limited space.

Not an expert on this, does it occupy kernel memory?

bfforever commented 1 month ago

Maybe we need to firstly define some simple fixed format,because ebpf prog seems not support var args. For example:

I am not sure whether the format should mix with string args %s, the situation may become complex. Dose anything need to supplement?

The struct possible like this:

struct log_event {
    __u8 type;
    __u8 level;
    char fmt[MAX_MSG_LEN];
    __u32 arg1;
    __u32 arg2;
    __u32 arg3;
};
nlgwcy commented 1 month ago

Logs are recorded in memory through trace_pipe and can be viewed using bpftool prog tracelog, limited space.

Not an expert on this, does it occupy kernel memory?

This is a debugfs file system, and it will be cleared after the system reboot.

nlgwcy commented 1 month ago

Maybe we need to firstly define some simple fixed format,because ebpf prog seems not support var args. For example:

I am not sure whether the format should mix with string args %s, the situation may become complex. Dose anything need to supplement?

The struct possible like this:

struct log_event {
    __u8 type;
    __u8 level;
    char fmt[MAX_MSG_LEN];
    __u32 arg1;
    __u32 arg2;
    __u32 arg3;
};

As describe, the situation may become complex because of the formatting parameters. IMO, we can use BPF_SNPRINTF to store format string, and then record into ringbuf map for user-space dumping. But I didn't test the feasibility, for details about BPF_SNPRINTF usage example, see: https://github.com/torvalds/linux/commit/c2e39c6bdc7eb48459ec1d34d4f27eb82299f4b7

bfforever commented 3 weeks ago

Resolve 5.10 problem.

  1. Define a flag to indicate whether vargs include ipaddr info.
  2. By kernel version, determine using BPF_LOG_K or BPF_LOG_U, these 2 marco be included in BPF_LOG.