Kanidm[2]

June 7

On Monday, I started out by reviewing William’s PR comments on “Tracing Logging”. I had accidentally committed a few junk files, so the first thing I did was take care of those by adding them to the .gitignore, or by moving the changes to different branches.

William also provided feedback on how to make logging subscribers work, which resolved the red squigglies. However, I hit a wall when I tried to compile: the anyhow crate had an error that I had no idea how to approach. Google had nothing. I tried only compiling what I needed to run my test, but it still needed anyhow. I looked at the source code and it looked like there was a compiler flag that would allow me to avoid the error, but I had no idea how to change the flag to make it work.

I eventually realized that the issue was that I was running the nightly compiler. I figured this out by first isolating the issue and finding that I wasn’t able to use ptr::addr_of at all. I thought maybe I wasn’t up to date, so I looked up how to update and saw someone say to try rustc --version to check the version. When I did this, I saw I was on the nightly unstable version, and that maybe that might be the issue. So I switched back to stable and it worked! This makes sense, because my code compiled fine last time.

Another issue I encounted was the my scoped subscriber wasn’t capturing anything, only the global one was, but I didn’t realize that I had to run all the tests to get all the logs, since the test I was running didn’t produce any.

After I got subscribers working, I started working on the main purpose: spans. spans allow each log to know the context it was produced in, providing much more useful messages, especially during asynchronous code. I figured out that spans have to created in the scope of a local subscriber and not the other way around. Additionally, they shouldn’t contain any await calls, since the program could leave the span and do other code that’s not contained while the span is still active.

I found this very challenging, however, because there are so many await calls that it would’ve been very challenging to annotate all the synchronous parts with custom scopes because they would be so fragmented. This made spans feel kind of pointless. I ended up spending about an hour on this :(.

A question I came up with was that when I set the capture level to DEBUG, I got a ton of things like hyper::client::pool: pooling idle connection for ("http", 127.0.0.1:28080). Thanks to @yaleman for pointing out that the tracing crate is designed to pick up on logs yielded by env_logger’s macros.

I then spent some time familiarizing with the tracing API, and found the tracing::subscriber::set_default function, which allows you to hold a subscriber guard that ends when it is dropped, instead of having to put everything inside of a function. Very cool!

June 8

Decided to start making daily TODO lists. Here’s mine for Tuesday:

  1. Review new comments on “Add email syntax”.
  2. Implement suggestions on “Tracing Logging” and update the PR.

I started by responding to comments on “Add email syntax”. There are still some things I was confused about, so I asked a few clarifying questions. I feel like I’m starting to get a feel for the coding style and practices used. The whole process took two hours, but I think was able to provide good feedback and ask solid questions.

After code review, I went through feedback on “Tracing Logging”, and began implementing the suggestions William and @yaleman offered. I added my own custom field to the KanidmUnixConfig struct to indicate the log formatting (JSON vs pretty), but I wasn’t really sure how to actually access that config setting in my tests.

Using William’s feedback, I was able to rebase my current branch and get rid of the junk files and update the pull request. I definitely struggled with resolving conflicts and some stuff got messed up, but it was mostly intact by the time it got pushed two hours later. I fortunately was able to avoid the git reflog, though.

June 9

Had a medical emergency and didn’t work on Wednesday. :(

June 10

Thursday TODO list:

  1. Review “Add email syntax” PR comments, compile list of new issues that need to be opened.
  2. Implement suggestions on “Tracing Logging” and update the PR.

All of my questions for “Add email syntax” had been resolved or redirected to separate issues, so the PR was looking ready to merge and I didn’t end up leaving more feedback. I compiled a list of loose ends below for separate issues:

  • SyntaxType to usize: https://github.com/kanidm/kanidm/pull/465#discussion_r647471555
  • Value things: https://github.com/kanidm/kanidm/issues/468
  • cleanup kanidm_client bool/return values: https://github.com/kanidm/kanidm/pull/465#discussion_r647877749
  • dbvalue serde renames

After this, I went back to work on “Tracing Logging”, but I hit a compilation error when I tried to run the tests. The error message was super verbose with massive type trees, so I wasn’t able to figure out exactly what went wrong. Tried changing to rustc 1.47.0 (because that’s what William was running), but that didn’t solve the issue. I eventually figured out that the error was that I refactored some stuff in cache.rs, so I just reverted my changes and that seemed to fix the problem.

At this point, I wasn’t sure if I could do much more for logging until I had my own VM and Kanidm instance set up. I followed the developer’s guide for how to set up an instance, but I also got stuck there, so I submitted my current progress to the PR as well as a question on how to solve my VM issue.

June 11

Friday TODO list:

  1. Open new issues.
  2. Try to get VM set up for Kanidm instance, more logging testing.
  3. Start refactoring kanidm_unix_int to use spans for more explanatory logs.

Today I spent a lot of time on GitHub and not a lot of time coding, unfortunately. I took William’s advice in my PR comments about opening new issues for the loose ends, starting with leaving a comment on #468 about a change potentially deprecating a function.

I also really want to do the Value rewrite, because it seems like something I would actually be able to do and provide a lot of value in (haha…).

I submitted a new issue (#472) for rewriting some return types in kanidm_client, and also submitted a new issue (#473) for clarifying type field names in dbvalue.rs. I realized that a lot of things that are serialized to the database are not taking advantage of serde rename macros, and instead are using really indescriptive short names. This is definitely an issue that I want to tackle, because I’m a huge fan of code clarity and I want to get more experience using serde.

After I opened the issues, I followed William’s feedback for getting the server running (it was a tiny mistake on my end), but I got a ton of logs that I didn’t know what to make of. They were all hardly readable, so I sent William a message and decided to call it a day there and finish up by writing this blog post.

Written on June 11, 2021