Skip to content

Commit

Permalink
Add tenant to tee (#11573)
Browse files Browse the repository at this point in the history
It is useful for implementations of Tee to also know the tenant who sent
the logs. This PR adds tenant to the tee interface.
  • Loading branch information
MasslessParticle committed Jan 3, 2024
1 parent e9446a9 commit d2f4378
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ func (d *Distributor) Push(ctx context.Context, req *logproto.PushRequest) (*log
// Nil check for performance reasons, to avoid dynamic lookup and/or no-op
// function calls that cannot be inlined.
if d.tee != nil {
d.tee.Duplicate(streams)
d.tee.Duplicate(tenantID, streams)
}

const maxExpectedReplicationSet = 5 // typical replication factor 3 plus one for inactive plus one for luck
Expand Down
6 changes: 5 additions & 1 deletion pkg/distributor/distributor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1251,12 +1251,14 @@ func (s *fakeRateStore) RateFor(_ string, _ uint64) (int64, float64) {
type mockTee struct {
mu sync.Mutex
duplicated [][]KeyedStream
tenant string
}

func (mt *mockTee) Duplicate(streams []KeyedStream) {
func (mt *mockTee) Duplicate(tenant string, streams []KeyedStream) {
mt.mu.Lock()
defer mt.mu.Unlock()
mt.duplicated = append(mt.duplicated, streams)
mt.tenant = tenant
}

func TestDistributorTee(t *testing.T) {
Expand Down Expand Up @@ -1307,5 +1309,7 @@ func TestDistributorTee(t *testing.T) {
for j, streams := range td.Streams {
assert.Equal(t, tee.duplicated[i][j].Stream.Entries, streams.Entries)
}

require.Equal(t, "test", tee.tenant)
}
}
4 changes: 2 additions & 2 deletions pkg/distributor/tee.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package distributor

// Tee imlpementations can duplicate the log streams to another endpoint.
// Tee implementations can duplicate the log streams to another endpoint.
type Tee interface {
Duplicate([]KeyedStream)
Duplicate(tenant string, streams []KeyedStream)
}

0 comments on commit d2f4378

Please sign in to comment.