Skip to content

Logger improvements #13

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

Merged
merged 23 commits into from
Mar 27, 2025
Merged

Logger improvements #13

merged 23 commits into from
Mar 27, 2025

Conversation

edolstra
Copy link
Collaborator

Motivation

Some logger improvements to allow collecting useful info (especially in CI) such as hash mismatches, derivation/substitution results, etc.

  • New option json-log-path that writes all log messages to the specified path (which can be a Unix domain socket) in addition to the regular output. This is implemented using a new TeeLogger.
  • Add a structured log message for FOD hash mismatches. It looks like this:
    {
      "action": "result",
      "id": 5930065640554503,
      "payload": {
        "got": {
          "algo": "sha256",
          "base16": "8bef61bfc134bb9b968176270017cd8c4b48ab6dd3a755244f7a359d502079d7"
        },
        "storePath": "/nix/store/g9qc0lk1ra00hb1apdaw84b2l4j7187b-nix-0.10.1.tar.bz2.drv",
        "wanted": {
          "algo": "sha256",
          "base16": "8bed21bfc134bb9b968176270017cd8c4b48ab6dd3a755244f7a359d502079d7"
        }
      },
      "type": 109
    }
    
  • Add a structured log message for the BuildResult of derivation/substitution goals. Example:
    {
      "action": "result",
      "id": 5901577122480358,
      "payload": {
        "path": {
          "drvPath": "/nix/store/xv0nd4m0sf329n2vdxch2kd6v3vihai4-patchelf-0.14.3.drv",
          "outputs": {
            "out": "/nix/store/6fcrjgfjip2ww3sx51rrmmghfsf60jvi-patchelf-0.14.3"
          }
        },
        "startTime": 1741891047,
        "status": "Built",
        "stopTime": 1741891057,
        "timesBuilt": 1
      },
      "type": 110
    }
    

Context


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

edolstra added 13 commits March 13, 2025 12:52
Logging to another Logger was kind of nonsensical - it was really just
an easy way to get it to write its output to stderr, but that only
works if the underlying logger writes to stderr.

This change is needed to make it easy to log JSON output somewhere
else (like a file or socket).
If the NIX_LOG_FILE environment variable is set, Nix will write JSON
log messages to that file in addition to the regular logger (e.g. the
progress bar).
It doesn't work on unrealized paths.
We now ignore connection / write errors.
Copy link

github-actions bot commented Mar 14, 2025

@github-actions github-actions bot temporarily deployed to pull request March 14, 2025 16:39 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 21, 2025 15:06 Inactive
We don't want to inherit the parent's JSON logger since then messages
from different daemon processes may clobber each other.
@github-actions github-actions bot temporarily deployed to pull request March 26, 2025 22:27 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 26, 2025 22:54 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 27, 2025 13:12 Inactive
@github-actions github-actions bot temporarily deployed to pull request March 27, 2025 16:22 Inactive
Copy link
Member

@cole-h cole-h left a comment

Choose a reason for hiding this comment

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

LGTM and worked in local testing!

@github-actions github-actions bot temporarily deployed to pull request March 27, 2025 18:13 Inactive
@edolstra edolstra enabled auto-merge March 27, 2025 18:13
@edolstra edolstra added this pull request to the merge queue Mar 27, 2025
Merged via the queue into detsys-main with commit afcce6f Mar 27, 2025
19 checks passed
@edolstra edolstra deleted the logger-improvements branch March 27, 2025 18:32
Copy link

Choose a reason for hiding this comment

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

It looks like you are incrementally expanding the internal-json format with new Message IDs and such. This is a signal for me that the internal-json interface is actually consumed by someone (except for nix-output-monitor and us) somewhere and that we can make some soft assumptions about stability (it's not gonna get ripped out tomorrow), as well as the fact that we won't be changing the internal-json message format anytime soon.

Am I correct in my rough assessment on future path of internal-json?

I had a few discussions with with other contributors due to ergonomic pains in using internal-json, however the PR alleviates some of the pains including one of the most important: locking of the output stream so the log messages don't arrive messed up.

Copy link
Member

Choose a reason for hiding this comment

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

(without speaking on behalf of Eelco and his plans:) determinate-nixd consumes it, which let us drop the use of the post-build-hook. My intention is for determinate-nixd to be the only consumer of the Nix daemon's log output, since we accept and rebroadcast the events over the determinate-nixd events API.

Since we ship determinate-nixd and nix-daemon in a matched set (they're both at version 3.1.1) we're able to have greater interface flexibility than we would otherwise. To me this means we could change this format more, and in breaking ways. But not without good reason.

I guess what I mean to say is: I don't intend for this format to be a stable API, since that is what the determinate-nixd events API is intended to provide. However, you can probably build against it without too much annoyance or worry.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can't remember why we called it internal-json, probably because we were afraid to commit to stability and it's not documented anywhere. However, it's used between the client and the daemon so it's de facto required to be a stable format.

One thing I don't like about the current format is that message types are integers. They should probably be strings (e.g. "hash-mismatch" instead of 109).

Copy link

Choose a reason for hiding this comment

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

message types are integers. They should probably be strings

That was also discussed as a change one could make, since we are not using the self-documenting features of json currently. I don't see any problem in doing that change since the internal-json name came across correctly, as long as one makes sure to keep in touch with nix-output-monitor and friends.

I also believe that the internal-json messages passed around between the client and daemon are not part of the nix language behaviour as the name implies and one should be allowed to break older versions with newer daemons and vice versa along those lines, if communicated correctly.

@edolstra
Copy link
Collaborator Author

Upstream PRs:

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.

4 participants