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

AMLII-1647 Added duration to Flare's stream-logs #25507

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions cmd/agent/subcommands/flare/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type cliParams struct {
profileMutexFraction int
profileBlocking bool
profileBlockingRate int
withStreamLog bool
withStreamLogs time.Duration
}

// Commands returns a slice of subcommands for the 'agent' command.
Expand Down Expand Up @@ -152,7 +152,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
flareCmd.Flags().IntVarP(&cliParams.profileMutexFraction, "profile-mutex-fraction", "", 100, "Set the fraction of mutex contention events that are reported in the mutex profile")
flareCmd.Flags().BoolVarP(&cliParams.profileBlocking, "profile-blocking", "B", false, "Add gorouting blocking profile to the performance data in the flare")
flareCmd.Flags().IntVarP(&cliParams.profileBlockingRate, "profile-blocking-rate", "", 10000, "Set the fraction of goroutine blocking events that are reported in the blocking profile")
flareCmd.Flags().BoolVarP(&cliParams.withStreamLog, "with-stream-logs", "L", false, "Log 60s of the stream-logs command to the agent log file")
flareCmd.Flags().DurationVarP(&cliParams.withStreamLogs, "with-stream-logs", "L", 0*time.Second, "Add stream-logs data to the flare. It will collect logs for the amount of seconds passed to the flag")
flareCmd.SetArgs([]string{"caseID"})

return []*cobra.Command{flareCmd}
Expand Down Expand Up @@ -278,6 +278,16 @@ func makeFlare(flareComp flare.Component,
err error
)

streamLogParams := streamlogs.CliParams{
FilePath: commonpath.DefaultStreamlogsLogFile,
Duration: cliParams.withStreamLogs,
Quiet: true,
}

if streamLogParams.Duration < 0 {
fmt.Fprintln(color.Output, color.YellowString("Invalid duration provided for streaming logs, please provide a positive value"))
}

fmt.Fprintln(color.Output, color.BlueString("NEW: You can now generate a flare from the comfort of your Datadog UI!"))
fmt.Fprintln(color.Output, color.BlueString("See https://docs.datadoghq.com/agent/troubleshooting/send_a_flare/?tab=agentv6v7#send-a-flare-from-the-datadog-site for more info."))

Expand Down Expand Up @@ -342,14 +352,8 @@ func makeFlare(flareComp flare.Component,
return err
}

streamLogParams := streamlogs.CliParams{
FilePath: commonpath.DefaultStreamlogsLogFile,
Duration: 60 * time.Second, // default duration
Quiet: true,
}

if cliParams.withStreamLog {
fmt.Fprintln(color.Output, color.GreenString("Asking the agent to stream logs."))
if streamLogParams.Duration > 0 {
fmt.Fprintln(color.Output, color.GreenString((fmt.Sprintf("Asking the agent to stream logs for %s", streamLogParams.Duration))))
err := streamlogs.StreamLogs(lc, config, &streamLogParams)
if err != nil {
fmt.Fprintln(color.Output, color.RedString(fmt.Sprintf("Error streaming logs: %s", err)))
Expand Down
Loading