Skip to content

Commit a53becf

Browse files
[9.0] (backport #10218) Fix troubleshooting message URL for versions after 9.x (#10477)
* 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 * Solve conflicts * Solve lint issues --------- Co-authored-by: Stefan Traistaru <[email protected]>
1 parent 2cb6cad commit a53becf

17 files changed

+68
-32
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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ occurs on every start of the container set FLEET_FORCE to 1.
168168
}
169169

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

174174
func logInfo(streams *cli.IOStreams, a ...interface{}) {
@@ -409,7 +409,7 @@ func ensureServiceToken(streams *cli.IOStreams, cfg *setupConfig) error {
409409
if err != nil {
410410
return err
411411
}
412-
code, r, err := client.Connection.Request("POST", "/api/fleet/service_tokens", nil, nil, nil)
412+
code, r, err := client.Request("POST", "/api/fleet/service_tokens", nil, nil, nil)
413413
if err != nil {
414414
return fmt.Errorf("request to get security token from Kibana failed: %w", err)
415415
}
@@ -712,14 +712,14 @@ func isTrue(val string) bool {
712712
func performGET(cfg setupConfig, client *kibana.Client, path string, response interface{}, writer io.Writer, msg string) error {
713713
var lastErr error
714714
for i := 0; i < cfg.Kibana.RetryMaxCount; i++ {
715-
code, result, err := client.Connection.Request("GET", path, nil, nil, nil)
715+
code, result, err := client.Request("GET", path, nil, nil, nil)
716716
if err != nil || code != 200 {
717717
if err != nil {
718718
err = fmt.Errorf("http GET request to %s%s fails: %w. Response: %s",
719-
client.Connection.URL, path, err, truncateString(result))
719+
client.URL, path, err, truncateString(result))
720720
} else {
721721
err = fmt.Errorf("http GET request to %s%s fails. StatusCode: %d Response: %s",
722-
client.Connection.URL, path, code, truncateString(result))
722+
client.URL, path, code, truncateString(result))
723723
}
724724
fmt.Fprintf(writer, "%s failed: %s\n", msg, err)
725725
<-time.After(cfg.Kibana.RetrySleepDuration)
@@ -740,7 +740,7 @@ func truncateString(b []byte) string {
740740
runes = append(runes[:maxLength], []rune("... (truncated)")...)
741741
}
742742

743-
return strings.Replace(string(runes), "\n", " ", -1)
743+
return strings.ReplaceAll(string(runes), "\n", " ")
744744
}
745745

746746
// runLegacyAPMServer extracts the bundled apm-server from elastic-agent

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
},

internal/pkg/agent/cmd/enroll.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func newEnrollCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command
4343
Long: "This command will enroll the Elastic Agent into Fleet.",
4444
Run: func(c *cobra.Command, args []string) {
4545
if err := enroll(streams, c); err != nil {
46-
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage())
46+
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage)
4747
logExternal(fmt.Sprintf("%s enroll failed: %s", paths.BinaryName, err))
4848
os.Exit(1)
4949
}

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
},

internal/pkg/agent/cmd/privileged.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ privileged it will still perform all the same work, including stopping and start
3434
Args: cobra.ExactArgs(0),
3535
Run: func(c *cobra.Command, args []string) {
3636
if err := privilegedCmd(streams, c); err != nil {
37-
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage())
37+
fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage)
3838
os.Exit(1)
3939
}
4040
},

0 commit comments

Comments
 (0)