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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
15 changes: 13 additions & 2 deletions remotelog/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func (l *Loki) start(hCh chan *decoder.HEP) {

pktMeta.Reset()

l.entry = entry{model.LabelSet{}, logproto.Entry{Timestamp: curPktTime}}

if pkt.ProtoString == "rtcp" {
var document map[string]interface{}
err := json.Unmarshal([]byte(pkt.Payload), &document)
Expand All @@ -121,6 +123,9 @@ func (l *Loki) start(hCh chan *decoder.HEP) {
} else {
document["cid"] = 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)
Expand All @@ -131,7 +136,6 @@ func (l *Loki) start(hCh chan *decoder.HEP) {
} else {
pktMeta.WriteString(pkt.Payload)
}
l.entry = entry{model.LabelSet{}, logproto.Entry{Timestamp: curPktTime}}

switch {
case pkt.SIP != nil && pkt.ProtoType == 1:
Expand All @@ -142,8 +146,15 @@ func (l *Loki) start(hCh chan *decoder.HEP) {
protocol = "tcp"
} else if pkt.Protocol == 17 {
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") {
Expand Down
2 changes: 1 addition & 1 deletion sipparser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (s *SipMsg) addHdr(str string) {
s.parseVia(s.hdrv)
case s.hdr == "From" || s.hdr == "FROM" || s.hdr == "from":
s.parseFrom(s.hdrv)
case s.hdr == "Call-ID" || s.hdr == "CALL-ID" || s.hdr == "Call-Id" || s.hdr == "Call-id" || s.hdr == "call-id":
case s.hdr == "Call-ID" || s.hdr == "CALL-ID" || s.hdr == "Call-Id" || s.hdr == "Call-id" || s.hdr == "call-id" || s.hdr == "i":
s.CallID = s.hdrv
case s.hdr == "CSeq" || s.hdr == "CSEQ" || s.hdr == "Cseq" || s.hdr == "cseq":
s.CseqVal = s.hdrv
Expand Down