Skip to content

Commit d179324

Browse files
committed
--wip-- [skip ci]
1 parent bdc03f4 commit d179324

File tree

6 files changed

+58
-46
lines changed

6 files changed

+58
-46
lines changed

openfeature/exposure.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,17 @@ type exposurePayload struct {
8585
Exposures []exposureEvent `json:"exposures"`
8686
}
8787

88+
type bufferKey struct {
89+
flagKey string
90+
allocationKey string
91+
variantKey string
92+
subjectID string
93+
}
94+
8895
// exposureWriter manages buffering and flushing of exposure events to the Datadog Agent
8996
type exposureWriter struct {
9097
mu sync.Mutex
91-
buffer map[string]exposureEvent // Deduplicate by composite key
98+
buffer map[bufferKey]exposureEvent // Deduplicate by composite key
9299
flushInterval time.Duration
93100
httpClient *http.Client
94101
agentURL *url.URL
@@ -136,7 +143,7 @@ func newExposureWriter(config *ProviderConfig) *exposureWriter {
136143
}
137144

138145
w := &exposureWriter{
139-
buffer: make(map[string]exposureEvent),
146+
buffer: make(map[bufferKey]exposureEvent),
140147
flushInterval: flushInterval,
141148
httpClient: httpClient,
142149
agentURL: agentURL,
@@ -176,7 +183,12 @@ func (w *exposureWriter) append(event exposureEvent) {
176183

177184
// Create composite key for deduplication
178185
// Deduplicate by flag, allocation, variant, and subject.id
179-
key := fmt.Sprintf("%s|%s|%s|%s", event.Flag.Key, event.Allocation.Key, event.Variant.Key, event.Subject.ID)
186+
key := bufferKey{
187+
flagKey: event.Flag.Key,
188+
allocationKey: event.Allocation.Key,
189+
variantKey: event.Variant.Key,
190+
subjectID: event.Subject.ID,
191+
}
180192

181193
// Store event (will overwrite if duplicate)
182194
w.buffer[key] = event
@@ -195,7 +207,7 @@ func (w *exposureWriter) flush() {
195207
for _, event := range w.buffer {
196208
events = append(events, event)
197209
}
198-
w.buffer = make(map[string]exposureEvent)
210+
w.buffer = make(map[bufferKey]exposureEvent)
199211
w.mu.Unlock()
200212

201213
// Build payload

openfeature/integration_test.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
// using the actual OpenFeature SDK client.
1919
func TestEndToEnd_BooleanFlag(t *testing.T) {
2020
// Create provider and configuration
21-
provider := newDatadogProvider()
21+
provider := newDatadogProvider(nil)
2222
config := createE2EBooleanConfig()
2323
provider.updateConfiguration(&config)
2424

@@ -88,7 +88,7 @@ func TestEndToEnd_BooleanFlag(t *testing.T) {
8888

8989
// TestEndToEnd_StringFlag tests string flag evaluation with the OpenFeature SDK.
9090
func TestEndToEnd_StringFlag(t *testing.T) {
91-
provider := newDatadogProvider()
91+
provider := newDatadogProvider(nil)
9292
config := createE2EStringConfig()
9393
provider.updateConfiguration(config)
9494

@@ -133,7 +133,7 @@ func TestEndToEnd_StringFlag(t *testing.T) {
133133

134134
// TestEndToEnd_IntegerFlag tests integer flag evaluation.
135135
func TestEndToEnd_IntegerFlag(t *testing.T) {
136-
provider := newDatadogProvider()
136+
provider := newDatadogProvider(nil)
137137
config := createE2EIntegerConfig()
138138
provider.updateConfiguration(config)
139139

@@ -178,7 +178,7 @@ func TestEndToEnd_IntegerFlag(t *testing.T) {
178178

179179
// TestEndToEnd_FloatFlag tests float flag evaluation.
180180
func TestEndToEnd_FloatFlag(t *testing.T) {
181-
provider := newDatadogProvider()
181+
provider := newDatadogProvider(nil)
182182
config := createE2EFloatConfig()
183183
provider.updateConfiguration(config)
184184

@@ -206,7 +206,7 @@ func TestEndToEnd_FloatFlag(t *testing.T) {
206206

207207
// TestEndToEnd_ObjectFlag tests JSON/object flag evaluation.
208208
func TestEndToEnd_ObjectFlag(t *testing.T) {
209-
provider := newDatadogProvider()
209+
provider := newDatadogProvider(nil)
210210
config := createE2EObjectConfig()
211211
provider.updateConfiguration(config)
212212

@@ -252,7 +252,7 @@ func TestEndToEnd_ObjectFlag(t *testing.T) {
252252

253253
// TestEndToEnd_DisabledFlag tests that disabled flags return defaults.
254254
func TestEndToEnd_DisabledFlag(t *testing.T) {
255-
provider := newDatadogProvider()
255+
provider := newDatadogProvider(nil)
256256
config := &universalFlagsConfiguration{
257257
Format: "SERVER",
258258
Environment: environment{
@@ -297,7 +297,7 @@ func TestEndToEnd_DisabledFlag(t *testing.T) {
297297

298298
// TestEndToEnd_MissingFlag tests error handling for non-existent flags.
299299
func TestEndToEnd_MissingFlag(t *testing.T) {
300-
provider := newDatadogProvider()
300+
provider := newDatadogProvider(nil)
301301
config := &universalFlagsConfiguration{
302302
Format: "SERVER",
303303
Environment: environment{
@@ -334,7 +334,7 @@ func TestEndToEnd_MissingFlag(t *testing.T) {
334334

335335
// TestEndToEnd_ConfigurationUpdate tests that configuration updates are reflected in evaluations.
336336
func TestEndToEnd_ConfigurationUpdate(t *testing.T) {
337-
provider := newDatadogProvider()
337+
provider := newDatadogProvider(nil)
338338
provider.updateConfiguration(&universalFlagsConfiguration{})
339339
err := of.SetProviderAndWait(provider)
340340
if err != nil {
@@ -368,7 +368,7 @@ func TestEndToEnd_ConfigurationUpdate(t *testing.T) {
368368

369369
// TestEndToEnd_TrafficSharding tests that traffic distribution works correctly.
370370
func TestEndToEnd_TrafficSharding(t *testing.T) {
371-
provider := newDatadogProvider()
371+
provider := newDatadogProvider(nil)
372372
config := createE2EShardingConfig()
373373
provider.updateConfiguration(config)
374374

@@ -826,7 +826,7 @@ func TestEndToEnd_JSONSerialization(t *testing.T) {
826826
}
827827

828828
// Use the parsed config
829-
provider := newDatadogProvider()
829+
provider := newDatadogProvider(nil)
830830
provider.updateConfiguration(&parsedConfig)
831831

832832
err = of.SetProviderAndWait(provider)
@@ -853,7 +853,7 @@ func TestEndToEnd_JSONSerialization(t *testing.T) {
853853
// TestEndToEnd_EmptyRulesAllocation tests that an allocation with no rules matches all users.
854854
// This covers the fix where empty rules should match everyone (no targeting restrictions).
855855
func TestEndToEnd_EmptyRulesAllocation(t *testing.T) {
856-
provider := newDatadogProvider()
856+
provider := newDatadogProvider(nil)
857857
config := &universalFlagsConfiguration{
858858
Format: "SERVER",
859859
Environment: environment{
@@ -925,7 +925,7 @@ func TestEndToEnd_EmptyRulesAllocation(t *testing.T) {
925925
// TestEndToEnd_ShardCalculationWithDash tests that the shard calculation uses
926926
// salt + "-" + targetingKey (with dash separator) to match Eppo SDK implementation.
927927
func TestEndToEnd_ShardCalculationWithDash(t *testing.T) {
928-
provider := newDatadogProvider()
928+
provider := newDatadogProvider(nil)
929929
config := &universalFlagsConfiguration{
930930
Format: "SERVER",
931931
Environment: environment{
@@ -1035,7 +1035,7 @@ func TestEndToEnd_ShardCalculationWithDash(t *testing.T) {
10351035
// TestEndToEnd_IdAttributeFallback tests that when an attribute named "id" is not
10361036
// explicitly provided, the targeting key is used as the "id" value.
10371037
func TestEndToEnd_IdAttributeFallback(t *testing.T) {
1038-
provider := newDatadogProvider()
1038+
provider := newDatadogProvider(nil)
10391039
config := &universalFlagsConfiguration{
10401040
Format: "SERVER",
10411041
Environment: environment{
@@ -1151,7 +1151,7 @@ func TestEndToEnd_IdAttributeFallback(t *testing.T) {
11511151

11521152
// TestEndToEnd_AllThreeFixes tests a complex scenario that exercises all three fixes together.
11531153
func TestEndToEnd_AllThreeFixes(t *testing.T) {
1154-
provider := newDatadogProvider()
1154+
provider := newDatadogProvider(nil)
11551155
config := &universalFlagsConfiguration{
11561156
Format: "SERVER",
11571157
Environment: environment{

openfeature/provider_bench_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// BenchmarkBooleanEvaluation benchmarks boolean flag evaluation
1616
func BenchmarkBooleanEvaluation(b *testing.B) {
17-
provider := newDatadogProvider()
17+
provider := newDatadogProvider(nil)
1818
config := createTestConfig()
1919
provider.updateConfiguration(config)
2020

@@ -34,7 +34,7 @@ func BenchmarkBooleanEvaluation(b *testing.B) {
3434

3535
// BenchmarkStringEvaluation benchmarks string flag evaluation
3636
func BenchmarkStringEvaluation(b *testing.B) {
37-
provider := newDatadogProvider()
37+
provider := newDatadogProvider(nil)
3838
config := createTestConfig()
3939
provider.updateConfiguration(config)
4040

@@ -54,7 +54,7 @@ func BenchmarkStringEvaluation(b *testing.B) {
5454

5555
// BenchmarkIntEvaluation benchmarks integer flag evaluation
5656
func BenchmarkIntEvaluation(b *testing.B) {
57-
provider := newDatadogProvider()
57+
provider := newDatadogProvider(nil)
5858
config := createTestConfig()
5959
provider.updateConfiguration(config)
6060

@@ -74,7 +74,7 @@ func BenchmarkIntEvaluation(b *testing.B) {
7474

7575
// BenchmarkFloatEvaluation benchmarks float flag evaluation
7676
func BenchmarkFloatEvaluation(b *testing.B) {
77-
provider := newDatadogProvider()
77+
provider := newDatadogProvider(nil)
7878
config := createTestConfig()
7979
provider.updateConfiguration(config)
8080

@@ -94,7 +94,7 @@ func BenchmarkFloatEvaluation(b *testing.B) {
9494

9595
// BenchmarkObjectEvaluation benchmarks object flag evaluation
9696
func BenchmarkEvaluation(b *testing.B) {
97-
provider := newDatadogProvider()
97+
provider := newDatadogProvider(nil)
9898
config := createTestConfig()
9999
provider.updateConfiguration(config)
100100

@@ -126,7 +126,7 @@ func BenchmarkEvaluationWithVaryingContextSize(b *testing.B) {
126126

127127
for _, size := range contextSizes {
128128
b.Run(size.name, func(b *testing.B) {
129-
provider := newDatadogProvider()
129+
provider := newDatadogProvider(nil)
130130
config := createTestConfig()
131131
provider.updateConfiguration(config)
132132

@@ -165,7 +165,7 @@ func BenchmarkEvaluationWithVaryingFlagCounts(b *testing.B) {
165165

166166
for _, count := range flagCounts {
167167
b.Run(count.name, func(b *testing.B) {
168-
provider := newDatadogProvider()
168+
provider := newDatadogProvider(nil)
169169
config := createTestConfig()
170170

171171
// Add additional flags
@@ -213,7 +213,7 @@ func BenchmarkEvaluationWithVaryingFlagCounts(b *testing.B) {
213213

214214
// BenchmarkConcurrentEvaluations benchmarks concurrent flag evaluations
215215
func BenchmarkConcurrentEvaluations(b *testing.B) {
216-
provider := newDatadogProvider()
216+
provider := newDatadogProvider(nil)
217217
config := createTestConfig()
218218
provider.updateConfiguration(config)
219219

openfeature/provider_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func createTestConfig() *universalFlagsConfiguration {
243243
}
244244

245245
func TestNewDatadogProvider(t *testing.T) {
246-
provider := newDatadogProvider()
246+
provider := newDatadogProvider(nil)
247247
if provider == nil {
248248
t.Fatal("expected provider to be non-nil")
249249
}
@@ -254,13 +254,13 @@ func TestNewDatadogProvider(t *testing.T) {
254254
}
255255

256256
hooks := provider.Hooks()
257-
if len(hooks) != 0 {
258-
t.Errorf("expected no hooks, got %d", len(hooks))
257+
if len(hooks) != 1 {
258+
t.Errorf("expected 1 hook, got %d", len(hooks))
259259
}
260260
}
261261

262262
func TestBooleanEvaluation(t *testing.T) {
263-
provider := newDatadogProvider()
263+
provider := newDatadogProvider(nil)
264264
config := createTestConfig()
265265
provider.updateConfiguration(config)
266266

@@ -332,7 +332,7 @@ func TestBooleanEvaluation(t *testing.T) {
332332
}
333333

334334
func TestStringEvaluation(t *testing.T) {
335-
provider := newDatadogProvider()
335+
provider := newDatadogProvider(nil)
336336
config := createTestConfig()
337337
provider.updateConfiguration(config)
338338

@@ -373,7 +373,7 @@ func TestStringEvaluation(t *testing.T) {
373373
}
374374

375375
func TestIntEvaluation(t *testing.T) {
376-
provider := newDatadogProvider()
376+
provider := newDatadogProvider(nil)
377377
config := createTestConfig()
378378
provider.updateConfiguration(config)
379379

@@ -410,7 +410,7 @@ func TestIntEvaluation(t *testing.T) {
410410
}
411411

412412
func TestFloatEvaluation(t *testing.T) {
413-
provider := newDatadogProvider()
413+
provider := newDatadogProvider(nil)
414414
config := createTestConfig()
415415
provider.updateConfiguration(config)
416416

@@ -448,7 +448,7 @@ func TestFloatEvaluation(t *testing.T) {
448448
}
449449

450450
func TestObjectEvaluation(t *testing.T) {
451-
provider := newDatadogProvider()
451+
provider := newDatadogProvider(nil)
452452
config := createTestConfig()
453453
provider.updateConfiguration(config)
454454

@@ -498,7 +498,7 @@ func TestObjectEvaluation(t *testing.T) {
498498
}
499499

500500
func TestProviderWithoutConfiguration(t *testing.T) {
501-
provider := newDatadogProvider()
501+
provider := newDatadogProvider(nil)
502502
ctx := context.Background()
503503

504504
flatCtx := openfeature.FlattenedContext{
@@ -521,7 +521,7 @@ func TestProviderWithoutConfiguration(t *testing.T) {
521521
}
522522

523523
func TestProviderConfigurationUpdate(t *testing.T) {
524-
provider := newDatadogProvider()
524+
provider := newDatadogProvider(nil)
525525

526526
// Initially no config
527527
if provider.getConfiguration() != nil {
@@ -543,7 +543,7 @@ func TestProviderConfigurationUpdate(t *testing.T) {
543543
}
544544

545545
func TestConcurrentEvaluations(t *testing.T) {
546-
provider := newDatadogProvider()
546+
provider := newDatadogProvider(nil)
547547
config := createTestConfig()
548548
provider.updateConfiguration(config)
549549

openfeature/remoteconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func processConfigUpdate(provider *DatadogProvider, path string, data []byte) rc
7070
}
7171

7272
// Parse the configuration
73-
log.Debug("openfeature: remote config: processing configuration update %q: %s", path, len(data))
73+
log.Debug("openfeature: remote config: processing configuration update %q", path)
7474

7575
var config universalFlagsConfiguration
7676
if err := json.Unmarshal(data, &config); err != nil {

0 commit comments

Comments
 (0)