Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matcher and Webhook Updates #487

Merged
merged 10 commits into from
Jul 25, 2024
1 change: 0 additions & 1 deletion caduceus.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"os"
"runtime/debug"
"time"

"github.com/alecthomas/kong"
"github.com/goschtalt/goschtalt"
Expand Down
17 changes: 16 additions & 1 deletion internal/sink/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,24 @@ type CommonWebhook struct {
logger *zap.Logger
}

func NewMatcher(l Listener, logger *zap.Logger) (matcher Matcher, err error) {
switch v := l.(type) {
case *ListenerV1:
m := &MatcherV1{}
m.logger = logger
if err := m.update(*v); err != nil {
return nil, err
}
matcher = m
return matcher, nil
default:
return nil, fmt.Errorf("invalid listner")
}
}

// Update applies user configurable values for the outbound sender when a
// webhook is registered
func (m1 *MatcherV1) Update(l ListenerV1) error {
func (m1 *MatcherV1) update(l ListenerV1) error {

//TODO: don't believe the logger for webhook is being set anywhere just yet
m1.logger = m1.logger.With(zap.String("webhook.address", l.Registration.Address))
Expand Down
21 changes: 14 additions & 7 deletions internal/sink/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,22 @@ type WebhookV1 struct {
// clientMiddleware func(http.Client) http.Client
}

func NewWebhookV1(s *sender) {
v1 := &WebhookV1{
id: s.id,
deliveryInterval: s.deliveryInterval,
deliveryRetries: s.deliveryRetries,
logger: s.logger,
func NewSink(c Config, logger *zap.Logger, listener Listener) Sink {
var sink Sink
switch l := listener.(type) {
case *ListenerV1:
sink = &WebhookV1{
id: l.GetId(),
deliveryInterval: c.DeliveryInterval,
deliveryRetries: c.DeliveryRetries,
logger: logger,
}
default:
return nil
}
s.sink = v1
return sink
}

func (v1 *WebhookV1) Update(l Listener) (err error) {
v1.id = l.GetId()
return nil
Expand Down
17 changes: 4 additions & 13 deletions internal/sink/sinkSender.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
disablePartnerIDs bool
customPIDs []string
mutex sync.RWMutex
config Config
deliverUntil time.Time
dropUntil time.Time
deliveryInterval time.Duration
Expand Down Expand Up @@ -120,6 +121,7 @@
queueSize: w.config.QueueSizePerSender,
deliverUntil: l.GetUntil(),
logger: w.logger,
config: w.config, //TODO: need to figure out which config options are used for just sender, just sink, and both
// dropUntil: where is this being set in old caduceus?,
cutOffPeriod: w.config.CutOffPeriod,
deliveryRetries: w.config.DeliveryRetries,
Expand Down Expand Up @@ -157,19 +159,8 @@
}

func (s *sender) Update(l Listener) (err error) {
switch v := l.(type) {
case *ListenerV1:
m := &MatcherV1{}
m.logger = s.logger
if err = m.Update(*v); err != nil {
return
}
s.matcher = m
NewWebhookV1(s)

default:
err = fmt.Errorf("invalid listner")
}
s.matcher, err = NewMatcher(l, s.logger)
s.sink = NewSink(s.config, s.logger)

Check failure on line 163 in internal/sink/sinkSender.go

View workflow job for this annotation

GitHub Actions / ci / Build Go Program

not enough arguments in call to NewSink

Check failure on line 163 in internal/sink/sinkSender.go

View workflow job for this annotation

GitHub Actions / ci / Go Unit Tests

not enough arguments in call to NewSink

s.renewalTimeGauge.Set(float64(time.Now().Unix()))

Expand Down
Loading