Skip to content

Commit

Permalink
don't encode empty streams
Browse files Browse the repository at this point in the history
- separate emptyBuffer method
  • Loading branch information
barrettj12 committed Aug 2, 2023
1 parent 8f820a6 commit 34eddbb
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions internals/overlord/logstate/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ func (c *lokiClient) Flush(ctx context.Context) error {
return nil // no-op
}

defer func() {
for svc := range c.entries {
c.entries[svc] = c.entries[svc][:0]
}
}()
defer c.emptyBuffer()

// Build request
req := lokiRequest{}
for service, entries := range c.entries {
if len(entries) == 0 {
continue
}
stream := lokiStream{
Labels: map[string]string{
"pebble_service": service,
Expand Down Expand Up @@ -120,6 +119,12 @@ func (c *lokiClient) Flush(ctx context.Context) error {
return nil
}

func (c *lokiClient) emptyBuffer() {
for svc := range c.entries {
c.entries[svc] = c.entries[svc][:0]
}
}

type lokiRequest struct {
Streams []lokiStream `json:"streams"`
}
Expand Down

0 comments on commit 34eddbb

Please sign in to comment.