Skip to content
2 changes: 1 addition & 1 deletion .github/workflows/build-and-push-docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ env:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions pkg/hawk/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ type HawkCatcherConfig struct {

// Hawk collector URL
URL string `env:"HAWK_URL"`

// Whether enable Hawk Catcher
Enabled bool `env:"HAWK_ENABLED" envDefault:"false"`
}
6 changes: 5 additions & 1 deletion pkg/hawk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ func Init() error {

// load settings from ENV
if err := env.Parse(&cfg); err != nil {
return errors.New("Failed to parse ENV")
return errors.New("failed to parse ENV")
}

if !cfg.Enabled || cfg.Token == "" || cfg.URL == "" {
return errors.New("hawk Catcher is disabled")
}

// Initialize Catcher with Websocket transport
Expand Down
12 changes: 3 additions & 9 deletions pkg/server/errorshandler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/prometheus/client_golang/prometheus"
log "github.com/sirupsen/logrus"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)

const DefaultQueueName = "errors/default"
Expand Down Expand Up @@ -87,18 +86,13 @@ func (handler *Handler) process(body []byte) ResponseMessage {
}

// Validate if message is a valid JSON
stringMessage := string(message.Payload)
if !gjson.Valid(stringMessage) {
stringPayload := string(message.Payload)
if !gjson.Valid(stringPayload) {
return ResponseMessage{400, true, "Invalid payload JSON format"}
}

modifiedMessage, err := sjson.Set(stringMessage, "timestamp", time.Now().Unix())
if err != nil {
return ResponseMessage{400, true, fmt.Sprintf("%s", err)}
}

// convert message to JSON format
messageToSend := BrokerMessage{ProjectId: projectId, Payload: []byte(modifiedMessage), CatcherType: message.CatcherType}
messageToSend := BrokerMessage{Timestamp: time.Now().Unix(), ProjectId: projectId, Payload: []byte(stringPayload), CatcherType: message.CatcherType}
rawMessage, err := json.Marshal(messageToSend)
if err != nil {
log.Errorf("Message marshalling error: %v", err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/server/errorshandler/handler_sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package errorshandler
import (
"encoding/json"
"fmt"
"time"

"github.com/codex-team/hawk.collector/pkg/broker"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -102,7 +103,7 @@ func (handler *Handler) HandleSentry(ctx *fasthttp.RequestCtx) {
sendAnswerHTTP(ctx, ResponseMessage{400, true, "Cannot serialize envelope"})
}

messageToSend := BrokerMessage{ProjectId: projectId, Payload: json.RawMessage(jsonMessage), CatcherType: CatcherType}
messageToSend := BrokerMessage{Timestamp: time.Now().Unix(), ProjectId: projectId, Payload: json.RawMessage(jsonMessage), CatcherType: CatcherType}
payloadToSend, err := json.Marshal(messageToSend)
if err != nil {
log.Errorf("Message marshalling error: %v", err)
Expand Down
1 change: 1 addition & 0 deletions pkg/server/errorshandler/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type BrokerMessage struct {
ProjectId string `json:"projectId"`
Payload json.RawMessage `json:"payload"`
CatcherType string `json:"catcherType"`
Timestamp int64 `json:"timestamp"`
}

type RawSentryMessage struct {
Expand Down
Loading