mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-02 08:19:23 +02:00
Optimize policy iterators (#5184)
* Optimize policy iterators (go1.23) This modifies (*Options).GetAllPolicies() to use a go 1.23 iterator instead of copying all policies on every call, which can be extremely expensive. All existing usages of this function were updated as necessary. Additionally, a new (*Options).NumPolicies() method was added which quickly computes the number of policies that would be given by GetAllPolicies(), since there were several usages where only the number of policies was needed. * Fix race condition when assigning default envoy opts to a policy
This commit is contained in:
parent
3961098681
commit
56ba07e53e
16 changed files with 136 additions and 87 deletions
|
@ -74,7 +74,7 @@ func New(cfg *config.Config) (*Proxy, error) {
|
|||
p.webauthn = webauthn.New(p.getWebauthnState)
|
||||
|
||||
metrics.AddPolicyCountCallback("pomerium-proxy", func() int64 {
|
||||
return int64(len(p.currentOptions.Load().GetAllPolicies()))
|
||||
return int64(p.currentOptions.Load().NumPolicies())
|
||||
})
|
||||
|
||||
return p, nil
|
||||
|
@ -103,7 +103,7 @@ func (p *Proxy) OnConfigChange(_ context.Context, cfg *config.Config) {
|
|||
}
|
||||
|
||||
func (p *Proxy) setHandlers(opts *config.Options) error {
|
||||
if len(opts.GetAllPolicies()) == 0 {
|
||||
if opts.NumPolicies() == 0 {
|
||||
log.Warn(context.TODO()).Msg("proxy: configuration has no policies")
|
||||
}
|
||||
r := httputil.NewRouter()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue