Skip to content

Commit

Permalink
Save projectId to queue
Browse files Browse the repository at this point in the history
  • Loading branch information
n0str authored and n0str committed Dec 4, 2024
1 parent 86bf099 commit f0ff36f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/server/errorshandler/handler_sentry.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package errorshandler

import (
"encoding/json"
"fmt"

"github.com/codex-team/hawk.collector/pkg/broker"
Expand Down Expand Up @@ -38,13 +39,13 @@ func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {

body := ctx.PostBody()

jsonBody, err := decompressGzipString(body)
sentryEnvelopeBody, err := decompressGzipString(body)
if err != nil {
log.Warnf("Failed to decompress gzip body: %s", err)
sendAnswerHTTP(ctx, ResponseMessage{Code: 400, Error: true, Message: "Failed to decompress gzip body"})
return
}
log.Debugf("Decompressed body: %s", jsonBody)
log.Debugf("Decompressed body: %s", sentryEnvelopeBody)

projectId, ok := handler.AccountsMongoDBClient.ValidTokens[hawkToken]
if !ok {
Expand All @@ -60,8 +61,23 @@ func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {
return
}

// convert message to JSON format
rawMessage := RawSentryMessage{Envelope: sentryEnvelopeBody}
jsonMessage, err := json.Marshal(rawMessage)
if err != nil {
log.Errorf("Message marshalling error: %v", err)
sendAnswerHTTP(ctx, ResponseMessage{400, true, "Cannot serialize envelope"})
}

messageToSend := BrokerMessage{ProjectId: projectId, Payload: json.RawMessage(jsonMessage), CatcherType: CatcherType}
payloadToSend, err := json.Marshal(messageToSend)
if err != nil {
log.Errorf("Message marshalling error: %v", err)
sendAnswerHTTP(ctx, ResponseMessage{400, true, "Cannot serialize envelope"})
}

// send serialized message to a broker
brokerMessage := broker.Message{Payload: jsonBody, Route: SentryQueueName}
brokerMessage := broker.Message{Payload: payloadToSend, Route: SentryQueueName}
log.Debugf("Send to queue: %s", brokerMessage)
handler.Broker.Chan <- brokerMessage

Expand Down
4 changes: 4 additions & 0 deletions pkg/server/errorshandler/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ type BrokerMessage struct {
Payload json.RawMessage `json:"payload"`
CatcherType string `json:"catcherType"`
}

type RawSentryMessage struct {
Envelope []byte `json:"envelope"`
}

0 comments on commit f0ff36f

Please sign in to comment.