Skip to content

Commit

Permalink
extends regex for json logs
Browse files Browse the repository at this point in the history
  • Loading branch information
M4tteoP committed Dec 6, 2024
1 parent 5d5a781 commit fb6c5d4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/knadh/koanf/providers/rawbytes v0.1.0
github.com/knadh/koanf/v2 v2.1.2
github.com/kyokomi/emoji/v2 v2.2.13
github.com/magefile/mage bdc92f694516
github.com/magefile/mage v1.15.1-0.20241126214340-bdc92f694516
github.com/rs/zerolog v1.33.0
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kyokomi/emoji/v2 v2.2.13 h1:GhTfQa67venUUvmleTNFnb+bi7S3aocF7ZCXU9fSO7U=
github.com/kyokomi/emoji/v2 v2.2.13/go.mod h1:JUcn42DTdsXJo1SWanHh4HKDEyPaR5CqkmoirZZP9qE=
github.com/magefile/mage v1.15.1-0.20241124190125-32e01077f0aa h1:RAKYgtUC3OPrwUYKQcwB0wWXCHo09ZWh5TFlnF0nVfA=
github.com/magefile/mage v1.15.1-0.20241124190125-32e01077f0aa/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magefile/mage v1.15.1-0.20241126214340-bdc92f694516 h1:aAO0L0ulox6m/CLRYvJff+jWXYYCKGpEm3os7dM/Z+M=
github.com/magefile/mage v1.15.1-0.20241126214340-bdc92f694516/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand Down
2 changes: 1 addition & 1 deletion waflog/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (ll *FTWLogLines) TriggeredRules() []uint {
ll.triggeredRulesInitialized = true

lines := ll.getMarkedLines()
regex := regexp.MustCompile(`\[id "(\d+)"\]|"id":\s*"?(\d+)"?`)
regex := regexp.MustCompile(`\[id \\?"(\d+)\\?"\]|"id":\s*"?(\d+)"?`)
for _, line := range lines {
log.Trace().Msgf("ftw/waflog: Looking for any rule in '%s'", line)
match := regex.FindAllSubmatch(line, -1)
Expand Down
7 changes: 4 additions & 3 deletions waflog/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,11 @@ func (s *readTestSuite) TestFindAllIdsInLogs() {
markerLine := "X-cRs-TeSt: " + stageID
logLines := fmt.Sprint("\n", markerLine,
`[id "1"] something else [id "2"]`,
`"id": 3, something else {"id":4}`+"\n",
`"id": 3, something else {"id":4},`,
`something else [id \"5\"]`+"\n",
"\n", markerLine)
filename, err := utils.CreateTempFileWithContent(logLines, "test-errorlog-")
s.Require().NoError(err)

cfg.LogFile = filename
log, err := os.Open(filename)
s.Require().NoError(err)
Expand All @@ -388,9 +388,10 @@ func (s *readTestSuite) TestFindAllIdsInLogs() {
ll.WithEndMarker([]byte(markerLine))

foundRuleIds := ll.TriggeredRules()
s.Len(foundRuleIds, 4)
s.Len(foundRuleIds, 5)
s.Contains(foundRuleIds, uint(1))
s.Contains(foundRuleIds, uint(2))
s.Contains(foundRuleIds, uint(3))
s.Contains(foundRuleIds, uint(4))
s.Contains(foundRuleIds, uint(5))
}

0 comments on commit fb6c5d4

Please sign in to comment.