Skip to content

Commit 303ff31

Browse files
authored
fix: proxy LogBanditAction through LruAssignmentLogger (#64)
1 parent 1985c48 commit 303ff31

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

eppoclient/lruassignmentlogger.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ type LruAssignmentLogger struct {
1111
inner IAssignmentLogger
1212
}
1313

14-
// We are only interested in whether a subject was ever a part of an
15-
// assignment. We are not interested in the order of assignments or
16-
// knowing the latest assignment. Therefore, both allocation and
17-
// variation are part of the cacheKey.
1814
type cacheKey struct {
1915
flag string
2016
subject string
@@ -54,3 +50,9 @@ func (lal *LruAssignmentLogger) LogAssignment(event AssignmentEvent) {
5450
lal.cache.Add(key, value)
5551
}
5652
}
53+
54+
func (lal *LruAssignmentLogger) LogBanditAction(event BanditEvent) {
55+
if logger, ok := lal.inner.(BanditActionLogger); ok {
56+
logger.LogBanditAction(event)
57+
}
58+
}

eppoclient/lruassignmentlogger_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,35 @@ func Test_LruAssignmentLogger_variationOscillationLogsAll(t *testing.T) {
237237

238238
innerLogger.AssertNumberOfCalls(t, "LogAssignment", 4)
239239
}
240+
241+
func Test_LruAssignmentLogger_proxyLogBanditAction(t *testing.T) {
242+
innerLogger := new(mockLogger)
243+
innerLogger.On("LogAssignment", mock.Anything).Return()
244+
innerLogger.On("LogBanditAction", mock.Anything).Return()
245+
246+
logger, err := NewLruAssignmentLogger(innerLogger, 1000)
247+
assert.NoError(t, err)
248+
249+
event := BanditEvent{
250+
FlagKey: "flag",
251+
BanditKey: "bandit",
252+
Subject: "subject",
253+
Action: "action",
254+
ActionProbability: 0.1,
255+
OptimalityGap: 0.1,
256+
ModelVersion: "model-version",
257+
Timestamp: "timestamp",
258+
SubjectNumericAttributes: map[string]float64{},
259+
SubjectCategoricalAttributes: map[string]string{},
260+
ActionNumericAttributes: map[string]float64{},
261+
ActionCategoricalAttributes: map[string]string{},
262+
MetaData: map[string]string{},
263+
}
264+
265+
banditLogger := logger.(BanditActionLogger)
266+
267+
banditLogger.LogBanditAction(event)
268+
banditLogger.LogBanditAction(event)
269+
270+
innerLogger.AssertNumberOfCalls(t, "LogBanditAction", 2)
271+
}

0 commit comments

Comments
 (0)