Skip to content

Commit

Permalink
fix(packaging): cleanup build version number (#1703)
Browse files Browse the repository at this point in the history
Version numbers introduced by the new packaging implementation are not supported by the backend when sending collector information. When this new format is recognized clean it up to send a version that is compatible with the backend.
  • Loading branch information
fguimond authored Nov 14, 2024
1 parent 4d57200 commit b1ea0a9
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
20 changes: 19 additions & 1 deletion pkg/extension/sumologicextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"net/http"
"net/url"
"os"
"regexp"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -798,7 +799,7 @@ func (se *SumologicExtension) updateMetadataWithHTTPClient(ctx context.Context,
Environment: se.conf.CollectorEnvironment,
},
CollectorDetails: api.OpenMetadataCollectorDetails{
RunningVersion: se.buildVersion,
RunningVersion: cleanupBuildVersion(se.buildVersion),
},
NetworkDetails: api.OpenMetadataNetworkDetails{
HostIpAddress: ip,
Expand Down Expand Up @@ -1057,3 +1058,20 @@ func getHostname(logger *zap.Logger) (string, error) {

return os.Hostname()
}

// cleanupBuildVersion adds a leading 'v' and removes the tailing build hash to make sure the
// backend understand the build number. Note that only version strings with the following format will be
// cleaned up. All other version formats will remain the same.
// Cleaned up format: 0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113
func cleanupBuildVersion(version string) string {
pattern := "(^[0-9]+\\.[0-9]+\\.[0-9]+-sumo-[0-9]+)-[0-9a-f]{40}$"
re := regexp.MustCompile(pattern)

sm := re.FindAllStringSubmatch(version, 1)
if len(sm) == 1 {
ver := sm[0][1]
return "v" + ver
}

return version
}
34 changes: 34 additions & 0 deletions pkg/extension/sumologicextension/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1593,3 +1593,37 @@ func TestUpdateMetadataRequestPayload(t *testing.T) {
err = se.updateMetadataWithHTTPClient(context.TODO(), httpClient)
require.NoError(t, err)
}

func Test_cleanupBuildVersion(t *testing.T) {
type args struct {
version string
}
tests := []struct {
name string
args args
want string
}{
{
name: "with hash",
args: args{version: "0.108.0-sumo-2-4d57200692d5c5c39effad4ae3b29fef79209113"},
want: "v0.108.0-sumo-2",
}, {
name: "already ok",
args: args{version: "v0.108.0-sumo-2"},
want: "v0.108.0-sumo-2",
}, {
name: "non v",
args: args{version: "0.108.0-sumo-2"},
want: "0.108.0-sumo-2",
}, {
name: "nonsense",
args: args{version: "hfiwe-23rhc8eg.fhf"},
want: "hfiwe-23rhc8eg.fhf",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, cleanupBuildVersion(tt.args.version), "cleanupBuildVersion(%v)", tt.args.version)
})
}
}

0 comments on commit b1ea0a9

Please sign in to comment.