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

Nomad Monitor #6499

Merged
merged 34 commits into from
Nov 5, 2019
Merged

Nomad Monitor #6499

merged 34 commits into from
Nov 5, 2019

Conversation

drewbailey
Copy link
Contributor

@drewbailey drewbailey commented Oct 15, 2019

This PR adds a new top level command nomad monitor.

This command is similar to consul monitor in that it is used to stream logs using a configurable log level without needing to change the server/client log levels.

#6365

api/agent_test.go Outdated Show resolved Hide resolved
@drewbailey drewbailey force-pushed the f-nomad-monitor branch 2 times, most recently from 0b5b068 to 41b053f Compare October 25, 2019 14:53
@drewbailey drewbailey marked this pull request as ready for review October 25, 2019 18:32
@drewbailey drewbailey changed the title [WIP] Nomad Monitor Nomad Monitor Oct 25, 2019
Copy link
Member

@schmichael schmichael left a comment

Choose a reason for hiding this comment

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

Yay! Very excited about this. The framing might be obnoxious, but that can be done in a followup PR. I'm not quite through yet but will pick this up in the morning.

api/agent.go Outdated Show resolved Hide resolved
api/agent_test.go Outdated Show resolved Hide resolved
api/agent_test.go Show resolved Hide resolved
client/monitor_endpoint.go Outdated Show resolved Hide resolved
client/monitor_endpoint.go Outdated Show resolved Hide resolved
command/agent/monitor/monitor.go Outdated Show resolved Hide resolved
command/agent/monitor/monitor.go Outdated Show resolved Hide resolved
command/agent/monitor/monitor.go Outdated Show resolved Hide resolved
command/agent/monitor/monitor.go Outdated Show resolved Hide resolved
command/agent/monitor/monitor.go Outdated Show resolved Hide resolved
command/agent_monitor.go Outdated Show resolved Hide resolved
command/agent_monitor.go Outdated Show resolved Hide resolved
command/agent_monitor.go Outdated Show resolved Hide resolved
nomad/client_agent_endpoint.go Outdated Show resolved Hide resolved
nomad/client_agent_endpoint.go Outdated Show resolved Hide resolved
nomad/client_agent_endpoint.go Outdated Show resolved Hide resolved
@drewbailey drewbailey force-pushed the f-nomad-monitor branch 2 times, most recently from e385bc9 to b0a0cf0 Compare November 4, 2019 14:36
api/agent.go Show resolved Hide resolved
client/agent_endpoint.go Outdated Show resolved Hide resolved
Copy link
Contributor

@cgbaker cgbaker left a comment

Choose a reason for hiding this comment

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

a few questions about locking in Monitor, but i'll leave it up to your judgement and check again if you have questions.

client/agent_endpoint.go Outdated Show resolved Hide resolved
client/agent_endpoint.go Outdated Show resolved Hide resolved
}
}

func TestMonitor_Monitor_ACL(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 💯 🏆

command/agent/monitor/monitor.go Outdated Show resolved Hide resolved
command/agent/monitor/monitor.go Outdated Show resolved Hide resolved
command/agent/monitor/monitor.go Show resolved Hide resolved
command/agent/monitor/monitor.go Outdated Show resolved Hide resolved
command/agent/monitor/monitor.go Show resolved Hide resolved
break LOOP
case <-time.After(d.droppedDuration):
d.Lock()
defer d.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm thinking that this shouldn't be a defer, but instead an inline call to unlock after the if block

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we want to hold onto the lock until after all the selects to ensure that a write doesn't steal the space we create to add the dropped message

}
case <-stopCh:
d.Lock()
defer d.Unlock()
Copy link
Contributor

@cgbaker cgbaker Nov 4, 2019

Choose a reason for hiding this comment

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

not sure whether this lock/unlock is needed, but it doesn't hurt anything.

not sure whether this is still true based on our personal conversation and other changes in flight

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think its unnecessary as well, will remove

Copy link
Contributor

Choose a reason for hiding this comment

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

if we are closing d.logCh here, then we need the lock to protect from other goroutines using this channel. if we aren't closing this channel, then i think we can drop the lock here.

This version of gziphandler includes a fix that fixes GzipResponseWriter
to implement CloseNotifier

nytimes/gziphandler#63
AgentMonitor is an endpoint to stream logs for a given agent. It allows
callers to pass in a supplied log level, which may be different than the
agents config allowing for temporary debugging with lower log levels.

Pass in logWriter when setting up Agent
Queries /v1/agent/monitor and receives streaming logs from client
Adds nomad monitor command. Like consul monitor, this command allows you
to stream logs from a nomad agent in real time with a a specified log
level

add endpoint tests

Upgrade go-hclog to latest version

The current version of go-hclog pads log prefixes to equal lengths
so info becomes [INFO ] and debug becomes [DEBUG]. This breaks
hashicorp/logutils/level.go Check function. Upgrading to the latest
version removes this padding and fixes log filtering that uses logutils
Check
multisink logger

remove usage of logwriter
prefix output with proper spacing

update gzip handler, adjust first byte flow to allow gzip handler bypass

wip, first stab at wiring up rpc endpoint
Adds new package that can be used by client and server RPC endpoints to
facilitate monitoring based off of a logger

clean up old code

small comment about write

rm old comment about minsize

rename to Monitor

Removes connection logic from monitor command

Keep connection logic in endpoints, use a channel to send results from
monitoring

use new multisink logger and interfaces

small test for dropped messages

update go-hclogger and update sink/intercept logger interfaces
underscores instead of dashes for query params
Addresses feedback around monitor implementation

subselect on stopCh to prevent blocking forever.

Set up a separate goroutine to check every 3 seconds for dropped
messages.

rename returned ch to avoid confusion
rm redundant lock

wip to use framing

wip switch to stream frames
rm extra new line

fix lint errors

return after close

fix, simplify test
fix typo command/agent/monitor/monitor.go

Co-Authored-By: Chris Baker <[email protected]>

Update command/agent/monitor/monitor.go

Co-Authored-By: Chris Baker <[email protected]>

address feedback, lock to prevent send on closed channel

fix lock/unlock for dropped messages
Copy link
Contributor

@cgbaker cgbaker left a comment

Choose a reason for hiding this comment

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

looks correct, i think there's some opportunity for simplification

command/agent/monitor/monitor.go Outdated Show resolved Hide resolved
}
case <-stopCh:
d.Lock()
defer d.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

if we are closing d.logCh here, then we need the lock to protect from other goroutines using this channel. if we aren't closing this channel, then i think we can drop the lock here.

Copy link
Contributor

@cgbaker cgbaker left a comment

Choose a reason for hiding this comment

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

need to unlock before quitting the dropped-goroutine

command/agent/monitor/monitor.go Outdated Show resolved Hide resolved
command/agent/monitor/monitor.go Outdated Show resolved Hide resolved
Copy link
Contributor

@cgbaker cgbaker left a comment

Choose a reason for hiding this comment

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

👍 🚀

@drewbailey drewbailey merged commit eb51141 into master Nov 5, 2019
@drewbailey drewbailey deleted the f-nomad-monitor branch November 5, 2019 17:42
@drewbailey drewbailey added this to the 0.10.2 milestone Nov 6, 2019
@preetapan preetapan mentioned this pull request Nov 20, 2019
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants