Skip to content

Commit

Permalink
made a couple of edits to solution 2
Browse files Browse the repository at this point in the history
  • Loading branch information
maurafortino committed Feb 28, 2024
1 parent b193526 commit e04cd13
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
28 changes: 18 additions & 10 deletions listenerStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,13 @@ type DeliveryConfig struct {
type Registration interface {
UpdateSender(*SinkSender) error
GetId() string
GetAddress() string
}

func (v1 *RegistrationV1) UpdateSender(ss *SinkSender) (err error) {
l := ss.logger.With(zap.String("webhook.address", v1.Address))

// Validate the failure URL, if present
if v1.FailureURL != "" {
_, err := url.ParseRequestURI(v1.FailureURL)
if err = validateFailureURL(v1.FailureURL); err != nil {
return err
}
// Create and validate the event regex objects
Expand Down Expand Up @@ -249,7 +248,7 @@ func (v1 *RegistrationV1) UpdateSender(ss *SinkSender) (err error) {
for i := 0; i < urlCount; i++ {
_, err := url.Parse(v1.Config.AlternativeURLs[i])
if err != nil {
ss.logger.Error("failed to update url", zap.Any("url", v1.Config.AlternativeURLs[i]), zap.Error(err))
l.Error("failed to update url", zap.Any("url", v1.Config.AlternativeURLs[i]), zap.Error(err))
return err
}
}
Expand All @@ -259,6 +258,8 @@ func (v1 *RegistrationV1) UpdateSender(ss *SinkSender) (err error) {
// write/update obs
ss.mutex.Lock()

ss.id = v1.Config.ReceiverURL
ss.logger = l
ss.deliverUntil = v1.Until
ss.deliverUntilGauge.Set(float64(ss.deliverUntil.Unix()))

Expand Down Expand Up @@ -302,15 +303,22 @@ func (v1 *RegistrationV1) GetId() string {
return v1.Config.ReceiverURL
}

func (v1 *RegistrationV1) GetAddress() string {
return v1.Address
}
func (v2 *RegistrationV2) UpdateSender(ss *SinkSender) (err error) {
// Validate the failure URL, if present
if err = validateFailureURL(v2.FailureURL); err != nil {
return err
}

// TODO: is this what we want to return for the ids Map for V2?
return
}
func (v2 *RegistrationV2) GetId() string {
return v2.CanonicalName
}

func (v2 *RegistrationV2) GetAddress() string {
return v2.Address
func validateFailureURL(fUrl string) (err error) {
if fUrl == "" {
_, err = url.ParseRequestURI(fUrl)
return
}
return
}
6 changes: 2 additions & 4 deletions sinkSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type SinkSender struct {
clientMiddleware func(Client) Client
}

func newSinkSender(sw *SinkWrapper, listener ListenerStub, address string) (s *SinkSender, err error) {
func newSinkSender(sw *SinkWrapper, listener ListenerStub) (s *SinkSender, err error) {
if sw.clientMiddleware == nil {
sw.clientMiddleware = nopClient
}
Expand All @@ -134,13 +134,11 @@ func newSinkSender(sw *SinkWrapper, listener ListenerStub, address string) (s *S
return
}

decoratedLogger := sw.logger.With(zap.String("webhook.address", address))

sinkSender := &SinkSender{
client: sw.client,
listener: listener,
queueSize: sw.config.QueueSizePerSender,
cutOffPeriod: sw.config.CutOffPeriod,
logger: decoratedLogger,
deliveryRetries: sw.config.DeliveryRetries,
deliveryInterval: sw.config.DeliveryInterval,
maxWorkers: sw.config.NumWorkersPerSender,
Expand Down
2 changes: 1 addition & 1 deletion sinkWrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (sw *SinkWrapper) Update(list []ListenerStub) {

sw.clientMiddleware = metricWrapper.roundTripper

ss, err := newSinkSender(sw, listener, listener.Registration.GetAddress())
ss, err := newSinkSender(sw, listener)

if err == nil {
sw.senders[inValue.ID] = ss
Expand Down

0 comments on commit e04cd13

Please sign in to comment.