rpc: use "+" concatination in hot path RPC rate limit metrics. (#16923)
This commit is contained in:
parent
37ddd2dd86
commit
367cfa6d93
|
@ -515,15 +515,15 @@ func (ai *AuthenticatedIdentity) String() string {
|
|||
return "unauthenticated"
|
||||
}
|
||||
if ai.ACLToken != nil {
|
||||
return fmt.Sprintf("token:%s", ai.ACLToken.AccessorID)
|
||||
return "token:" + ai.ACLToken.AccessorID
|
||||
}
|
||||
if ai.Claims != nil {
|
||||
return fmt.Sprintf("alloc:%s", ai.Claims.AllocationID)
|
||||
return "alloc:" + ai.Claims.AllocationID
|
||||
}
|
||||
if ai.ClientID != "" {
|
||||
return fmt.Sprintf("client:%s", ai.ClientID)
|
||||
return "client:" + ai.ClientID
|
||||
}
|
||||
return fmt.Sprintf("%s:%s", ai.TLSName, ai.RemoteIP.String())
|
||||
return ai.TLSName + ":" + ai.RemoteIP.String()
|
||||
}
|
||||
|
||||
func (ai *AuthenticatedIdentity) IsExpired(now time.Time) bool {
|
||||
|
|
|
@ -5,6 +5,7 @@ package structs
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
@ -22,6 +23,62 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAuthenticatedIdentity_String(t *testing.T) {
|
||||
ci.Parallel(t)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
inputAuthenticatedIdentity *AuthenticatedIdentity
|
||||
expectedOutput string
|
||||
}{
|
||||
{
|
||||
name: "nil",
|
||||
inputAuthenticatedIdentity: nil,
|
||||
expectedOutput: "unauthenticated",
|
||||
},
|
||||
{
|
||||
name: "ACL token",
|
||||
inputAuthenticatedIdentity: &AuthenticatedIdentity{
|
||||
ACLToken: &ACLToken{
|
||||
AccessorID: "my-testing-accessor-id",
|
||||
},
|
||||
},
|
||||
expectedOutput: "token:my-testing-accessor-id",
|
||||
},
|
||||
{
|
||||
name: "alloc claim",
|
||||
inputAuthenticatedIdentity: &AuthenticatedIdentity{
|
||||
Claims: &IdentityClaims{
|
||||
AllocationID: "my-testing-alloc-id",
|
||||
},
|
||||
},
|
||||
expectedOutput: "alloc:my-testing-alloc-id",
|
||||
},
|
||||
{
|
||||
name: "client",
|
||||
inputAuthenticatedIdentity: &AuthenticatedIdentity{
|
||||
ClientID: "my-testing-client-id",
|
||||
},
|
||||
expectedOutput: "client:my-testing-client-id",
|
||||
},
|
||||
{
|
||||
name: "tls remote IP",
|
||||
inputAuthenticatedIdentity: &AuthenticatedIdentity{
|
||||
TLSName: "my-testing-tls-name",
|
||||
RemoteIP: net.IPv4(192, 168, 135, 232),
|
||||
},
|
||||
expectedOutput: "my-testing-tls-name:192.168.135.232",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
actualOutput := tc.inputAuthenticatedIdentity.String()
|
||||
must.Eq(t, tc.expectedOutput, actualOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestJob_Validate(t *testing.T) {
|
||||
ci.Parallel(t)
|
||||
|
||||
|
|
Loading…
Reference in New Issue