Skip to content

Commit

Permalink
more strategic locking...
Browse files Browse the repository at this point in the history
Signed-off-by: Beau Croteau <[email protected]>
  • Loading branch information
bc-sb committed Oct 31, 2022
1 parent d80b603 commit e1cfc56
Show file tree
Hide file tree
Showing 13 changed files with 7 additions and 24 deletions.
4 changes: 4 additions & 0 deletions outputs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ func NewClient(outputType string, defaultEndpointURL string, mutualTLSEnabled bo

// Post sends event (payload) to Output.
func (c *Client) Post(payload interface{}) error {
c.m.Lock()
defer c.m.Unlock()
// defer + recover to catch panic if output doesn't respond
defer func() {
if err := recover(); err != nil {
Expand Down Expand Up @@ -281,5 +283,7 @@ func (c *Client) BasicAuth(username, password string) {

// AddHeader adds an HTTP Header to the Client.
func (c *Client) AddHeader(key, value string) {
c.m.Lock()
defer c.m.Unlock()
c.HeaderList = append(c.HeaderList, Header{Key: key, Value: value})
}
3 changes: 1 addition & 2 deletions outputs/cliq.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ func newCliqPayload(falcopayload types.FalcoPayload, config *types.Configuration
// CliqPost posts event to cliq
func (c *Client) CliqPost(falcopayload types.FalcoPayload) {
c.Stats.Cliq.Add(Total, 1)
c.m.Lock()
defer c.m.Unlock()

c.AddHeader(ContentTypeHeaderKey, "application/json")
err := c.Post(newCliqPayload(falcopayload, c.Config))
if err != nil {
Expand Down
2 changes: 0 additions & 2 deletions outputs/fission.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ func (c *Client) FissionCall(falcopayload types.FalcoPayload) {
}
log.Printf("[INFO] : %s - Function Response : %v\n", Fission, string(rawbody))
} else {
c.m.Lock()
defer c.m.Unlock()
c.AddHeader(FissionEventIDKey, uuid.New().String())
c.ContentType = FissionContentType

Expand Down
2 changes: 0 additions & 2 deletions outputs/gcpcloudrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ func (c *Client) CloudRunFunctionPost(falcopayload types.FalcoPayload) {
c.Stats.GCPCloudRun.Add(Total, 1)

if c.Config.GCP.CloudRun.JWT != "" {
c.m.Lock()
defer c.m.Unlock()
c.AddHeader(AuthorizationHeaderKey, "Bearer "+c.Config.GCP.CloudRun.JWT)
}

Expand Down
2 changes: 0 additions & 2 deletions outputs/gotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ func (c *Client) GotifyPost(falcopayload types.FalcoPayload) {
c.Stats.Gotify.Add(Total, 1)

if c.Config.Gotify.Token != "" {
c.m.Lock()
defer c.m.Unlock()
c.AddHeader("X-Gotify-Key", c.Config.Gotify.Token)
}

Expand Down
3 changes: 1 addition & 2 deletions outputs/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ func newGrafanaPayload(falcopayload types.FalcoPayload, config *types.Configurat
func (c *Client) GrafanaPost(falcopayload types.FalcoPayload) {
c.Stats.Grafana.Add(Total, 1)
c.ContentType = GrafanaContentType
c.m.Lock()
defer c.m.Unlock()

c.AddHeader("Authorization", "Bearer "+c.Config.Grafana.APIKey)

err := c.Post(newGrafanaPayload(falcopayload, c.Config))
Expand Down
3 changes: 1 addition & 2 deletions outputs/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ func newInfluxdbPayload(falcopayload types.FalcoPayload, config *types.Configura
// InfluxdbPost posts event to InfluxDB
func (c *Client) InfluxdbPost(falcopayload types.FalcoPayload) {
c.Stats.Influxdb.Add(Total, 1)
c.m.Lock()
defer c.m.Unlock()

c.AddHeader("Accept", "application/json")

if c.Config.Influxdb.Token != "" {
Expand Down
2 changes: 0 additions & 2 deletions outputs/kubeless.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ func (c *Client) KubelessCall(falcopayload types.FalcoPayload) {
}
log.Printf("[INFO] : Kubeless - Function Response : %v\n", string(rawbody))
} else {
c.m.Lock()
defer c.m.Unlock()
c.AddHeader(KubelessEventIDKey, uuid.New().String())
c.AddHeader(KubelessEventTypeKey, KubelessEventTypeValue)
c.AddHeader(KubelessEventNamespaceKey, c.Config.Kubeless.Namespace)
Expand Down
2 changes: 0 additions & 2 deletions outputs/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ func (c *Client) LokiPost(falcopayload types.FalcoPayload) {
c.Stats.Loki.Add(Total, 1)
c.ContentType = LokiContentType
if c.Config.Loki.Tenant != "" {
c.m.Lock()
defer c.m.Unlock()
c.AddHeader("X-Scope-OrgID", c.Config.Loki.Tenant)
}

Expand Down
2 changes: 0 additions & 2 deletions outputs/nodered.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
func (c *Client) NodeRedPost(falcopayload types.FalcoPayload) {
c.Stats.NodeRed.Add(Total, 1)

c.m.Lock()
defer c.m.Unlock()
if c.Config.NodeRed.User != "" && c.Config.NodeRed.Password != "" {
c.AddHeader("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(c.Config.NodeRed.User+":"+c.Config.NodeRed.Password)))
}
Expand Down
2 changes: 0 additions & 2 deletions outputs/opsgenie.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ func newOpsgeniePayload(falcopayload types.FalcoPayload, config *types.Configura
// OpsgeniePost posts event to OpsGenie
func (c *Client) OpsgeniePost(falcopayload types.FalcoPayload) {
c.Stats.Opsgenie.Add(Total, 1)
c.m.Lock()
defer c.m.Unlock()
c.AddHeader(AuthorizationHeaderKey, "GenieKey "+c.Config.Opsgenie.APIKey)

err := c.Post(newOpsgeniePayload(falcopayload, c.Config))
Expand Down
2 changes: 0 additions & 2 deletions outputs/spyderbat.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ func NewSpyderbatClient(config *types.Configuration, stats *types.Statistics, pr
func (c *Client) SpyderbatPost(falcopayload types.FalcoPayload) {
c.Stats.Spyderbat.Add(Total, 1)

c.m.Lock()
defer c.m.Unlock()
c.AddHeader("Authorization", "Bearer "+c.Config.Spyderbat.APIKey)
c.AddHeader("Content-Encoding", "gzip")

Expand Down
2 changes: 0 additions & 2 deletions outputs/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
func (c *Client) WebhookPost(falcopayload types.FalcoPayload) {
c.Stats.Webhook.Add(Total, 1)

c.m.Lock()
defer c.m.Unlock()
if len(c.Config.Webhook.CustomHeaders) != 0 {
for i, j := range c.Config.Webhook.CustomHeaders {
c.AddHeader(i, j)
Expand Down

0 comments on commit e1cfc56

Please sign in to comment.