Skip to content

Adds Flare Command#282

Merged
gmmeyer merged 29 commits intomasterfrom
greg/flare
Jun 16, 2017
Merged

Adds Flare Command#282
gmmeyer merged 29 commits intomasterfrom
greg/flare

Conversation

@gmmeyer
Copy link
Copy Markdown
Contributor

@gmmeyer gmmeyer commented Jun 7, 2017

What does this PR do?

This creates a flare and sends it up to Datadog.

Additional Notes

  1. 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.

  2. 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).

  3. We will need to do a lot of resiliancy testing to ensure that it will always work.

  4. It needs to be tested on Windows.

  5. 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.)

  6. 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.

  7. 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!

@gmmeyer gmmeyer changed the title [WIP] Flare Adds Flare Command Jun 11, 2017
@gmmeyer gmmeyer force-pushed the greg/flare branch 2 times, most recently from 1e127e8 to d509c84 Compare June 12, 2017 20:00
Copy link
Copy Markdown
Contributor

@masci masci left a comment

Choose a reason for hiding this comment

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

Left few comments, some of them might be because this is somehow still WIP so feel free to ignore.

Comment thread cmd/agent/api/agent/agent.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is reading/decoding the request body needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is not since I am no longer sending the flare from the agent side but rather from the client side.

Comment thread cmd/agent/api/agent/agent.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea. I will do that.

Comment thread cmd/agent/app/flare.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: can you wrap all the declarations in a var() block?

Comment thread cmd/agent/app/flare.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So long, my shrug friend! 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can keep it if you'd like ¯_(ツ)_/¯

Comment thread cmd/agent/app/flare.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could print the error contained in the response body here

Comment thread cmd/agent/app/flare.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SendFlare could be invoked by the IPC api as well, through a new endpoint like agent/flare/send or similar

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes it could, do you think we should do this? I am not adverse to this idea.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't have a strong opinion and don't want to add too much to this PR, we can just keep this in mind

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made some adjustments that will allow it to do that!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't write that into it yet, but I abstracted a few things out that will make it easier to do

Comment thread pkg/util/flare/flare.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: no need to export this function I guess

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right!

Comment thread cmd/agent/app/flare.go
} else {
fmt.Println("The agent was unable to make the flare.")
}
fmt.Println("Initiating flare locally.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a good idea to me.

Comment thread pkg/util/flare/archive.go
@@ -0,0 +1,140 @@
package flare
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the package is specific enough to live in pkg/flare, same level as (for example) version and pidfile.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll move it out there

Comment thread pkg/util/flare/archive.go Outdated

err = filepath.Walk(config.Datadog.GetString("confd_path"), func(path string, f os.FileInfo, err error) error {
if f.IsDir() {
return nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread pkg/util/flare/archive.go
return err
}

if config.Datadog.ConfigFileUsed() != "" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should keep in mind env vars can override the contents of the config file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread pkg/util/flare/input.go Outdated
// 'Are you sure you want to continue [y/N]? '

func askForInput(before string, after string) (string, error) {
reader := bufio.NewReader(os.Stdin)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, we can do that

Copy link
Copy Markdown
Contributor

@masci masci left a comment

Choose a reason for hiding this comment

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

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

@gmmeyer
Copy link
Copy Markdown
Contributor Author

gmmeyer commented Jun 15, 2017

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?

Copy link
Copy Markdown
Contributor

@masci masci left a comment

Choose a reason for hiding this comment

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

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

Comment thread pkg/util/flare/archive.go Outdated

err = filepath.Walk(config.Datadog.GetString("confd_path"), func(path string, f os.FileInfo, err error) error {
if f.IsDir() {
return nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@masci
Copy link
Copy Markdown
Contributor

masci commented Jun 16, 2017

:shipit: !

@gmmeyer gmmeyer merged commit bb9a051 into master Jun 16, 2017
@gmmeyer gmmeyer deleted the greg/flare branch June 16, 2017 18:39
s-alad pushed a commit that referenced this pull request Jan 6, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants