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

Add conn param and conn-skip flag to diagnostics command #4946

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: enhancement

# Change summary; a 80ish characters long description of the change.
summary: Add diagnostics skip-conn flag

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
description: Add --skip-conn flag to elastic-agent diagnostics subcommand to skip collecting connection request diagnostics.

# Affected component; a word indicating the component this changeset affects.
component:

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
pr: https://github.com/elastic/elastic-agent/pull/4946

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
#issue: https://github.com/owner/repo/1234
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("skip-conn", "", 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("skip-conn")
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_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_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.