Skip to content

Commit 82f50f5

Browse files
committed
chore: update nrdot-collector-builder with nrdot fork updating
1 parent 63bf2bc commit 82f50f5

6 files changed

Lines changed: 188 additions & 20 deletions

File tree

cmd/nrdot-collector-builder/cmd/manifest/update.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var UpdateCmd = &cobra.Command{
3333

3434
// Get version overrides from persistent flags.
3535
nrdotVersion := persistentFlag(cmd, "nrdot-version")
36+
nrForkContribVersion := persistentFlag(cmd, "nr-fork-contrib-version")
3637
coreStable := persistentFlag(cmd, "core-stable")
3738
coreBeta := persistentFlag(cmd, "core-beta")
3839
contribBeta := persistentFlag(cmd, "contrib-beta")
@@ -42,6 +43,9 @@ var UpdateCmd = &cobra.Command{
4243
if nrdotVersion != "" {
4344
nrdotUpdates[manifest.NrModule] = manifest.VersionUpdate{BetaVersion: nrdotVersion}
4445
}
46+
if nrForkContribVersion != "" {
47+
nrdotUpdates[manifest.NrForkContribModule] = manifest.VersionUpdate{BetaVersion: nrForkContribVersion}
48+
}
4549
if coreStable != "" || coreBeta != "" {
4650
nrdotUpdates[manifest.CoreModule] = manifest.VersionUpdate{StableVersion: coreStable, BetaVersion: coreBeta}
4751
}

cmd/nrdot-collector-builder/cmd/root.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import (
1010
)
1111

1212
var (
13-
jsonOutput bool
14-
verbose bool
15-
nrdotVersion string
16-
coreStableVersion string
17-
coreBetaVersion string
18-
contribBetaVersion string
13+
jsonOutput bool
14+
verbose bool
15+
nrdotVersion string
16+
nrForkContribVersion string
17+
coreStableVersion string
18+
coreBetaVersion string
19+
contribBetaVersion string
1920
)
2021

2122
// rootCmd represents the base command when called without any subcommands
@@ -33,6 +34,7 @@ func init() {
3334
rootCmd.PersistentFlags().BoolVar(&jsonOutput, "json", false, "Output results in JSON format")
3435
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Verbose output")
3536
rootCmd.PersistentFlags().StringVar(&nrdotVersion, "nrdot-version", "", "Pin nrdot-collector-components to this version")
37+
rootCmd.PersistentFlags().StringVar(&nrForkContribVersion, "nr-fork-contrib-version", "", "Pin newrelic-forks/opentelemetry-collector-contrib to this version")
3638
rootCmd.PersistentFlags().StringVar(&coreStableVersion, "core-stable", "", "Pin OTel core stable (v1.x) modules to this version")
3739
rootCmd.PersistentFlags().StringVar(&coreBetaVersion, "core-beta", "", "Pin OTel core beta (v0.x) modules to this version")
3840
rootCmd.PersistentFlags().StringVar(&contribBetaVersion, "contrib-beta", "", "Pin OTel contrib modules to this version")

cmd/nrdot-collector-builder/internal/manifest/config.go

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,18 @@ import (
2222
var errMissingGoMod = errors.New("missing gomod specification for module")
2323

2424
const (
25-
CoreModule = "go.opentelemetry.io/collector"
26-
ContribModule = "github.com/open-telemetry/opentelemetry-collector-contrib"
27-
NrModule = "github.com/newrelic/nrdot-collector-components"
25+
CoreModule = "go.opentelemetry.io/collector"
26+
ContribModule = "github.com/open-telemetry/opentelemetry-collector-contrib"
27+
NrModule = "github.com/newrelic/nrdot-collector-components"
28+
NrForkContribModule = "github.com/newrelic-forks/opentelemetry-collector-contrib"
2829
)
2930

3031
type Versions struct {
31-
BetaCoreVersion string `json:"betaCoreVersion"`
32-
BetaContribVersion string `json:"betaContribVersion"`
33-
StableCoreVersion string `json:"stableCoreVersion"`
34-
NrdotVersion string `json:"nrdotVersion"`
32+
BetaCoreVersion string `json:"betaCoreVersion"`
33+
BetaContribVersion string `json:"betaContribVersion"`
34+
StableCoreVersion string `json:"stableCoreVersion"`
35+
NrdotVersion string `json:"nrdotVersion"`
36+
NrForkContribVersion string `json:"nrForkContribVersion"`
3537
}
3638

3739
// Config holds the builder's configuration
@@ -95,6 +97,10 @@ func isNrdotComponent(component Module) bool {
9597
return strings.HasPrefix(component.GoMod, NrModule)
9698
}
9799

100+
func isNrForkContribComponent(component Module) bool {
101+
return strings.HasPrefix(component.GoMod, NrForkContribModule)
102+
}
103+
98104
func isOtelComponent(component Module) bool {
99105
return isOtelCoreComponent(component.GoMod) || isOtelContribComponent(component.GoMod)
100106
}
@@ -103,8 +109,13 @@ func isStableVersion(version string) bool {
103109
return semver.Compare(version, "v1.0.0") >= 0
104110
}
105111

106-
func isCompatibleWithNrdotComponent(nrdotVersion, betaVersion string) bool {
107-
return semver.Compare(nrdotVersion, betaVersion) >= 0
112+
func isCompatibleWithNrComponent(nrComponentVersion, betaVersion string) bool {
113+
return semver.Compare(nrComponentVersion, betaVersion) >= 0
114+
}
115+
116+
func isCompatibleWithNrVersions(nrdotVersion, nrForkContribVersion, betaVersion string) bool {
117+
return (nrdotVersion == "" || isCompatibleWithNrComponent(nrdotVersion, betaVersion)) &&
118+
(nrForkContribVersion == "" || isCompatibleWithNrComponent(nrForkContribVersion, betaVersion))
108119
}
109120

110121
func (c *Config) SetVersions() error {
@@ -122,18 +133,29 @@ func (c *Config) SetVersions() error {
122133
}
123134
}
124135

136+
for _, component := range c.allNrForkContribComponents() {
137+
if isNrForkContribComponent(component) {
138+
componentVersion := strings.Split(component.GoMod, " ")[1]
139+
versions.NrForkContribVersion = componentVersion
140+
}
141+
142+
if versions.NrForkContribVersion != "" {
143+
break
144+
}
145+
}
146+
125147
for _, component := range c.allOtelComponents() {
126148
if isOtelComponent(component) {
127149
componentVersion := strings.Split(component.GoMod, " ")[1]
128150
if isOtelCoreComponent(component.GoMod) {
129151
if isStableVersion(componentVersion) {
130152
versions.StableCoreVersion = componentVersion
131-
} else if versions.NrdotVersion == "" || isCompatibleWithNrdotComponent(versions.NrdotVersion, componentVersion) {
153+
} else if isCompatibleWithNrVersions(versions.NrdotVersion, versions.NrForkContribVersion, componentVersion) {
132154
versions.BetaCoreVersion = componentVersion
133155
}
134156
}
135157

136-
if isOtelContribComponent(component.GoMod) && !isStableVersion(componentVersion) && (versions.NrdotVersion == "" || isCompatibleWithNrdotComponent(versions.NrdotVersion, componentVersion)) {
158+
if isOtelContribComponent(component.GoMod) && !isStableVersion(componentVersion) && isCompatibleWithNrVersions(versions.NrdotVersion, versions.NrForkContribVersion, componentVersion) {
137159
versions.BetaContribVersion = componentVersion
138160
}
139161

@@ -245,6 +267,16 @@ func (cfg *Config) allNrdotComponents() []Module {
245267
return allNrdotComponents
246268
}
247269

270+
func (cfg *Config) allNrForkContribComponents() []Module {
271+
allNrForkContribComponents := []Module{}
272+
for _, component := range cfg.allComponents() {
273+
if isNrForkContribComponent(component) {
274+
allNrForkContribComponents = append(allNrForkContribComponents, component)
275+
}
276+
}
277+
return allNrForkContribComponents
278+
}
279+
248280
func validateModules(name string, mods []Module) error {
249281
for i, mod := range mods {
250282
if mod.GoMod == "" {

cmd/nrdot-collector-builder/internal/manifest/config_test.go

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,36 @@ func TestConfig_IsNrdotComponent(t *testing.T) {
9393
assert.False(t, isNrdotComponent(Module{GoMod: "github.com/some/other/module"}))
9494
}
9595

96+
func TestConfig_IsNrForkContribVersion(t *testing.T) {
97+
assert.True(t, isNrForkContribComponent(Module{GoMod: "github.com/newrelic-forks/opentelemetry-collector-contrib v1.0.0"}))
98+
assert.True(t, isNrForkContribComponent(Module{GoMod: "github.com/newrelic-forks/opentelemetry-collector-contrib"}))
99+
assert.False(t, isNrForkContribComponent(Module{GoMod: "github.com/some/other/module"}))
100+
}
101+
96102
func TestConfig_SetVersions(t *testing.T) {
103+
cfg := &Config{
104+
Extensions: []Module{
105+
{GoMod: "github.com/open-telemetry/opentelemetry-collector-contrib/component v0.1.0"},
106+
{GoMod: "github.com/newrelic/nrdot-collector-components/component v0.1.0"},
107+
{GoMod: "github.com/newrelic-forks/opentelemetry-collector-contrib/component v0.1.0"},
108+
},
109+
Receivers: []Module{
110+
{GoMod: "go.opentelemetry.io/collector v1.0.0"},
111+
{GoMod: "go.opentelemetry.io/collector/component v0.1.0"},
112+
},
113+
}
114+
115+
err := cfg.SetVersions()
116+
assert.NoError(t, err)
117+
118+
assert.Equal(t, "v1.0.0", cfg.Versions.StableCoreVersion)
119+
assert.Equal(t, "v0.1.0", cfg.Versions.BetaCoreVersion)
120+
assert.Equal(t, "v0.1.0", cfg.Versions.BetaContribVersion)
121+
assert.Equal(t, "v0.1.0", cfg.Versions.NrdotVersion)
122+
assert.Equal(t, "v0.1.0", cfg.Versions.NrForkContribVersion)
123+
}
124+
125+
func TestConfig_SetVersions_MissingFork(t *testing.T) {
97126
cfg := &Config{
98127
Extensions: []Module{
99128
{GoMod: "github.com/open-telemetry/opentelemetry-collector-contrib/component v0.1.0"},
@@ -112,6 +141,7 @@ func TestConfig_SetVersions(t *testing.T) {
112141
assert.Equal(t, "v0.1.0", cfg.Versions.BetaCoreVersion)
113142
assert.Equal(t, "v0.1.0", cfg.Versions.BetaContribVersion)
114143
assert.Equal(t, "v0.1.0", cfg.Versions.NrdotVersion)
144+
assert.Empty(t, cfg.Versions.NrForkContribVersion)
115145
}
116146

117147
func TestConfig_SetVersions_MissingCore(t *testing.T) {
@@ -130,7 +160,7 @@ func TestConfig_SetVersions_MissingCore(t *testing.T) {
130160

131161
}
132162

133-
func TestIsCompatibleWithNrdotComponent(t *testing.T) {
163+
func TestIsCompatibleWithNrComponent(t *testing.T) {
134164
tests := []struct {
135165
name string
136166
nrdotVersion string
@@ -177,10 +207,79 @@ func TestIsCompatibleWithNrdotComponent(t *testing.T) {
177207

178208
for _, tt := range tests {
179209
t.Run(tt.name, func(t *testing.T) {
180-
result := isCompatibleWithNrdotComponent(tt.nrdotVersion, tt.betaVersion)
210+
result := isCompatibleWithNrComponent(tt.nrdotVersion, tt.betaVersion)
181211
assert.Equal(t, tt.expectedMatch, result,
182212
"isCompatibleWithNrdotComponent(%s, %s) = %v, want %v",
183213
tt.nrdotVersion, tt.betaVersion, result, tt.expectedMatch)
184214
})
185215
}
186216
}
217+
218+
func TestIsCompatibleWithNrVersions(t *testing.T) {
219+
tests := []struct {
220+
name string
221+
nrdotVersion string
222+
nrForkContribVersion string
223+
betaVersion string
224+
expectedMatch bool
225+
}{
226+
{
227+
name: "all versions populated and equal",
228+
nrdotVersion: "v0.142.0",
229+
nrForkContribVersion: "v0.142.0",
230+
betaVersion: "v0.142.0",
231+
expectedMatch: true,
232+
},
233+
{
234+
name: "all versions populated, beta higher than one",
235+
nrdotVersion: "v0.141.0",
236+
nrForkContribVersion: "v0.142.0",
237+
betaVersion: "v0.142.0",
238+
expectedMatch: false,
239+
},
240+
{
241+
name: "nrdotVersion empty, beta equal",
242+
nrdotVersion: "",
243+
nrForkContribVersion: "v0.142.0",
244+
betaVersion: "v0.142.0",
245+
expectedMatch: true,
246+
},
247+
{
248+
name: "nrdotVersion empty, beta higher",
249+
nrdotVersion: "",
250+
nrForkContribVersion: "v0.141.0",
251+
betaVersion: "v0.142.0",
252+
expectedMatch: false,
253+
},
254+
{
255+
name: "nrForkContribVersion empty, beta equal",
256+
nrdotVersion: "v0.142.0",
257+
nrForkContribVersion: "",
258+
betaVersion: "v0.142.0",
259+
expectedMatch: true,
260+
},
261+
{
262+
name: "nrForkContribVersion empty, beta higher",
263+
nrdotVersion: "v0.141.0",
264+
nrForkContribVersion: "",
265+
betaVersion: "v0.142.0",
266+
expectedMatch: false,
267+
},
268+
{
269+
name: "both nr versions empty",
270+
nrdotVersion: "",
271+
nrForkContribVersion: "",
272+
betaVersion: "v0.142.0",
273+
expectedMatch: true,
274+
},
275+
}
276+
277+
for _, tt := range tests {
278+
t.Run(tt.name, func(t *testing.T) {
279+
result := isCompatibleWithNrVersions(tt.nrdotVersion, tt.nrForkContribVersion, tt.betaVersion)
280+
assert.Equal(t, tt.expectedMatch, result,
281+
"isCompatibleWithNrVersions(%s, %s, %s) = %v, want %v",
282+
tt.nrdotVersion, tt.nrForkContribVersion, tt.betaVersion, result, tt.expectedMatch)
283+
})
284+
}
285+
}

cmd/nrdot-collector-builder/internal/manifest/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func fetchAllModuleVersions(cfg *Config, modules []string) (map[string][]string,
7878
func fetchLatestModuleVersions(cfg *Config) (map[string][]string, error) {
7979
updates := make(map[string][]string)
8080

81-
var components = slices.Concat(cfg.allOtelComponents(), cfg.allNrdotComponents())
81+
var components = slices.Concat(cfg.allOtelComponents(), cfg.allNrdotComponents(), cfg.allNrForkContribComponents())
8282
var modules []string
8383
for _, component := range components {
8484
module, _, _ := strings.Cut(component.GoMod, " ")

cmd/nrdot-collector-builder/internal/manifest/main_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,37 @@ func TestCopyAndUpdateConfigModules_Nrdot(t *testing.T) {
123123
assert.Equal(t, "github.com/newrelic/nrdot-collector-components/processor/adaptivetelemetryprocessor v0.147.0", result.Processors[0].GoMod)
124124
}
125125

126+
func TestCopyAndUpdateConfigModules_NrForkContrib(t *testing.T) {
127+
cfg := newTestCfg()
128+
cfg.Receivers = []Module{
129+
{GoMod: "github.com/newrelic-forks/opentelemetry-collector-contrib/receiver/nroracledbreceiver v0.154.4"},
130+
}
131+
updates := map[string]VersionUpdate{
132+
"github.com/newrelic-forks/opentelemetry-collector-contrib": {BetaVersion: "v0.155.0"},
133+
}
134+
result, err := CopyAndUpdateConfigModules(cfg, updates)
135+
assert.NoError(t, err)
136+
assert.Equal(t, "github.com/newrelic-forks/opentelemetry-collector-contrib/receiver/nroracledbreceiver v0.155.0", result.Receivers[0].GoMod)
137+
}
138+
139+
func TestCopyAndUpdateConfigModules_NrdotAndNrFork(t *testing.T) {
140+
cfg := newTestCfg()
141+
cfg.Processors = []Module{
142+
{GoMod: "github.com/newrelic/nrdot-collector-components/processor/adaptivetelemetryprocessor v0.154.0"},
143+
}
144+
cfg.Receivers = []Module{
145+
{GoMod: "github.com/newrelic-forks/opentelemetry-collector-contrib/receiver/nroracledbreceiver v0.154.4"},
146+
}
147+
updates := map[string]VersionUpdate{
148+
"github.com/newrelic/nrdot-collector-components": {BetaVersion: "v0.155.0"},
149+
"github.com/newrelic-forks/opentelemetry-collector-contrib": {BetaVersion: "v0.155.0"},
150+
}
151+
result, err := CopyAndUpdateConfigModules(cfg, updates)
152+
assert.NoError(t, err)
153+
assert.Equal(t, "github.com/newrelic/nrdot-collector-components/processor/adaptivetelemetryprocessor v0.155.0", result.Processors[0].GoMod)
154+
assert.Equal(t, "github.com/newrelic-forks/opentelemetry-collector-contrib/receiver/nroracledbreceiver v0.155.0", result.Receivers[0].GoMod)
155+
}
156+
126157
func TestCopyAndUpdateConfigModules_NoMatchUnchanged(t *testing.T) {
127158
cfg := newTestCfg()
128159
cfg.Receivers = []Module{

0 commit comments

Comments
 (0)