Skip to content

Commit

Permalink
feat: add default sampling rate to mlobs logger (#567)
Browse files Browse the repository at this point in the history
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. Run unit tests and ensure that they are passing
2. If your change introduces any API changes, make sure to update the
e2e tests
3. Make sure documentation is updated for your PR!

-->
# Description
<!-- Briefly describe the motivation for the change. Please include
illustrations where appropriate. -->
As of now, the mlobs logger logs every single message sent to the
logger. As there is no good way at the moment to use different logger
configuration for different model, tentatively, we will be adding a
default sampling rate that will apply to all models that enable mlobs
logger.

# Modifications
<!-- Summarize the key code changes. -->
Add a 2% sampling rate to mlobs sink.

# Tests
<!-- Besides the existing / updated automated tests, what specific
scenarios should be tested? Consider the backward compatibility of the
changes, whether corner cases are covered, etc. Please describe the
tests and check the ones that have been completed. Eg:
- [x] Deploying new and existing standard models
- [ ] Deploying PyFunc models
-->

# Checklist
- [ ] Added PR label
- [ ] Added unit test, integration, and/or e2e tests
- [ ] Tested locally
- [ ] Updated documentation
- [ ] Update Swagger spec if the PR introduce API changes
- [ ] Regenerated Golang and Python client if the PR introduces API
changes

# Release Notes
<!--
Does this PR introduce a user-facing change?
If no, just write "NONE" in the release-note block below.
If yes, a release note is required. Enter your extended release note in
the block below.
If the PR requires additional action from users switching to the new
release, include the string "action required".

For more information about release notes, see kubernetes' guide here:
http://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note

```
  • Loading branch information
khorshuheng committed Apr 16, 2024
1 parent 54172f8 commit 5623e85
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 5623e85

Please sign in to comment.