-
Notifications
You must be signed in to change notification settings - Fork 3
Conversation
main.go
Outdated
http://www.apache.org/licenses/LICENSE-2.0.txt | ||
|
||
|
||
Copyright 2015-2017 Intel Corporation |
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.
it should be only 2017
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.
@PatrykMatyjasek, the reason I left 2015-2017 is because that most CLI code base is from Snap repo. What do you think? Keep 2015-2017 or 2017?:-)
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.
@candysmurf It should stay only 2017
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.
@PatrykMatyjasek, changed all to 2017. Please take another look
snaptel/commands.go
Outdated
http://www.apache.org/licenses/LICENSE-2.0.txt | ||
|
||
|
||
Copyright 2015-2017 Intel Corporation |
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.
it should be only 2017
snaptel/commands.go
Outdated
{ | ||
Name: "create", | ||
Description: "Creates a new task in the snap scheduler", | ||
Usage: "There are two ways to create a task.\n\t1) Use a task manifest with [--task-manifest]\n\t2) Provide a workflow manifest and schedule details.\n\n\t* Note: Start and stop date/time are optional.\n", |
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 there should be all flags described in usage. For example there is specified flag to create task using task manifest but there is lack of options which should be used to run task using workflow and schedule
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.
can you give an example what you want? This is same as what we have in Snap today, Total parity. We can create an issue for your suggestions as future enhancements.
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.
First way of creating task is described with flag which should be used to run. But the other way is not described in such details. I agree about issue :)
snaptel/commands.go
Outdated
Usage: "list", | ||
Action: listTask, | ||
Flags: []cli.Flag{ | ||
flVerbose, |
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.
flag is not specified in usage
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.
@PatrykMatyjasek urfave/cli automatically generates help based on provided Flags
, output for this command is:
./build/linux/x86_64/snaptel task list --help
NAME:
snaptel task list - list or list --verbose
USAGE:
snaptel task list [command options] [arguments...]
OPTIONS:
--verbose Verbose output
snaptel/commands.go
Outdated
Usage: "watch <task_id>", | ||
Action: watchTask, | ||
Flags: []cli.Flag{ | ||
flVerbose, |
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.
missing in usage
snaptel/metric.go
Outdated
http://www.apache.org/licenses/LICENSE-2.0.txt | ||
|
||
|
||
Copyright 2015-2017 Intel Corporation |
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 be only 2017
snaptel/plugin.go
Outdated
http://www.apache.org/licenses/LICENSE-2.0.txt | ||
|
||
|
||
Copyright 2015 Intel Corporation |
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.
2017
snaptel/plugin.go
Outdated
} | ||
|
||
func unloadPlugin(ctx *cli.Context) error { | ||
pType := ctx.Args().Get(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.
shouldn't we check len of ctx.Args()?
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 used existing code that's how I didn't focus on those. I'll add a check.
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 was just curious if there could be problems in case of less parameters provided by user
snaptel/task.go
Outdated
http://www.apache.org/licenses/LICENSE-2.0.txt | ||
|
||
|
||
Copyright 2015-2017 Intel Corporation |
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 be 2017
snaptel/watch.go
Outdated
http://www.apache.org/licenses/LICENSE-2.0.txt | ||
|
||
|
||
Copyright 2015-2017 Intel Corporation |
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 be 2017
FlTimeout = cli.DurationFlag{ | ||
Name: "timeout, t", | ||
Usage: "Timeout to be set on HTTP request to the server", | ||
Value: 10 * time.Second, |
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.
Is this parameter passed anywhere? Please consider snaptel task watch timeout bug, fixed by this PR:
intelsdi-x/snap#1537
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.
it seems used by this library - github.com/urfave/cli. Not sue how it's used though.
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 meant the timeout parameter, I don't see if value of timeout flag is used anywhere, so it is no difference if this tool is used with --timeout=0
or --timeout=9999999
?
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 see that everywhere in CLI, timeout-less client methods are used, for example:
params := tasks.NewGetTaskParams()
instead of
params := tasks.NewGetTasksParamsWithTimeout(FlTimeout.Value)
so --timeout
flag is not used anywhere. I think it should be removed for now if not implemented, or should be implemented in this PR, because it seems to be pretty easy (replace all client methods with <MethodName>WithTimeout(FlTimeout.Value)
equivalent)
snaptel/watch.go
Outdated
id := ctx.Args().First() | ||
url := fmt.Sprintf("%s/%s/tasks/%s/watch", FlURL.Value, FlAPIVer.Value, id) | ||
|
||
resp, err := http.Get(url) |
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.
Shouldn't you set the HTTP timeout here? Please consider snaptel task watch timeout bug, fixed by this PR:
intelsdi-x/snap#1537
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.
@mkleina, a good question. The fix 1537 just set no timeout for watching a task. I'll see what I can do here. Please review my next update.
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.
@mkleina, played with client timeout. Unfortunately, streaming cannot appropriately handle the idle timeout atm. Therefore no timeout can be set.
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.
@candysmurf Original snaptel
CLI has --timeout
option which sets timeout for all HTTP requests except task watch (which timeout is fixed to 0 after fix 1537), just wanted you to be aware of this timeout setting, because I see http.Get() called here without any timeout configuration.
snaptel/metric.go
Outdated
return err | ||
} | ||
} | ||
} else if len == 1 { |
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 branch looks unnecessary, preceding condition can be just >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.
@lmroz, cannot believe it passed code review before:-).
} | ||
fmt.Printf("\n Rules for collecting %s:\n\n", namespace) | ||
printFields(w, true, 6, "NAME", "TYPE", "DEFAULT", "REQUIRED", "MINIMUM", "MAXIMUM") | ||
for _, rule := range metric.Policy { |
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.
Is this code printing config policy for each namespace? If so, there will be terrible flood because config policies affect all subnamespaces.
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.
@lmroz, code does what you said which is the current behavior. Feel free to open an issue for future enhancement.
snaptel/metric.go
Outdated
|
||
if ns != "" { | ||
//if the user doesn't provide '/*' we fix it | ||
if ns[len(ns)-2:] != "/*" { |
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.
What if separator for given namespace is different than /
?
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.
@lmroz, let us open an issue for this one as well. It'll break if the separator is not "/".
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.
@lmroz, code seems not used. I removed it.
} else { | ||
argArray = append(argArray, "") | ||
} | ||
if i < (len(fields) - 1) { |
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 code could be simplified just by moving append to the beginning of for loop and testing i != 0
or just using strings.Join
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.
@lmroz, could a field be nil but not the first one?
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 don't see any early return depending on if its nil
or not so inserting tab after each element but last one is equivalent to inserting tab before each element but first one.
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.
then it needs to check if it's the first one. No saving :-)
f9fa285
to
0355221
Compare
@PatrykMatyjasek, @lmroz, @intelsdi-x/snap-maintainers, this PR incorporated all your code reviews. Would you please take another look. |
@intelsdi-x/snap-maintainers, PR in snap-client-go is merged. It makes the testing of this PR much easier. Please test this PR against the PR submitted in Snap PR 1535 |
549a7ac
to
ad4f82d
Compare
snaptel/common.go
Outdated
func getErrorDetail(err error, ctx *cli.Context) error { | ||
switch err.(type) { | ||
case *plugins.GetMetricsNotFound: | ||
return newUsageError(fmt.Sprintf("%v", err.(*plugins.GetMetricsNotFound).Payload.Message), ctx) |
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.
Maybe my fault but I am getting error messages here:
snaptel/common.go:71: err.(*plugins.GetMetricsNotFound).Payload.Message undefined (type *models.Error has no field or method Message)
snaptel/common.go:73: err.(*plugins.GetMetricsInternalServerError).Payload.Message undefined (type *models.Error has no field or method Message)
snaptel/common.go:75: err.(*plugins.LoadPluginBadRequest).Payload.Message undefined (type *models.Error has no field or method Message)
snaptel/common.go:77: err.(*plugins.LoadPluginConflict).Payload.Message undefined (type *models.Error has no field or method Message)
snaptel/common.go:79: err.(*plugins.LoadPluginInternalServerError).Payload.Message undefined (type *models.Error has no field or method Message)
snaptel/common.go:81: err.(*plugins.LoadPluginUnsupportedMediaType).Payload.Message undefined (type *models.Error has no field or method Message)
snaptel/common.go:83: err.(*plugins.UnloadPluginBadRequest).Payload.Message undefined (type *models.Error has no field or method Message)
snaptel/common.go:85: err.(*plugins.UnloadPluginConflict).Payload.Message undefined (type *models.Error has no field or method Message)
snaptel/common.go:87: err.(*plugins.UnloadPluginInternalServerError).Payload.Message undefined (type *models.Error has no field or method Message)
snaptel/common.go:89: err.(*plugins.UnloadPluginNotFound).Payload.Message undefined (type *models.Error has no field or method Message)
Payload
is models.Error
in all cases, for example:
type GetMetricsNotFound struct {
Payload *models.Error
}
But there are no Message
field for models.Error
:
https://github.com/candysmurf/snap-client-go/blob/2017-05-16/models/error.go
There are only ErrorMessage
field.
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.
@mkleina, fixed it.
snaptel/plugin.go
Outdated
|
||
printFields(w, false, 0, "NAME", "HIT COUNT", "LAST HIT", "TYPE", "PPROF PORT") | ||
for _, rp := range resp.Payload.Plugins { | ||
printFields(w, false, 0, rp.Name, rp.Hitcount, time.Unix(rp.LastHitTimestamp, 0).Format(time.RFC1123), rp.Type, rp.PprofPort) |
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 be rp.HitCount
:
snaptel/plugin.go:141: rp.Hitcount undefined (type *models.Plugin has no field or method Hitcount, but does have HitCount)
snaptel/watch.go
Outdated
break | ||
} | ||
} | ||
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.
Please remove all w.Flush()
statements and insert final w.Flush()
just before return nil
. Flush()
should be called once after everything was printed to buffer, otherwise column formatting won't be correct.
main.go
Outdated
app.Version = gitversion | ||
app.Usage = "The open telemetry framework" | ||
app.Flags = []cli.Flag{snaptel.FlURL, snaptel.FlSecure, snaptel.FlAPIVer, snaptel.FlPassword, snaptel.FlConfig, snaptel.FlTimeout} | ||
app.Setup() |
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.
Please move app.Setup()
just before app.Run()
after setting all app
fields. Otherwise, snaptel --help
does not print out available commands.
635ac92
to
582f6ab
Compare
glide.yaml
Outdated
@@ -0,0 +1,55 @@ | |||
package: github.com/intelsdi-x/snap |
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 be github.com/intelsdi-x/snap-cli
LGTM - after updating the package name at the top of the glide.yaml. |
LGTM |
Summary of changes
Test done