Skip to content

Commit 0a81450

Browse files
authored
[FSSDK-11980] Update Agent to use go-sdk v2.1.1 client.CmabConfig API (#446)
* Add CMAB testing setup - Update go-sdk to v2.1.1 (latest master) for CMAB UUID support - Configure datafileURLTemplate for staging environment - Add CMAB testing documentation with test scenarios - Setup for testing with SDK key DCx4eoV52jhgaC9MSab3g * Update to go-sdk v2.1.1 client.CmabConfig API - Replace cmab.Config with client.CmabConfig - Remove RetryConfig parsing (now handled internally by go-sdk) - Simplify CMAB configuration to use stable public API * Remove testing config changes - keep only go-sdk API update * Add test for CMAB endpoint environment variable to increase coverage
1 parent 49cd757 commit 0a81450

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/golang-jwt/jwt/v4 v4.5.2
1515
github.com/google/uuid v1.3.1
1616
github.com/lestrrat-go/jwx/v2 v2.0.20
17-
github.com/optimizely/go-sdk/v2 v2.0.0-20250820180618-907917e11924
17+
github.com/optimizely/go-sdk/v2 v2.1.1-0.20250930190916-92b83d299b7a
1818
github.com/orcaman/concurrent-map v1.0.0
1919
github.com/prometheus/client_golang v1.18.0
2020
github.com/rakyll/statik v0.1.7

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
229229
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
230230
github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE=
231231
github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs=
232-
github.com/optimizely/go-sdk/v2 v2.0.0-20250820180618-907917e11924 h1:RxRZkvwvqMVEGphhGvs9zHT642g10ql+IDEDK7dcwZ4=
233-
github.com/optimizely/go-sdk/v2 v2.0.0-20250820180618-907917e11924/go.mod h1:MusRCFsU7+XzJCoCTgheLoENJSf1iiFYm4KbJqz6BYA=
232+
github.com/optimizely/go-sdk/v2 v2.1.1-0.20250930190916-92b83d299b7a h1:wB445WJVx9JLYsHFQiy2OruPJlZ9ejae8vfsRHKZAtQ=
233+
github.com/optimizely/go-sdk/v2 v2.1.1-0.20250930190916-92b83d299b7a/go.mod h1:MusRCFsU7+XzJCoCTgheLoENJSf1iiFYm4KbJqz6BYA=
234234
github.com/orcaman/concurrent-map v1.0.0 h1:I/2A2XPCb4IuQWcQhBhSwGfiuybl/J0ev9HDbW65HOY=
235235
github.com/orcaman/concurrent-map v1.0.0/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
236236
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=

pkg/optimizely/cache.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -333,34 +333,11 @@ func defaultLoader(
333333
cacheTTL = cmab.DefaultCacheTTL
334334
}
335335

336-
// Create retry config
337-
retryConfig := &cmab.RetryConfig{
338-
MaxRetries: clientConf.CMAB.RetryConfig.MaxRetries,
339-
InitialBackoff: clientConf.CMAB.RetryConfig.InitialBackoff,
340-
MaxBackoff: clientConf.CMAB.RetryConfig.MaxBackoff,
341-
BackoffMultiplier: clientConf.CMAB.RetryConfig.BackoffMultiplier,
342-
}
343-
344-
// Apply defaults for retry config if not set
345-
if retryConfig.MaxRetries == 0 {
346-
retryConfig.MaxRetries = cmab.DefaultMaxRetries
347-
}
348-
if retryConfig.InitialBackoff == 0 {
349-
retryConfig.InitialBackoff = cmab.DefaultInitialBackoff
350-
}
351-
if retryConfig.MaxBackoff == 0 {
352-
retryConfig.MaxBackoff = cmab.DefaultMaxBackoff
353-
}
354-
if retryConfig.BackoffMultiplier == 0 {
355-
retryConfig.BackoffMultiplier = cmab.DefaultBackoffMultiplier
356-
}
357-
358-
// Create CMAB config (NO endpoint configuration - not configurable)
359-
cmabConfig := cmab.Config{
336+
// Create CMAB config using client API (RetryConfig now handled internally by go-sdk)
337+
cmabConfig := client.CmabConfig{
360338
CacheSize: cacheSize,
361339
CacheTTL: cacheTTL,
362340
HTTPTimeout: clientConf.CMAB.RequestTimeout,
363-
RetryConfig: retryConfig,
364341
}
365342

366343
// Add to client options

pkg/optimizely/cache_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package optimizely
2020
import (
2121
"context"
2222
"fmt"
23+
"os"
2324
"sync"
2425
"testing"
2526
"time"
@@ -1107,6 +1108,37 @@ func (s *DefaultLoaderTestSuite) TestCMABWithExistingServices() {
11071108
s.NotNil(client.odpCache, "ODP Cache should still be configured")
11081109
}
11091110

1111+
func (s *DefaultLoaderTestSuite) TestCMABEndpointEnvironmentVariable() {
1112+
// Save original value and restore after test
1113+
originalEndpoint := os.Getenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT")
1114+
defer func() {
1115+
if originalEndpoint == "" {
1116+
os.Unsetenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT")
1117+
} else {
1118+
os.Setenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT", originalEndpoint)
1119+
}
1120+
}()
1121+
1122+
// Set custom endpoint
1123+
testEndpoint := "https://test.prediction.endpoint.com/predict/%s"
1124+
os.Setenv("OPTIMIZELY_CMAB_PREDICTIONENDPOINT", testEndpoint)
1125+
1126+
conf := config.ClientConfig{
1127+
SdkKeyRegex: "sdkkey",
1128+
CMAB: config.CMABConfig{
1129+
RequestTimeout: 5 * time.Second,
1130+
Cache: config.CMABCacheConfig{},
1131+
RetryConfig: config.CMABRetryConfig{},
1132+
},
1133+
}
1134+
1135+
loader := defaultLoader(config.AgentConfig{Client: conf}, s.registry, nil, s.upsMap, s.odpCacheMap, s.pcFactory, s.bpFactory)
1136+
client, err := loader("sdkkey")
1137+
1138+
s.NoError(err)
1139+
s.NotNil(client)
1140+
}
1141+
11101142
func TestDefaultLoaderTestSuite(t *testing.T) {
11111143
suite.Run(t, new(DefaultLoaderTestSuite))
11121144
}

0 commit comments

Comments
 (0)