Skip to content

Commit

Permalink
Add conn param and conn-skip flag to diagnostics command
Browse files Browse the repository at this point in the history
Add CONN param to control protocol so the elastic-agent can use CONN as
an additional parameter when requesting diagnostics actions. The CONN
param will be used to execute the optional connection request
diagnostics and included by default. Add a conn-skip flag to the
diagnostics command that will not send the CONN param so request
diagnostics are skipped.
  • Loading branch information
michel-laterman committed Jun 17, 2024
1 parent bf9d488 commit cc0875d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 52 deletions.
1 change: 1 addition & 0 deletions control_v2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ message DiagnosticAgentRequest {
// DiagnosticAgentRequestAdditional is an enum of additional diagnostic metrics that can be requested from Elastic Agent.
enum AdditionalDiagnosticRequest {
CPU = 0;
CONN = 1;
}

// DiagnosticComponentsRequest is the message to request diagnostics from individual components.
Expand Down
11 changes: 8 additions & 3 deletions internal/pkg/agent/cmd/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func newDiagnosticsCommand(_ []string, streams *cli.IOStreams) *cobra.Command {

cmd.Flags().StringP("file", "f", "", "name of the output diagnostics zip archive")
cmd.Flags().BoolP("cpu-profile", "p", false, "wait to collect a CPU profile")
cmd.Flags().BoolP("conn-skip", "", false, "Skip connection request diagnostics")
cmd.Flags().Bool("exclude-events", false, "do not collect events log file")

return cmd
Expand Down Expand Up @@ -64,7 +65,8 @@ func diagnosticCmd(streams *cli.IOStreams, cmd *cobra.Command) error {
defer f.Close()

cpuProfile, _ := cmd.Flags().GetBool("cpu-profile")
agentDiag, unitDiags, compDiags, err := collectDiagnostics(ctx, streams, cpuProfile)
connSkip, _ := cmd.Flags().GetBool("cpu-profile")
agentDiag, unitDiags, compDiags, err := collectDiagnostics(ctx, streams, cpuProfile, connSkip)
if err != nil {
return fmt.Errorf("failed collecting diagnostics: %w", err)
}
Expand All @@ -77,7 +79,7 @@ func diagnosticCmd(streams *cli.IOStreams, cmd *cobra.Command) error {
return nil
}

func collectDiagnostics(ctx context.Context, streams *cli.IOStreams, cpuProfile bool) ([]client.DiagnosticFileResult, []client.DiagnosticUnitResult, []client.DiagnosticComponentResult, error) {
func collectDiagnostics(ctx context.Context, streams *cli.IOStreams, cpuProfile, connSkip bool) ([]client.DiagnosticFileResult, []client.DiagnosticUnitResult, []client.DiagnosticComponentResult, error) {
daemon := client.New()
err := daemon.Connect(ctx)
if err != nil {
Expand All @@ -86,10 +88,13 @@ func collectDiagnostics(ctx context.Context, streams *cli.IOStreams, cpuProfile
defer daemon.Disconnect()

var additionalDiags []cproto.AdditionalDiagnosticRequest
if !connSkip {
additionalDiags = append(additionalDiags, []cproto.AdditionalDiagnosticRequest{cproto.AdditionalDiagnosticRequest_CONN})
}
if cpuProfile {
// console will just hang while we wait for the CPU profile; print something so user doesn't get confused
fmt.Fprintf(streams.Out, "Creating diagnostics archive, waiting for CPU profile...\n")
additionalDiags = []cproto.AdditionalDiagnosticRequest{cproto.AdditionalDiagnosticRequest_CPU}
additionalDiags = append(additionalDiags, []cproto.AdditionalDiagnosticRequest{cproto.AdditionalDiagnosticRequest_CPU})
}

agentDiag, err := daemon.DiagnosticAgent(ctx, additionalDiags)
Expand Down
2 changes: 1 addition & 1 deletion pkg/control/v1/proto/control_v1.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/control/v1/proto/control_v1_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 50 additions & 46 deletions pkg/control/v2/cproto/control_v2.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/control/v2/cproto/control_v2_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cc0875d

Please sign in to comment.