Skip to content

Commit

Permalink
feat: add debug request option (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
mabdh committed Nov 5, 2023
1 parent d3c5704 commit 4447a08
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/api/v1beta1/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/goto/siren/core/alert"
sirenv1beta1 "github.com/goto/siren/proto/gotocompany/siren/v1beta1"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/timestamppb"
)

Expand Down Expand Up @@ -57,6 +58,13 @@ func (s *GRPCServer) CreateAlertsWithNamespace(ctx context.Context, req *sirenv1
if !s.useGlobalSubscription {
namespaceID = req.GetNamespaceId()
}
if s.withDebugRequest {
reqJSON, err := protojson.Marshal(req)
if err != nil {
s.logger.Debug("cannot marshal CreateAlertsWithNamespace req to json", "err", err.Error())
}
s.logger.Debug("incoming create alert with namespace", "json", string(reqJSON))
}
items, err := s.createAlerts(ctx, req.GetProviderType(), req.GetProviderId(), namespaceID, req.GetBody().AsMap())
if err != nil {
return nil, s.generateRPCErr(err)
Expand Down
7 changes: 7 additions & 0 deletions internal/api/v1beta1/v1beta1.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ func WithGlobalSubscription(useGlobalSubscription bool) GRPCServerOption {
}
}

func WithDebugRequest(debugRequest bool) GRPCServerOption {
return func(s *GRPCServer) {
s.withDebugRequest = debugRequest
}
}

type GRPCServer struct {
newrelic *newrelic.Application
logger log.Logger
headers api.HeadersConfig
useGlobalSubscription bool
withDebugRequest bool
sirenv1beta1.UnimplementedSirenServiceServer
templateService api.TemplateService
ruleService api.RuleService
Expand Down
2 changes: 2 additions & 0 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Config struct {
EncryptionKey string `mapstructure:"encryption_key" yaml:"encryption_key" default:"_ENCRYPTIONKEY_OF_32_CHARACTERS_"`
APIHeaders api.HeadersConfig `mapstructure:"api_headers" yaml:"api_headers"`
UseGlobalSubscription bool `mapstructure:"use_global_subscription" yaml:"use_global_subscription" default:"false"`
DebugRequest bool `mapstructure:"debug_request" yaml:"debug_request" default:"false"`
GRPC GRPCConfig `mapstructure:"grpc"`
}

Expand Down Expand Up @@ -134,6 +135,7 @@ func RunServer(
c.APIHeaders,
apiDeps,
v1beta1.WithGlobalSubscription(c.UseGlobalSubscription),
v1beta1.WithDebugRequest(c.DebugRequest),
)
grpcServer.RegisterService(&sirenv1beta1.SirenService_ServiceDesc, sirenServiceRPC)
grpcServer.RegisterService(&grpc_health_v1.Health_ServiceDesc, sirenServiceRPC)
Expand Down

0 comments on commit 4447a08

Please sign in to comment.