Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module github.com/codex-team/hawk.collector

require (
github.com/alicebob/miniredis/v2 v2.34.0
github.com/andybalholm/brotli v1.0.2
github.com/caarlos0/env/v6 v6.6.0
github.com/cenkalti/backoff/v4 v4.1.0
github.com/codex-team/hawk.go v1.0.5
Expand All @@ -17,7 +18,6 @@ require (
github.com/streadway/amqp v1.0.0
github.com/stretchr/testify v1.7.0
github.com/tidwall/gjson v1.8.0
github.com/tidwall/sjson v1.1.6
github.com/valyala/fasthttp v1.25.0
go.mongodb.org/mongo-driver v1.7.1
)
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,13 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
github.com/tidwall/gjson v1.8.0 h1:Qt+orfosKn0rbNTZqHYDqBrmm3UDA4KRkv70fDzG+PQ=
github.com/tidwall/gjson v1.8.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk=
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8=
github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/sjson v1.1.6 h1:8fDdlahON04OZBlTQCIatW8FstSFJz8oxidj5h0rmSQ=
github.com/tidwall/sjson v1.1.6/go.mod h1:KN3FZ7odvXIHPbJdhNorK/M9lWweVUbXsXXhrJ/kGOA=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
Expand Down
10 changes: 9 additions & 1 deletion pkg/server/errorshandler/handler_sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,15 @@ func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: "Failed to decompress gzip body"})
return
}
log.Debugf("Decompressed body: %s", sentryEnvelopeBody)
log.Debugf("Decompressed gzip body: %s", sentryEnvelopeBody)
} else if contentEncoding == "br" {
sentryEnvelopeBody, err = decompressBrotliString(sentryEnvelopeBody)
if err != nil {
log.Warnf("Failed to decompress brotli body: %s", err)
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: "Failed to decompress brotli body"})
return
}
log.Debugf("Decompressed brotli body: %s", sentryEnvelopeBody)
} else {
log.Debugf("Body: %s", sentryEnvelopeBody)
}
Expand Down
26 changes: 20 additions & 6 deletions pkg/server/errorshandler/sentry_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"fmt"
"io"
"strings"
log "github.com/sirupsen/logrus"

"github.com/andybalholm/brotli"
log "github.com/sirupsen/logrus"
)

func decompressGzipString(gzipString []byte) ([]byte, error) {
Expand All @@ -26,15 +28,27 @@ func decompressGzipString(gzipString []byte) ([]byte, error) {
return result.Bytes(), nil
}

func decompressBrotliString(brotliString []byte) ([]byte, error) {
reader := brotli.NewReader(bytes.NewReader(brotliString))

var result bytes.Buffer
_, err := io.Copy(&result, reader)
if err != nil {
return []byte(""), fmt.Errorf("failed to decompress brotli data: %w", err)
}

return result.Bytes(), nil
}

func getSentryKeyFromAuth(auth string) (string, error) {
auth = strings.TrimPrefix(auth, "Sentry ")
pairs := strings.Split(auth, ",")
for _, pair := range pairs {
pair = strings.TrimSpace(pair)
kv := strings.SplitN(pair, "=", 2)
if len(kv) == 2 && strings.TrimSpace(kv[0]) == "sentry_key" {
return strings.TrimSpace(kv[1]), nil
}
pair = strings.TrimSpace(pair)
kv := strings.SplitN(pair, "=", 2)
if len(kv) == 2 && strings.TrimSpace(kv[0]) == "sentry_key" {
return strings.TrimSpace(kv[1]), nil
}
}

log.Infof("Sentry key not found in auth header: %s", auth)
Expand Down
Loading