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

aya-log-common: support logging byte slices #585

Merged
merged 7 commits into from
May 10, 2023
Merged

aya-log-common: support logging byte slices #585

merged 7 commits into from
May 10, 2023

Conversation

tamird
Copy link
Member

@tamird tamird commented Apr 19, 2023

These only support LowerHex and UpperHex hints for now.

@netlify
Copy link

netlify bot commented Apr 19, 2023

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit d9f966e
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs-docs/deploys/645a813cbea5cc0008ade6cd
😎 Deploy Preview https://deploy-preview-585--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@tamird tamird changed the title aya-log: allow logging values backed by byte generators aya-log-common: support logging byte slices Apr 25, 2023
Copy link
Collaborator

@alessandrod alessandrod left a comment

Choose a reason for hiding this comment

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

Looks great! Could you add an integration test for the new hex formatter? Somewhere here https://github.com/aya-rs/aya/blob/main/test/integration-ebpf/src/log.rs

@tamird
Copy link
Member Author

tamird commented Apr 27, 2023

Added!

tamird added 4 commits May 4, 2023 11:44
Remove mem::forget::<HashMap>() calls in tests which fail to compile when
HashMap is provided by hashbrown:

  info: running `cargo check --all-targets --no-default-features` on aya-obj (11/23)
      Checking aya-obj v0.1.0 (/home/tamird/src/aya/aya-obj)
  error[E0505]: cannot move out of `map` because it is borrowed
     --> aya-obj/src/relocation.rs:594:21
      |
  578 |         let map = fake_legacy_map(1);
      |             --- binding `map` declared here
  579 |         let maps_by_symbol = HashMap::from([(1, ("test_map", Some(1), &map))]);
      |                                                                       ---- borrow of `map` occurs here
  ...
  594 |         mem::forget(map);
      |                     ^^^ move out of `map` occurs here
  595 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  error[E0505]: cannot move out of `map_1` because it is borrowed
     --> aya-obj/src/relocation.rs:655:21
      |
  632 |         let map_1 = fake_legacy_map(1);
      |             ----- binding `map_1` declared here
  ...
  635 |             (1, ("test_map_1", Some(1), &map_1)),
      |                                         ------ borrow of `map_1` occurs here
  ...
  655 |         mem::forget(map_1);
      |                     ^^^^^ move out of `map_1` occurs here
  656 |         mem::forget(map_2);
  657 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  error[E0505]: cannot move out of `map_2` because it is borrowed
     --> aya-obj/src/relocation.rs:656:21
      |
  633 |         let map_2 = fake_legacy_map(2);
      |             ----- binding `map_2` declared here
  ...
  636 |             (2, ("test_map_2", Some(2), &map_2)),
      |                                         ------ borrow of `map_2` occurs here
  ...
  656 |         mem::forget(map_2);
      |                     ^^^^^ move out of `map_2` occurs here
  657 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  error[E0505]: cannot move out of `map` because it is borrowed
     --> aya-obj/src/relocation.rs:694:21
      |
  678 |         let map = fake_btf_map(1);
      |             --- binding `map` declared here
  679 |         let maps_by_symbol = HashMap::from([(1, ("test_map", Some(1), &map))]);
      |                                                                       ---- borrow of `map` occurs here
  ...
  694 |         mem::forget(map);
      |                     ^^^ move out of `map` occurs here
  695 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  error[E0505]: cannot move out of `map_1` because it is borrowed
     --> aya-obj/src/relocation.rs:755:21
      |
  732 |         let map_1 = fake_btf_map(1);
      |             ----- binding `map_1` declared here
  ...
  735 |             (1, ("test_map_1", Some(1), &map_1)),
      |                                         ------ borrow of `map_1` occurs here
  ...
  755 |         mem::forget(map_1);
      |                     ^^^^^ move out of `map_1` occurs here
  756 |         mem::forget(map_2);
  757 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  error[E0505]: cannot move out of `map_2` because it is borrowed
     --> aya-obj/src/relocation.rs:756:21
      |
  733 |         let map_2 = fake_btf_map(2);
      |             ----- binding `map_2` declared here
  ...
  736 |             (2, ("test_map_2", Some(2), &map_2)),
      |                                         ------ borrow of `map_2` occurs here
  ...
  756 |         mem::forget(map_2);
      |                     ^^^^^ move out of `map_2` occurs here
  757 |     }
      |     - borrow might be used here, when `maps_by_symbol` is dropped and runs the destructor for type `hashbrown::HashMap<usize, (&str, Option<i32>, &maps::Map)>`

  For more information about this error, try `rustc --explain E0505`.
  error: could not compile `aya-obj` due to 6 previous errors
  warning: build failed, waiting for other jobs to finish...
  error: process didn't exit successfully: `/home/tamird/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/cargo check --all-targets --manifest-path aya-obj/Cargo.toml --no-default-features` (exit status: 101)
Previously `struct TagLenValue` was defined in both aya-log and
aya-log-common where the former implemented reading and the latter
writing; the reading logic doesn't need the struct, so remove it.
Previously any old `write` method could be selected.
@tamird
Copy link
Member Author

tamird commented May 4, 2023

@alessandrod ping.

Copy link
Collaborator

@alessandrod alessandrod left a comment

Choose a reason for hiding this comment

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

Looks good, just a couple of comments

aya-log-common/src/lib.rs Show resolved Hide resolved
aya-log-common/src/lib.rs Show resolved Hide resolved
aya-log/src/lib.rs Outdated Show resolved Hide resolved
@tamird
Copy link
Member Author

tamird commented May 5, 2023

Not sure what to make of these build failures; they don't appear to be related to this PR.

@alessandrod
Copy link
Collaborator

Not sure what to make of these build failures; they don't appear to be related to this PR.

I'll kick CI once new cargo nightly gets uploaded rust-lang/cargo#12088

@weihanglo
Copy link

I'll kick CI once new cargo nightly gets uploaded rust-lang/cargo#12088

Could you give it an attempt? The fix should be available starting from toolchain nightly-2023-05-05.

@alessandrod
Copy link
Collaborator

I'll kick CI once new cargo nightly gets uploaded rust-lang/cargo#12088

Could you give it an attempt? The fix should be available starting from toolchain nightly-2023-05-05.

Seems to work, thanks for the quick fix :)

tamird added 3 commits May 9, 2023 13:20
- Replace all `#[repr(usize)]` with `#[repr(u8)]`; this saves
  3*(sizeof(word)-1) bytes per log message.
- Encode payload length as u16 rather than usize; this saves
  sizeof(word)-1 bytes per log message. This is safe because the maximum
  size of a log message is less than (1 << 16 - 1).

This changes `level` to a require field in every log message. It was
already always present, but was treated as optional when reading.
This allows logging values backed by generators.
These only support LowerHex and UpperHex hints for now.
@alessandrod alessandrod merged commit 5165bf2 into aya-rs:main May 10, 2023
@tamird tamird deleted the tag-len-value branch May 10, 2023 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants