fix(inputs.cloud_pubsub): Fix gzip decompression (#13238)

This commit is contained in:
Daniel Ayvar 2023-05-04 12:19:06 -05:00 committed by GitHub
parent 1b8339ace8
commit 43048aad8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -62,9 +62,10 @@ type PubSub struct {
wg *sync.WaitGroup
acc telegraf.TrackingAccumulator
undelivered map[telegraf.TrackingID]message
sem semaphore
decoder internal.ContentDecoder
undelivered map[telegraf.TrackingID]message
sem semaphore
decoder internal.ContentDecoder
decoderMutex sync.Mutex
}
func (*PubSub) SampleConfig() string {
@ -216,10 +217,13 @@ func (ps *PubSub) decompressData(data []byte) ([]byte, error) {
return data, nil
}
ps.decoderMutex.Lock()
data, err := ps.decoder.Decode(data, int64(ps.MaxDecompressionSize))
if err != nil {
ps.decoderMutex.Unlock()
return nil, err
}
ps.decoderMutex.Unlock()
decompressedData := make([]byte, len(data))
copy(decompressedData, data)