Skip to content

Commit 31a068e

Browse files
authored
chore: update bump-component-versions and nrdot-collector-builder with ability to update nr forks repo (#614)
1 parent 63bf2bc commit 31a068e

12 files changed

Lines changed: 374 additions & 34 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This config is for testing purposes and should not be used in production.
2+
#
3+
4+
dist:
5+
module: github.com/newrelic/nrdot-collector-releases/nrdot-collector
6+
name: nrdot-collector
7+
description: NRDOT Collector
8+
version: 1.1.0
9+
output_path: ./_build
10+
11+
receivers:
12+
- gomod: go.opentelemetry.io/collector/receiver/nopreceiver v0.154.0
13+
- gomod: github.com/newrelic-forks/opentelemetry-collector-contrib/receiver/nrsqlserverreceiver v0.154.4
14+
processors:
15+
- gomod: github.com/newrelic/nrdot-collector-components/processor/adaptivetelemetryprocessor v0.154.0
16+
exporters:
17+
- gomod: go.opentelemetry.io/collector/exporter/nopexporter v0.154.0

cmd/nrdot-collector-builder/cmd/manifest/testdata/test-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ providers:
2727
- gomod: go.opentelemetry.io/collector/confmap/provider/httpprovider v1.31.0
2828
- gomod: go.opentelemetry.io/collector/confmap/provider/httpsprovider v1.31.0
2929
- gomod: go.opentelemetry.io/collector/confmap/provider/yamlprovider v1.31.0
30-

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/manifest/update_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,50 @@ func TestUpdateCmd_RunE_InvalidConfig(t *testing.T) {
8282
err = UpdateCmd.RunE(cmd, []string{})
8383
assert.Error(t, err)
8484
}
85+
86+
func TestUpdateCmd_RunE_NrdotComponents(t *testing.T) {
87+
// Load the test-config-nrdot.yaml file
88+
testConfigPath := "testdata/test-config-nrdot.yaml"
89+
yamlData, err := os.ReadFile(testConfigPath)
90+
assert.NoError(t, err)
91+
92+
// Create a temporary file to simulate writing to a file
93+
tempFile, err := os.CreateTemp("", "test-config-*.yaml")
94+
assert.NoError(t, err)
95+
defer os.Remove(tempFile.Name()) // Clean up the file after the test
96+
97+
// Write the loaded YAML data to the temporary file
98+
_, err = tempFile.Write(yamlData)
99+
assert.NoError(t, err)
100+
tempFile.Close() // Close the file to ensure the changes are flushed
101+
102+
targetStable := "v1.61.0"
103+
targetBeta := "v0.155.0"
104+
105+
cmd := &cobra.Command{}
106+
cmd.Flags().String("config", tempFile.Name(), "")
107+
108+
// Version overrides are read from the root command's persistent flags.
109+
cmd.PersistentFlags().String("nrdot-version", targetBeta, "")
110+
cmd.PersistentFlags().String("nr-fork-contrib-version", targetBeta, "")
111+
cmd.PersistentFlags().String("core-stable", targetStable, "")
112+
cmd.PersistentFlags().String("core-beta", targetBeta, "")
113+
cmd.PersistentFlags().String("contrib-beta", targetBeta, "")
114+
115+
err = UpdateCmd.RunE(cmd, []string{})
116+
assert.NoError(t, err)
117+
118+
updatedYamlData, err := os.ReadFile(tempFile.Name())
119+
assert.NoError(t, err)
120+
updated := string(updatedYamlData)
121+
122+
betaModules := []string{
123+
"github.com/newrelic/nrdot-collector-components/processor/adaptivetelemetryprocessor",
124+
"github.com/newrelic-forks/opentelemetry-collector-contrib/receiver/nrsqlserverreceiver",
125+
"go.opentelemetry.io/collector/receiver/nopreceiver",
126+
"go.opentelemetry.io/collector/exporter/nopexporter",
127+
}
128+
for _, module := range betaModules {
129+
assert.Contains(t, updated, module+" "+targetBeta)
130+
}
131+
}

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: 49 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.MajorMinor(nrComponentVersion) == semver.MajorMinor(betaVersion)
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,35 @@ 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 {
154+
if !isCompatibleWithNrVersions(versions.NrdotVersion, versions.NrForkContribVersion, componentVersion) {
155+
return fmt.Errorf("beta core version %s incompatible with nrdot %s or nr-fork %s", componentVersion, versions.NrdotVersion, versions.NrForkContribVersion)
156+
}
132157
versions.BetaCoreVersion = componentVersion
133158
}
134159
}
135160

136-
if isOtelContribComponent(component.GoMod) && !isStableVersion(componentVersion) && (versions.NrdotVersion == "" || isCompatibleWithNrdotComponent(versions.NrdotVersion, componentVersion)) {
161+
if isOtelContribComponent(component.GoMod) && !isStableVersion(componentVersion) {
162+
if !isCompatibleWithNrVersions(versions.NrdotVersion, versions.NrForkContribVersion, componentVersion) {
163+
return fmt.Errorf("contrib version %s incompatible with nrdot %s or nr-fork %s", componentVersion, versions.NrdotVersion, versions.NrForkContribVersion)
164+
}
137165
versions.BetaContribVersion = componentVersion
138166
}
139167

@@ -245,6 +273,16 @@ func (cfg *Config) allNrdotComponents() []Module {
245273
return allNrdotComponents
246274
}
247275

276+
func (cfg *Config) allNrForkContribComponents() []Module {
277+
allNrForkContribComponents := []Module{}
278+
for _, component := range cfg.allComponents() {
279+
if isNrForkContribComponent(component) {
280+
allNrForkContribComponents = append(allNrForkContribComponents, component)
281+
}
282+
}
283+
return allNrForkContribComponents
284+
}
285+
248286
func validateModules(name string, mods []Module) error {
249287
for i, mod := range mods {
250288
if mod.GoMod == "" {

0 commit comments

Comments
 (0)