Skip to content

Commit e69586e

Browse files
committed
Delete lazyloading of cloudtrail-related regexes
1 parent 2bfbac7 commit e69586e

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

aws/logs_monitoring_go/internal/handling/cloudtrail.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,17 @@ import (
1515
"log/slog"
1616
"regexp"
1717
"strings"
18-
"sync"
1918
)
2019

2120
const (
2221
cloudTrailARNKey = "arn"
2322
cloudTrailUserIdentityKey = "userIdentity"
2423
)
2524

26-
var cloudTrailRegex = regexp.MustCompile(`\d+_CloudTrail(|-Digest|-Insight)_\w{2}(|-gov|-cn)-\w{4,9}-\d_(|.+)\d{8}T\d{4,6}Z(|.+)\.json\.gz$`)
27-
28-
var ec2InstanceRegexp = sync.OnceValue(func() *regexp.Regexp {
29-
return regexp.MustCompile(`^arn:aws:sts::.*?:assumed-role/(?P<role>.*?)/(?P<host>i-([0-9a-f]{8}|[0-9a-f]{17}))$`)
30-
})
25+
var (
26+
cloudTrailRegex = regexp.MustCompile(`\d+_CloudTrail(|-Digest|-Insight)_\w{2}(|-gov|-cn)-\w{4,9}-\d_(|.+)\d{8}T\d{4,6}Z(|.+)\.json\.gz$`)
27+
ec2InstanceRegexp = regexp.MustCompile(`^arn:aws:sts::.*?:assumed-role/(?P<role>.*?)/(?P<host>i-([0-9a-f]{8}|[0-9a-f]{17}))$`)
28+
)
3129

3230
func decodeCloudTrail(r io.Reader) iter.Seq2[string, error] {
3331
return func(yield func(string, error) bool) {

aws/logs_monitoring_go/internal/handling/cloudtrail_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestCloudTrailRegex(t *testing.T) {
5757
for name, tc := range tests {
5858
t.Run(name, func(t *testing.T) {
5959
t.Parallel()
60-
got := cloudTrailRegex().MatchString(tc.key)
60+
got := cloudTrailRegex.MatchString(tc.key)
6161
if got != tc.want {
6262
t.Errorf("cloudTrailRegex().MatchString(%q) = %v, want %v", tc.key, got, tc.want)
6363
}

aws/logs_monitoring_go/internal/handling/s3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (h S3Handler) processRecord(ctx context.Context, client S3APIClient, out ch
7777
}()
7878

7979
var records iter.Seq2[string, error]
80-
isCloudTrail := cloudTrailRegex().MatchString(key)
80+
isCloudTrail := cloudTrailRegex.MatchString(key)
8181
if isCloudTrail {
8282
records = decodeCloudTrail(body)
8383
} else {

0 commit comments

Comments
 (0)