Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding call_id, from and to labels to loki logs #562

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added config options for to, from and call_id labels on loki
htmluz committed Jan 19, 2025
commit 1b66845bfa9b696d4a387664253452fe9f3535da
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@ type HeplifyServer struct {
LokiBuffer int `default:"100000"`
LokiHEPFilter []int `default:"1,5,100"`
LokiIPPortLabels bool `default:"false"`
LokiFromToLabels bool `default:"false"`
LokiCallIDLabels bool `default:"false"`
LokiAllowOutOfOrder bool `default:"false"`
ForceHEPPayload []int `default:""`
PromAddr string `default:":9096"`
14 changes: 10 additions & 4 deletions remotelog/loki.go
Original file line number Diff line number Diff line change
@@ -122,8 +122,10 @@ func (l *Loki) start(hCh chan *decoder.HEP) {
pktMeta.WriteString(pkt.Payload)
} else {
document["cid"] = pkt.CID
l.entry.labels["call_id"] = model.LabelValue(pkt.CID)
documentJson, err := json.Marshal(document)
if config.Setting.LokiCallIDLabels {
l.entry.labels["call_id"] = model.LabelValue(pkt.CID)
}
if err != nil {
logp.Err("Unable to re-generate rtcp json: %v", err)
pktMeta.WriteString(pkt.Payload)
@@ -138,9 +140,6 @@ func (l *Loki) start(hCh chan *decoder.HEP) {
switch {
case pkt.SIP != nil && pkt.ProtoType == 1:
l.entry.labels["method"] = model.LabelValue(pkt.SIP.CseqMethod)
l.entry.labels["call_id"] = model.LabelValue(pkt.SIP.CallID)
l.entry.labels["from"] = model.LabelValue(pkt.SIP.From.Val)
l.entry.labels["to"] = model.LabelValue(pkt.SIP.To.Val)
l.entry.labels["response"] = model.LabelValue(pkt.SIP.FirstMethod)
protocol := ""
if pkt.Protocol == 6 {
@@ -149,6 +148,13 @@ func (l *Loki) start(hCh chan *decoder.HEP) {
protocol = "udp"
}
l.entry.labels["protocol"] = model.LabelValue(protocol)
if config.Setting.LokiCallIDLabels {
l.entry.labels["call_id"] = model.LabelValue(pkt.SIP.CallID)
}
if config.Setting.LokiFromToLabels {
l.entry.labels["from"] = model.LabelValue(pkt.SIP.From.Val)
l.entry.labels["to"] = model.LabelValue(pkt.SIP.To.Val)
}
case pkt.ProtoType == 100:
protocol := "udp"
if strings.Contains(pkt.Payload, "Fax") || strings.Contains(pkt.Payload, "T38") {