Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions internal/pkg/agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"strings"
"syscall"
"time"

Check failure on line 19 in internal/pkg/agent/cmd/run.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

File is not properly formatted (goimports)
"github.com/elastic/elastic-agent/internal/pkg/agent/application/enroll"
fleetgateway "github.com/elastic/elastic-agent/internal/pkg/agent/application/gateway/fleet"
"github.com/gofrs/uuid/v5"

"go.elastic.co/apm/v2"
apmtransport "go.elastic.co/apm/v2/transport"
Expand Down Expand Up @@ -719,8 +720,21 @@
tracer *apm.Tracer,
coord *coordinator.Coordinator,
) (*reload.ServerReloader, error) {
if err := report.SetupMetrics(logger, agentName, version.GetDefaultVersion()); err != nil { //nolint:staticcheck // ignore deprecation
return nil, err

ephemeralID, err := generateEphemeralID()
if err != nil {
return nil, fmt.Errorf("failed to generate ephemeral ID: %w", err)
}

if err := report.SetupMetricsOptions(report.MetricOptions{
Name: agentName,
Version: version.GetDefaultVersion(),
Logger: logger,
EphemeralID: ephemeralID,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SystemMetrics: monitoringLib.Default.GetOrCreateRegistry("system"),
ProcessMetrics: monitoringLib.Default.GetOrCreateRegistry("beat"),
}); err != nil {
return nil, fmt.Errorf("failed to setup metrics: %w", err)
}

s, err := monitoring.NewServer(logger, monitoringLib.GetNamespace, tracer, coord, cfg)
Expand Down Expand Up @@ -793,3 +807,13 @@

return nil
}

// generateEphemeralID generates a random UUID
func generateEphemeralID() (string, error) {
uid, err := uuid.NewV4()
if err != nil {
return "", fmt.Errorf("error while generating UUID for agent: %w", err)
}

return uid.String(), nil
}
Loading