Skip to content

Commit

Permalink
feat: add default sampling rate to mlobs logger
Browse files Browse the repository at this point in the history
  • Loading branch information
khorshuheng committed Apr 16, 2024
1 parent 6e17697 commit c2b9834
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions api/pkg/inference-logger/logger/mlobs_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math/rand"

"google.golang.org/protobuf/types/known/timestamppb"

Expand All @@ -19,6 +20,10 @@ var (
ErrMalformedLogEntry = errors.New("malformed log entry")
)

const (
SamplingRate = 0.01
)

type MLObsSink struct {
logger *zap.SugaredLogger
producer KafkaProducer
Expand Down Expand Up @@ -163,6 +168,9 @@ func (m *MLObsSink) buildNewKafkaMessage(predictionLog *upiv1.PredictionLog) (*k

func (m *MLObsSink) Sink(rawLogEntries []*LogEntry) error {
for _, rawLogEntry := range rawLogEntries {
if rand.Float64() >= SamplingRate {
continue
}
predictionLog, err := m.newPredictionLog(rawLogEntry)
if err != nil {
m.logger.Errorf("unable to convert log entry: %v", err)
Expand Down

0 comments on commit c2b9834

Please sign in to comment.