Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ linters:
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # Detects when assignments to existing variables are not used
- misspell # Finds commonly misspelled English words in comments
- perfsprint # replace uses of fmt.Sprintf and fmt.Errorf with better (both in CPU and memory) alternatives
- pkgconfigusage # Linter for checking usage of pkgconfig inside components folder
- revive # Revive is a replacement for golint, a coding style checker
- staticcheck # staticcheck is a go vet on steroids, applying a ton of static analysis checks
Expand Down
3 changes: 2 additions & 1 deletion cmd/agent/common/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package common

import (
"errors"
"fmt"
"os"
"os/user"
Expand Down Expand Up @@ -230,7 +231,7 @@ func copyFile(src, dst string, overwrite bool, transformations []TransformationF
return fmt.Errorf("unable to create a backup copy of the destination file: %v", err)
}
} else {
return fmt.Errorf("destination file already exists, run the command again with --force or -f to overwrite it")
return errors.New("destination file already exists, run the command again with --force or -f to overwrite it")
}
}

Expand Down
5 changes: 3 additions & 2 deletions cmd/agent/subcommands/analyzelogs/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package analyzelogs
import (
"context"
"encoding/json"
"errors"
"fmt"
"os"
"time"
Expand Down Expand Up @@ -72,7 +73,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
Long: `Run a Datadog agent logs configuration and print the results to stdout`,
RunE: func(_ *cobra.Command, args []string) error {
if len(args) < 1 {
return fmt.Errorf("log config file path is required")
return errors.New("log config file path is required")
}
cliParams.LogConfigPath = args[0]
return fxutil.OneShot(runAnalyzeLogs,
Expand Down Expand Up @@ -214,5 +215,5 @@ func resolveCheckConfig(ac autodiscovery.Component, cliParams *CliParams) ([]*so
}
return sources, nil
}
return nil, fmt.Errorf("Cannot get source")
return nil, errors.New("Cannot get source")
}
2 changes: 1 addition & 1 deletion cmd/agent/subcommands/dogstatsdcapture/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func dogstatsdCapture(_ log.Component, config config.Component, cliParams *cliPa
defer cancel()

md := metadata.MD{
"authorization": []string{fmt.Sprintf("Bearer %s", ipc.GetAuthToken())}, // TODO IPC: replace with GRPC Client
"authorization": []string{"Bearer " + ipc.GetAuthToken()}, // TODO IPC: replace with GRPC Client
}
ctx = metadata.NewOutgoingContext(ctx, md)

Expand Down
5 changes: 3 additions & 2 deletions cmd/agent/subcommands/dogstatsdreplay/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package dogstatsdreplay

import (
"context"
"errors"
"fmt"
"net"
"os"
Expand Down Expand Up @@ -95,7 +96,7 @@ func dogstatsdReplay(_ log.Component, config config.Component, cliParams *cliPar
fmt.Printf("Replaying dogstatsd traffic...\n\n")

md := metadata.MD{
"authorization": []string{fmt.Sprintf("Bearer %s", ipc.GetAuthToken())},
"authorization": []string{"Bearer " + ipc.GetAuthToken()},
}
ctx = metadata.NewOutgoingContext(ctx, md)

Expand Down Expand Up @@ -123,7 +124,7 @@ func dogstatsdReplay(_ log.Component, config config.Component, cliParams *cliPar

s := pkgconfigsetup.Datadog().GetString("dogstatsd_socket")
if s == "" {
return fmt.Errorf("Dogstatsd UNIX socket disabled")
return errors.New("Dogstatsd UNIX socket disabled")
}

addr, err := net.ResolveUnixAddr("unixgram", s)
Expand Down
3 changes: 2 additions & 1 deletion cmd/agent/subcommands/import/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package cmdimport

import (
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -56,7 +57,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {

func importCmd(cliParams *cliParams) error {
if len(cliParams.args) != 2 {
return fmt.Errorf("please provide all the required arguments")
return errors.New("please provide all the required arguments")
}

if cliParams.ConfFilePath != "" {
Expand Down
30 changes: 13 additions & 17 deletions cmd/agent/subcommands/integrations/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ You must specify a version of the package to install using the syntax: <package>
},
}
installCmd.Flags().BoolVarP(
&cliParams.localWheel, "local-wheel", "w", false, fmt.Sprintf("install an agent check from a locally available wheel file. %s", disclaimer),
&cliParams.localWheel, "local-wheel", "w", false, "install an agent check from a locally available wheel file. "+disclaimer,
)
installCmd.Flags().BoolVarP(
&cliParams.thirdParty, "third-party", "t", false, "install a community or vendor-contributed integration",
Expand Down Expand Up @@ -288,9 +288,9 @@ func getCommandPython(useSysPython bool) (string, error) {

func validateArgs(args []string, local bool) error {
if len(args) > 1 {
return fmt.Errorf("Too many arguments")
return errors.New("Too many arguments")
} else if len(args) == 0 {
return fmt.Errorf("Missing package argument")
return errors.New("Missing package argument")
}

if !local {
Expand Down Expand Up @@ -323,7 +323,7 @@ func pip(cliParams *cliParams, args []string, stdout io.Writer, stderr io.Writer
args = append([]string{"-mpip"}, cmd)

if cliParams.verbose > 0 {
args = append(args, fmt.Sprintf("-%s", strings.Repeat("v", cliParams.verbose)))
args = append(args, "-"+strings.Repeat("v", cliParams.verbose))
}

// Append implicit flags to the *pip* command
Expand Down Expand Up @@ -420,22 +420,20 @@ func install(cliParams *cliParams, _ log.Component) error {
return fmt.Errorf("Some errors prevented moving %s configuration files: %v", integration, err)
}

fmt.Println(color.GreenString(fmt.Sprintf(
"Successfully completed the installation of %s", integration,
)))
fmt.Println(color.GreenString("Successfully completed the installation of " + integration))

return nil
}

// Additional verification for installation
if len(strings.Split(cliParams.args[0], "==")) != 2 {
return fmt.Errorf("you must specify a version to install with <package>==<version>")
return errors.New("you must specify a version to install with <package>==<version>")
}

intVer := strings.Split(cliParams.args[0], "==")
integration := normalizePackageName(strings.TrimSpace(intVer[0]))
if integration == "datadog-checks-base" {
return fmt.Errorf("this command does not allow installing datadog-checks-base")
return errors.New("this command does not allow installing datadog-checks-base")
}
versionToInstall, err := semver.NewVersion(strings.TrimSpace(intVer[1]))
if err != nil || versionToInstall == nil {
Expand Down Expand Up @@ -517,7 +515,7 @@ func downloadWheel(cliParams *cliParams, integration, version, rootLayoutType st
"--type", rootLayoutType,
}
if cliParams.verbose > 0 {
args = append(args, fmt.Sprintf("-%s", strings.Repeat("v", cliParams.verbose)))
args = append(args, "-"+strings.Repeat("v", cliParams.verbose))
}

if cliParams.unsafeDisableVerification {
Expand Down Expand Up @@ -554,9 +552,9 @@ func downloadWheel(cliParams *cliParams, integration, version, rootLayoutType st
proxies := pkgconfigsetup.Datadog().GetProxies()
if proxies != nil {
downloaderCmd.Env = append(downloaderCmd.Env,
fmt.Sprintf("HTTP_PROXY=%s", proxies.HTTP),
fmt.Sprintf("HTTPS_PROXY=%s", proxies.HTTPS),
fmt.Sprintf("NO_PROXY=%s", strings.Join(proxies.NoProxy, ",")),
"HTTP_PROXY="+proxies.HTTP,
"HTTPS_PROXY="+proxies.HTTPS,
"NO_PROXY="+strings.Join(proxies.NoProxy, ","),
)
}

Expand Down Expand Up @@ -790,7 +788,7 @@ func getVersionFromReqLine(integration string, lines string) (*semver.Version, b
func moveConfigurationFilesOf(cliParams *cliParams, integration string) error {
confFolder := pkgconfigsetup.Datadog().GetString("confd_path")
check := getIntegrationName(integration)
confFileDest := filepath.Join(confFolder, fmt.Sprintf("%s.d", check))
confFileDest := filepath.Join(confFolder, check+".d")
if err := os.MkdirAll(confFileDest, os.ModeDir|0755); err != nil {
return err
}
Expand Down Expand Up @@ -845,9 +843,7 @@ func moveConfigurationFiles(srcFolder string, dstFolder string) error {
errorMsg = fmt.Sprintf("%s\nError writing configuration file %s: %v", errorMsg, dst, err)
continue
}
fmt.Println(color.GreenString(fmt.Sprintf(
"Successfully copied configuration file %s", filename,
)))
fmt.Println(color.GreenString("Successfully copied configuration file " + filename))
}
if errorMsg != "" {
return errors.New(errorMsg)
Expand Down
4 changes: 2 additions & 2 deletions cmd/agent/subcommands/integrations/integrations_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
package integrations

import (
"fmt"
"errors"
"os"
)

func validateUser(_ bool) error {
if os.Geteuid() != 0 {
return fmt.Errorf("please run this tool with the root user")
return errors.New("please run this tool with the root user")
}
return nil
}
4 changes: 2 additions & 2 deletions cmd/agent/subcommands/integrations/integrations_nix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
package integrations

import (
"fmt"
"errors"
"os"
)

func validateUser(allowRoot bool) error {
if os.Geteuid() == 0 && !allowRoot {
return fmt.Errorf("operation is disabled for root user. Please run this tool with the agent-running user or add '--allow-root/-r' to force")
return errors.New("operation is disabled for root user. Please run this tool with the agent-running user or add '--allow-root/-r' to force")
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
)

func getRelPyPath() string {
return filepath.Join("embedded", "bin", fmt.Sprintf("%s3", pythonBin))
return filepath.Join("embedded", "bin", pythonBin+"3")
}

func getRelChecksPath(cliParams *cliParams) (string, error) {
Expand Down
3 changes: 2 additions & 1 deletion cmd/agent/subcommands/launchgui/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package launchgui

import (
"errors"
"fmt"
"net"

Expand Down Expand Up @@ -56,7 +57,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
func launchGui(config config.Component, _ *cliParams, _ log.Component, client ipc.HTTPClient) error {
guiPort := config.GetString("GUI_port")
if guiPort == "-1" {
return fmt.Errorf("GUI not enabled: to enable, please set an appropriate port in your datadog.yaml file")
return errors.New("GUI not enabled: to enable, please set an appropriate port in your datadog.yaml file")
}

// 'http://localhost' is preferred over 'http://127.0.0.1' due to Internet Explorer behavior.
Expand Down
4 changes: 2 additions & 2 deletions cmd/agent/subcommands/remoteconfig/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func reset(_ *cliParams, config config.Component, ipc ipc.Component) error {
ctx, closeFn := context.WithCancel(context.Background())
defer closeFn()
md := metadata.MD{
"authorization": []string{fmt.Sprintf("Bearer %s", ipc.GetAuthToken())},
"authorization": []string{"Bearer " + ipc.GetAuthToken()},
}
ctx = metadata.NewOutgoingContext(ctx, md)

Expand Down Expand Up @@ -126,7 +126,7 @@ func state(_ *cliParams, config config.Component, ipc ipc.Component) error {
ctx, closeFn := context.WithCancel(context.Background())
defer closeFn()
md := metadata.MD{
"authorization": []string{fmt.Sprintf("Bearer %s", ipc.GetAuthToken())}, // TODO IPC: use GRPC client
"authorization": []string{"Bearer " + ipc.GetAuthToken()}, // TODO IPC: use GRPC client
}
ctx = metadata.NewOutgoingContext(ctx, md)

Expand Down
4 changes: 2 additions & 2 deletions cmd/agent/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ package run

import (
"context"
"errors"
_ "expvar" // Blank import used because this isn't directly used in this file
"fmt"
"net/http"
_ "net/http/pprof" // Blank import used because this isn't directly used in this file
"os"
Expand Down Expand Up @@ -321,7 +321,7 @@ func run(log log.Component,
stopCh <- nil
case <-signals.ErrorStopper:
_ = log.Critical("The Agent has encountered an error, shutting down...")
stopCh <- fmt.Errorf("shutting down because of an error")
stopCh <- errors.New("shutting down because of an error")
case sig := <-signalCh:
log.Infof("Received signal '%s', shutting down...", sig)
stopCh <- nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/agent/subcommands/status/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func requestStatus(cliParams *cliParams, client ipc.HTTPClient) error {

func componentStatusCmd(_ log.Component, cliParams *cliParams, client ipc.HTTPClient) error {
if len(cliParams.args) > 1 {
return fmt.Errorf("only one section must be specified")
return errors.New("only one section must be specified")
}

return redactError(componentStatus(cliParams, cliParams.args[0], client))
Expand Down
3 changes: 2 additions & 1 deletion cmd/agent/subcommands/streamlogs/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"bufio"
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -79,7 +80,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
// PreRunE is used to validate duration before stream-logs is run.
cmd.PreRunE = func(_ *cobra.Command, _ []string) error {
if cliParams.Duration < 0 {
return fmt.Errorf("duration must be a positive value")
return errors.New("duration must be a positive value")
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster-agent-cloudfoundry/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
package command

import (
"fmt"
"os"

"github.com/fatih/color"
Expand Down Expand Up @@ -47,7 +46,7 @@ func MakeCommand(subcommandFactories []SubcommandFactory) *cobra.Command {

// AgentCmd is the root command
agentCmd := &cobra.Command{
Use: fmt.Sprintf("%s [command]", os.Args[0]),
Use: os.Args[0] + " [command]",
Short: "Datadog Cluster Agent for Cloud Foundry at your service.",
Long: `
Datadog Cluster Agent for Cloud Foundry takes care of running checks that need to run only
Expand Down
5 changes: 3 additions & 2 deletions cmd/cluster-agent-cloudfoundry/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package run

import (
"context"
"errors"
"fmt"
"os"
"os/signal"
Expand Down Expand Up @@ -202,7 +203,7 @@ func run(
}
pkglog.Infof("Hostname is: %s", hname)

demultiplexer.AddAgentStartupTelemetry(fmt.Sprintf("%s - Datadog Cluster Agent", version.AgentVersion))
demultiplexer.AddAgentStartupTelemetry(version.AgentVersion + " - Datadog Cluster Agent")

pkglog.Infof("Datadog Cluster Agent is now running.")

Expand Down Expand Up @@ -338,7 +339,7 @@ func initializeBBSCache(ctx context.Context) error {
}
case <-timer.C:
ticker.Stop()
return fmt.Errorf("BBS Cache failed to warm up. Misconfiguration error? Inspect logs")
return errors.New("BBS Cache failed to warm up. Misconfiguration error? Inspect logs")
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cluster-agent/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestValidateTokenMiddleware(t *testing.T) {
req, err := http.NewRequest("GET", tt.path, nil)
require.NoError(t, err)

req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", tt.authToken))
req.Header.Add("Authorization", "Bearer "+tt.authToken)

rr := httptest.NewRecorder()

Expand Down
4 changes: 2 additions & 2 deletions cmd/cluster-agent/api/v1/kubernetes_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestGetNodeAnnotations(t *testing.T) {
}{
{
name: "no filters passed only host aliases annotations returned",
path: fmt.Sprintf("/annotations/node/%s", testNode),
path: "/annotations/node/" + testNode,
muxVars: map[string]string{"nodeName": testNode},
body: map[string]string{"annotation1": "abc"}, // hardcoded above in workloadmeta mock
status: http.StatusOK,
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestGetNodeUID(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req, _ := http.NewRequest("GET", fmt.Sprintf("/uid/node/%s", tt.node), nil)
req, _ := http.NewRequest("GET", "/uid/node/"+tt.node, nil)
req = mux.SetURLVars(req, map[string]string{"nodeName": tt.node})

respw := httptest.NewRecorder()
Expand Down
Loading