Skip to content

Commit 8a81961

Browse files
Copilotadubovikov
andauthored
Merge branch 'master' into copilot/add-skip-port-labels-option
Resolved merge conflict in config/config.go by including both: - LokiSkipTCPPortLabels (from this PR) - LokiCustomLabels (from master) All tests pass and build succeeds. Co-authored-by: adubovikov <4513061+adubovikov@users.noreply.github.com>
2 parents 2bb9d3e + 494dfff commit 8a81961

29 files changed

Lines changed: 556 additions & 1748 deletions

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Go
2020
uses: actions/setup-go@v3
2121
with:
22-
go-version: 1.17
22+
go-version: 1.25
2323

2424
- name: Libraries
2525
run: sudo apt-get install -y libpcap-dev libluajit-5.1-dev

config/config.go

Lines changed: 81 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,88 @@
11
package config
22

3-
const Version = "heplify-server 1.60.1"
3+
const Version = "heplify-server 1.60.2"
44

55
var Setting HeplifyServer
66

77
type HeplifyServer struct {
8-
HEPAddr string `default:"0.0.0.0:9060"`
9-
HEPTCPAddr string `default:""`
10-
HEPTLSAddr string `default:""`
11-
HEPWSAddr string `default:""`
12-
ESAddr string `default:""`
13-
ESDiscovery bool `default:"true"`
14-
HEPv2Enable bool `default:"true"`
15-
ESUser string `default:""`
16-
ESPass string `default:""`
17-
LokiURL string `default:""`
18-
LokiOrgID string `default:""`
19-
LokiBulk int `default:"400"`
20-
LokiTimer int `default:"4"`
21-
LokiBuffer int `default:"100000"`
22-
LokiHEPFilter []int `default:"1,5,100"`
23-
LokiIPPortLabels bool `default:"false"`
24-
LokiSkipTCPPortLabels bool `default:"true"`
25-
LokiFromToLabels bool `default:"false"`
26-
LokiCallIDLabels bool `default:"false"`
27-
LokiAllowOutOfOrder bool `default:"false"`
28-
LineprotoURL string `default:""`
29-
LineprotoBulk int `default:"400"`
30-
LineprotoTimer int `default:"4"`
31-
LineprotoBuffer int `default:"100000"`
32-
LineprotoHEPFilter []int `default:"1,5,100"`
33-
LineprotoIPPortLabels bool `default:"false"`
34-
ForceHEPPayload []int `default:""`
35-
PromAddr string `default:":9096"`
36-
PromTargetIP string `default:""`
37-
PromTargetName string `default:""`
38-
DBShema string `default:"homer5"`
39-
DBDriver string `default:"mysql"`
40-
DBAddr string `default:"localhost:3306"`
41-
DBSSLMode string `default:"disable"`
42-
DBUser string `default:"root"`
43-
DBPass string `default:""`
44-
DBDataTable string `default:"homer_data"`
45-
DBConfTable string `default:"homer_configuration"`
46-
DBBulk int `default:"400"`
47-
DBTimer int `default:"4"`
48-
DBBuffer int `default:"400000"`
49-
DBWorker int `default:"8"`
50-
DBRotate bool `default:"true"`
51-
DBPartLog string `default:"2h"`
52-
DBPartIsup string `default:"6h"`
53-
DBPartSip string `default:"2h"`
54-
DBPartQos string `default:"6h"`
55-
DBDropDays int `default:"14"`
56-
DBDropDaysCall int `default:"0"`
57-
DBDropDaysRegister int `default:"0"`
58-
DBDropDaysDefault int `default:"0"`
59-
DBDropOnStart bool `default:"false"`
60-
DBUsageProtection bool `default:"false"`
61-
DBUsageScheme string `default:"percentage"`
62-
DBPercentageUsage string `default:"80%"`
63-
DBMaxSize string `default:"20GB"`
64-
DBProcDropLimit int `default:"2"`
65-
Dedup bool `default:"false"`
66-
DiscardMethod []string `default:""`
67-
CensorMethod []string `default:""`
68-
AlegIDs []string `default:""`
69-
ForceALegID bool `default:"false"`
70-
CustomHeader []string `default:""`
71-
IgnoreCaseCH bool `default:"false"`
72-
SIPHeader []string `default:"ruri_user,ruri_domain,from_user,from_tag,to_user,to_tag,callid,cseq,method,user_agent"`
73-
LogDbg string `default:""`
74-
LogLvl string `default:"info"`
75-
LogStd bool `default:"false"`
76-
LogSys bool `default:"false"`
77-
Config string `default:"./heplify-server.toml"`
78-
ConfigHTTPAddr string `default:""`
79-
ConfigHTTPPW string `default:""`
80-
Version bool `default:"false"`
81-
ScriptEnable bool `default:"false"`
82-
ScriptEngine string `default:"lua"`
83-
ScriptFolder string `default:""`
84-
ScriptHEPFilter []int `default:"1,5,100"`
85-
TLSCertFolder string `default:"."`
86-
TLSMinVersion string `default:"1.2"`
8+
HEPAddr string `default:"0.0.0.0:9060"`
9+
HEPTCPAddr string `default:""`
10+
HEPTLSAddr string `default:""`
11+
HEPWSAddr string `default:""`
12+
ESAddr string `default:""`
13+
ESDiscovery bool `default:"true"`
14+
HEPv2Enable bool `default:"true"`
15+
ESUser string `default:""`
16+
ESPass string `default:""`
17+
LokiURL string `default:""`
18+
LokiOrgID string `default:""`
19+
LokiBulk int `default:"400"`
20+
LokiTimer int `default:"4"`
21+
LokiBuffer int `default:"100000"`
22+
LokiHEPFilter []int `default:"1,5,100"`
23+
LokiIPPortLabels bool `default:"false"`
24+
LokiSkipTCPPortLabels bool `default:"true"`
25+
LokiFromToLabels bool `default:"false"`
26+
LokiCallIDLabels bool `default:"false"`
27+
LokiAllowOutOfOrder bool `default:"false"`
28+
LokiCustomLabels []string `default:""`
29+
LineprotoURL string `default:""`
30+
LineprotoBulk int `default:"400"`
31+
LineprotoTimer int `default:"4"`
32+
LineprotoBuffer int `default:"100000"`
33+
LineprotoHEPFilter []int `default:"1,5,100"`
34+
LineprotoIPPortLabels bool `default:"false"`
35+
ForceHEPPayload []int `default:""`
36+
PromAddr string `default:":9096"`
37+
PromTargetIP string `default:""`
38+
PromTargetName string `default:""`
39+
DBShema string `default:"homer5"`
40+
DBDriver string `default:"mysql"`
41+
DBAddr string `default:"localhost:3306"`
42+
DBSSLMode string `default:"disable"`
43+
DBUser string `default:"root"`
44+
DBPass string `default:""`
45+
DBDataTable string `default:"homer_data"`
46+
DBConfTable string `default:"homer_configuration"`
47+
DBBulk int `default:"400"`
48+
DBTimer int `default:"4"`
49+
DBBuffer int `default:"400000"`
50+
DBWorker int `default:"8"`
51+
DBRotate bool `default:"true"`
52+
DBPartLog string `default:"2h"`
53+
DBPartIsup string `default:"6h"`
54+
DBPartSip string `default:"2h"`
55+
DBPartQos string `default:"6h"`
56+
DBDropDays int `default:"14"`
57+
DBDropDaysCall int `default:"0"`
58+
DBDropDaysRegister int `default:"0"`
59+
DBDropDaysDefault int `default:"0"`
60+
DBDropOnStart bool `default:"false"`
61+
DBUsageProtection bool `default:"false"`
62+
DBUsageScheme string `default:"percentage"`
63+
DBPercentageUsage string `default:"80%"`
64+
DBMaxSize string `default:"20GB"`
65+
DBProcDropLimit int `default:"2"`
66+
Dedup bool `default:"false"`
67+
DiscardMethod []string `default:""`
68+
CensorMethod []string `default:""`
69+
AlegIDs []string `default:""`
70+
ForceALegID bool `default:"false"`
71+
CustomHeader []string `default:""`
72+
IgnoreCaseCH bool `default:"false"`
73+
SIPHeader []string `default:"ruri_user,ruri_domain,from_user,from_tag,to_user,to_tag,callid,cseq,method,user_agent"`
74+
LogDbg string `default:""`
75+
LogLvl string `default:"info"`
76+
LogStd bool `default:"false"`
77+
LogSys bool `default:"false"`
78+
Config string `default:"./heplify-server.toml"`
79+
ConfigHTTPAddr string `default:""`
80+
ConfigHTTPPW string `default:""`
81+
Version bool `default:"false"`
82+
ScriptEnable bool `default:"false"`
83+
ScriptEngine string `default:"lua"`
84+
ScriptFolder string `default:""`
85+
ScriptHEPFilter []int `default:"1,5,100"`
86+
TLSCertFolder string `default:"."`
87+
TLSMinVersion string `default:"1.2"`
8788
}

database/mysql.go

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ func (m *MySQL) setup() error {
109109
m.db.SetMaxOpenConns(config.Setting.DBWorker * 4)
110110
m.db.SetMaxIdleConns(config.Setting.DBWorker)
111111

112-
m.bulkCnt = config.Setting.DBBulk
113-
if m.bulkCnt < 1 {
114-
m.bulkCnt = 1
115-
}
112+
m.bulkCnt = max(config.Setting.DBBulk, 1)
116113
m.dbTimer = time.Duration(config.Setting.DBTimer) * time.Second
117114

118115
m.sipBulkVal = sipQueryVal(m.bulkCnt)
@@ -128,13 +125,13 @@ func (m *MySQL) insert(hCh chan *decoder.HEP) {
128125

129126
pkt *decoder.HEP
130127
ok bool
131-
callRows = make([]interface{}, 0, m.bulkCnt)
132-
regRows = make([]interface{}, 0, m.bulkCnt)
133-
restRows = make([]interface{}, 0, m.bulkCnt)
134-
dnsRows = make([]interface{}, 0, m.bulkCnt)
135-
logRows = make([]interface{}, 0, m.bulkCnt)
136-
rtcpRows = make([]interface{}, 0, m.bulkCnt)
137-
reportRows = make([]interface{}, 0, m.bulkCnt)
128+
callRows = make([]any, 0, m.bulkCnt)
129+
regRows = make([]any, 0, m.bulkCnt)
130+
restRows = make([]any, 0, m.bulkCnt)
131+
dnsRows = make([]any, 0, m.bulkCnt)
132+
logRows = make([]any, 0, m.bulkCnt)
133+
rtcpRows = make([]any, 0, m.bulkCnt)
134+
reportRows = make([]any, 0, m.bulkCnt)
138135
maxWait = m.dbTimer
139136
)
140137

@@ -149,8 +146,8 @@ func (m *MySQL) insert(hCh chan *decoder.HEP) {
149146
}
150147
defer stop()
151148

152-
addSIPRow := func(r []interface{}) []interface{} {
153-
r = append(r, []interface{}{
149+
addSIPRow := func(r []any) []any {
150+
r = append(r, []any{
154151
pkt.Timestamp.Format("2006-01-02 15:04:05.999999"),
155152
pkt.Timestamp.UnixNano() / 1000,
156153
short(pkt.SIP.FirstMethod, 50),
@@ -193,8 +190,8 @@ func (m *MySQL) insert(hCh chan *decoder.HEP) {
193190
return r
194191
}
195192

196-
addRTCRow := func(r []interface{}) []interface{} {
197-
r = append(r, []interface{}{
193+
addRTCRow := func(r []any) []any {
194+
r = append(r, []any{
198195
pkt.Timestamp.Format("2006-01-02 15:04:05.999999"),
199196
pkt.Timestamp.UnixNano() / 1000,
200197
pkt.CID,
@@ -220,23 +217,23 @@ func (m *MySQL) insert(hCh chan *decoder.HEP) {
220217
callCnt++
221218
if callCnt == m.bulkCnt {
222219
m.bulkInsert(callQuery, m.sipBulkVal, callRows)
223-
callRows = []interface{}{}
220+
callRows = []any{}
224221
callCnt = 0
225222
}
226223
case "REGISTER":
227224
regRows = addSIPRow(regRows)
228225
regCnt++
229226
if regCnt == m.bulkCnt {
230227
m.bulkInsert(registerQuery, m.sipBulkVal, regRows)
231-
regRows = []interface{}{}
228+
regRows = []any{}
232229
regCnt = 0
233230
}
234231
default:
235232
restRows = addSIPRow(restRows)
236233
restCnt++
237234
if restCnt == m.bulkCnt {
238235
m.bulkInsert(restQuery, m.sipBulkVal, restRows)
239-
restRows = []interface{}{}
236+
restRows = []any{}
240237
restCnt = 0
241238
}
242239

@@ -248,23 +245,23 @@ func (m *MySQL) insert(hCh chan *decoder.HEP) {
248245
rtcpCnt++
249246
if rtcpCnt == m.bulkCnt {
250247
m.bulkInsert(rtcpQuery, m.rtcBulkVal, rtcpRows)
251-
rtcpRows = []interface{}{}
248+
rtcpRows = []any{}
252249
rtcpCnt = 0
253250
}
254251
case 53:
255252
dnsRows = addRTCRow(dnsRows)
256253
dnsCnt++
257254
if dnsCnt == m.bulkCnt {
258255
m.bulkInsert(dnsQuery, m.rtcBulkVal, dnsRows)
259-
dnsRows = []interface{}{}
256+
dnsRows = []any{}
260257
dnsCnt = 0
261258
}
262259
case 100:
263260
logRows = addRTCRow(logRows)
264261
logCnt++
265262
if logCnt == m.bulkCnt {
266263
m.bulkInsert(logQuery, m.rtcBulkVal, logRows)
267-
logRows = []interface{}{}
264+
logRows = []any{}
268265
logCnt = 0
269266
}
270267
default:
@@ -274,7 +271,7 @@ func (m *MySQL) insert(hCh chan *decoder.HEP) {
274271
reportCnt++
275272
if reportCnt == m.bulkCnt {
276273
m.bulkInsert(reportQuery, m.rtcBulkVal, reportRows)
277-
reportRows = []interface{}{}
274+
reportRows = []any{}
278275
reportCnt = 0
279276
}
280277
}
@@ -284,50 +281,50 @@ func (m *MySQL) insert(hCh chan *decoder.HEP) {
284281
if callCnt > 0 {
285282
l := len(callRows)
286283
m.bulkInsert(callQuery, sipQueryVal(l/sipValCnt), callRows[:l])
287-
callRows = []interface{}{}
284+
callRows = []any{}
288285
callCnt = 0
289286
}
290287
if regCnt > 0 {
291288
l := len(regRows)
292289
m.bulkInsert(registerQuery, sipQueryVal(l/sipValCnt), regRows[:l])
293-
regRows = []interface{}{}
290+
regRows = []any{}
294291
regCnt = 0
295292
}
296293
if restCnt > 0 {
297294
l := len(restRows)
298295
m.bulkInsert(restQuery, sipQueryVal(l/sipValCnt), restRows[:l])
299-
restRows = []interface{}{}
296+
restRows = []any{}
300297
restCnt = 0
301298
}
302299
if rtcpCnt > 0 {
303300
l := len(rtcpRows)
304301
m.bulkInsert(rtcpQuery, rtcQueryVal(l/rtcValCnt), rtcpRows[:l])
305-
rtcpRows = []interface{}{}
302+
rtcpRows = []any{}
306303
rtcpCnt = 0
307304
}
308305
if reportCnt > 0 {
309306
l := len(reportRows)
310307
m.bulkInsert(reportQuery, rtcQueryVal(l/rtcValCnt), reportRows[:l])
311-
reportRows = []interface{}{}
308+
reportRows = []any{}
312309
reportCnt = 0
313310
}
314311
if dnsCnt > 0 {
315312
l := len(dnsRows)
316313
m.bulkInsert(dnsQuery, rtcQueryVal(l/rtcValCnt), dnsRows[:l])
317-
dnsRows = []interface{}{}
314+
dnsRows = []any{}
318315
dnsCnt = 0
319316
}
320317
if logCnt > 0 {
321318
l := len(logRows)
322319
m.bulkInsert(logQuery, rtcQueryVal(l/rtcValCnt), logRows[:l])
323-
logRows = []interface{}{}
320+
logRows = []any{}
324321
logCnt = 0
325322
}
326323
}
327324
}
328325
}
329326

330-
func (m *MySQL) bulkInsert(q, v []byte, rows []interface{}) {
327+
func (m *MySQL) bulkInsert(q, v []byte, rows []any) {
331328
tblDate := time.Now().In(time.UTC).AppendFormat(q, "20060102")
332329
query := make([]byte, len(tblDate)+len(v))
333330
tdl := copy(query, tblDate)
@@ -348,7 +345,7 @@ func short(s string, i int) string {
348345
func sipQueryVal(c int) []byte {
349346
out := make([]byte, c*len(sipPlaceholder)+len(sipVal)-1)
350347
bs := copy(out, sipVal)
351-
for i := 0; i < c; i++ {
348+
for i := range c {
352349
bp := i * len(sipPlaceholder)
353350
copy(out[bs+bp:], sipPlaceholder)
354351
}
@@ -358,7 +355,7 @@ func sipQueryVal(c int) []byte {
358355
func rtcQueryVal(c int) []byte {
359356
out := make([]byte, c*len(rtcPlaceholder)+len(rtcVal)-1)
360357
bs := copy(out, rtcVal)
361-
for i := 0; i < c; i++ {
358+
for i := range c {
362359
bp := i * len(rtcPlaceholder)
363360
copy(out[bs+bp:], rtcPlaceholder)
364361
}

0 commit comments

Comments
 (0)