Skip to content

Log console output to allocation logs#220

Open
Freddo3000 wants to merge 5 commits into
hashicorp:mainfrom
Freddo3000:feature/console-output
Open

Log console output to allocation logs#220
Freddo3000 wants to merge 5 commits into
hashicorp:mainfrom
Freddo3000:feature/console-output

Conversation

@Freddo3000

Copy link
Copy Markdown
Contributor

This pull request implements some basic console logging by having the VM open a UNIX socket which is then read from and output to the nomad allocation log FIFO.

image

@Freddo3000 Freddo3000 requested review from a team as code owners May 16, 2026 15:10
@chrisroberts chrisroberts self-assigned this May 19, 2026
Freddo3000 and others added 4 commits June 19, 2026 16:04
Use two serial devices bound to host sockets for sending stdout
and stderr from task commands and stream to Nomad. Optionally,
allow sending cloud-init logs to stdout.
@chrisroberts chrisroberts force-pushed the feature/console-output branch from 2b921c5 to b63cb5c Compare June 20, 2026 00:10
@chrisroberts

Copy link
Copy Markdown
Member

Hi @Freddo3000! Sorry there was a bit of a delay getting to this PR. We were still wrapping up some other things and I needed to take some time to sit and play around with this a bit.

Thanks so much for this PR and getting things moving on task logs. After getting your changeset rebased I spun it up and it worked just as described 🎉 One side effect I encountered was that using virsh console X stopped working (though could be worked around with providing devname to use the console device). Getting the output from the serial device was great but once the system was booted, the logs would show nothing more than the final login prompt.

So I started to wonder if we could instead get cloud-init to point its logs at the serial device instead, and then consume that and stream it to Nomad. The cloud-init configuration allows for configuring multiple loggers, so I took a swing at wiring that in and found it worked rather well, which was great. While doing that I also came across the output key, which looked like it might be just the thing for logging the output of the commands defined for the task.

The output key supports splitting the output to send stdout and stderr to different locations. If two serial devices were created in the VM and bound to host sockets, we could have one for stdout and one for stderr. After adding in the extra serial device and getting the logging configuration all updated, the results turned out pretty well.

Using this example job that spins up a simple http server using python, this is what I get in the UI:

shot-1781913953

with request logs going to stderr:

shot-1781913966

which is great. Now we are getting output for the life of the command and the task is behaving more like tasks from other drivers. I found that being able to see the logs from cloud-init was really useful, but likely not something that would always want to be seen. Instead of always sending cloud-init logs, tasks can optionally enable them in the task config:

config {
  logging {
    cloudinit = true
    level     = "debug"
  }

  ...
}

If cloudinit logging is enabled, then an extra logger is added to cloudinit to write to the "stdout" serial device and we get something like this:

shot-1781914068

Would be really happy to hear any feedback you have about these changes, and thank you again for this PR!

@chrisroberts chrisroberts requested a review from gulducat June 22, 2026 17:19
@Freddo3000

Copy link
Copy Markdown
Contributor Author

Took a brief look at it and it looks good to me, albeit a bit more complex than my initial implementation. Only thought I have is whether the disable toggle is needed for the logging block seeing as there's a task-wide option to disable logs already: https://developer.hashicorp.com/nomad/docs/job-specification/logs though perhaps this allows us to skip some threads?

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.

2 participants