Skip to content

Commit 8cc791d

Browse files
authored
feat: drop global ephemeralID (#253)
## What does this PR do? require explicitly passing an ephemeralID to metrics setup and drop global ephemeralID ## Why is it important? beats already has a ephemeralID field, avoid the global field and move to passing the id explicitly this also allows dropping a call to `logp.Err` ## Checklist <!-- Mandatory Add a checklist of things that are required to be reviewed in order to have the PR approved List here all the items you have verified BEFORE sending this PR. Please DO NOT remove any item, striking through those that do not apply. (Just in case, strikethrough uses two tildes. ~~Scratch this.~~) --> - [ ] My code follows the style guidelines of this project - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] I have added an entry in `CHANGELOG.md` ## Author's Checklist <!-- Recommended Add a checklist of things that are required to be reviewed in order to have the PR approved --> - [ ] ## Related issues <!-- Recommended Link related issues below. Insert the issue link or reference after the word "Closes" if merging this should automatically close it. - Closes #123 - Relates #123 - Requires #123 - Superseds #123 --> -
1 parent d6cb3a9 commit 8cc791d

File tree

6 files changed

+7
-26
lines changed

6 files changed

+7
-26
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010
github.com/elastic/go-sysinfo v1.14.1
1111
github.com/elastic/go-windows v1.0.1
1212
github.com/elastic/gosigar v0.14.2
13-
github.com/gofrs/uuid/v5 v5.2.0
1413
github.com/magefile/mage v1.15.0
1514
github.com/shirou/gopsutil/v4 v4.24.7
1615
github.com/stretchr/testify v1.9.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
4646
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
4747
github.com/gobuffalo/here v0.6.0 h1:hYrd0a6gDmWxBM4TnrGw8mQg24iSVoIkHEk7FodQcBI=
4848
github.com/gobuffalo/here v0.6.0/go.mod h1:wAG085dHOYqUpf+Ap+WOdrPTp5IYcDAs/x7PLa8Y5fM=
49-
github.com/gofrs/uuid/v5 v5.2.0 h1:qw1GMx6/y8vhVsx626ImfKMuS5CvJmhIKKtuyvfajMM=
50-
github.com/gofrs/uuid/v5 v5.2.0/go.mod h1:CDOjlDMVAtN56jqyRUZh58JT31Tiw7/oQyEXZV+9bD8=
5149
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
5250
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
5351
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=

report/metrics_common.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,12 @@ package report
1919

2020
import (
2121
"time"
22-
23-
"github.com/gofrs/uuid/v5"
24-
25-
"github.com/elastic/elastic-agent-libs/logp"
2622
)
2723

2824
var (
29-
ephemeralID uuid.UUID
30-
startTime time.Time
25+
startTime time.Time
3126
)
3227

3328
func init() {
3429
startTime = time.Now()
35-
36-
var err error
37-
ephemeralID, err = uuid.NewV4()
38-
if err != nil {
39-
logp.Err("Error while generating ephemeral ID for Beat")
40-
}
41-
}
42-
43-
// EphemeralID returns generated EphemeralID
44-
func EphemeralID() uuid.UUID {
45-
return ephemeralID
4630
}

report/metrics_report_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
func TestSystemMetricsReport(t *testing.T) {
3333
systemMetrics := monitoring.NewRegistry()
3434
processMetrics := monitoring.NewRegistry()
35-
err := SetupMetrics(logptest.NewTestingLogger(t, ""), "TestSys", "test", systemMetrics, processMetrics)
35+
err := SetupMetrics(logptest.NewTestingLogger(t, ""), "TestSys", "test", "", systemMetrics, processMetrics)
3636
require.NoError(t, err)
3737

3838
var gotCPU, gotMem, gotInfo atomic.Bool

report/setup.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var (
4040
const monitoringCgroupsHierarchyOverride = "LIBBEAT_MONITORING_CGROUPS_HIERARCHY_OVERRIDE"
4141

4242
// SetupMetrics creates a basic suite of metrics handlers for monitoring, including build info and system resources
43-
func SetupMetrics(logger *logp.Logger, name, version string, systemMetrics *monitoring.Registry, processMetrics *monitoring.Registry) error {
43+
func SetupMetrics(logger *logp.Logger, name, version, ephemeralID string, systemMetrics *monitoring.Registry, processMetrics *monitoring.Registry) error {
4444
monitoring.NewFunc(systemMetrics, "cpu", ReportSystemCPUUsage, monitoring.Report)
4545

4646
name = processName(name)
@@ -60,7 +60,7 @@ func SetupMetrics(logger *logp.Logger, name, version string, systemMetrics *moni
6060
monitoring.NewFunc(processMetrics, "memstats", MemStatsReporter(logger, processStats), monitoring.Report)
6161
monitoring.NewFunc(processMetrics, "cpu", InstanceCPUReporter(logger, processStats), monitoring.Report)
6262
monitoring.NewFunc(processMetrics, "runtime", ReportRuntime, monitoring.Report)
63-
monitoring.NewFunc(processMetrics, "info", infoReporter(name, version), monitoring.Report)
63+
monitoring.NewFunc(processMetrics, "info", infoReporter(name, version, ephemeralID), monitoring.Report)
6464

6565
setupPlatformSpecificMetrics(logger, processStats, systemMetrics, processMetrics)
6666

@@ -88,7 +88,7 @@ func isWindows() bool {
8888
return runtime.GOOS == "windows"
8989
}
9090

91-
func infoReporter(serviceName, version string) func(_ monitoring.Mode, V monitoring.Visitor) {
91+
func infoReporter(serviceName, version, ephemeralID string) func(_ monitoring.Mode, V monitoring.Visitor) {
9292
return func(_ monitoring.Mode, V monitoring.Visitor) {
9393
V.OnRegistryStart()
9494
defer V.OnRegistryFinished()
@@ -99,7 +99,7 @@ func infoReporter(serviceName, version string) func(_ monitoring.Mode, V monitor
9999
monitoring.ReportInt(V, "ms", uptime)
100100
})
101101

102-
monitoring.ReportString(V, "ephemeral_id", ephemeralID.String())
102+
monitoring.ReportString(V, "ephemeral_id", ephemeralID)
103103
monitoring.ReportString(V, "name", serviceName)
104104
monitoring.ReportString(V, "version", version)
105105
}

report/setup_other.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/elastic/elastic-agent-libs/monitoring"
2929
)
3030

31-
func SetupMetrics(logger *logp.Logger, name, version string, systemMetrics *monitoring.Registry, processMetrics *monitoring.Registry) error {
31+
func SetupMetrics(logger *logp.Logger, name, version, ephemeralID string, systemMetrics *monitoring.Registry, processMetrics *monitoring.Registry) error {
3232
logp.Warn("Metrics not implemented for this OS.")
3333
return nil
3434
}

0 commit comments

Comments
 (0)