From c68d79af505dc61a05f0008e8eacb4ef5d0d2454 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Thu, 29 Jun 2023 11:30:37 +0200 Subject: [PATCH 1/2] set source/destination labels --- config/config.go | 1 + remotelog/loki.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index bf37f7b..69d4465 100644 --- a/config/config.go +++ b/config/config.go @@ -19,6 +19,7 @@ type HeplifyServer struct { LokiTimer int `default:"4"` LokiBuffer int `default:"100000"` LokiHEPFilter []int `default:"1,5,100"` + LokiIPPortLabels bool `default:"false"` ForceHEPPayload []int `default:""` PromAddr string `default:":9096"` PromTargetIP string `default:""` diff --git a/remotelog/loki.go b/remotelog/loki.go index c20a186..214b8d3 100644 --- a/remotelog/loki.go +++ b/remotelog/loki.go @@ -6,9 +6,10 @@ import ( "context" "fmt" "io" - "os" "net/http" "net/url" + "os" + "strconv" "strings" "time" @@ -128,6 +129,13 @@ func (l *Loki) start(hCh chan *decoder.HEP) { l.entry.labels["type"] = model.LabelValue(pkt.ProtoString) l.entry.Entry.Line = pktMeta.String() + if config.Setting.LokiIPPortLabels { + l.entry.labels["src_ip"] = model.LabelValue(pkt.SrcIP) + l.entry.labels["src_port"] = model.LabelValue(strconv.FormatUint(uint64(pkt.SrcPort), 10)) + l.entry.labels["dst_ip"] = model.LabelValue(pkt.DstIP) + l.entry.labels["dst_port"] = model.LabelValue(strconv.FormatUint(uint64(pkt.DstPort), 10)) + } + if batchSize+len(l.entry.Line) > l.BatchSize { if err := l.sendBatch(batch); err != nil { logp.Err("send size batch: %v", err) From 2485b0d03a997eac7a895cef497d29d83ea46d45 Mon Sep 17 00:00:00 2001 From: Alexandr Dubovikov Date: Thu, 29 Jun 2023 21:05:53 +0200 Subject: [PATCH 2/2] increased version --- config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 69d4465..01fbb4e 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,6 @@ package config -const Version = "heplify-server 1.59.3" +const Version = "heplify-server 1.59.4" var Setting HeplifyServer