Skip to content

Commit

Permalink
fix(loki): fix the deadlock in Loki integration
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Leanovich <maxim@cube.dev>
  • Loading branch information
bsod90 authored and poiana committed Sep 26, 2023
1 parent 63d23f9 commit 76871b4
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions outputs/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,38 @@ func newLokiPayload(falcopayload types.FalcoPayload, config *types.Configuration
}}
}

// LokiPost posts event to Loki
func (c *Client) LokiPost(falcopayload types.FalcoPayload) {
c.Stats.Loki.Add(Total, 1)
c.ContentType = LokiContentType
func (c *Client) configureTenant() {
if c.Config.Loki.Tenant != "" {
c.httpClientLock.Lock()
defer c.httpClientLock.Unlock()
c.AddHeader("X-Scope-OrgID", c.Config.Loki.Tenant)
}
}

func (c *Client) configureAuth() {
if c.Config.Loki.User != "" && c.Config.Loki.APIKey != "" {
c.httpClientLock.Lock()
defer c.httpClientLock.Unlock()
c.BasicAuth(c.Config.Loki.User, c.Config.Loki.APIKey)
}
}

func (c *Client) configureCustomHeaders() {
c.httpClientLock.Lock()
defer c.httpClientLock.Unlock()
for i, j := range c.Config.Loki.CustomHeaders {
c.AddHeader(i, j)
}
}

// LokiPost posts event to Loki
func (c *Client) LokiPost(falcopayload types.FalcoPayload) {
c.Stats.Loki.Add(Total, 1)
c.ContentType = LokiContentType

c.configureTenant()
c.configureAuth()
c.configureCustomHeaders()

err := c.Post(newLokiPayload(falcopayload, c.Config))
if err != nil {
Expand Down

0 comments on commit 76871b4

Please sign in to comment.