Skip to content

Commit

Permalink
feat(aggregator): ignore logs older than 24 hours
Browse files Browse the repository at this point in the history
  • Loading branch information
NithinKuruba committed Feb 7, 2025
1 parent e0adcae commit 3406f33
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
33 changes: 23 additions & 10 deletions aggregator/promtail/index.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package promtail

import (
"log"
"net/http"
"time"

Expand Down Expand Up @@ -45,23 +46,35 @@ func PromtailPushHandler(w http.ResponseWriter, r *http.Request) {
clientId = ""
eventType = ""
date = time.Now()
timestamp = ""
)

for _, v := range ls {
switch v.Name {
case "environment":
environment = v.Value
case "realm_id":
realmId = v.Value
case "client_id":
clientId = v.Value
case "event_type":
eventType = v.Value
}
case "environment":
environment = v.Value
case "realm_id":
realmId = v.Value
case "client_id":
clientId = v.Value
case "event_type":
eventType = v.Value
case "timestamp":
timestamp = v.Value
}
}

t, err := time.Parse(time.RFC3339Nano, timestamp)

if(err != nil) {
log.Printf("Error parsing timestamp: %v", err)
}

duration := time.Since(t)

// only collect event logs, skip the system logs
if eventType == "" {
// reject logs older than 24 hours
if (eventType == "" || duration >= 24*time.Hour) {
continue
}

Expand Down
3 changes: 2 additions & 1 deletion helm/promtail-aggregator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ promtail:
image:
registry: docker.io
repository: grafana/promtail
tag: ""
tag: ''
pullPolicy: IfNotPresent

imagePullSecrets: []
Expand Down Expand Up @@ -93,6 +93,7 @@ promtail:
event_type: type
realm_id:
client_id:
timestamp:
persistentVolume:
size: 100Mi
Expand Down

0 comments on commit 3406f33

Please sign in to comment.