Skip to content

Commit

Permalink
Merge branch 'main' into kustomizepoc
Browse files Browse the repository at this point in the history
  • Loading branch information
gizas authored Jun 19, 2024
2 parents d1a2837 + 33598b6 commit 0010ae3
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 179 deletions.
4 changes: 2 additions & 2 deletions .buildkite/pull-requests.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"pipelineSlug": "elastic-agent-package",
"allow_org_users": true,
"allowed_repo_permissions": ["admin", "write"],
"allowed_list": [],
"allowed_list": ["dependabot[bot]", "mergify[bot]"],
"set_commit_status": false,
"build_on_commit": false,
"build_on_comment": true,
Expand All @@ -37,7 +37,7 @@
"pipelineSlug": "elastic-agent-binary-dra",
"allow_org_users": true,
"allowed_repo_permissions": ["admin", "write"],
"allowed_list": [],
"allowed_list": ["dependabot[bot]", "mergify[bot]"],
"set_commit_status": false,
"build_on_commit": false,
"build_on_comment": true,
Expand Down
32 changes: 32 additions & 0 deletions changelog/fragments/1718660806-Add-diagnostics-skip-conn-flag.yaml
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
4 changes: 4 additions & 0 deletions internal/pkg/agent/application/gateway/fleet/fleet_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ func (f *FleetGateway) execute(ctx context.Context) (*fleetapi.CheckinResponse,
// convert components into checkin components structure
components := f.convertToCheckinComponents(state.Components)

f.log.Debugf("correcting agent loglevel from %s to %s using coordinator state", ecsMeta.Elastic.Agent.LogLevel, state.LogLevel.String())
// Fix loglevel with the current log level used by coordinator
ecsMeta.Elastic.Agent.LogLevel = state.LogLevel.String()

// checkin
cmd := fleetapi.NewCheckinCmd(f.agentInfo, f.client)
req := &fleetapi.CheckinRequest{
Expand Down
4 changes: 4 additions & 0 deletions internal/pkg/agent/application/info/agent_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func TestECSMetadata(t *testing.T) {
metadata, err := agentInfo.ECSMetadata(l)
require.NoError(t, err)

if assert.NotNil(t, metadata.Elastic, "metadata.Elastic must not be nil") {
assert.NotNil(t, metadata.Elastic.Agent, "metadata.Elastic.Agent must not be nil")
}

sysInfo, err := sysinfo.Host()
require.NoError(t, err)

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.

Loading

0 comments on commit 0010ae3

Please sign in to comment.