Skip to content

Commit

Permalink
go back to using pointers for integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
santihernandezc committed May 27, 2024
1 parent 8090d88 commit 11482fe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/alertmanager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ func run() int {
})

// Build the map of receiver to integrations.
receivers := make(map[string][]notify.Integration, len(activeReceiversMap))
receivers := make(map[string][]*notify.Integration, len(activeReceiversMap))
var integrationsNum int
for _, rcv := range conf.Receivers {
if _, found := activeReceiversMap[rcv.Name]; !found {
Expand Down
4 changes: 2 additions & 2 deletions config/receiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ import (

// BuildReceiverIntegrations builds a list of integration notifiers off of a
// receiver config.
func BuildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logger log.Logger, httpOpts ...commoncfg.HTTPClientOption) ([]notify.Integration, error) {
func BuildReceiverIntegrations(nc config.Receiver, tmpl *template.Template, logger log.Logger, httpOpts ...commoncfg.HTTPClientOption) ([]*notify.Integration, error) {
var (
errs types.MultiError
integrations []notify.Integration
integrations []*notify.Integration
add = func(name string, i int, rs notify.ResolvedSender, f func(l log.Logger) (notify.Notifier, error)) {
n, err := f(log.With(logger, "integration", name))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions config/receiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestBuildReceiverIntegrations(t *testing.T) {
for _, tc := range []struct {
receiver config.Receiver
err bool
exp []notify.Integration
exp []*notify.Integration
}{
{
receiver: config.Receiver{
Expand All @@ -48,7 +48,7 @@ func TestBuildReceiverIntegrations(t *testing.T) {
},
},
},
exp: []notify.Integration{
exp: []*notify.Integration{
notify.NewIntegration(nil, sendResolved(false), "webhook", 0, "foo"),
notify.NewIntegration(nil, sendResolved(true), "webhook", 1, "foo"),
},
Expand Down
16 changes: 8 additions & 8 deletions notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ type Integration struct {
}

// NewIntegration returns a new integration.
func NewIntegration(notifier Notifier, rs ResolvedSender, name string, idx int, receiverName string) Integration {
return Integration{
func NewIntegration(notifier Notifier, rs ResolvedSender, name string, idx int, receiverName string) *Integration {
return &Integration{
notifier: notifier,
rs: rs,
name: name,
Expand Down Expand Up @@ -311,7 +311,7 @@ func NewMetrics(r prometheus.Registerer, ff featurecontrol.Flagger) *Metrics {
return m
}

func (m *Metrics) InitializeFor(receivers map[string][]Integration) {
func (m *Metrics) InitializeFor(receivers map[string][]*Integration) {
if m.ff.EnableReceiverNamesInMetrics() {

// Reset the vectors to take into account receiver names changing after hot reloads.
Expand Down Expand Up @@ -378,7 +378,7 @@ func NewPipelineBuilder(r prometheus.Registerer, ff featurecontrol.Flagger) *Pip

// New returns a map of receivers to Stages.
func (pb *PipelineBuilder) New(
receivers map[string][]Integration,
receivers map[string][]*Integration,
wait func() time.Duration,
inhibitor *inhibit.Inhibitor,
silencer *silence.Silencer,
Expand Down Expand Up @@ -407,7 +407,7 @@ func (pb *PipelineBuilder) New(
// createReceiverStage creates a pipeline of stages for a receiver.
func createReceiverStage(
name string,
integrations []Integration,
integrations []*Integration,
wait func() time.Duration,
notificationLog NotificationLog,
metrics *Metrics,
Expand All @@ -421,7 +421,7 @@ func createReceiverStage(
}
var s MultiStage
s = append(s, NewWaitStage(wait))
s = append(s, NewDedupStage(&integrations[i], notificationLog, recv))
s = append(s, NewDedupStage(integrations[i], notificationLog, recv))
s = append(s, NewRetryStage(integrations[i], name, metrics))
s = append(s, NewSetNotifiesStage(notificationLog, recv))

Expand Down Expand Up @@ -735,14 +735,14 @@ func (n *DedupStage) Exec(ctx context.Context, _ log.Logger, alerts ...*types.Al
// RetryStage notifies via passed integration with exponential backoff until it
// succeeds. It aborts if the context is canceled or timed out.
type RetryStage struct {
integration Integration
integration *Integration
groupName string
metrics *Metrics
labelValues []string
}

// NewRetryStage returns a new instance of a RetryStage.
func NewRetryStage(i Integration, groupName string, metrics *Metrics) *RetryStage {
func NewRetryStage(i *Integration, groupName string, metrics *Metrics) *RetryStage {
labelValues := []string{i.Name()}

if metrics.ff.EnableReceiverNamesInMetrics() {
Expand Down
10 changes: 5 additions & 5 deletions notify/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func TestRoutingStage(t *testing.T) {
func TestRetryStageWithError(t *testing.T) {
fail, retry := true, true
sent := []*types.Alert{}
i := Integration{
i := &Integration{
notifier: notifierFunc(func(ctx context.Context, alerts ...*types.Alert) (bool, error) {
if fail {
fail = false
Expand Down Expand Up @@ -435,7 +435,7 @@ func TestRetryStageWithErrorCode(t *testing.T) {
for _, testData := range testcases {
retry := false
testData := testData
i := Integration{
i := &Integration{
name: "test",
notifier: notifierFunc(func(ctx context.Context, alerts ...*types.Alert) (bool, error) {
if !testData.isNewErrorWithReason {
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestRetryStageWithErrorCode(t *testing.T) {
func TestRetryStageWithContextCanceled(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())

i := Integration{
i := &Integration{
name: "test",
notifier: notifierFunc(func(ctx context.Context, alerts ...*types.Alert) (bool, error) {
cancel()
Expand Down Expand Up @@ -504,7 +504,7 @@ func TestRetryStageWithContextCanceled(t *testing.T) {

func TestRetryStageNoResolved(t *testing.T) {
sent := []*types.Alert{}
i := Integration{
i := &Integration{
notifier: notifierFunc(func(ctx context.Context, alerts ...*types.Alert) (bool, error) {
sent = append(sent, alerts...)
return false, nil
Expand Down Expand Up @@ -555,7 +555,7 @@ func TestRetryStageNoResolved(t *testing.T) {

func TestRetryStageSendResolved(t *testing.T) {
sent := []*types.Alert{}
i := Integration{
i := &Integration{
notifier: notifierFunc(func(ctx context.Context, alerts ...*types.Alert) (bool, error) {
sent = append(sent, alerts...)
return false, nil
Expand Down

0 comments on commit 11482fe

Please sign in to comment.