Skip to content

Commit b33379d

Browse files
committed
oops
Signed-off-by: sspaink <[email protected]>
1 parent 8a07e75 commit b33379d

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

Diff for: v1/plugins/logs/eventBuffer.go

+13-20
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package logs
77
import (
88
"context"
99
"encoding/json"
10-
"fmt"
1110
"sync"
1211

1312
"github.com/open-policy-agent/opa/v1/logging"
@@ -44,6 +43,7 @@ func newEventBuffer(bufferSizeLimitEvents int64, client rest.Client, uploadPath
4443

4544
func (b *eventBuffer) WithMetrics(m metrics.Metrics) *eventBuffer {
4645
b.metrics = m
46+
b.encoder.metrics = m
4747
return b
4848
}
4949

@@ -158,18 +158,22 @@ func (b *eventBuffer) readEvent() *bufferItem {
158158
}
159159
}
160160

161-
// processEvent serializes the event and determines if the ND cache needs to be dropped
162-
func (b *eventBuffer) processEvent(event *bufferItem) ([][]byte, error) {
161+
// Handle serializes the event and determines if the ND cache needs to be dropped
162+
func (b *eventBuffer) Handle(event *bufferItem) [][]byte {
163+
if event == nil {
164+
return nil
165+
}
166+
163167
if event.chunk != nil { // this is a chunk that has failed to upload and is being retried
164-
return [][]byte{event.chunk}, nil
168+
return [][]byte{event.chunk}
165169
}
166170

167171
serialized, err := json.Marshal(event.EventV1)
168172

169173
// The non-deterministic cache (NDBuiltinCache) could cause issues, if it is too big or can't be encoded try to drop it.
170174
if err != nil || int64(len(serialized)) >= b.uploadSizeLimitBytes {
171175
if event.NDBuiltinCache == nil {
172-
return nil, fmt.Errorf("upload event size (%d) exceeds upload_size_limit_bytes (%d), dropping event with decision ID: %v",
176+
b.logError("upload event size (%d) exceeds upload_size_limit_bytes (%d), dropping event with decision ID: %v",
173177
int64(len(serialized)), b.uploadSizeLimitBytes, event.DecisionID)
174178
}
175179

@@ -179,10 +183,10 @@ func (b *eventBuffer) processEvent(event *bufferItem) ([][]byte, error) {
179183
serialized, err = json.Marshal(event.EventV1)
180184
if err != nil {
181185
b.incrMetric(logEncodingFailureCounterName)
182-
return nil, fmt.Errorf("encoding failure: %v, dropping event with decision ID: %v", err, event.DecisionID)
186+
b.logError("encoding failure: %v, dropping event with decision ID: %v", err, event.DecisionID)
183187
}
184188
if int64(len(serialized)) > b.uploadSizeLimitBytes {
185-
return nil, fmt.Errorf("upload event size (%d) exceeds upload_size_limit_bytes (%d), dropping event with decision ID: %v",
189+
b.logError("upload event size (%d) exceeds upload_size_limit_bytes (%d), dropping event with decision ID: %v",
186190
int64(len(serialized)), b.uploadSizeLimitBytes, event.DecisionID)
187191
}
188192

@@ -194,28 +198,17 @@ func (b *eventBuffer) processEvent(event *bufferItem) ([][]byte, error) {
194198
if err != nil {
195199
b.incrMetric(logEncodingFailureCounterName)
196200
b.logError("encoding failure: %v, dropping event with decision ID: %v", err, event.DecisionID)
197-
return nil, err
201+
return nil
198202
}
199203

200-
return result, nil
204+
return result
201205
}
202206

203207
// Input returns the buffer channel to be read from
204208
func (b *eventBuffer) Input() <-chan *bufferItem {
205209
return b.buffer
206210
}
207211

208-
// Handle takes an event and encodes it as a chunk
209-
func (b *eventBuffer) Handle(event *bufferItem) [][]byte {
210-
result, err := b.processEvent(event)
211-
if err != nil {
212-
b.logError("%v", err)
213-
return nil
214-
}
215-
216-
return result
217-
}
218-
219212
// Flush empties the encoder and returns whatever is ready
220213
func (b *eventBuffer) Flush() [][]byte {
221214
result, err := b.encoder.Flush()

Diff for: v1/plugins/logs/plugin.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -984,11 +984,11 @@ func (p *Plugin) oneShot(ctx context.Context) error {
984984
return &bufferEmpty{}
985985
}
986986

987-
var finalErr error
988987
for bs := oldBuffer.Pop(); bs != nil; bs = oldBuffer.Pop() {
989-
err = uploadChunk(ctx, p.manager.Client(p.config.Service), *p.config.Resource, bs)
988+
if err == nil {
989+
err = uploadChunk(ctx, p.manager.Client(p.config.Service), *p.config.Resource, bs)
990+
}
990991
if err != nil {
991-
finalErr = err
992992
if p.limiter != nil {
993993
events, decErr := newChunkDecoder(bs).decode()
994994
if decErr != nil {
@@ -1007,7 +1007,7 @@ func (p *Plugin) oneShot(ctx context.Context) error {
10071007
}
10081008
}
10091009

1010-
return finalErr
1010+
return err
10111011
}
10121012

10131013
func (p *Plugin) reconfigure(ctx context.Context, config interface{}) {
@@ -1250,6 +1250,7 @@ func (p *Plugin) dropEvent(ctx context.Context, txn storage.Transaction, input a
12501250
}
12511251

12521252
func uploadChunk(ctx context.Context, client rest.Client, uploadPath string, data []byte) error {
1253+
12531254
resp, err := client.
12541255
WithHeader("Content-Type", "application/json").
12551256
WithHeader("Content-Encoding", "gzip").

0 commit comments

Comments
 (0)