Skip to content

Commit e6e976f

Browse files
straistarumergify[bot]
authored andcommitted
Fix troubleshooting message URL for versions after 9.x (#10218)
* Fix troubleshooting message URL for versions after 9.x * Add changelog fragment * Change troubleshoot message to a const variable * Fix build issue created by the merge * Fix linter issue * Revert linter fix and add nolint comment (cherry picked from commit b74942a) # Conflicts: # internal/pkg/agent/cmd/diagnostics_otel.go # internal/pkg/agent/cmd/enroll.go
1 parent 68d42da commit e6e976f

18 files changed

+181
-27
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# REQUIRED
2+
# Kind can be one of:
3+
# - breaking-change: a change to previously-documented behavior
4+
# - deprecation: functionality that is being removed in a later release
5+
# - bug-fix: fixes a problem in a previous version
6+
# - enhancement: extends functionality but does not break or fix existing behavior
7+
# - feature: new functionality
8+
# - known-issue: problems that we are aware of in a given version
9+
# - security: impacts on the security of a product or a user’s deployment.
10+
# - upgrade: important information for someone upgrading from a prior version
11+
# - other: does not fit into any of the other categories
12+
kind: bug-fix
13+
14+
# REQUIRED for all kinds
15+
# Change summary; a 80ish characters long description of the change.
16+
summary: Fix troubleshooting docs URL for 9.x+ to prevent invalid version links
17+
# this field accommodate a description without length limits.
18+
# description:
19+
20+
# REQUIRED for breaking-change, deprecation, known-issue
21+
# impact:
22+
23+
# REQUIRED for breaking-change, deprecation, known-issue
24+
# action:
25+
26+
# REQUIRED for all kinds
27+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
28+
component: elastic-agent
29+
30+
# AUTOMATED
31+
# OPTIONAL to manually add other PR URLs
32+
# PR URL: A link the PR that added the changeset.
33+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
34+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
35+
# Please provide it if you are adding a fragment for a different PR.
36+
# pr: https://github.com/owner/repo/1234
37+
38+
# AUTOMATED
39+
# OPTIONAL to manually add other issue URLs
40+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
41+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
42+
# issue: https://github.com/owner/repo/1234

internal/pkg/agent/cmd/apply_flavor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func newApplyFlavorCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Co
2424
Short: "Apply Flavor cleans up unnecessary components from agent installation directory",
2525
Run: func(c *cobra.Command, _ []string) {
2626
if err := applyCmd(); err != nil {
27-
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage())
27+
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage)
2828
logExternal(fmt.Sprintf("%s apply flavor failed: %s", paths.BinaryName, err))
2929
os.Exit(1)
3030
}

internal/pkg/agent/cmd/common.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ package cmd
66

77
import (
88
"flag"
9-
"fmt"
109
"os"
11-
"strings"
1210

1311
"github.com/spf13/cobra"
1412

@@ -17,15 +15,12 @@ import (
1715

1816
"github.com/elastic/elastic-agent/internal/pkg/basecmd"
1917
"github.com/elastic/elastic-agent/internal/pkg/cli"
20-
"github.com/elastic/elastic-agent/internal/pkg/release"
2118
"github.com/elastic/elastic-agent/version"
2219
)
2320

24-
func troubleshootMessage() string {
25-
v := strings.Split(release.Version(), ".")
26-
version := strings.Join(v[:2], ".")
27-
return fmt.Sprintf("For help, please see our troubleshooting guide at https://www.elastic.co/guide/en/fleet/%s/fleet-troubleshooting.html", version)
28-
}
21+
const (
22+
troubleshootMessage = "For help, please see our troubleshooting guide at https://www.elastic.co/docs/troubleshoot/ingest/fleet/common-problems"
23+
)
2924

3025
// NewCommand returns the default command for the agent.
3126
func NewCommand() *cobra.Command {

internal/pkg/agent/cmd/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ occurs on every start of the container set FLEET_FORCE to 1.
169169
}
170170

171171
func logError(streams *cli.IOStreams, err error) {
172-
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage())
172+
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage)
173173
}
174174

175175
func logInfo(streams *cli.IOStreams, a ...interface{}) {

internal/pkg/agent/cmd/diagnostics.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func newDiagnosticsCommand(_ []string, streams *cli.IOStreams) *cobra.Command {
2828
Long: "This command gathers diagnostics information from the Elastic Agent and writes it to a zip archive.",
2929
Run: func(c *cobra.Command, args []string) {
3030
if err := diagnosticCmd(streams, c); err != nil {
31-
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage())
31+
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage)
3232
os.Exit(1)
3333
}
3434
},
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2+
// or more contributor license agreements. Licensed under the Elastic License 2.0;
3+
// you may not use this file except in compliance with the Elastic License 2.0.
4+
5+
package cmd
6+
7+
import (
8+
"fmt"
9+
"os"
10+
"time"
11+
12+
"github.com/spf13/cobra"
13+
14+
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
15+
"github.com/elastic/elastic-agent/internal/pkg/cli"
16+
"github.com/elastic/elastic-agent/internal/pkg/diagnostics"
17+
"github.com/elastic/elastic-agent/internal/pkg/otel"
18+
"github.com/elastic/elastic-agent/pkg/control/v2/client"
19+
)
20+
21+
func newOtelDiagnosticsCommand(streams *cli.IOStreams) *cobra.Command {
22+
cmd := &cobra.Command{
23+
Use: "diagnostics",
24+
Short: "Gather diagnostics information from the EDOT and write it to a zip archive",
25+
Long: "This command gathers diagnostics information from the EDOT and writes it to a zip archive",
26+
RunE: func(cmd *cobra.Command, _ []string) error {
27+
if err := otelDiagnosticCmd(streams, cmd); err != nil {
28+
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage)
29+
os.Exit(1)
30+
}
31+
return nil
32+
},
33+
SilenceUsage: true,
34+
SilenceErrors: true,
35+
}
36+
cmd.Flags().StringP("file", "f", "", "name of the output diagnostics zip archive")
37+
cmd.Flags().BoolP("cpu-profile", "p", false, "wait to collect a CPU profile")
38+
return cmd
39+
}
40+
41+
func otelDiagnosticCmd(streams *cli.IOStreams, cmd *cobra.Command) error {
42+
cpuProfile, _ := cmd.Flags().GetBool("cpu-profile")
43+
resp, err := otel.PerformDiagnosticsExt(cmd.Context(), cpuProfile)
44+
if err != nil {
45+
return fmt.Errorf("failed to get edot diagnostics: %w", err)
46+
}
47+
48+
agentDiag := make([]client.DiagnosticFileResult, 0)
49+
for _, r := range resp.GlobalDiagnostics {
50+
agentDiag = append(agentDiag, client.DiagnosticFileResult{
51+
Name: r.Name,
52+
Filename: r.Filename,
53+
ContentType: r.ContentType,
54+
Content: r.Content,
55+
Description: r.Description,
56+
})
57+
}
58+
59+
componentDiag := make([]client.DiagnosticComponentResult, 0)
60+
for _, r := range resp.ComponentDiagnostics {
61+
res := client.DiagnosticComponentResult{
62+
Results: make([]client.DiagnosticFileResult, 0),
63+
}
64+
res.Results = append(res.Results, client.DiagnosticFileResult{
65+
Name: r.Name,
66+
Filename: r.Filename,
67+
ContentType: r.ContentType,
68+
Content: r.Content,
69+
Description: r.Description,
70+
})
71+
res.ComponentID = r.Name
72+
componentDiag = append(componentDiag, res)
73+
}
74+
componentDiag = aggregateComponentDiagnostics(componentDiag)
75+
76+
filepath, _ := cmd.Flags().GetString("file")
77+
if filepath == "" {
78+
ts := time.Now().UTC()
79+
filepath = "edot-diagnostics-" + ts.Format("2006-01-02T15-04-05Z07-00") + ".zip" // RFC3339 format that replaces : with -, so it will work on Windows
80+
}
81+
f, err := createFile(filepath)
82+
if err != nil {
83+
return fmt.Errorf("could not create diagnostics file %q: %w", filepath, err)
84+
}
85+
defer f.Close()
86+
87+
// In EDOT, the logs path does not exist, so we ignore that error.
88+
if err := diagnostics.ZipArchive(streams.Err, f, paths.Top(), agentDiag, nil, componentDiag, false); err != nil && !os.IsNotExist(err) {
89+
return fmt.Errorf("unable to create archive %q: %w", filepath, err)
90+
}
91+
fmt.Fprintf(streams.Out, "Created diagnostics archive %q\n", filepath)
92+
fmt.Fprintln(streams.Out, "** WARNING **\nCreated archive may contain plain text credentials.\nEnsure that files in archive are redacted before sharing.\n*******")
93+
return nil
94+
}
95+
96+
// aggregateComponentDiagnostics takes a slice of DiagnosticComponentResult and merges
97+
// results for components with the same ComponentID.
98+
func aggregateComponentDiagnostics(diags []client.DiagnosticComponentResult) []client.DiagnosticComponentResult {
99+
m := make(map[string]client.DiagnosticComponentResult)
100+
for _, d := range diags {
101+
if existing, ok := m[d.ComponentID]; ok {
102+
existing.Results = append(existing.Results, d.Results...)
103+
m[d.ComponentID] = existing
104+
} else {
105+
m[d.ComponentID] = d
106+
}
107+
}
108+
result := make([]client.DiagnosticComponentResult, 0, len(m))
109+
for _, v := range m {
110+
result = append(result, v)
111+
}
112+
return result
113+
}

internal/pkg/agent/cmd/enroll.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ func newEnrollCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command
4343
Short: "Enroll the Elastic Agent into Fleet",
4444
Long: "This command will enroll the Elastic Agent into Fleet.",
4545
Run: func(c *cobra.Command, args []string) {
46+
<<<<<<< HEAD
4647
if err := enroll(streams, c); err != nil {
4748
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage())
49+
=======
50+
if err := doEnroll(streams, c); err != nil {
51+
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage)
52+
>>>>>>> b74942add (Fix troubleshooting message URL for versions after 9.x (#10218))
4853
logExternal(fmt.Sprintf("%s enroll failed: %s", paths.BinaryName, err))
4954
os.Exit(1)
5055
}

internal/pkg/agent/cmd/inspect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ wait that amount of time before using the variables for the configuration.
5858
ctx, cancel := context.WithCancel(context.Background())
5959
service.HandleSignals(func() {}, cancel)
6060
if err := inspectConfig(ctx, paths.ConfigFile(), opts, streams); err != nil {
61-
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage())
61+
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage)
6262
os.Exit(1)
6363
}
6464
},
@@ -111,7 +111,7 @@ variables for the configuration.
111111
service.HandleSignals(func() {}, cancel)
112112

113113
if err := inspectComponents(ctx, paths.ConfigFile(), opts, streams); err != nil {
114-
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage())
114+
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage)
115115
os.Exit(1)
116116
}
117117
},

internal/pkg/agent/cmd/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ would like the Agent to operate.
4949
`,
5050
Run: func(c *cobra.Command, _ []string) {
5151
if err := installCmd(streams, c); err != nil {
52-
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage())
52+
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage)
5353
logExternal(fmt.Sprintf("%s install failed: %s", paths.BinaryName, err))
5454
os.Exit(1)
5555
}

internal/pkg/agent/cmd/logs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func newLogsCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command {
170170
Long: "This command allows to output, watch and filter Elastic Agent logs.",
171171
Run: func(c *cobra.Command, _ []string) {
172172
if err := logsCmd(streams, c, logsDir, eventLogsDir); err != nil {
173-
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage())
173+
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage)
174174
os.Exit(1)
175175
}
176176
},

0 commit comments

Comments
 (0)