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

feat(client,server): rework logging #1692

Merged
merged 5 commits into from
Mar 21, 2024
Merged

Conversation

mxinden
Copy link
Collaborator

@mxinden mxinden commented Feb 28, 2024

  • In neqo-client and neqo-server use neqo_common::log instead of println! and eprintln!.
  • Add -q, -v, -vv, -vvv, -vvvv log level flags via clap_verbosity_flag.
  • Set default log level to INFO. Demote many qinfo! to qdebug!.

Fixes #685.

neqo-client/src/main.rs Outdated Show resolved Hide resolved
@mxinden mxinden changed the title feat(client.server): use neqo_common::log feat(client,server): use neqo_common::log Feb 28, 2024
@mxinden
Copy link
Collaborator Author

mxinden commented Mar 1, 2024

Maybe add a -v command line parameter to increase the log level?

Would -v then set the RUST_LOG environment variable to be later picked up by neqo_common::log::init? That looks like spaghetti code to me. An alternative would be to introduce a neqo_common::log::init_with_level. Though in case you want this, I suggest doing so in a separate pull request to keep this one focused on #685.

Exploring another alternative: I removed the RUST_LOG hint (514e0ac) and instead changed neqo-client to continue printing request content (or content metadata) to the console (28bed42).

A request to google.com now looks like the below. Always printing request content is somewhat similar to curl's default behavior.

➜  neqo git:(common-log) cargo run --bin neqo-client -- 'https://google.com/'                   
    Finished dev [unoptimized + debuginfo] target(s) in 0.13s
     Running `target/debug/neqo-client 'https://google.com/'`
READ[0]: 220 bytes
READ[0]: 0 bytes
READ[0]: 0 bytes

➜  neqo git:(common-log) cargo run --bin neqo-client -- 'https://google.com/' --output-read-data   
    Finished dev [unoptimized + debuginfo] target(s) in 0.16s
     Running `target/debug/neqo-client 'https://google.com/' --output-read-data`
READ[0]: <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.com/">here</A>.
</BODY></HTML>

@larseggert let me know what you think.

@mxinden
Copy link
Collaborator Author

mxinden commented Mar 5, 2024

Friendly ping @larseggert.

I don't feel strongly about any of the proposals in this pull request. I want to start on #1696, laying the groundwork for #1693. For the sake of keeping merge conflicts small, shall we merge or close here?

@larseggert
Copy link
Collaborator

I don't feel strongly either. I have a mile preference that if we're going to use the logging framework for things, we should use it as much as possible, i.e., avoid esp. eprintln! but probably also println!. Adding a neqo_common::log::init_with_level to set the level based on a command line options seems fine.

@KershawChang
Copy link
Collaborator

Friendly ping @larseggert.

I don't feel strongly about any of the proposals in this pull request. I want to start on #1696, laying the groundwork for #1693. For the sake of keeping merge conflicts small, shall we merge or close here?

Probably close?
I am fine with leaving eprintln! and println! in neqo_client and neqo_server.

@larseggert
Copy link
Collaborator

larseggert commented Mar 18, 2024

I've changed my mind on this, we should use the neqo log functions, and also use clap_verbosity_flag to control verbosity. The demo client and server can be quite noisy on the console when large amounts of data are transferred, and it would be good if the less interesting output could be suppressed.

(Also, because right now http3.rs uses println! whereas old_http.rs uses eprintln!...)

@mxinden
Copy link
Collaborator Author

mxinden commented Mar 18, 2024

and also use clap_verbosity_flag to control verbosity

Neat!

I will revive the pull request.

- In `neqo-client` and `neqo-server` use `neqo_common::log` instead of `println!`
  and `eprintln!`.
- Add `-q`, `-v`, `-vv`, `-vvv`, `-vvvv` log level flags via
  `clap_verbosity_flag`.
- Set default log level to INFO. Demote many `qinfo!` to `qdebug!`.
@mxinden mxinden changed the title feat(client,server): use neqo_common::log feat(client,server): rework logging Mar 19, 2024
@mxinden
Copy link
Collaborator Author

mxinden commented Mar 19, 2024

I updated the pull request with the above suggestion, i.e. to use clap_verbosity_flag.

In addition I demoted multiple qinfo! to qdebug!. (Note, I don't feel strongly about any particular one, though I do believe most of them are useful for debugging, not informational purposes.)

Sample output:

➜  neqo git:(common-log) cargo run --bin neqo-client -- http://127.0.0.1:12345/10        
   Compiling neqo-bin v0.7.2 (/home/mxinden/code/github.com/mozilla/neqo/neqo-bin)
    Finished dev [unoptimized + debuginfo] target(s) in 0.87s
     Running `target/debug/neqo-client 'http://127.0.0.1:12345/10'`
0s  0ms INFO H3 Client connecting: 0.0.0.0:48590 -> 127.0.0.1:12345
0s  3ms INFO [Http3 connection] Fetch method=GET target: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Ipv4(127.0.0.1)), port: Some(12345), path: "/10", query: None, fragment: None }
0s  3ms INFO [Client 09f5ee994b496ebc] Connection established
0s  3ms WARN Crypto operation failed NssError { name: "SEC_ERROR_BAD_DATA", code: -8190, desc: "security library: received bad data." }
0s  3ms WARN [Client ...] Dropped received packet: Decryption failure; Total: 1
0s  3ms INFO [Http3 connection] Fetch method=GET target: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Ipv4(127.0.0.1)), port: Some(12345), path: "/10", query: None, fragment: None }
0s  5ms INFO [Http3 connection] Fetch method=GET target: Url { scheme: "http", cannot_be_a_base: false, username: "", password: None, host: Some(Ipv4(127.0.0.1)), port: Some(12345), path: "/10", query: None, fragment: None }
0s  9ms INFO [Http3 client] Close the connection error=0 msg=kthxbye!.
0s  9ms WARN close(0) called when streams still active
0s  9ms WARN Unhandled event StateChange(Closing(Application(0)))
0s  9ms INFO [Http3 client] Close the connection error=0 msg=kthxbye!.
0s 32ms INFO [Http3 client] Close the connection error=0 msg=kthxbye!.
0s 32ms INFO Closing timer expired

@larseggert @KershawChang would you mind taking another look? I am not familiar with how Neqo logging is used within Firefox, thus please review carefully.

Copy link
Collaborator

@larseggert larseggert left a comment

Choose a reason for hiding this comment

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

LGTM but want to hear from the other owners.

@larseggert larseggert added this pull request to the merge queue Mar 21, 2024
Merged via the queue into mozilla:main with commit e4bc0c1 Mar 21, 2024
12 of 13 checks passed
mxinden added a commit to mxinden/neqo that referenced this pull request Apr 19, 2024
mozilla#1692 introduced verbosity command line
flags in `neqo-server` and `neqo-client`.

This commit makes use of the flags instead of the `RUST_LOG` environment variable.
mxinden added a commit to mxinden/neqo that referenced this pull request Apr 19, 2024
There are two ways to specify the maximum log level of `neqo-server` and
`neqo-client`. Via the `RUST_LOG` environment variable and since
mozilla#1692 via the verbosity flags (e.g. `-v`).

Previously, if no verbosity flag was provided, `INFO` was set as the maximum log
level, the `RUST_LOG` environment variable was simply ignored.

With this commit, if no flag is set, the `RUST_LOG` environment variable is
considered, and only then the `env_logger` crate default value (`ERROR`) is used.

In other words, the precedence order now is:

1. command line flags (e.g. `-v`)
2. `RUST_LOG` environment variable
3. default `ERROR` level
mxinden added a commit to mxinden/neqo that referenced this pull request Apr 19, 2024
There are two ways to specify the maximum log level of `neqo-server` and
`neqo-client`. Via the `RUST_LOG` environment variable and since
mozilla#1692 via the verbosity flags (e.g. `-v`).

Previously, if no verbosity flag was provided, `INFO` was set as the maximum log
level, the `RUST_LOG` environment variable was simply ignored.

With this commit, if no flag is set, the `RUST_LOG` environment variable is
considered, and only then the `env_logger` crate default value (`ERROR`) is used.

In other words, the precedence order now is:

1. command line flags (e.g. `-v`)
2. `RUST_LOG` environment variable
3. default `ERROR` level
github-merge-queue bot pushed a commit that referenced this pull request Apr 25, 2024
* fix(bin): consider env when no verbosity flag is set

There are two ways to specify the maximum log level of `neqo-server` and
`neqo-client`. Via the `RUST_LOG` environment variable and since
#1692 via the verbosity flags (e.g. `-v`).

Previously, if no verbosity flag was provided, `INFO` was set as the maximum log
level, the `RUST_LOG` environment variable was simply ignored.

With this commit, if no flag is set, the `RUST_LOG` environment variable is
considered, and only then the `env_logger` crate default value (`ERROR`) is used.

In other words, the precedence order now is:

1. command line flags (e.g. `-v`)
2. `RUST_LOG` environment variable
3. default `ERROR` level

* clippy

* Move `verbose` into `SharedArgs`
mxinden added a commit to mxinden/neqo that referenced this pull request May 4, 2024
There are two server implementations based on neqo:

1. https://github.com/mozilla/neqo/tree/main/neqo-bin/src/server
  - http3 and http09 implementation
  - used for manual testing and QUIC Interop

2. https://searchfox.org/mozilla-central/source/netwerk/test/http3server/src/main.rs
  - used to test Firefox

I assume one was once an exact copy of the other. Both implement their own I/O,
event loop, ... Since then, the two implementations diverged significantly.
Especially (1) saw a lot of improvements in recent months:

- mozilla#1564
- mozilla#1569
- mozilla#1578
- mozilla#1581
- mozilla#1604
- mozilla#1612
- mozilla#1676
- mozilla#1692
- mozilla#1707
- mozilla#1708
- mozilla#1727
- mozilla#1753
- mozilla#1756
- mozilla#1766
- mozilla#1772
- mozilla#1786
- mozilla#1787
- mozilla#1788
- mozilla#1794
- mozilla#1806
- mozilla#1808
- mozilla#1848
- mozilla#1866

At this point, bugs in (2) are hard to fix, see e.g.
mozilla#1801.

This commit merges (2) into (1), thus removing all duplicate logic and
having (2) benefit from all the recent improvements to (1).
KershawChang pushed a commit to KershawChang/neqo that referenced this pull request May 7, 2024
There are two server implementations based on neqo:

1. https://github.com/mozilla/neqo/tree/main/neqo-bin/src/server
  - http3 and http09 implementation
  - used for manual testing and QUIC Interop

2. https://searchfox.org/mozilla-central/source/netwerk/test/http3server/src/main.rs
  - used to test Firefox

I assume one was once an exact copy of the other. Both implement their own I/O,
event loop, ... Since then, the two implementations diverged significantly.
Especially (1) saw a lot of improvements in recent months:

- mozilla#1564
- mozilla#1569
- mozilla#1578
- mozilla#1581
- mozilla#1604
- mozilla#1612
- mozilla#1676
- mozilla#1692
- mozilla#1707
- mozilla#1708
- mozilla#1727
- mozilla#1753
- mozilla#1756
- mozilla#1766
- mozilla#1772
- mozilla#1786
- mozilla#1787
- mozilla#1788
- mozilla#1794
- mozilla#1806
- mozilla#1808
- mozilla#1848
- mozilla#1866

At this point, bugs in (2) are hard to fix, see e.g.
mozilla#1801.

This commit merges (2) into (1), thus removing all duplicate logic and
having (2) benefit from all the recent improvements to (1).
github-merge-queue bot pushed a commit that referenced this pull request May 8, 2024
* refactor(bin): introduce server/http3.rs and server/http09.rs

The QUIC Interop Runner requires an http3 and http09 implementation for both
client and server. The client code is already structured into an http3 and an
http09 implementation since #1727.

This commit does the same for the server side, i.e. splits the http3 and http09
implementation into separate Rust modules.

* refactor: merge mozilla-central http3 server into neqo-bin

There are two server implementations based on neqo:

1. https://github.com/mozilla/neqo/tree/main/neqo-bin/src/server
  - http3 and http09 implementation
  - used for manual testing and QUIC Interop

2. https://searchfox.org/mozilla-central/source/netwerk/test/http3server/src/main.rs
  - used to test Firefox

I assume one was once an exact copy of the other. Both implement their own I/O,
event loop, ... Since then, the two implementations diverged significantly.
Especially (1) saw a lot of improvements in recent months:

- #1564
- #1569
- #1578
- #1581
- #1604
- #1612
- #1676
- #1692
- #1707
- #1708
- #1727
- #1753
- #1756
- #1766
- #1772
- #1786
- #1787
- #1788
- #1794
- #1806
- #1808
- #1848
- #1866

At this point, bugs in (2) are hard to fix, see e.g.
#1801.

This commit merges (2) into (1), thus removing all duplicate logic and
having (2) benefit from all the recent improvements to (1).

* Move firefox.rs to mozilla-central

* Reduce HttpServer trait functions

* Extract constructor

* Remove unused deps

* Remove clap color feature

Nice to have. Adds multiple dependencies. Hard to justify for mozilla-central.
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.

neqo-client: use common logging macros
4 participants