Skip to content

Commit

Permalink
add more checks for the upload on GCP Storage
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Labarussias <[email protected]>
  • Loading branch information
Issif authored and poiana committed Apr 27, 2024
1 parent 80495c9 commit 67b4948
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions outputs/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,28 @@ func (c *Client) UploadGCS(falcopayload types.FalcoPayload) {

key := fmt.Sprintf("%s/%s/%s.json", prefix, t.Format("2006-01-02"), t.Format(time.RFC3339Nano))
bucketWriter := c.GCSStorageClient.Bucket(c.Config.GCP.Storage.Bucket).Object(key).NewWriter(context.Background())
defer bucketWriter.Close()
_, err := bucketWriter.Write(payload)
n, err := bucketWriter.Write(payload)
if err != nil {
log.Printf("[ERROR] : GCPStorage - %v - %v\n", "Error while Uploading message", err.Error())
c.Stats.GCPStorage.Add(Error, 1)
go c.CountMetric("outputs", 1, []string{"output:gcpstorage", "status:error"})
c.PromStats.Outputs.With(map[string]string{"destination": "gcpstorage", "status": Error}).Inc()
return
}
if n == 0 {
log.Printf("[ERROR] : GCPStorage - %v\n", "Empty payload uploaded")
c.Stats.GCPStorage.Add(Error, 1)
go c.CountMetric("outputs", 1, []string{"output:gcpstorage", "status:error"})
c.PromStats.Outputs.With(map[string]string{"destination": "gcpstorage", "status": Error}).Inc()
return
}
if err := bucketWriter.Close(); err != nil {
log.Printf("[ERROR] : GCPStorage - %v - %v\n", "Error while closing the writer", err.Error())
c.Stats.GCPStorage.Add(Error, 1)
go c.CountMetric("outputs", 1, []string{"output:gcpstorage", "status:error"})
c.PromStats.Outputs.With(map[string]string{"destination": "gcpstorage", "status": Error}).Inc()
return
}

log.Printf("[INFO] : GCPStorage - Upload to bucket OK \n")
c.Stats.GCPStorage.Add(OK, 1)
Expand Down

0 comments on commit 67b4948

Please sign in to comment.