Conversation
1e127e8 to
d509c84
Compare
masci
left a comment
There was a problem hiding this comment.
Left few comments, some of them might be because this is somehow still WIP so feel free to ignore.
There was a problem hiding this comment.
is reading/decoding the request body needed?
There was a problem hiding this comment.
It is not since I am no longer sending the flare from the agent side but rather from the client side.
There was a problem hiding this comment.
In this case we should return the complete error string to the client I think - a client might not have access to the agent logs and they would only see "The flare failed to be created".
Also, http.Error returns plain text in the response body, so we should set the Content-Type header last thing, or not setting at all and return the file path as plain text.
There was a problem hiding this comment.
That's a good idea. I will do that.
There was a problem hiding this comment.
nit: can you wrap all the declarations in a var() block?
There was a problem hiding this comment.
We can keep it if you'd like ¯_(ツ)_/¯
There was a problem hiding this comment.
We could print the error contained in the response body here
There was a problem hiding this comment.
SendFlare could be invoked by the IPC api as well, through a new endpoint like agent/flare/send or similar
There was a problem hiding this comment.
Yes it could, do you think we should do this? I am not adverse to this idea.
There was a problem hiding this comment.
Don't have a strong opinion and don't want to add too much to this PR, we can just keep this in mind
There was a problem hiding this comment.
I made some adjustments that will allow it to do that!
There was a problem hiding this comment.
I didn't write that into it yet, but I abstracted a few things out that will make it easier to do
There was a problem hiding this comment.
nit: no need to export this function I guess
| } else { | ||
| fmt.Println("The agent was unable to make the flare.") | ||
| } | ||
| fmt.Println("Initiating flare locally.") |
There was a problem hiding this comment.
Do you think would it be useful adding to the flare whether it's been created locally or by a running agent? We can derive this info from the agent logs - they would contain a line about flare creation.
There was a problem hiding this comment.
Sounds like a good idea to me.
| @@ -0,0 +1,140 @@ | |||
| package flare | |||
There was a problem hiding this comment.
I think the package is specific enough to live in pkg/flare, same level as (for example) version and pidfile.
There was a problem hiding this comment.
I'll move it out there
|
|
||
| err = filepath.Walk(config.Datadog.GetString("confd_path"), func(path string, f os.FileInfo, err error) error { | ||
| if f.IsDir() { | ||
| return nil |
There was a problem hiding this comment.
not sure this plays well with the new check.d option, where you can have config files within folders, like http_check.d/123.yaml
There was a problem hiding this comment.
Ah I didn't know that was a thing now. We'll need to configure it to handle that. How do we detect that elsewhere?
There was a problem hiding this comment.
The file Configuration Provider does this: https://github.com/DataDog/datadog-agent/blob/master/pkg/collector/providers/file.go#L113
| return err | ||
| } | ||
|
|
||
| if config.Datadog.ConfigFileUsed() != "" { |
There was a problem hiding this comment.
we should keep in mind env vars can override the contents of the config file
There was a problem hiding this comment.
That's why I add the parsed config file above: https://github.com/DataDog/datadog-agent/pull/282/files/4001c64157dab3f0c7d532c1f2741afd7d88fb6a#diff-9e878f3fd97d7fc945eb0efd548b865bR68
| // 'Are you sure you want to continue [y/N]? ' | ||
|
|
||
| func askForInput(before string, after string) (string, error) { | ||
| reader := bufio.NewReader(os.Stdin) |
There was a problem hiding this comment.
What about using a scanner instead (https://golang.org/pkg/bufio/#Scanner)? This way we could set a reasonable buffer and avoid overflow attacks (I know the threat is very little but this way we show we care about security).
There was a problem hiding this comment.
Sure, we can do that
masci
left a comment
There was a problem hiding this comment.
took another pass trying to identify critical paths, I still think the PR is good but left few comments on something I didn't notice on the first pass
|
I created a second test and made the command more robust. However, in making it more robust, I also ensured that it will create a flare even if there is nothing to put into the flare. Is this how it should work? |
masci
left a comment
There was a problem hiding this comment.
LGTM! Feel free to add here the support to checks.d config folders, pre-approving the review in case you want to do it in a separate PR
|
|
||
| err = filepath.Walk(config.Datadog.GetString("confd_path"), func(path string, f os.FileInfo, err error) error { | ||
| if f.IsDir() { | ||
| return nil |
There was a problem hiding this comment.
The file Configuration Provider does this: https://github.com/DataDog/datadog-agent/blob/master/pkg/collector/providers/file.go#L113
|
|
…s a config option or an env var (#282) * allowing for implicit auth to be set as a config option or an env var * addressed comments
What does this PR do?
This creates a flare and sends it up to Datadog.
Additional Notes
Not everything is implemented. This is a first stab at the flare command. The info command is not yet implemented, so that will not yet work. The goexpvar is not output into the flare. The autoconf is not output into the flare. These will all need to be implemented in the final product.
I have some tests, we'll likely want to write more. My tests just check that the files are properly stripped and that an archive is created. I think we'll likely want to test the archive that's created as well (that's a more involved process than can be accomplished in a unit test).
We will need to do a lot of resiliancy testing to ensure that it will always work.
It needs to be tested on Windows.
I added something new as well. In addition to zipping up all the files, it will dump the in memory config out into its own file. (Viper has a wonderful ability to do this.)
One other deviation is that I run the full cleaner against every file, rather than having cleaners for config files and the root config file be different. Since we've unified a lot of the structure of the settings, this makes sense to do.
I do not use the logger for the flare. I use regular print statements, as they are more natural for this kind of output than logging output. There is very little output for the flare.
However, it works and zips up all we have right now!