diff --git a/pkg/util/useragent.go b/pkg/util/useragent.go index 53a115c15..d56fc554b 100644 --- a/pkg/util/useragent.go +++ b/pkg/util/useragent.go @@ -8,7 +8,7 @@ import ( var ( agentInfoRe = regexp.MustCompile(`^([a-zA-Z]*)\/(\d*.\d*.\d*)[-]?([a-z0-9]*?) SDK/(\d*.\d*.\d.*) ([a-z][a-zA-Z0-9-]*) ([a-z][a-zA-Z0-9-]*) (binary|docker)[ ]?(reactive)?`) - agentInfoReV2 = regexp.MustCompile(`^([a-zA-Z]*)\/(\d*.\d*.\d*)[-]?([-a-z0-9A-Z]*?) \(sdkVer:(\d*.\d*.\d.*)\; env:([a-zA-Z0-9-]*)\; agent:([a-zA-Z0-9-]*)\; reactive:(true|false)\; hostname:([a-zA-Z0-9-_]*)\) ??(grpc-go.*\/\d*.\d*.\d*)?$`) + agentInfoReV2 = regexp.MustCompile(`^([a-zA-Z]*)\/(\d*.\d*.\d*)[-]?([-a-z0-9A-Z]*?) \(sdkVer:(\d*.\d*.\d.*)\; env:([a-zA-Z0-9-]*)\; agent:([a-zA-Z0-9-]*)\; reactive:(true|false)\; hostname:([a-zA-Z0-9-_.]*)\) ??(grpc-go.*\/\d*.\d*.\d*)?$`) ) type CentralUserAgent struct { diff --git a/pkg/util/useragent_test.go b/pkg/util/useragent_test.go index 968601c8c..eb0790d49 100644 --- a/pkg/util/useragent_test.go +++ b/pkg/util/useragent_test.go @@ -52,6 +52,7 @@ func TestFormatUserAgents(t *testing.T) { func TestParseUserAgents(t *testing.T) { hostname, _ := os.Hostname() + hostname2 := "test-test.abc.com" tests := []struct { name string userAgent string @@ -132,6 +133,21 @@ func TestParseUserAgents(t *testing.T) { userAgent: "invalid user-agent", expectedUA: nil, }, + { + name: "test-6", + userAgent: fmt.Sprintf("Test/1.0.0-APIGOV-Test (sdkVer:1.0.0; env:env; agent:agent; reactive:false; hostname:%s)", hostname2), + expectedUA: &CentralUserAgent{ + AgentType: "Test", + Version: "1.0.0", + CommitSHA: "7e7eb72d", + SDKVersion: "1.0.0", + Environment: "env", + AgentName: "agent", + IsGRPC: false, + HostName: hostname2, + UseGRPCStatusUpdate: false, + }, + }, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) {