-
Notifications
You must be signed in to change notification settings - Fork 493
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
WIP: Add diagnostic session service #1578
Conversation
7fc5a7f
to
013f733
Compare
@nathanielc I still need to add a few tests, but for the time it should be reviewable at this point. |
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.
Looks great.
I have made a few comments on how to deal with the fact that this streams forever.
client/v1/client.go
Outdated
@@ -659,6 +660,39 @@ func (c *Client) Do(req *http.Request, result interface{}, codes ...int) (*http. | |||
return resp, nil | |||
} | |||
|
|||
func (c *Client) Logs(w io.Writer, q map[string]string) 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 really isn't too useful since it never returns, unless there is an error.
We should add a context.Context argument so users can cancel the request if they like.
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.
fixed.
cmd/kapacitor/main.go
Outdated
if len(args) != 1 { | ||
return errors.New("must provide task ID.") | ||
} | ||
err := cli.Logs(os.Stdout, map[string]string{"task": args[0]}) |
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.
Should we setup a signal handler here to cancel the context and cleanly as possible exit?
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.
yup. fixed.
cmd/kapacitor/main.go
Outdated
@@ -2246,3 +2258,48 @@ func doBackup(args []string) error { | |||
} | |||
return nil | |||
} | |||
|
|||
func watchUsage() { | |||
var u = `Usage: kapacitor watch <output file> |
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 think writing to Stdout is fine, no need for an output file. Also allowing optional list of key value pairs after the task id would be nice. That way you could filter down by node or whatever within a task easily.
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.
typo :) fixed.
cmd/kapacitor/main.go
Outdated
} | ||
m[pair[0]] = pair[1] | ||
} | ||
err := cli.Logs(os.Stdout, m) |
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.
Same here I think we want to catch signals and cancel the context.
server/server.go
Outdated
@@ -421,6 +423,14 @@ func (s *Server) appendTaskStoreService() { | |||
s.AppendService("task_store", srv) | |||
} | |||
|
|||
func (s *Server) appendSessionService() { | |||
// TODO: add diagnostic |
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.
The irony :)
services/diagnostic/api.go
Outdated
Method: "GET", | ||
Pattern: sessionsPath, | ||
HandlerFunc: s.handleSessions, | ||
NoGzip: 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.
A comment here explaining why these flag are set would be helpful, since it took us quite a while to figure out why they are needed.
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.
fixed.
services/diagnostic/api.go
Outdated
} | ||
|
||
func (s *SessionService) Close() error { | ||
return nil |
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.
In close you should remove the routes from the HTTPD service.
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.
fixed
services/diagnostic/sessions.go
Outdated
defer kv.mu.Unlock() | ||
|
||
flusher, ok := w.(http.Flusher) | ||
var wf WriteFlusher = &noopWriteFlusher{w: w} |
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.
You could put this creation of the noopWriteFlusher in the else block. It would save an allocation :)
services/diagnostic/sessions.go
Outdated
flusher, ok := w.(http.Flusher) | ||
var wf WriteFlusher = &noopWriteFlusher{w: w} | ||
if ok { | ||
wf = &httpWriteFlusher{w: w, f: flusher} |
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.
You shouldn't need the type httpWriteFlusher, as w is already a writer and you have asserted that its a flusher, so you can now just type assert it to be a WriteFlusher interface.
wf = w.(WriteFlusher)
Actually you can skip the direct flusher check and just check it its a WriteFlusher
to begin with.
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.
fixed
cmd/kapacitor/main.go
Outdated
|
||
Examples: | ||
|
||
$ kapacitor logs mytask |
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.
These examples are wrong
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.
fixed
cmd/kapacitor/main.go
Outdated
done = true | ||
}() | ||
|
||
if err := cli.Logs(ctx, os.Stdout, m); err != nil && !done { |
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 creates a race on the done
variable.
} | ||
|
||
func doLogs(args []string) error { | ||
m := map[string]string{} |
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.
Should we create a helper function that both doLogs and doWatch use so that this logic is not duplicated?
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.
fixed
cmd/kapacitor/main.go
Outdated
done = true | ||
}() | ||
|
||
if err := cli.Logs(ctx, os.Stdout, m); err != nil && !done { |
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.
Again same race on done
.
@nathanielc made the changes you suggested. |
@nathanielc made changes you suggested |
@nathanielc anything else here that needs to be done? |
cmd/kapacitor/main.go
Outdated
ctx, cancel := context.WithCancel(context.Background()) | ||
done := false | ||
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGINT) |
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 should read like this https://github.com/influxdata/kapacitor/blob/master/cmd/kapacitord/main.go#L92
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.
Fixed
27a6512
to
a71dc4f
Compare
@nathanielc Just rebased. Should be good to merge on your signal. |
@desa The server shutsdown if an invalid TICkscript is provided. We need the soft behavior, i.e. keep running if at all possible. A typo is a script should not cause the server to shutdown. We can still fail to start if there is an invalid script, but should not shutdown if it fails to reload. |
@nathanielc Fixed. Removed the logic for hard errors previously, but forgot to ignore the error it returned. |
whoops just realized that I think the previous comment applies to the other PR, or does
apply to the logging stuff? |
Oops, yeah I commented on the wrong one :-P |
@desa Now actually testing this PR... How can we make it easy to get logs for all levels greater than info? |
Testing this out I realized we haven't updated the bash completion scripts for the new CLI options. |
I know this isn't directly related but why is starting a task
Looking around I see quite a few things are warns. In general I don't think we need warns. In fact I'd be fine if we removed it entirely. Maybe we should open up a separate PR for remove warns? |
I think this is an issue with the sessions logger. I fixed it. It should be
I'll add another PR for removing warns in general. @nathanielc added completions. |
@nathanielc just rebased. I think things should be good to go now. (hopefully :)) |
@nathanielc fixed issue with |
going to add some tests related to the log level setting |
@nathanielc added test for issue you uncovered |
Rename constants Add pruning of sessions Add changelog entry Close channel on service close Restructure everything into a single package Fix tests SQUASH: saving state Get logs via the API Switch to streaming http Add JSON logging Add table test template for json logger Add tests for JSON logs Add todo comment Fixup todo comment Add diagnostic session changes Add kapacitor CLI commands for logs Change dao to sessions Reorganize code Reorganize Add context to Log function Fix kapacitor subcommand logic Address issues from PR Add diagnostic to session service Remove unreachable code Remove deadlock introduced by using diagnostic Remove TODOs Add test for content type Fix race on watch/logs subcommand And pull out similar logic Fix notify signals Fix bad usage of warn Expose loglevels with + in kv pairs Update bash-completion Make logLevelFromName case insensitive Add tests for handleSessions http hander
No description provided.