Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/golang-jwt/jwt/v4 v4.5.2
github.com/google/uuid v1.3.1
github.com/lestrrat-go/jwx/v2 v2.0.20
github.com/optimizely/go-sdk/v2 v2.0.0-20250820180618-907917e11924
github.com/optimizely/go-sdk/v2 v2.1.1-0.20250930190916-92b83d299b7a
github.com/orcaman/concurrent-map v1.0.0
github.com/prometheus/client_golang v1.18.0
github.com/rakyll/statik v0.1.7
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
github.com/optimizely/go-sdk/v2 v2.0.0-20250820180618-907917e11924 h1:RxRZkvwvqMVEGphhGvs9zHT642g10ql+IDEDK7dcwZ4=
github.com/optimizely/go-sdk/v2 v2.0.0-20250820180618-907917e11924/go.mod h1:MusRCFsU7+XzJCoCTgheLoENJSf1iiFYm4KbJqz6BYA=
github.com/optimizely/go-sdk/v2 v2.1.1-0.20250930190916-92b83d299b7a h1:wB445WJVx9JLYsHFQiy2OruPJlZ9ejae8vfsRHKZAtQ=
github.com/optimizely/go-sdk/v2 v2.1.1-0.20250930190916-92b83d299b7a/go.mod h1:MusRCFsU7+XzJCoCTgheLoENJSf1iiFYm4KbJqz6BYA=
github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HDbW65HOY=
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
Expand Down
27 changes: 2 additions & 25 deletions pkg/optimizely/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,34 +333,11 @@ func defaultLoader(
cacheTTL = cmab.DefaultCacheTTL
}

// Create retry config
retryConfig := &cmab.RetryConfig{
MaxRetries: clientConf.CMAB.RetryConfig.MaxRetries,
InitialBackoff: clientConf.CMAB.RetryConfig.InitialBackoff,
MaxBackoff: clientConf.CMAB.RetryConfig.MaxBackoff,
BackoffMultiplier: clientConf.CMAB.RetryConfig.BackoffMultiplier,
}

// Apply defaults for retry config if not set
if retryConfig.MaxRetries == 0 {
retryConfig.MaxRetries = cmab.DefaultMaxRetries
}
if retryConfig.InitialBackoff == 0 {
retryConfig.InitialBackoff = cmab.DefaultInitialBackoff
}
if retryConfig.MaxBackoff == 0 {
retryConfig.MaxBackoff = cmab.DefaultMaxBackoff
}
if retryConfig.BackoffMultiplier == 0 {
retryConfig.BackoffMultiplier = cmab.DefaultBackoffMultiplier
}

// Create CMAB config (NO endpoint configuration - not configurable)
cmabConfig := cmab.Config{
// Create CMAB config using client API (RetryConfig now handled internally by go-sdk)
cmabConfig := client.CmabConfig{
CacheSize: cacheSize,
CacheTTL: cacheTTL,
HTTPTimeout: clientConf.CMAB.RequestTimeout,
RetryConfig: retryConfig,
}

// Add to client options
Expand Down
32 changes: 32 additions & 0 deletions pkg/optimizely/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package optimizely
import (
"context"
"fmt"
"os"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -1107,6 +1108,37 @@ func (s *DefaultLoaderTestSuite) TestCMABWithExistingServices() {
s.NotNil(client.odpCache, "ODP Cache should still be configured")
}

func (s *DefaultLoaderTestSuite) TestCMABEndpointEnvironmentVariable() {
// Save original value and restore after test
originalEndpoint := os.Getenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT")
defer func() {
if originalEndpoint == "" {
os.Unsetenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT")
} else {
os.Setenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT", originalEndpoint)
}
}()

// Set custom endpoint
testEndpoint := "https://test.prediction.endpoint.com/predict/%s"
os.Setenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT", testEndpoint)

conf := config.ClientConfig{
SdkKeyRegex: "sdkkey",
CMAB: config.CMABConfig{
RequestTimeout: 5 * time.Second,
Cache: config.CMABCacheConfig{},
RetryConfig: config.CMABRetryConfig{},
},
}

loader := defaultLoader(config.AgentConfig{Client: conf}, s.registry, nil, s.upsMap, s.odpCacheMap, s.pcFactory, s.bpFactory)
client, err := loader("sdkkey")

s.NoError(err)
s.NotNil(client)
}

func TestDefaultLoaderTestSuite(t *testing.T) {
suite.Run(t, new(DefaultLoaderTestSuite))
}