Skip to content

Commit

Permalink
usm: Fix imports (#31634)
Browse files Browse the repository at this point in the history
upgrade(installer): Return specific error codes (#31619)

Co-authored-by: arbll <[email protected]>

(fleet) env cleanup (#31628)

create benchmark for consumer operations

fixed test

changed test to be user mode only

revert newEventGenerator changes as it not needed for the benchmark

changed return value

changed events counts to support correct loads

improve some ut structure
  • Loading branch information
guyarb authored and amitslavin committed Dec 4, 2024
1 parent 98b799c commit e0be619
Show file tree
Hide file tree
Showing 44 changed files with 363 additions and 191 deletions.
24 changes: 22 additions & 2 deletions cmd/installer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,33 @@
package main

import (
"fmt"
"os"

"github.com/DataDog/datadog-agent/cmd/installer/command"
"github.com/DataDog/datadog-agent/cmd/installer/subcommands"
"github.com/DataDog/datadog-agent/cmd/internal/runcmd"
"github.com/spf13/cobra"
"go.uber.org/dig"

installerErrors "github.com/DataDog/datadog-agent/pkg/fleet/installer/errors"
)

func main() {
os.Exit(runcmd.Run(command.MakeCommand(subcommands.InstallerSubcommands())))
os.Exit(runCmd(command.MakeCommand(subcommands.InstallerSubcommands())))
}

func runCmd(cmd *cobra.Command) int {
// always silence errors, since they are handled here
cmd.SilenceErrors = true

err := cmd.Execute()
if err != nil {
if rootCauseErr := dig.RootCause(err); rootCauseErr != err {
fmt.Fprintln(cmd.ErrOrStderr(), installerErrors.FromErr(rootCauseErr).ToJSON())
} else {
fmt.Fprintln(cmd.ErrOrStderr(), installerErrors.FromErr(err).ToJSON())
}
return -1
}
return 0
}
4 changes: 2 additions & 2 deletions cmd/installer/subcommands/installer/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

"github.com/DataDog/datadog-agent/cmd/installer/command"
"github.com/DataDog/datadog-agent/pkg/fleet/bootstrapper"
"github.com/DataDog/datadog-agent/pkg/fleet/env"
"github.com/DataDog/datadog-agent/pkg/fleet/installer"
"github.com/DataDog/datadog-agent/pkg/fleet/installer/env"
"github.com/DataDog/datadog-agent/pkg/fleet/telemetry"
"github.com/DataDog/datadog-agent/pkg/version"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -226,7 +226,7 @@ func newTelemetry(env *env.Env) *telemetry.Telemetry {
if site == "" {
site = config.Site
}
t, err := telemetry.NewTelemetry(apiKey, site, "datadog-installer") // No sampling rules for commands
t, err := telemetry.NewTelemetry(env.HTTPClient(), apiKey, site, "datadog-installer") // No sampling rules for commands
if err != nil {
fmt.Printf("failed to initialize telemetry: %v\n", err)
return nil
Expand Down
17 changes: 11 additions & 6 deletions comp/updater/telemetry/telemetryimpl/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
package telemetryimpl

import (
"net/http"

"go.uber.org/fx"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"

"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/updater/telemetry"
"github.com/DataDog/datadog-agent/pkg/fleet/env"
"github.com/DataDog/datadog-agent/pkg/config/utils"
fleettelemetry "github.com/DataDog/datadog-agent/pkg/fleet/telemetry"
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
httputils "github.com/DataDog/datadog-agent/pkg/util/http"
)

type dependencies struct {
Expand All @@ -32,12 +35,14 @@ func Module() fxutil.Module {
}

func newTelemetry(deps dependencies) (telemetry.Component, error) {
env := env.FromConfig(deps.Config)
telemetry, err := fleettelemetry.NewTelemetry(env.APIKey, env.Site, "datadog-installer",
client := &http.Client{
Transport: httputils.CreateHTTPTransport(deps.Config),
}
telemetry, err := fleettelemetry.NewTelemetry(client, utils.SanitizeAPIKey(deps.Config.GetString("api_key")), deps.Config.GetString("site"), "datadog-installer-daemon",
fleettelemetry.WithSamplingRules(
tracer.NameServiceRule("cdn.*", "datadog-installer", 0.1),
tracer.NameServiceRule("*garbage_collect*", "datadog-installer", 0.05),
tracer.NameServiceRule("HTTPClient.*", "datadog-installer", 0.05),
tracer.NameServiceRule("cdn.*", "datadog-installer-daemon", 0.1),
tracer.NameServiceRule("*garbage_collect*", "datadog-installer-daemon", 0.05),
tracer.NameServiceRule("HTTPClient.*", "datadog-installer-daemon", 0.05),
),
)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion comp/updater/updater/updaterimpl/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
package updaterimpl

import (
"context"
"errors"
"fmt"

"go.uber.org/fx"

"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/comp/core/hostname"
log "github.com/DataDog/datadog-agent/comp/core/log/def"
"github.com/DataDog/datadog-agent/comp/remote-config/rcservice"
updatercomp "github.com/DataDog/datadog-agent/comp/updater/updater"
Expand All @@ -36,6 +38,7 @@ func Module() fxutil.Module {
type dependencies struct {
fx.In

Hostname hostname.Component
Log log.Component
Config config.Component
RemoteConfig optional.Option[rcservice.Component]
Expand All @@ -46,7 +49,11 @@ func newUpdaterComponent(lc fx.Lifecycle, dependencies dependencies) (updatercom
if !ok {
return nil, errRemoteConfigRequired
}
daemon, err := daemon.NewDaemon(remoteConfig, dependencies.Config)
hostname, err := dependencies.Hostname.Get(context.Background())
if err != nil {
return nil, fmt.Errorf("could not get hostname: %w", err)
}
daemon, err := daemon.NewDaemon(hostname, remoteConfig, dependencies.Config)
if err != nil {
return nil, fmt.Errorf("could not create updater: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fleet/bootstrapper/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"context"
"fmt"

"github.com/DataDog/datadog-agent/pkg/fleet/env"
"github.com/DataDog/datadog-agent/pkg/fleet/installer/env"
"github.com/DataDog/datadog-agent/pkg/fleet/internal/bootstrap"
"github.com/DataDog/datadog-agent/pkg/fleet/internal/exec"
"github.com/DataDog/datadog-agent/pkg/fleet/internal/oci"
Expand Down
25 changes: 21 additions & 4 deletions pkg/fleet/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
osexec "os/exec"
"path/filepath"
"runtime"
"strings"
"sync"
"time"

Expand All @@ -24,8 +25,9 @@ import (

"github.com/DataDog/datadog-agent/comp/core/config"
"github.com/DataDog/datadog-agent/pkg/config/remote/client"
"github.com/DataDog/datadog-agent/pkg/fleet/env"
"github.com/DataDog/datadog-agent/pkg/config/utils"
"github.com/DataDog/datadog-agent/pkg/fleet/installer"
"github.com/DataDog/datadog-agent/pkg/fleet/installer/env"
installerErrors "github.com/DataDog/datadog-agent/pkg/fleet/installer/errors"
"github.com/DataDog/datadog-agent/pkg/fleet/installer/repository"
"github.com/DataDog/datadog-agent/pkg/fleet/internal/bootstrap"
Expand Down Expand Up @@ -83,7 +85,7 @@ func newInstaller(env *env.Env, installerBin string) installer.Installer {
}

// NewDaemon returns a new daemon.
func NewDaemon(rcFetcher client.ConfigFetcher, config config.Reader) (Daemon, error) {
func NewDaemon(hostname string, rcFetcher client.ConfigFetcher, config config.Reader) (Daemon, error) {
installerBin, err := os.Executable()
if err != nil {
return nil, fmt.Errorf("could not get installer executable path: %w", err)
Expand All @@ -96,7 +98,22 @@ func NewDaemon(rcFetcher client.ConfigFetcher, config config.Reader) (Daemon, er
if err != nil {
return nil, fmt.Errorf("could not create remote config client: %w", err)
}
env := env.FromConfig(config)
env := &env.Env{
APIKey: utils.SanitizeAPIKey(config.GetString("api_key")),
Site: config.GetString("site"),
RemoteUpdates: config.GetBool("remote_updates"),
RemotePolicies: config.GetBool("remote_policies"),
Mirror: config.GetString("installer.mirror"),
RegistryOverride: config.GetString("installer.registry.url"),
RegistryAuthOverride: config.GetString("installer.registry.auth"),
RegistryUsername: config.GetString("installer.registry.username"),
RegistryPassword: config.GetString("installer.registry.password"),
Tags: utils.GetConfiguredTags(config, false),
Hostname: hostname,
HTTPProxy: config.GetString("proxy.http"),
HTTPSProxy: config.GetString("proxy.https"),
NoProxy: strings.Join(config.GetStringSlice("proxy.no_proxy"), ","),
}
installer := newInstaller(env, installerBin)
cdn, err := cdn.New(env, filepath.Join(paths.RunPath, "rc_daemon"))
if err != nil {
Expand Down Expand Up @@ -552,7 +569,7 @@ func setRequestDone(ctx context.Context, err error) {
state.State = pbgo.TaskState_DONE
if err != nil {
state.State = pbgo.TaskState_ERROR
state.Err = installerErrors.From(err)
state.Err = installerErrors.FromErr(err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/fleet/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/DataDog/datadog-agent/pkg/fleet/env"
"github.com/DataDog/datadog-agent/pkg/fleet/installer/env"
"github.com/DataDog/datadog-agent/pkg/fleet/installer/repository"
"github.com/DataDog/datadog-agent/pkg/fleet/internal/cdn"
pbgo "github.com/DataDog/datadog-agent/pkg/proto/pbgo/core"
Expand Down
22 changes: 0 additions & 22 deletions pkg/fleet/env/http_client.go

This file was deleted.

33 changes: 0 additions & 33 deletions pkg/fleet/env/install_script.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/fleet/installer/default_packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"slices"
"strings"

"github.com/DataDog/datadog-agent/pkg/fleet/env"
"github.com/DataDog/datadog-agent/pkg/fleet/installer/env"
"github.com/DataDog/datadog-agent/pkg/fleet/internal/oci"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/fleet/installer/default_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package installer
import (
"testing"

"github.com/DataDog/datadog-agent/pkg/fleet/env"
"github.com/DataDog/datadog-agent/pkg/fleet/installer/env"
"github.com/DataDog/datadog-agent/pkg/fleet/internal/oci"
"github.com/stretchr/testify/assert"
)
Expand Down
Loading

0 comments on commit e0be619

Please sign in to comment.