Skip to content

Commit c7edbb9

Browse files
committed
add automemlimit
Signed-off-by: Markus Blaschke <[email protected]>
1 parent 6e98181 commit c7edbb9

File tree

5 files changed

+105
-18
lines changed

5 files changed

+105
-18
lines changed

logger.go renamed to common.logger.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package main
22

33
import (
4+
"log/slog"
5+
46
"go.uber.org/zap"
7+
"go.uber.org/zap/exp/zapslog"
58
"go.uber.org/zap/zapcore"
69
)
710

811
var (
9-
logger *zap.SugaredLogger
12+
logger *zap.SugaredLogger
13+
slogger *slog.Logger
1014
)
1115

1216
func initLogger() *zap.SugaredLogger {
1317
var config zap.Config
14-
if opts.Logger.Development {
18+
if Opts.Logger.Development {
1519
config = zap.NewDevelopmentConfig()
1620
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
1721
} else {
@@ -22,12 +26,12 @@ func initLogger() *zap.SugaredLogger {
2226
config.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
2327

2428
// debug level
25-
if opts.Logger.Debug {
29+
if Opts.Logger.Debug {
2630
config.Level = zap.NewAtomicLevelAt(zapcore.DebugLevel)
2731
}
2832

2933
// json log format
30-
if opts.Logger.Json {
34+
if Opts.Logger.Json {
3135
config.Encoding = "json"
3236

3337
// if running in containers, logs already enriched with timestamp by the container runtime
@@ -39,6 +43,9 @@ func initLogger() *zap.SugaredLogger {
3943
if err != nil {
4044
panic(err)
4145
}
46+
4247
logger = log.Sugar()
48+
slogger = slog.New(zapslog.NewHandler(log.Core(), nil))
49+
4350
return logger
4451
}

common.system.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"github.com/KimMachineGun/automemlimit/memlimit"
5+
humanize "github.com/dustin/go-humanize"
6+
)
7+
8+
func initSystem() {
9+
// set memory limit
10+
goMemLimit, err := memlimit.SetGoMemLimitWithOpts(
11+
memlimit.WithProvider(
12+
memlimit.ApplyFallback(
13+
memlimit.FromCgroup,
14+
memlimit.FromSystem,
15+
),
16+
),
17+
memlimit.WithLogger(slogger),
18+
)
19+
20+
if goMemLimit > 0 {
21+
logger.Infof(`GOMEMLIMIT updated to %v`, humanize.Bytes(uint64(goMemLimit)))
22+
}
23+
24+
if err != nil {
25+
logger.Fatal(err)
26+
}
27+
}

go.mod

+12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ require (
1616
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armsubscriptions v1.3.0
1717
github.com/Azure/go-autorest/autorest v0.11.29
1818
github.com/Azure/go-autorest/autorest/to v0.4.0
19+
github.com/KimMachineGun/automemlimit v0.6.1
1920
github.com/Masterminds/sprig/v3 v3.2.3
21+
github.com/dustin/go-humanize v1.0.1
2022
github.com/gofrs/uuid v4.4.0+incompatible
2123
github.com/google/uuid v1.6.0
2224
github.com/jeremywohl/flatten/v2 v2.0.0-20211013061545-07e4a09fb8e4
@@ -27,6 +29,7 @@ require (
2729
github.com/robfig/cron/v3 v3.0.1
2830
github.com/webdevops/go-common v0.0.0-20240817151728-d02b3cd2f9fe
2931
go.uber.org/zap v1.27.0
32+
go.uber.org/zap/exp v0.2.0
3033
gopkg.in/yaml.v3 v3.0.1
3134
)
3235

@@ -44,10 +47,15 @@ require (
4447
github.com/Masterminds/semver/v3 v3.2.1 // indirect
4548
github.com/beorn7/perks v1.0.1 // indirect
4649
github.com/cespare/xxhash/v2 v2.3.0 // indirect
50+
github.com/cilium/ebpf v0.16.0 // indirect
4751
github.com/cjlapao/common-go v0.0.40 // indirect
52+
github.com/containerd/cgroups/v3 v3.0.3 // indirect
53+
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
4854
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
55+
github.com/docker/go-units v0.5.0 // indirect
4956
github.com/go-logr/logr v1.4.2 // indirect
5057
github.com/go-logr/stdr v1.2.2 // indirect
58+
github.com/godbus/dbus/v5 v5.1.0 // indirect
5159
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
5260
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
5361
github.com/huandu/xstrings v1.5.0 // indirect
@@ -66,13 +74,16 @@ require (
6674
github.com/mitchellh/copystructure v1.2.0 // indirect
6775
github.com/mitchellh/reflectwalk v1.0.2 // indirect
6876
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
77+
github.com/opencontainers/runtime-spec v1.2.0 // indirect
78+
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
6979
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
7080
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
7181
github.com/prometheus/client_model v0.6.1 // indirect
7282
github.com/prometheus/common v0.55.0 // indirect
7383
github.com/prometheus/procfs v0.15.1 // indirect
7484
github.com/remeh/sizedwaitgroup v1.0.0 // indirect
7585
github.com/shopspring/decimal v1.4.0 // indirect
86+
github.com/sirupsen/logrus v1.9.3 // indirect
7687
github.com/spf13/cast v1.7.0 // indirect
7788
github.com/std-uritemplate/std-uritemplate/go v1.0.5 // indirect
7889
github.com/stretchr/testify v1.9.0 // indirect
@@ -81,6 +92,7 @@ require (
8192
go.opentelemetry.io/otel/trace v1.28.0 // indirect
8293
go.uber.org/multierr v1.11.0 // indirect
8394
golang.org/x/crypto v0.26.0 // indirect
95+
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
8496
golang.org/x/net v0.28.0 // indirect
8597
golang.org/x/sys v0.24.0 // indirect
8698
golang.org/x/text v0.17.0 // indirect

go.sum

+39
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUM
4848
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
4949
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2 h1:XHOnouVk1mxXfQidrMEnLlPk9UMeRtyBTnEFtxkV0kU=
5050
github.com/AzureAD/microsoft-authentication-library-for-go v1.2.2/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
51+
github.com/KimMachineGun/automemlimit v0.6.1 h1:ILa9j1onAAMadBsyyUJv5cack8Y1WT26yLj/V+ulKp8=
52+
github.com/KimMachineGun/automemlimit v0.6.1/go.mod h1:T7xYht7B8r6AG/AqFcUdc7fzd2bIdBKmepfP2S1svPY=
5153
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
5254
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
5355
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
@@ -59,19 +61,34 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
5961
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
6062
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
6163
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
64+
github.com/cilium/ebpf v0.16.0 h1:+BiEnHL6Z7lXnlGUsXQPPAE7+kenAd4ES8MQ5min0Ok=
65+
github.com/cilium/ebpf v0.16.0/go.mod h1:L7u2Blt2jMM/vLAVgjxluxtBKlz3/GWjB0dMOEngfwE=
6266
github.com/cjlapao/common-go v0.0.40 h1:zbn75fpZLoF8mR9z4QF2IHZjzpEkplisgPFGfnSzknI=
6367
github.com/cjlapao/common-go v0.0.40/go.mod h1:ao5wEp0hYMNehJiHoarSjc5dKK5wi4LvnwjXaC2SxUI=
68+
github.com/containerd/cgroups/v3 v3.0.3 h1:S5ByHZ/h9PMe5IOQoN7E+nMc2UcLEM/V48DGDJ9kip0=
69+
github.com/containerd/cgroups/v3 v3.0.3/go.mod h1:8HBe7V3aWGLFPd/k03swSIsGjZhHI2WzJmticMgVuz0=
70+
github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs=
71+
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
6472
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6573
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6674
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
6775
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
76+
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
77+
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
78+
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
79+
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
6880
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
6981
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
7082
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
7183
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
7284
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
7385
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
7486
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
87+
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
88+
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
89+
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
90+
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
91+
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
7592
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
7693
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
7794
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
@@ -94,6 +111,10 @@ github.com/jeremywohl/flatten/v2 v2.0.0-20211013061545-07e4a09fb8e4 h1:eA9wi6Zzp
94111
github.com/jeremywohl/flatten/v2 v2.0.0-20211013061545-07e4a09fb8e4/go.mod h1:s9g9Dfls+aEgucKXKW+i8MRZuLXT2MrD/WjYpMnWfOw=
95112
github.com/jessevdk/go-flags v1.6.1 h1:Cvu5U8UGrLay1rZfv/zP7iLpSHGUZ/Ou68T0iX1bBK4=
96113
github.com/jessevdk/go-flags v1.6.1/go.mod h1:Mk8T1hIAWpOiJiHa9rJASDK2UGWji0EuPGBnNLMooyc=
114+
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
115+
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
116+
github.com/jsimonetti/rtnetlink/v2 v2.0.1 h1:xda7qaHDSVOsADNouv7ukSuicKZO7GgVUCXxpaIEIlM=
117+
github.com/jsimonetti/rtnetlink/v2 v2.0.1/go.mod h1:7MoNYNbb3UaDHtF8udiJo/RH6VsTKP1pqKLUTVCvToE=
97118
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
98119
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
99120
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
@@ -102,6 +123,10 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
102123
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
103124
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
104125
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
126+
github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g=
127+
github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw=
128+
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
129+
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
105130
github.com/microsoft/kiota-abstractions-go v1.6.1 h1:NXK50S3BwJn9Wj6bO0YFuAig7y2WVgdQ/ie1ktMl2J4=
106131
github.com/microsoft/kiota-abstractions-go v1.6.1/go.mod h1:FI1I2OHg0E7bK5t8DPnw+9C/CHVyLP6XeqDBT+95pTE=
107132
github.com/microsoft/kiota-authentication-azure-go v1.1.0 h1:HudH57Enel9zFQ4TEaJw6lMiyZ5RbBdrRHwdU0NP2RY=
@@ -128,8 +153,12 @@ github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zx
128153
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
129154
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
130155
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
156+
github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE7dzrbT927iTk=
157+
github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
131158
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
132159
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
160+
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 h1:onHthvaw9LFnH4t2DcNVpwGmV9E1BkGknEliJkfwQj0=
161+
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58/go.mod h1:DXv8WO4yhMYhSNPKjeNKa5WY9YCIEBRbNzFFPJbWO6Y=
133162
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
134163
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
135164
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
@@ -154,6 +183,8 @@ github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99
154183
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
155184
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
156185
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
186+
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
187+
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
157188
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
158189
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
159190
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
@@ -164,6 +195,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
164195
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
165196
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
166197
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
198+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
167199
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
168200
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
169201
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
@@ -184,6 +216,8 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
184216
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
185217
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
186218
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
219+
go.uber.org/zap/exp v0.2.0 h1:FtGenNNeCATRB3CmB/yEUnjEFeJWpB/pMcy7e2bKPYs=
220+
go.uber.org/zap/exp v0.2.0/go.mod h1:t0gqAIdh1MfKv9EwN/dLwfZnJxe9ITAZN78HEWPFWDQ=
187221
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
188222
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
189223
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
@@ -192,6 +226,8 @@ golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58
192226
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
193227
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
194228
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
229+
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI=
230+
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
195231
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
196232
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
197233
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -206,11 +242,14 @@ golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
206242
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
207243
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
208244
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
245+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
246+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
209247
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
210248
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
211249
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
212250
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
213251
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
252+
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
214253
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
215254
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
216255
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

main.go

+16-14
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const (
3434

3535
var (
3636
argparser *flags.Parser
37-
opts config.Opts
37+
Opts config.Opts
3838

3939
azureAuditor *auditor.AzureAuditor
4040

@@ -45,25 +45,27 @@ var (
4545

4646
func main() {
4747
initArgparser()
48-
initLogger()
48+
defer initLogger().Sync() // nolint:errcheck
4949

5050
logger.Infof("starting azure-auditor v%s (%s; %s; by %v)", gitTag, gitCommit, runtime.Version(), Author)
51-
logger.Info(string(opts.GetJson()))
51+
logger.Info(string(Opts.GetJson()))
52+
53+
initSystem()
5254

5355
logger.Infof("starting audit")
5456
azureAuditor = auditor.NewAzureAuditor()
55-
azureAuditor.Opts = opts
57+
azureAuditor.Opts = Opts
5658
azureAuditor.Logger = logger
5759
azureAuditor.UserAgent = UserAgent + gitTag
58-
azureAuditor.ParseConfig(opts.Config...)
60+
azureAuditor.ParseConfig(Opts.Config...)
5961
azureAuditor.Run()
6062

61-
logger.Infof("Starting http server on %s", opts.Server.Bind)
63+
logger.Infof("Starting http server on %s", Opts.Server.Bind)
6264
startHttpServer()
6365
}
6466

6567
func initArgparser() {
66-
argparser = flags.NewParser(&opts, flags.Default)
68+
argparser = flags.NewParser(&Opts, flags.Default)
6769
_, err := argparser.Parse()
6870

6971
// check if there is a parse error
@@ -143,7 +145,7 @@ func startHttpServer() {
143145
logger.Panic(err)
144146
}
145147

146-
mux.HandleFunc(opts.Server.PathReport, func(w http.ResponseWriter, r *http.Request) {
148+
mux.HandleFunc(Opts.Server.PathReport, func(w http.ResponseWriter, r *http.Request) {
147149
cspNonce := base64.StdEncoding.EncodeToString([]byte(uuid.New().String()))
148150

149151
w.Header().Add("Content-Type", "text/html")
@@ -170,10 +172,10 @@ func startHttpServer() {
170172
}{
171173
Nonce: cspNonce,
172174
Config: azureAuditor.GetConfig(),
173-
ReportTitle: opts.Report.Title,
175+
ReportTitle: Opts.Report.Title,
174176
ReportConfig: nil,
175177
Reports: azureAuditor.GetReport(),
176-
ServerPathReport: opts.Server.PathReport,
178+
ServerPathReport: Opts.Server.PathReport,
177179
RequestReport: "",
178180
}
179181

@@ -215,7 +217,7 @@ func startHttpServer() {
215217
}
216218
})
217219

218-
mux.HandleFunc(opts.Server.PathReport+"/data", func(w http.ResponseWriter, r *http.Request) {
220+
mux.HandleFunc(Opts.Server.PathReport+"/data", func(w http.ResponseWriter, r *http.Request) {
219221
var reportGroupBy *string
220222
var reportFields *[]string
221223
var reportStatus *types.RuleStatus
@@ -350,10 +352,10 @@ func startHttpServer() {
350352
))
351353

352354
srv := &http.Server{
353-
Addr: opts.Server.Bind,
355+
Addr: Opts.Server.Bind,
354356
Handler: mux,
355-
ReadTimeout: opts.Server.ReadTimeout,
356-
WriteTimeout: opts.Server.WriteTimeout,
357+
ReadTimeout: Opts.Server.ReadTimeout,
358+
WriteTimeout: Opts.Server.WriteTimeout,
357359
}
358360
logger.Fatal(srv.ListenAndServe())
359361
}

0 commit comments

Comments
 (0)