-
Notifications
You must be signed in to change notification settings - Fork 2k
Add nomad monitor export command #26178
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
base: main
Are you sure you want to change the base?
Conversation
3a0e003
to
4a608b0
Compare
b105697
to
e430e42
Compare
68fdc38
to
2ddf97c
Compare
2ddf97c
to
2c0148a
Compare
2c0148a
to
8863e01
Compare
8863e01
to
71a05f0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you're not quite done @tehut but I made a first pass over this.
command/agent_monitor_export.go
Outdated
Sets the specific server to monitor | ||
|
||
-service-name <service-name> | ||
Sets the systemd unit name to query journalctl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should point out which fields only work on agents running on Linux.
command/agent_monitor_export.go
Outdated
Sets the systemd unit name to query journalctl | ||
|
||
-log-since <int> | ||
Sets the log period for journald logs. Defaults to 72 and ignored if on-disk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sets the log period for journald logs. Defaults to 72 and ignored if on-disk | |
Sets the log period for journald logs. Defaults to 72 and ignored if -on-disk=true |
Also, do we have to restrict ourselves to integer number of hours here? Can we accept a humanize-formatted duration string like we do everywhere else?
command/agent/agent_endpoint_test.go
Outdated
urlString := baseURL + | ||
"on_disk=" + tc.onDisk + | ||
"&service_name=" + tc.serviceName + | ||
"&follow=" + tc.follow + | ||
"&node_id=" + tc.nodeID + | ||
"&server_id=" + tc.serverID + | ||
"&mocked=" + "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: you can use https://pkg.go.dev/net/url#Values here.
command/agent/agent_endpoint_test.go
Outdated
must.Eq(t, err.(HTTPCodedError).Code(), tc.errCode) | ||
return | ||
} else { | ||
must.Unreachable(t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Unreachable" is totally correct, but this will report the error message that we shouldn't be getting:
must.Unreachable(t) | |
must.NoError(t, err) |
} else if !aclObj.AllowAgentRead() { | ||
handleStreamResultError(structs.ErrPermissionDenied, pointer.Of(int64(403)), encoder) | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sort of wonder if agent:read
is too low because we're giving access to other service logs, but the agent ACL is actually pretty powerful already, so maybe that's ok? Might be worth reviewing with @dduzgun-security
client/agent_endpoint.go
Outdated
if args.MockMonitor != nil { | ||
mon = args.MockMonitor | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we do decide to keep the mock monitor infrastructure in place, I'd really like if we could figure out a way to inject this at the time we create the monitor and not via request argument. Because this leaves the possibility open for a user to request we're using the mock. That's probably harmless but it's not intended to be user-accessible, so I'd rather just make it impossible. (Plus security audits tend to ding us on this kind of thing.)
client/agent_endpoint.go
Outdated
opts := monitor.MonitorExportOpts{ | ||
LogSince: args.LogSince, | ||
ServiceName: args.ServiceName, | ||
NomadLogPath: args.NomadLogPath, | ||
OnDisk: args.OnDisk, | ||
Follow: args.Follow, | ||
} | ||
|
||
logCh := mon.MonitorExport(opts) | ||
|
||
initialOffset := int64(0) | ||
var ( | ||
eofCancelCh chan error | ||
eofCancel bool | ||
) | ||
eofCancel = !opts.Follow | ||
// receive logs and build frames | ||
streamReader := cstructs.NewStreamReader(logCh) | ||
go func() { | ||
defer framer.Destroy() | ||
|
||
if err := streamReader.StreamFixed(ctx, initialOffset, "", 0, framer, eofCancelCh, eofCancel); err != nil { | ||
select { | ||
case errCh <- err: | ||
case <-ctx.Done(): | ||
} | ||
} | ||
}() | ||
var streamErr error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This chunk seems to be the primary difference between this and the Agent.monitor
RPC, which as you'll guess from my other comments suggests to me they could share a lot of code. It seems like we're repeating all the stream handling code in the RPC handlers when we could reuse that if we have 2 different monitor implementations with the same interface (i.e. the Start
/End
interface), instead of introducing a new method into the existing struct.
5e7423f
to
18ed5c1
Compare
18ed5c1
to
ec7eb62
Compare
0459d61
to
594237f
Compare
594237f
to
9215971
Compare
9215971
to
e546200
Compare
e546200
to
ab483cb
Compare
"path": "monitor" | ||
"routes": [ | ||
{ | ||
"title": "monitor", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"title": "monitor", | |
"title": "Overview", |
change to match how we label section index pages. And thanks for merging the docs directory changes!
c00547f
to
cf2d9f0
Compare
Description
The nomad monitor export command introduces the ability for nomad to export logs a given agent has written to journald or to the nomad log file. Journald logs can be requested for a specific period of time while we just return the agent's entire nomad log file. Introducing this RPC is a prerequisite for adding journald logs to the nomad support bundle.
Testing & Reproduction steps
Links
Contributor Checklist
changelog entry using the
make cl
command.ensure regressions will be caught.
and job configuration, please update the Nomad website documentation to reflect this. Refer to
the website README for docs guidelines. Please also consider whether the
change requires notes within the upgrade guide.
Reviewer Checklist
backporting document.
in the majority of situations. The main exceptions are long-lived feature branches or merges where
history should be preserved.
within the public repository.