refactor: make codebase more modular and use a single index for all services, tools and metics

This commit is contained in:
Patryk Hegenberg 2025-09-23 08:36:46 +02:00
parent 25dffecb43
commit 491eeaabd7
8 changed files with 343 additions and 130 deletions

View file

@ -198,6 +198,9 @@ func (jep *JournalEntryParser) extractSystemdFields(journalData map[string]any,
for _, field := range systemdFields {
if value, ok := journalData[field]; ok {
esFieldName := strings.ToLower(strings.TrimPrefix(field, "_"))
if entry.SyslogInfo.Fields == nil {
entry.SyslogInfo.Fields = make(map[string]any)
}
entry.SyslogInfo.Fields[esFieldName] = value
}
}
@ -238,7 +241,7 @@ var (
func parseTixstreamService(entry LogEntry) LogEntry {
newEntry := entry
var baseInfo TSBaseInfo
var baseInfo TSTransferInfo
matches := tsServicePattern.FindStringSubmatch(newEntry.LogMessage)
if len(matches) > 0 {
@ -285,13 +288,13 @@ func parseTixstreamService(entry LogEntry) LogEntry {
baseInfo.Lane = threadInt
baseInfo.Buffers = buffersInt
baseInfo.FileCount = fileCountInt
baseInfo.FileSize = fileSizeFloat
baseInfo.FileSizeMB = fileSizeFloat
baseInfo.ChunkSize = chunkSizeInt
baseInfo.Streams = streamsInt
baseInfo.TargetDatarate = datarateFloat
baseInfo.Protocoll = tsDetail[8]
baseInfo.Destination = tsDetail[9]
baseInfo.Sender = tsDetail[10]
baseInfo.Dest = tsDetail[9]
baseInfo.SenderID = tsDetail[10]
}
tsDetail = tsDetailPattern2.FindStringSubmatch(newEntry.LogMessage)
if len(tsDetail) > 0 {
@ -309,41 +312,43 @@ func parseTixstreamService(entry LogEntry) LogEntry {
baseInfo.Lane = threadInt
baseInfo.Buffers = buffersInt
baseInfo.FileCount = fileCountInt
baseInfo.FileSize = fileSizeFloat
baseInfo.FileSizeMB = fileSizeFloat
baseInfo.ChunkSize = chunkSizeInt
baseInfo.Streams = streamsInt
baseInfo.TargetDatarate = datarateFloat
baseInfo.Protocoll = tsDetail[8]
baseInfo.Source = tsDetail[9]
baseInfo.Src = tsDetail[9]
baseInfo.Receiver = tsDetail[10]
}
tsDetail = tsDetailPattern4.FindStringSubmatch(newEntry.LogMessage)
if len(tsDetail) > 0 {
threadInt, _ := strconv.Atoi(strings.Split(tsDetail[1], "/")[0])
baseInfo.Lane = threadInt
baseInfo.Source = tsDetail[2]
baseInfo.Destination = tsDetail[3]
baseInfo.Src = tsDetail[2]
baseInfo.Dest = tsDetail[3]
}
if strings.Contains(newEntry.LogMessage, "Transfer start") || strings.Contains(newEntry.LogMessage, "Transfer started,") {
baseInfo.StartTime = newEntry.Timestamp
} else {
baseInfo.StartTime = time.Now()
}
if strings.Contains(newEntry.LogMessage, "Transfer stopped local state=finished") {
baseInfo.EndTime = newEntry.Timestamp
} else {
baseInfo.EndTime = baseInfo.StartTime
}
if transferID != "" {
baseInfo.TransferID = transferID
} else {
baseInfo.TransferID = "no_transfer_id"
}
if !baseInfo.StartTime.IsZero() {
newEntry.BaseInformation = baseInfo
}
newEntry.ServiceInformation = baseInfo
return newEntry
}
func parseTJMService(entry LogEntry) LogEntry {
newEntry := entry
var baseInfo TJMBaseInfo
var baseInfo TJMTransferInfo
logContent := entry.LogMessage
msg := strings.TrimSpace(logContent)
@ -367,7 +372,7 @@ func parseTJMService(entry LogEntry) LogEntry {
}
newEntry.LogLevel = strings.TrimSpace(matches[2])
newEntry.LogMessage = strings.TrimSpace(matches[8])
baseInfo = TJMBaseInfo{
baseInfo = TJMTransferInfo{
ProcessID: strings.TrimSpace(matches[3]),
CorrelationID: strings.TrimSpace(matches[4]),
Username: strings.TrimSpace(matches[5]),
@ -405,7 +410,9 @@ func parseTJMService(entry LogEntry) LogEntry {
} else {
baseInfo.TransferID = "no_transfer_id"
}
newEntry.BaseInformation = baseInfo
baseInfo.StartTime = newEntry.Timestamp
baseInfo.StartTime = newEntry.Timestamp
newEntry.ServiceInformation = baseInfo
return newEntry
}
@ -433,7 +440,7 @@ func parseAMService(entry LogEntry) LogEntry {
}
newEntry.LogLevel = matches[2]
newEntry.LogMessage = matches[6]
newEntry.BaseInformation = baseInfo
newEntry.ServiceInformation = baseInfo
return newEntry
}
@ -461,7 +468,7 @@ func parseTCCService(entry LogEntry) LogEntry {
}
newEntry.LogLevel = matches[2]
newEntry.LogMessage = matches[6]
newEntry.BaseInformation = baseInfo
newEntry.ServiceInformation = baseInfo
return newEntry
}
@ -501,6 +508,7 @@ func parseNginxService(entry LogEntry) LogEntry {
baseInfo.RequestURI = requestParts[1]
baseInfo.HTTPVersion = requestParts[2]
}
newEntry.ServiceInformation = baseInfo
return newEntry
}