diff --git a/changelog/fragments/1759335344-fix-troubleshooting-message-url-for-versions-after-9.yaml b/changelog/fragments/1759335344-fix-troubleshooting-message-url-for-versions-after-9.yaml new file mode 100644 index 00000000000..2883c5388d9 --- /dev/null +++ b/changelog/fragments/1759335344-fix-troubleshooting-message-url-for-versions-after-9.yaml @@ -0,0 +1,42 @@ +# REQUIRED +# 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: bug-fix + +# REQUIRED for all kinds +# Change summary; a 80ish characters long description of the change. +summary: Fix troubleshooting docs URL for 9.x+ to prevent invalid version links +# this field accommodate a description without length limits. +# description: + +# REQUIRED for breaking-change, deprecation, known-issue +# impact: + +# REQUIRED for breaking-change, deprecation, known-issue +# action: + +# REQUIRED for all kinds +# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc. +component: elastic-agent + +# AUTOMATED +# OPTIONAL to manually add other PR URLs +# PR URL: A link the PR 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/owner/repo/1234 + +# AUTOMATED +# OPTIONAL to manually add other issue URLs +# 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 diff --git a/internal/pkg/agent/cmd/apply_flavor.go b/internal/pkg/agent/cmd/apply_flavor.go index f184df21185..d5051a3cb5c 100644 --- a/internal/pkg/agent/cmd/apply_flavor.go +++ b/internal/pkg/agent/cmd/apply_flavor.go @@ -24,7 +24,7 @@ func newApplyFlavorCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Co Short: "Apply Flavor cleans up unnecessary components from agent installation directory", Run: func(c *cobra.Command, _ []string) { if err := applyCmd(); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) logExternal(fmt.Sprintf("%s apply flavor failed: %s", paths.BinaryName, err)) os.Exit(1) } diff --git a/internal/pkg/agent/cmd/common.go b/internal/pkg/agent/cmd/common.go index 0bec7dc3540..e3d8cdf0968 100644 --- a/internal/pkg/agent/cmd/common.go +++ b/internal/pkg/agent/cmd/common.go @@ -6,9 +6,7 @@ package cmd import ( "flag" - "fmt" "os" - "strings" "github.com/spf13/cobra" @@ -17,15 +15,12 @@ import ( "github.com/elastic/elastic-agent/internal/pkg/basecmd" "github.com/elastic/elastic-agent/internal/pkg/cli" - "github.com/elastic/elastic-agent/internal/pkg/release" "github.com/elastic/elastic-agent/version" ) -func troubleshootMessage() string { - v := strings.Split(release.Version(), ".") - version := strings.Join(v[:2], ".") - return fmt.Sprintf("For help, please see our troubleshooting guide at https://www.elastic.co/guide/en/fleet/%s/fleet-troubleshooting.html", version) -} +const ( + troubleshootMessage = "For help, please see our troubleshooting guide at https://www.elastic.co/docs/troubleshoot/ingest/fleet/common-problems" +) // NewCommand returns the default command for the agent. func NewCommand() *cobra.Command { diff --git a/internal/pkg/agent/cmd/container.go b/internal/pkg/agent/cmd/container.go index e43a3145283..32021ed4f6f 100644 --- a/internal/pkg/agent/cmd/container.go +++ b/internal/pkg/agent/cmd/container.go @@ -168,7 +168,7 @@ occurs on every start of the container set FLEET_FORCE to 1. } func logError(streams *cli.IOStreams, err error) { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) } func logInfo(streams *cli.IOStreams, a ...interface{}) { @@ -409,7 +409,7 @@ func ensureServiceToken(streams *cli.IOStreams, cfg *setupConfig) error { if err != nil { return err } - code, r, err := client.Connection.Request("POST", "/api/fleet/service_tokens", nil, nil, nil) + code, r, err := client.Request("POST", "/api/fleet/service_tokens", nil, nil, nil) if err != nil { return fmt.Errorf("request to get security token from Kibana failed: %w", err) } @@ -712,14 +712,14 @@ func isTrue(val string) bool { func performGET(cfg setupConfig, client *kibana.Client, path string, response interface{}, writer io.Writer, msg string) error { var lastErr error for i := 0; i < cfg.Kibana.RetryMaxCount; i++ { - code, result, err := client.Connection.Request("GET", path, nil, nil, nil) + code, result, err := client.Request("GET", path, nil, nil, nil) if err != nil || code != 200 { if err != nil { err = fmt.Errorf("http GET request to %s%s fails: %w. Response: %s", - client.Connection.URL, path, err, truncateString(result)) + client.URL, path, err, truncateString(result)) } else { err = fmt.Errorf("http GET request to %s%s fails. StatusCode: %d Response: %s", - client.Connection.URL, path, code, truncateString(result)) + client.URL, path, code, truncateString(result)) } fmt.Fprintf(writer, "%s failed: %s\n", msg, err) <-time.After(cfg.Kibana.RetrySleepDuration) @@ -740,7 +740,7 @@ func truncateString(b []byte) string { runes = append(runes[:maxLength], []rune("... (truncated)")...) } - return strings.Replace(string(runes), "\n", " ", -1) + return strings.ReplaceAll(string(runes), "\n", " ") } // runLegacyAPMServer extracts the bundled apm-server from elastic-agent diff --git a/internal/pkg/agent/cmd/diagnostics.go b/internal/pkg/agent/cmd/diagnostics.go index ef13a4704a2..b9bb8317718 100644 --- a/internal/pkg/agent/cmd/diagnostics.go +++ b/internal/pkg/agent/cmd/diagnostics.go @@ -28,7 +28,7 @@ func newDiagnosticsCommand(_ []string, streams *cli.IOStreams) *cobra.Command { Long: "This command gathers diagnostics information from the Elastic Agent and writes it to a zip archive.", Run: func(c *cobra.Command, args []string) { if err := diagnosticCmd(streams, c); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) os.Exit(1) } }, diff --git a/internal/pkg/agent/cmd/enroll.go b/internal/pkg/agent/cmd/enroll.go index 3b0248fec1e..0fc2c63fa17 100644 --- a/internal/pkg/agent/cmd/enroll.go +++ b/internal/pkg/agent/cmd/enroll.go @@ -43,7 +43,7 @@ func newEnrollCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command Long: "This command will enroll the Elastic Agent into Fleet.", Run: func(c *cobra.Command, args []string) { if err := enroll(streams, c); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) logExternal(fmt.Sprintf("%s enroll failed: %s", paths.BinaryName, err)) os.Exit(1) } diff --git a/internal/pkg/agent/cmd/inspect.go b/internal/pkg/agent/cmd/inspect.go index b71096626f1..76958dc0983 100644 --- a/internal/pkg/agent/cmd/inspect.go +++ b/internal/pkg/agent/cmd/inspect.go @@ -58,7 +58,7 @@ wait that amount of time before using the variables for the configuration. ctx, cancel := context.WithCancel(context.Background()) service.HandleSignals(func() {}, cancel) if err := inspectConfig(ctx, paths.ConfigFile(), opts, streams); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) os.Exit(1) } }, @@ -111,7 +111,7 @@ variables for the configuration. service.HandleSignals(func() {}, cancel) if err := inspectComponents(ctx, paths.ConfigFile(), opts, streams); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) os.Exit(1) } }, diff --git a/internal/pkg/agent/cmd/install.go b/internal/pkg/agent/cmd/install.go index 9e48532c9ae..8c4ff4e941e 100644 --- a/internal/pkg/agent/cmd/install.go +++ b/internal/pkg/agent/cmd/install.go @@ -49,7 +49,7 @@ would like the Agent to operate. `, Run: func(c *cobra.Command, _ []string) { if err := installCmd(streams, c); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) logExternal(fmt.Sprintf("%s install failed: %s", paths.BinaryName, err)) os.Exit(1) } diff --git a/internal/pkg/agent/cmd/logs.go b/internal/pkg/agent/cmd/logs.go index 76978057de5..21009602d99 100644 --- a/internal/pkg/agent/cmd/logs.go +++ b/internal/pkg/agent/cmd/logs.go @@ -170,7 +170,7 @@ func newLogsCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command { Long: "This command allows to output, watch and filter Elastic Agent logs.", Run: func(c *cobra.Command, _ []string) { if err := logsCmd(streams, c, logsDir, eventLogsDir); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) os.Exit(1) } }, diff --git a/internal/pkg/agent/cmd/privileged.go b/internal/pkg/agent/cmd/privileged.go index 2d462ec16d9..29b4a611d32 100644 --- a/internal/pkg/agent/cmd/privileged.go +++ b/internal/pkg/agent/cmd/privileged.go @@ -34,7 +34,7 @@ privileged it will still perform all the same work, including stopping and start Args: cobra.ExactArgs(0), Run: func(c *cobra.Command, args []string) { if err := privilegedCmd(streams, c); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) os.Exit(1) } }, diff --git a/internal/pkg/agent/cmd/reexec_windows.go b/internal/pkg/agent/cmd/reexec_windows.go index 9b9a727cf9f..e0322a264bb 100644 --- a/internal/pkg/agent/cmd/reexec_windows.go +++ b/internal/pkg/agent/cmd/reexec_windows.go @@ -37,7 +37,7 @@ func newReExecWindowsCommand(_ []string, streams *cli.IOStreams) *cobra.Command cfg := getConfig(streams) log, err := configuredLogger(cfg, reexecName) if err != nil { - fmt.Fprintf(streams.Err, "Error configuring logger: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error configuring logger: %v\n%s\n", err, troubleshootMessage) os.Exit(3) } diff --git a/internal/pkg/agent/cmd/run.go b/internal/pkg/agent/cmd/run.go index ea4186c6465..7f8c189380d 100644 --- a/internal/pkg/agent/cmd/run.go +++ b/internal/pkg/agent/cmd/run.go @@ -87,7 +87,7 @@ func newRunCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command { fleetInitTimeout, _ := cmd.Flags().GetDuration("fleet-init-timeout") testingMode, _ := cmd.Flags().GetBool("testing-mode") if err := run(nil, testingMode, fleetInitTimeout); err != nil && !errors.Is(err, context.Canceled) { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) return err } return nil @@ -351,7 +351,7 @@ func runElasticAgent( return err } - monitoringServer, err := setupMetrics(l, cfg.Settings.DownloadConfig.OS(), cfg.Settings.MonitoringConfig, tracer, coord) + monitoringServer, err := setupMetrics(l, cfg.Settings.MonitoringConfig, tracer, coord) if err != nil { return err } @@ -710,7 +710,6 @@ func initTracer(agentName, version string, mcfg *monitoringCfg.MonitoringConfig) func setupMetrics( logger *logger.Logger, - operatingSystem string, cfg *monitoringCfg.MonitoringConfig, tracer *apm.Tracer, coord *coordinator.Coordinator, diff --git a/internal/pkg/agent/cmd/status.go b/internal/pkg/agent/cmd/status.go index d9c82359462..e014a48852b 100644 --- a/internal/pkg/agent/cmd/status.go +++ b/internal/pkg/agent/cmd/status.go @@ -44,7 +44,7 @@ func newStatusCommand(_ []string, streams *cli.IOStreams) *cobra.Command { Long: `This command shows the current status of the running Elastic Agent daemon.`, Run: func(c *cobra.Command, args []string) { if err := statusCmd(streams, c, args); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) os.Exit(1) } }, diff --git a/internal/pkg/agent/cmd/uninstall.go b/internal/pkg/agent/cmd/uninstall.go index a83df2e6055..fca0bc47f2b 100644 --- a/internal/pkg/agent/cmd/uninstall.go +++ b/internal/pkg/agent/cmd/uninstall.go @@ -28,7 +28,7 @@ Unless -f is used this command will ask confirmation before performing removal. `, Run: func(c *cobra.Command, _ []string) { if err := uninstallCmd(streams, c); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) logExternal(fmt.Sprintf("%s uninstall failed: %s", paths.BinaryName, err)) os.Exit(1) } diff --git a/internal/pkg/agent/cmd/unprivileged.go b/internal/pkg/agent/cmd/unprivileged.go index a6d7ea70f06..95a108d208c 100644 --- a/internal/pkg/agent/cmd/unprivileged.go +++ b/internal/pkg/agent/cmd/unprivileged.go @@ -36,7 +36,7 @@ unprivileged it will still perform all the same work, including stopping and sta Args: cobra.ExactArgs(0), Run: func(c *cobra.Command, args []string) { if err := unprivilegedCmd(streams, c); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) os.Exit(1) } }, diff --git a/internal/pkg/agent/cmd/upgrade.go b/internal/pkg/agent/cmd/upgrade.go index c944133e288..f7c94c80907 100644 --- a/internal/pkg/agent/cmd/upgrade.go +++ b/internal/pkg/agent/cmd/upgrade.go @@ -51,7 +51,7 @@ func newUpgradeCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Comman Run: func(c *cobra.Command, args []string) { c.SetContext(context.Background()) if err := upgradeCmd(streams, c, args); err != nil { - fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error: %v\n%s\n", err, troubleshootMessage) os.Exit(1) } }, diff --git a/internal/pkg/agent/cmd/watch.go b/internal/pkg/agent/cmd/watch.go index 037c01a91d0..c9400b6628f 100644 --- a/internal/pkg/agent/cmd/watch.go +++ b/internal/pkg/agent/cmd/watch.go @@ -46,7 +46,7 @@ func newWatchCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command cfg := getConfig(streams) log, err := configuredLogger(cfg, watcherName) if err != nil { - fmt.Fprintf(streams.Err, "Error configuring logger: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Error configuring logger: %v\n%s\n", err, troubleshootMessage) os.Exit(3) } @@ -55,7 +55,7 @@ func newWatchCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command if err := watchCmd(log, cfg); err != nil { log.Errorw("Watch command failed", "error.message", err) - fmt.Fprintf(streams.Err, "Watch command failed: %v\n%s\n", err, troubleshootMessage()) + fmt.Fprintf(streams.Err, "Watch command failed: %v\n%s\n", err, troubleshootMessage) os.Exit(4) } },