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

fix: log runtime output to env var "BPFTIME_LOG_OUTPUT" #301

Merged
merged 1 commit into from
Aug 17, 2024

Conversation

Kailian-Jacy
Copy link
Contributor

@Kailian-Jacy Kailian-Jacy commented Jun 2, 2024

Description

A draft version of logging. It implements:

  • Log spdlogs to target from env var BPFTIME_LOG_OUTPUT. Default to be stderr. All logs from runtime (syscall_server, agent, agent-transformer) go to given target.
  • Logs from client (cli/main.cpp) and ebpf program output untouched. I suppose ppl always want client feedback from stdout/err.

Used file but not named pipe. bpftime server should be similar to docker daemon, managing "services" of injected ebpf programs. The log should be persistent, reusable.

Now usage:

kailian@ubt23:~/bpftime$ sudo BPFTIME_LOG_OUTPUT=skeleton_logging.out /home/kailian/.bpftime/bpftime -i /home/kailian/.bpftime load ./example/opensnoop/opensnoop\
PID    COMM              FD ERR PATH
^CINFO [40749]: Global shm destructed

kailian@ubt23:~/bpftime$ cat skeleton_logging.out
[2024-06-02 10:12:32][info][40749] manager constructed
[2024-06-02 10:12:32][info][40749] Initialize syscall server
[2024-06-02 10:12:32][info][40749] Global shm constructed. shm_open_type 0 for bpftime_maps_shm
[2024-06-02 10:12:32][info][40749] Global shm initialized
[2024-06-02 10:12:32][info][40749] Enabling helper groups ufunc, kernel, shm_map by default
[2024-06-02 10:12:32][info][40749] bpftime-syscall-server started

I may add these feature in this PR, hoping suggestions or confirmation from you:

  • Provide a subcommand similar to trace to output logs we want.
  • Logs be optionally reserved under /var/log/ or syslog under linux. Log rotation are management automatically.
  • Merge logs from different processes as one. Add tags of source (which injected process causing) to the log.
  • Add documentations about logging.

resolves # 279

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Manually test: load & start.
sudo BPFTIME_LOG_OUTPUT=skeleton_logging.out /home/kailian/.bpftime/bpftime -i /home/kailian/.bpftime load ./example/opensnoop/opensnoop
sudo BPFTIME_LOG_OUTPUT=skeleton_logging.out /home/kailian/.bpftime/bpftime -i /home/kailian/.bpftime start  ./example/opensnoop/victim
sudo BPFTIME_LOG_OUTPUT=skeleton_logging.out /home/kailian/.bpftime/bpftime -i /home/kailian/.bpftime start  -s ./example/opensnoop/victim
  • Manually test: load & attach.
sudo BPFTIME_LOG_OUTPUT=victim_out.log ./example/opensnoop/victim
sudo BPFTIME_LOG_OUTPUT=skeleton_logging.out /home/kailian/.bpftime/bpftime -i /home/kailian/.bpftime attach `pidof victim`

Test Configuration:

  • Hardware: x86
  • Toolchain:g++
  • OS: ubuntu 23.10

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

@yunwei37 yunwei37 marked this pull request as ready for review August 10, 2024 07:56
@yunwei37 yunwei37 force-pushed the master branch 2 times, most recently from af3495e to 4fc55b3 Compare August 14, 2024 10:14
@yunwei37 yunwei37 changed the title resolves #279: log runtime output to env var "BPFTIME_LOG_OUTPUT" fix #279: log runtime output to env var "BPFTIME_LOG_OUTPUT" Aug 14, 2024
@yunwei37
Copy link
Member

Also:

  1. Fix compile for build without libbpf in Linux
  2. Add option build test in CI

@yunwei37 yunwei37 force-pushed the master branch 2 times, most recently from 1488e7b to 918ceff Compare August 15, 2024 18:25
@yunwei37 yunwei37 changed the title fix #279: log runtime output to env var "BPFTIME_LOG_OUTPUT" fix: log runtime output to env var "BPFTIME_LOG_OUTPUT" Aug 16, 2024
@yunwei37 yunwei37 force-pushed the master branch 3 times, most recently from 53b112e to 5892756 Compare August 17, 2024 07:38
@yunwei37 yunwei37 merged commit fb21d6e into eunomia-bpf:master Aug 17, 2024
70 checks passed
@@ -4,6 +4,11 @@
#include <cstdlib>
#include <string>

#ifndef DEFAULT_LOGGER_OUTPUT_PATH
#define DEFAULT_LOGGER_OUTPUT_PATH "~/.bpftime/runtime.log"
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using #define to define constants in C++

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I can fix that in next pr

if (input_path[0] == '~') {
const char *homeDir = getenv("HOME");
if (!homeDir) {
return "console";
Copy link
Contributor

Choose a reason for hiding this comment

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

Will string "console" be parsed as a path?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, to stderr. The console log output will also be used in CI

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, to stderr. The console log output will also be used in CI

I mean, if user want to print things to a file named console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants