Repository: fluxcd/notification-controller
Pull request #385 (2022-06-18 09:48:32)

Add context to Post function
The change adds a context to the Post function. Most notifiers do not require a context as they just use HTTP requests, but those that import an SDK tend to do. By passing a context in the Post function new contributions do not have to guess on which context to use and how long the timeout should be.

This change also fixes some context issues, adding context to Gitlab and fixing Azure DevOps context.


Patch:
diff --git a/internal/notifier/alertmanager.go b/internal/notifier/alertmanager.go
index 8bef655..4ff2fb7 100644
--- a/internal/notifier/alertmanager.go
+++ b/internal/notifier/alertmanager.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"crypto/x509"
 	"fmt"
 	"net/url"
@@ -50,7 +51,7 @@ func NewAlertmanager(hookURL string, proxyURL string, certPool *x509.CertPool) (
 	}, nil
 }
 
-func (s *Alertmanager) Post(event events.Event) error {
+func (s *Alertmanager) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
diff --git a/internal/notifier/azure_devops.go b/internal/notifier/azure_devops.go
index 4df4127..93313d7 100644
--- a/internal/notifier/azure_devops.go
+++ b/internal/notifier/azure_devops.go
@@ -23,7 +23,6 @@ import (
 	"errors"
 	"fmt"
 	"strings"
-	"time"
 
 	"github.com/fluxcd/pkg/runtime/events"
 
@@ -78,7 +77,7 @@ func NewAzureDevOps(addr string, token string, certPool *x509.CertPool) (*AzureD
 }
 
 // Post Azure DevOps commit status
-func (a AzureDevOps) Post(event events.Event) error {
+func (a AzureDevOps) Post(ctx context.Context, event events.Event) error {
 	// Skip progressing events
 	if event.Reason == "Progressing" {
 		return nil
@@ -97,9 +96,6 @@ func (a AzureDevOps) Post(event events.Event) error {
 		return err
 	}
 
-	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
-	defer cancel()
-
 	// Check if the exact status is already set
 	g := genre
 	name, desc := formatNameAndDescription(event)
@@ -130,7 +126,7 @@ func (a AzureDevOps) Post(event events.Event) error {
 	}
 
 	// Create a new status
-	_, err = a.Client.CreateCommitStatus(context.Background(), createArgs)
+	_, err = a.Client.CreateCommitStatus(ctx, createArgs)
 	if err != nil {
 		return fmt.Errorf("could not create commit status: %v", err)
 	}
diff --git a/internal/notifier/azure_eventhub.go b/internal/notifier/azure_eventhub.go
index b92b266..320ac9c 100644
--- a/internal/notifier/azure_eventhub.go
+++ b/internal/notifier/azure_eventhub.go
@@ -17,7 +17,6 @@ import (
 	"context"
 	"encoding/json"
 	"fmt"
-	"time"
 
 	"github.com/Azure/azure-amqp-common-go/v3/auth"
 	eventhub "github.com/Azure/azure-event-hubs-go/v3"
@@ -53,15 +52,12 @@ func NewAzureEventHub(endpointURL, token, eventHubNamespace string) (*AzureEvent
 }
 
 // Post all notification-controller messages to EventHub
-func (e *AzureEventHub) Post(event events.Event) error {
+func (e *AzureEventHub) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
 	}
 
-	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
-	defer cancel()
-
 	eventBytes, err := json.Marshal(event)
 	if err != nil {
 		return fmt.Errorf("Unable to marshall event: %w", err)
diff --git a/internal/notifier/bitbucket.go b/internal/notifier/bitbucket.go
index 3b331cf..4569a3f 100644
--- a/internal/notifier/bitbucket.go
+++ b/internal/notifier/bitbucket.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"crypto/tls"
 	"crypto/x509"
 	"encoding/json"
@@ -80,7 +81,7 @@ func NewBitbucket(addr string, token string, certPool *x509.CertPool) (*Bitbucke
 }
 
 // Post Bitbucket commit status
-func (b Bitbucket) Post(event events.Event) error {
+func (b Bitbucket) Post(ctx context.Context, event events.Event) error {
 	// Skip progressing events
 	if event.Reason == "Progressing" {
 		return nil
diff --git a/internal/notifier/discord.go b/internal/notifier/discord.go
index d19c865..c4c4a54 100644
--- a/internal/notifier/discord.go
+++ b/internal/notifier/discord.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"fmt"
 	"net/url"
 	"path"
@@ -56,7 +57,7 @@ func NewDiscord(hookURL string, proxyURL string, username string, channel string
 }
 
 // Post Discord message
-func (s *Discord) Post(event events.Event) error {
+func (s *Discord) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
diff --git a/internal/notifier/forwarder.go b/internal/notifier/forwarder.go
index 6107a94..16af4de 100644
--- a/internal/notifier/forwarder.go
+++ b/internal/notifier/forwarder.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"crypto/x509"
 	"fmt"
 	"net/url"
@@ -52,7 +53,7 @@ func NewForwarder(hookURL string, proxyURL string, headers map[string]string, ce
 	}, nil
 }
 
-func (f *Forwarder) Post(event events.Event) error {
+func (f *Forwarder) Post(ctx context.Context, event events.Event) error {
 	err := postMessage(f.URL, f.ProxyURL, f.CertPool, event, func(req *retryablehttp.Request) {
 		req.Header.Set(NotificationHeader, event.ReportingController)
 		for key, val := range f.Headers {
diff --git a/internal/notifier/github.go b/internal/notifier/github.go
index ef36dbe..58b3fe6 100644
--- a/internal/notifier/github.go
+++ b/internal/notifier/github.go
@@ -25,7 +25,6 @@ import (
 	"net/http"
 	"net/url"
 	"strings"
-	"time"
 
 	"github.com/fluxcd/pkg/runtime/events"
 
@@ -88,7 +87,7 @@ func NewGitHub(addr string, token string, certPool *x509.CertPool) (*GitHub, err
 }
 
 // Post Github commit status
-func (g *GitHub) Post(event events.Event) error {
+func (g *GitHub) Post(ctx context.Context, event events.Event) error {
 	// Skip progressing events
 	if event.Reason == "Progressing" {
 		return nil
@@ -114,9 +113,6 @@ func (g *GitHub) Post(event events.Event) error {
 		Description: &desc,
 	}
 
-	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
-	defer cancel()
-
 	opts := &github.ListOptions{PerPage: 50}
 	statuses, _, err := g.Client.Repositories.ListStatuses(ctx, g.Owner, g.Repo, rev, opts)
 	if err != nil {
diff --git a/internal/notifier/github_dispatch.go b/internal/notifier/github_dispatch.go
index 7c7a04a..163bd3e 100644
--- a/internal/notifier/github_dispatch.go
+++ b/internal/notifier/github_dispatch.go
@@ -26,7 +26,6 @@ import (
 	"net/http"
 	"net/url"
 	"strings"
-	"time"
 
 	"github.com/fluxcd/pkg/runtime/events"
 
@@ -89,7 +88,7 @@ func NewGitHubDispatch(addr string, token string, certPool *x509.CertPool) (*Git
 }
 
 // Post GitHub Repository Dispatch webhook
-func (g *GitHubDispatch) Post(event events.Event) error {
+func (g *GitHubDispatch) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
@@ -98,9 +97,6 @@ func (g *GitHubDispatch) Post(event events.Event) error {
 	eventType := fmt.Sprintf("%s/%s.%s",
 		event.InvolvedObject.Kind, event.InvolvedObject.Name, event.InvolvedObject.Namespace)
 
-	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
-	defer cancel()
-
 	eventData, err := json.Marshal(event)
 	if err != nil {
 		return fmt.Errorf("Failed to marshal object into json: %w", err)
diff --git a/internal/notifier/gitlab.go b/internal/notifier/gitlab.go
index 11f6cc0..0f5a9b4 100644
--- a/internal/notifier/gitlab.go
+++ b/internal/notifier/gitlab.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"crypto/tls"
 	"crypto/x509"
 	"errors"
@@ -66,7 +67,7 @@ func NewGitLab(addr string, token string, certPool *x509.CertPool) (*GitLab, err
 }
 
 // Post GitLab commit status
-func (g *GitLab) Post(event events.Event) error {
+func (g *GitLab) Post(ctx context.Context, event events.Event) error {
 	// Skip progressing events
 	if event.Reason == "Progressing" {
 		return nil
@@ -86,14 +87,6 @@ func (g *GitLab) Post(event events.Event) error {
 	}
 
 	name, desc := formatNameAndDescription(event)
-	options := &gitlab.SetCommitStatusOptions{
-		Name:        &name,
-		Description: &desc,
-		State:       state,
-	}
-
-	listOpts := &gitlab.GetCommitStatusesOptions{}
-
 	status := &gitlab.CommitStatus{
 		Name:        name,
 		SHA:         rev,
@@ -101,7 +94,8 @@ func (g *GitLab) Post(event events.Event) error {
 		Description: desc,
 	}
 
-	statuses, _, err := g.Client.Commits.GetCommitStatuses(g.Id, rev, listOpts)
+	getOpt := &gitlab.GetCommitStatusesOptions{}
+	statuses, _, err := g.Client.Commits.GetCommitStatuses(g.Id, rev, getOpt, gitlab.WithContext(ctx))
 	if err != nil {
 		return fmt.Errorf("unable to list commit status: %s", err)
 	}
@@ -109,7 +103,12 @@ func (g *GitLab) Post(event events.Event) error {
 		return nil
 	}
 
-	_, _, err = g.Client.Commits.SetCommitStatus(g.Id, rev, options)
+	setOpt := &gitlab.SetCommitStatusOptions{
+		Name:        &name,
+		Description: &desc,
+		State:       state,
+	}
+	_, _, err = g.Client.Commits.SetCommitStatus(g.Id, rev, setOpt, gitlab.WithContext(ctx))
 	if err != nil {
 		return err
 	}
diff --git a/internal/notifier/google_chat.go b/internal/notifier/google_chat.go
index 5d152a4..40208c9 100644
--- a/internal/notifier/google_chat.go
+++ b/internal/notifier/google_chat.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"fmt"
 	"net/url"
 	"strings"
@@ -85,7 +86,7 @@ func NewGoogleChat(hookURL string, proxyURL string) (*GoogleChat, error) {
 }
 
 // Post Google Chat message
-func (s *GoogleChat) Post(event events.Event) error {
+func (s *GoogleChat) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
diff --git a/internal/notifier/grafana.go b/internal/notifier/grafana.go
index a6cc13f..899c97d 100644
--- a/internal/notifier/grafana.go
+++ b/internal/notifier/grafana.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"crypto/x509"
 	"fmt"
 	"net/url"
@@ -60,7 +61,7 @@ func NewGrafana(URL string, proxyURL string, token string, certPool *x509.CertPo
 }
 
 // Post annotation
-func (g *Grafana) Post(event events.Event) error {
+func (g *Grafana) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
diff --git a/internal/notifier/lark.go b/internal/notifier/lark.go
index 71bc9d7..ba32869 100644
--- a/internal/notifier/lark.go
+++ b/internal/notifier/lark.go
@@ -1,6 +1,7 @@
 package notifier
 
 import (
+	"context"
 	"fmt"
 	"net/url"
 	"strings"
@@ -60,7 +61,7 @@ func NewLark(address string) (*Lark, error) {
 	}, nil
 }
 
-func (l *Lark) Post(event events.Event) error {
+func (l *Lark) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
diff --git a/internal/notifier/matrix.go b/internal/notifier/matrix.go
index 84db5e8..4dc9e6a 100644
--- a/internal/notifier/matrix.go
+++ b/internal/notifier/matrix.go
@@ -1,6 +1,7 @@
 package notifier
 
 import (
+	"context"
 	"crypto/sha1"
 	"crypto/x509"
 	"encoding/json"
@@ -39,7 +40,7 @@ func NewMatrix(serverURL, token, roomId string, certPool *x509.CertPool) (*Matri
 	}, nil
 }
 
-func (m *Matrix) Post(event events.Event) error {
+func (m *Matrix) Post(ctx context.Context, event events.Event) error {
 	txId, err := sha1sum(event)
 	if err != nil {
 		return fmt.Errorf("unable to generate unique tx id: %s", err)
diff --git a/internal/notifier/nop.go b/internal/notifier/nop.go
index 4bcb38f..5ec9b7e 100644
--- a/internal/notifier/nop.go
+++ b/internal/notifier/nop.go
@@ -16,10 +16,14 @@ limitations under the License.
 
 package notifier
 
-import "github.com/fluxcd/pkg/runtime/events"
+import (
+	"context"
+
+	"github.com/fluxcd/pkg/runtime/events"
+)
 
 type NopNotifier struct{}
 
-func (n *NopNotifier) Post(event events.Event) error {
+func (n *NopNotifier) Post(ctx context.Context, event events.Event) error {
 	return nil
 }
diff --git a/internal/notifier/notifier.go b/internal/notifier/notifier.go
index 7ff5bfc..4ed9a20 100644
--- a/internal/notifier/notifier.go
+++ b/internal/notifier/notifier.go
@@ -17,9 +17,11 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
+
 	"github.com/fluxcd/pkg/runtime/events"
 )
 
 type Interface interface {
-	Post(event events.Event) error
+	Post(ctx context.Context, event events.Event) error
 }
diff --git a/internal/notifier/opsgenie.go b/internal/notifier/opsgenie.go
index 46f293e..79c6219 100644
--- a/internal/notifier/opsgenie.go
+++ b/internal/notifier/opsgenie.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"crypto/x509"
 	"errors"
 	"fmt"
@@ -58,7 +59,7 @@ func NewOpsgenie(hookURL string, proxyURL string, certPool *x509.CertPool, token
 }
 
 // Post opsgenie alert message
-func (s *Opsgenie) Post(event events.Event) error {
+func (s *Opsgenie) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
diff --git a/internal/notifier/rocket.go b/internal/notifier/rocket.go
index 5de28e7..0c268e7 100644
--- a/internal/notifier/rocket.go
+++ b/internal/notifier/rocket.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"crypto/x509"
 	"errors"
 	"fmt"
@@ -60,7 +61,7 @@ func NewRocket(hookURL string, proxyURL string, certPool *x509.CertPool, usernam
 }
 
 // Post Rocket message
-func (s *Rocket) Post(event events.Event) error {
+func (s *Rocket) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
diff --git a/internal/notifier/sentry.go b/internal/notifier/sentry.go
index 3b157bd..5a9593b 100644
--- a/internal/notifier/sentry.go
+++ b/internal/notifier/sentry.go
@@ -58,7 +58,7 @@ func NewSentry(certPool *x509.CertPool, dsn string, environment string) (*Sentry
 }
 
 // Post event to Sentry
-func (s *Sentry) Post(event events.Event) error {
+func (s *Sentry) Post(ctx context.Context, event events.Event) error {
 	var sev *sentry.Event
 	// Send event to Sentry
 	switch event.Severity {
diff --git a/internal/notifier/slack.go b/internal/notifier/slack.go
index 23e7d81..57d3545 100644
--- a/internal/notifier/slack.go
+++ b/internal/notifier/slack.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"crypto/x509"
 	"fmt"
 	"net/url"
@@ -79,7 +80,7 @@ func NewSlack(hookURL string, proxyURL string, token string, certPool *x509.Cert
 }
 
 // Post Slack message
-func (s *Slack) Post(event events.Event) error {
+func (s *Slack) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
diff --git a/internal/notifier/teams.go b/internal/notifier/teams.go
index 4c4a0c2..6bea20d 100644
--- a/internal/notifier/teams.go
+++ b/internal/notifier/teams.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"crypto/x509"
 	"fmt"
 	"net/url"
@@ -68,7 +69,7 @@ func NewMSTeams(hookURL string, proxyURL string, certPool *x509.CertPool) (*MSTe
 }
 
 // Post MS Teams message
-func (s *MSTeams) Post(event events.Event) error {
+func (s *MSTeams) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
diff --git a/internal/notifier/telegram.go b/internal/notifier/telegram.go
index 21c59f5..8f79329 100644
--- a/internal/notifier/telegram.go
+++ b/internal/notifier/telegram.go
@@ -1,6 +1,7 @@
 package notifier
 
 import (
+	"context"
 	"errors"
 	"fmt"
 	"strings"
@@ -25,7 +26,7 @@ func NewTelegram(channel, token string) (*Telegram, error) {
 	}, nil
 }
 
-func (t *Telegram) Post(event events.Event) error {
+func (t *Telegram) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
diff --git a/internal/notifier/webex.go b/internal/notifier/webex.go
index f80f48b..d092766 100644
--- a/internal/notifier/webex.go
+++ b/internal/notifier/webex.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"crypto/x509"
 	"fmt"
 	"net/url"
@@ -96,7 +97,7 @@ func (s *Webex) CreateMarkdown(event *events.Event) string {
 }
 
 // Post Webex message
-func (s *Webex) Post(event events.Event) error {
+func (s *Webex) Post(ctx context.Context, event events.Event) error {
 	// Skip any update events
 	if isCommitStatus(event.Metadata, "update") {
 		return nil
diff --git a/internal/server/event_handlers.go b/internal/server/event_handlers.go
index ecb8cc8..d0b8e71 100644
--- a/internal/server/event_handlers.go
+++ b/internal/server/event_handlers.go
@@ -63,7 +63,7 @@ func (s *EventServer) handleEvent() func(w http.ResponseWriter, r *http.Request)
 
 		cleanupMetadata(event)
 
-		ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
+		ctx, cancel := context.WithTimeout(r.Context(), 15*time.Second)
 		defer cancel()
 
 		var allAlerts v1beta1.AlertList
@@ -265,7 +265,7 @@ func (s *EventServer) handleEvent() func(w http.ResponseWriter, r *http.Request)
 			}
 
 			go func(n notifier.Interface, e events.Event) {
-				if err := n.Post(e); err != nil {
+				if err := n.Post(ctx, e); err != nil {
 					maskedErrStr, maskErr := masktoken.MaskTokenFromString(err.Error(), token)
 					if maskErr != nil {
 						err = maskErr


Test patch:
diff --git a/internal/notifier/alertmanager_test.go b/internal/notifier/alertmanager_test.go
index c4fdc48..432ecd3 100644
--- a/internal/notifier/alertmanager_test.go
+++ b/internal/notifier/alertmanager_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"encoding/json"
 	"io"
 	"net/http"
@@ -40,6 +41,6 @@ func TestAlertmanager_Post(t *testing.T) {
 	alertmanager, err := NewAlertmanager(ts.URL, "", nil)
 	require.NoError(t, err)
 
-	err = alertmanager.Post(testEvent())
+	err = alertmanager.Post(context.TODO(), testEvent())
 	require.NoError(t, err)
 }
diff --git a/internal/notifier/discord_test.go b/internal/notifier/discord_test.go
index d588b56..db15eaa 100644
--- a/internal/notifier/discord_test.go
+++ b/internal/notifier/discord_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"encoding/json"
 	"io"
 	"net/http"
@@ -45,6 +46,6 @@ func TestDiscord_Post(t *testing.T) {
 	require.NoError(t, err)
 	assert.True(t, strings.HasSuffix(discord.URL, "/slack"))
 
-	err = discord.Post(testEvent())
+	err = discord.Post(context.TODO(), testEvent())
 	require.NoError(t, err)
 }
diff --git a/internal/notifier/forwarder_test.go b/internal/notifier/forwarder_test.go
index a1860bc..c3d97cc 100644
--- a/internal/notifier/forwarder_test.go
+++ b/internal/notifier/forwarder_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"encoding/json"
 	"io"
 	"net/http"
@@ -48,6 +49,6 @@ func TestForwarder_Post(t *testing.T) {
 	forwarder, err := NewForwarder(ts.URL, "", headers, nil)
 	require.NoError(t, err)
 
-	err = forwarder.Post(testEvent())
+	err = forwarder.Post(context.TODO(), testEvent())
 	require.NoError(t, err)
 }
diff --git a/internal/notifier/github_dispatch_test.go b/internal/notifier/github_dispatch_test.go
index c874375..0841f7d 100644
--- a/internal/notifier/github_dispatch_test.go
+++ b/internal/notifier/github_dispatch_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
@@ -55,6 +56,6 @@ func TestGitHubDispatch_PostUpdate(t *testing.T) {
 
 	event := testEvent()
 	event.Metadata["commit_status"] = "update"
-	err = githubDispatch.Post(event)
+	err = githubDispatch.Post(context.TODO(), event)
 	require.NoError(t, err)
 }
diff --git a/internal/notifier/google_chat_test.go b/internal/notifier/google_chat_test.go
index 3895747..8ca3074 100644
--- a/internal/notifier/google_chat_test.go
+++ b/internal/notifier/google_chat_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"encoding/json"
 	"io"
 	"net/http"
@@ -45,6 +46,6 @@ func TestGoogleChat_Post(t *testing.T) {
 	google_chat, err := NewGoogleChat(ts.URL, "")
 	require.NoError(t, err)
 
-	err = google_chat.Post(testEvent())
+	err = google_chat.Post(context.TODO(), testEvent())
 	require.NoError(t, err)
 }
diff --git a/internal/notifier/grafana_test.go b/internal/notifier/grafana_test.go
index d6eb0e3..6675cd9 100644
--- a/internal/notifier/grafana_test.go
+++ b/internal/notifier/grafana_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"encoding/json"
 	"io"
 	"net/http"
@@ -46,7 +47,7 @@ func TestGrafana_Post(t *testing.T) {
 		grafana, err := NewGrafana(ts.URL, "", "", nil, "", "")
 		require.NoError(t, err)
 
-		err = grafana.Post(testEvent())
+		err = grafana.Post(context.TODO(), testEvent())
 		assert.NoError(t, err)
 	})
 }
diff --git a/internal/notifier/lark_test.go b/internal/notifier/lark_test.go
index 9e74cf6..50f07ac 100644
--- a/internal/notifier/lark_test.go
+++ b/internal/notifier/lark_test.go
@@ -1,6 +1,7 @@
 package notifier
 
 import (
+	"context"
 	"encoding/json"
 	"io"
 	"net/http"
@@ -26,6 +27,6 @@ func TestLark_Post(t *testing.T) {
 	lark, err := NewLark(ts.URL)
 	require.NoError(t, err)
 
-	err = lark.Post(testEvent())
+	err = lark.Post(context.TODO(), testEvent())
 	require.NoError(t, err)
 }
diff --git a/internal/notifier/opsgenie_test.go b/internal/notifier/opsgenie_test.go
index 1dfe9bf..9e5690f 100644
--- a/internal/notifier/opsgenie_test.go
+++ b/internal/notifier/opsgenie_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"encoding/json"
 	"io"
 	"net/http"
@@ -40,6 +41,6 @@ func TestOpsgenie_Post(t *testing.T) {
 	opsgenie, err := NewOpsgenie(ts.URL, "", nil, "token")
 	require.NoError(t, err)
 
-	err = opsgenie.Post(testEvent())
+	err = opsgenie.Post(context.TODO(), testEvent())
 	require.NoError(t, err)
 }
diff --git a/internal/notifier/rocket_test.go b/internal/notifier/rocket_test.go
index a3e4915..bfddcfc 100644
--- a/internal/notifier/rocket_test.go
+++ b/internal/notifier/rocket_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"encoding/json"
 	"io"
 	"net/http"
@@ -42,6 +43,6 @@ func TestRocket_Post(t *testing.T) {
 	rocket, err := NewRocket(ts.URL, "", nil, "test", "test")
 	require.NoError(t, err)
 
-	err = rocket.Post(testEvent())
+	err = rocket.Post(context.TODO(), testEvent())
 	require.NoError(t, err)
 }
diff --git a/internal/notifier/slack_test.go b/internal/notifier/slack_test.go
index a41427a..e9bcc5a 100644
--- a/internal/notifier/slack_test.go
+++ b/internal/notifier/slack_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"encoding/json"
 	"io"
 	"net/http"
@@ -42,7 +43,7 @@ func TestSlack_Post(t *testing.T) {
 	slack, err := NewSlack(ts.URL, "", "", nil, "", "test")
 	require.NoError(t, err)
 
-	err = slack.Post(testEvent())
+	err = slack.Post(context.TODO(), testEvent())
 	require.NoError(t, err)
 }
 
@@ -52,6 +53,6 @@ func TestSlack_PostUpdate(t *testing.T) {
 
 	event := testEvent()
 	event.Metadata["commit_status"] = "update"
-	err = slack.Post(event)
+	err = slack.Post(context.TODO(), event)
 	require.NoError(t, err)
 }
diff --git a/internal/notifier/teams_test.go b/internal/notifier/teams_test.go
index 2335c6f..2d5111d 100644
--- a/internal/notifier/teams_test.go
+++ b/internal/notifier/teams_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"encoding/json"
 	"io"
 	"net/http"
@@ -42,6 +43,6 @@ func TestTeams_Post(t *testing.T) {
 	teams, err := NewMSTeams(ts.URL, "", nil)
 	require.NoError(t, err)
 
-	err = teams.Post(testEvent())
+	err = teams.Post(context.TODO(), testEvent())
 	require.NoError(t, err)
 }
diff --git a/internal/notifier/webex_test.go b/internal/notifier/webex_test.go
index 19fd03b..e8991e2 100644
--- a/internal/notifier/webex_test.go
+++ b/internal/notifier/webex_test.go
@@ -17,6 +17,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"encoding/json"
 	"io"
 	"net/http"
@@ -40,7 +41,7 @@ func TestWebex_Post(t *testing.T) {
 	webex, err := NewWebex(ts.URL, "", nil, "room", "token")
 	require.NoError(t, err)
 
-	err = webex.Post(testEvent())
+	err = webex.Post(context.TODO(), testEvent())
 	require.NoError(t, err)
 }
 
@@ -50,6 +51,6 @@ func TestWebex_PostUpdate(t *testing.T) {
 
 	event := testEvent()
 	event.Metadata["commit_status"] = "update"
-	err = webex.Post(event)
+	err = webex.Post(context.TODO(), event)
 	require.NoError(t, err)
 }
diff --git a/tests/fuzz/alertmanager_fuzzer.go b/tests/fuzz/alertmanager_fuzzer.go
index d10adc0..81cc42e 100644
--- a/tests/fuzz/alertmanager_fuzzer.go
+++ b/tests/fuzz/alertmanager_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -48,7 +49,7 @@ func FuzzAlertmanager(data []byte) int {
 		return 0
 	}
 
-	_ = alertmanager.Post(event)
+	_ = alertmanager.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/azure_devops_fuzzer.go b/tests/fuzz/azure_devops_fuzzer.go
index 2594dde..621e0bf 100644
--- a/tests/fuzz/azure_devops_fuzzer.go
+++ b/tests/fuzz/azure_devops_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -52,7 +53,7 @@ func FuzzAzureDevOps(data []byte) int {
 		return 0
 	}
 
-	_ = azureDevOps.Post(event)
+	_ = azureDevOps.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/bitbucket_fuzzer.go b/tests/fuzz/bitbucket_fuzzer.go
index 5d271c9..d0e8e1c 100644
--- a/tests/fuzz/bitbucket_fuzzer.go
+++ b/tests/fuzz/bitbucket_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -52,7 +53,7 @@ func FuzzBitbucket(data []byte) int {
 		return 0
 	}
 
-	_ = bitbucket.Post(event)
+	_ = bitbucket.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/discord_fuzzer.go b/tests/fuzz/discord_fuzzer.go
index 88dfb1d..9cebf57 100644
--- a/tests/fuzz/discord_fuzzer.go
+++ b/tests/fuzz/discord_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -57,7 +58,7 @@ func FuzzDiscord(data []byte) int {
 		return 0
 	}
 
-	_ = discord.Post(event)
+	_ = discord.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/forwarder_fuzzer.go b/tests/fuzz/forwarder_fuzzer.go
index 796d1eb..b045fa3 100644
--- a/tests/fuzz/forwarder_fuzzer.go
+++ b/tests/fuzz/forwarder_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -49,7 +50,7 @@ func FuzzForwarder(data []byte) int {
 		return 0
 	}
 
-	_ = forwarder.Post(event)
+	_ = forwarder.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/github_fuzzer.go b/tests/fuzz/github_fuzzer.go
index f263332..56917c3 100644
--- a/tests/fuzz/github_fuzzer.go
+++ b/tests/fuzz/github_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -52,7 +53,7 @@ func FuzzGitHub(data []byte) int {
 		return 0
 	}
 
-	_ = github.Post(event)
+	_ = github.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/gitlab_fuzzer.go b/tests/fuzz/gitlab_fuzzer.go
index 1d0930d..03fc6eb 100644
--- a/tests/fuzz/gitlab_fuzzer.go
+++ b/tests/fuzz/gitlab_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -52,7 +53,7 @@ func FuzzGitLab(data []byte) int {
 		return 0
 	}
 
-	_ = gitLab.Post(event)
+	_ = gitLab.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/google_chat_fuzzer.go b/tests/fuzz/google_chat_fuzzer.go
index 40d531e..e4fc68e 100644
--- a/tests/fuzz/google_chat_fuzzer.go
+++ b/tests/fuzz/google_chat_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -48,7 +49,7 @@ func FuzzGoogleChat(data []byte) int {
 		return 0
 	}
 
-	_ = googlechat.Post(event)
+	_ = googlechat.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/lark_fuzzer.go b/tests/fuzz/lark_fuzzer.go
index f5d8f91..2e05549 100644
--- a/tests/fuzz/lark_fuzzer.go
+++ b/tests/fuzz/lark_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -48,7 +49,7 @@ func FuzzLark(data []byte) int {
 		return 0
 	}
 
-	_ = lark.Post(event)
+	_ = lark.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/matrix_fuzzer.go b/tests/fuzz/matrix_fuzzer.go
index 8e9f1f5..4bcff2c 100644
--- a/tests/fuzz/matrix_fuzzer.go
+++ b/tests/fuzz/matrix_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -52,7 +53,7 @@ func FuzzMatrix(data []byte) int {
 		return 0
 	}
 
-	_ = matrix.Post(event)
+	_ = matrix.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/opsgenie_fuzzer.go b/tests/fuzz/opsgenie_fuzzer.go
index ad7a1ab..db6c6c9 100644
--- a/tests/fuzz/opsgenie_fuzzer.go
+++ b/tests/fuzz/opsgenie_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -48,7 +49,7 @@ func FuzzOpsGenie(data []byte) int {
 		return 0
 	}
 
-	_ = opsgenie.Post(event)
+	_ = opsgenie.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/rocket_fuzzer.go b/tests/fuzz/rocket_fuzzer.go
index f6da154..8035f99 100644
--- a/tests/fuzz/rocket_fuzzer.go
+++ b/tests/fuzz/rocket_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -57,7 +58,7 @@ func FuzzRocket(data []byte) int {
 		return 0
 	}
 
-	_ = rocket.Post(event)
+	_ = rocket.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/slack_fuzzer.go b/tests/fuzz/slack_fuzzer.go
index 9ba5dc3..a165b29 100644
--- a/tests/fuzz/slack_fuzzer.go
+++ b/tests/fuzz/slack_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -62,7 +63,7 @@ func FuzzSlack(data []byte) int {
 		return 0
 	}
 
-	_ = slack.Post(event)
+	_ = slack.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/teams_fuzzer.go b/tests/fuzz/teams_fuzzer.go
index c70959f..4e90e25 100644
--- a/tests/fuzz/teams_fuzzer.go
+++ b/tests/fuzz/teams_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -48,7 +49,7 @@ func FuzzMSTeams(data []byte) int {
 		return 0
 	}
 
-	_ = teams.Post(event)
+	_ = teams.Post(context.TODO(), event)
 
 	return 1
 }
diff --git a/tests/fuzz/webex_fuzzer.go b/tests/fuzz/webex_fuzzer.go
index da53646..6fbbde1 100644
--- a/tests/fuzz/webex_fuzzer.go
+++ b/tests/fuzz/webex_fuzzer.go
@@ -20,6 +20,7 @@ limitations under the License.
 package notifier
 
 import (
+	"context"
 	"io"
 	"net/http"
 	"net/http/httptest"
@@ -48,7 +49,7 @@ func FuzzWebex(data []byte) int {
 		return 0
 	}
 
-	_ = webex.Post(event)
+	_ = webex.Post(context.TODO(), event)
 
 	return 1
 }