mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-29 08:57:18 +02:00
authorize: avoid serializing databroker data map to improve performance (#995)
This commit is contained in:
parent
7110948296
commit
3ad8cbf4ec
5 changed files with 104 additions and 29 deletions
|
@ -1,16 +1,23 @@
|
|||
package evaluator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/pomerium/pomerium/config"
|
||||
"github.com/pomerium/pomerium/internal/grpc/databroker"
|
||||
"github.com/pomerium/pomerium/internal/grpc/directory"
|
||||
"github.com/pomerium/pomerium/internal/grpc/session"
|
||||
"github.com/pomerium/pomerium/internal/grpc/user"
|
||||
)
|
||||
|
||||
func TestJSONMarshal(t *testing.T) {
|
||||
|
@ -25,7 +32,7 @@ func TestJSONMarshal(t *testing.T) {
|
|||
"type.googleapis.com/user.User": map[string]interface{}{},
|
||||
}
|
||||
|
||||
bs, _ := json.Marshal(input{
|
||||
bs, _ := json.Marshal(new(Evaluator).newInput(&Request{
|
||||
DataBrokerData: dbd,
|
||||
HTTP: RequestHTTP{
|
||||
Method: "GET",
|
||||
|
@ -40,18 +47,9 @@ func TestJSONMarshal(t *testing.T) {
|
|||
ImpersonateEmail: "y@example.com",
|
||||
ImpersonateGroups: []string{"group1"},
|
||||
},
|
||||
IsValidClientCertificate: true,
|
||||
})
|
||||
}, true))
|
||||
assert.JSONEq(t, `{
|
||||
"databroker_data": {
|
||||
"type.googleapis.com/directory.User": {
|
||||
"user1": {
|
||||
"id": "user1",
|
||||
"groups": ["group1", "group2"]
|
||||
}
|
||||
},
|
||||
"type.googleapis.com/session.Session": {},
|
||||
"type.googleapis.com/user.User": {}
|
||||
},
|
||||
"http": {
|
||||
"client_certificate": "CLIENT_CERTIFICATE",
|
||||
|
@ -97,3 +95,68 @@ func mustParseURL(str string) *url.URL {
|
|||
}
|
||||
return u
|
||||
}
|
||||
|
||||
func BenchmarkEvaluator_Evaluate(b *testing.B) {
|
||||
e, err := New(&config.Options{
|
||||
AuthenticateURL: mustParseURL("https://authn.example.com"),
|
||||
})
|
||||
if !assert.NoError(b, err) {
|
||||
return
|
||||
}
|
||||
|
||||
lastSessionID := ""
|
||||
|
||||
dbd := make(DataBrokerData)
|
||||
for i := 0; i < 100; i++ {
|
||||
sessionID := uuid.New().String()
|
||||
lastSessionID = sessionID
|
||||
userID := uuid.New().String()
|
||||
data, _ := ptypes.MarshalAny(&session.Session{
|
||||
Version: fmt.Sprint(i),
|
||||
Id: sessionID,
|
||||
UserId: userID,
|
||||
IdToken: &session.IDToken{
|
||||
Issuer: "benchmark",
|
||||
Subject: userID,
|
||||
IssuedAt: ptypes.TimestampNow(),
|
||||
},
|
||||
OauthToken: &session.OAuthToken{
|
||||
AccessToken: "ACCESS TOKEN",
|
||||
TokenType: "Bearer",
|
||||
RefreshToken: "REFRESH TOKEN",
|
||||
},
|
||||
})
|
||||
dbd.Update(&databroker.Record{
|
||||
Version: fmt.Sprint(i),
|
||||
Type: "type.googleapis.com/session.Session",
|
||||
Id: sessionID,
|
||||
Data: data,
|
||||
})
|
||||
data, _ = ptypes.MarshalAny(&user.User{
|
||||
Version: fmt.Sprint(i),
|
||||
Id: userID,
|
||||
})
|
||||
dbd.Update(&databroker.Record{
|
||||
Version: fmt.Sprint(i),
|
||||
Type: "type.googleapis.com/user.User",
|
||||
Id: userID,
|
||||
Data: data,
|
||||
})
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
ctx := context.Background()
|
||||
for i := 0; i < b.N; i++ {
|
||||
e.Evaluate(ctx, &Request{
|
||||
DataBrokerData: dbd,
|
||||
HTTP: RequestHTTP{
|
||||
Method: "GET",
|
||||
URL: "https://example.com/path",
|
||||
Headers: map[string]string{},
|
||||
},
|
||||
Session: RequestSession{
|
||||
ID: lastSessionID,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue