Skip to content

Commit a419130

Browse files
authored
Merge pull request #77 from FIWARE/refactor/logger
Replace logrus with zap
2 parents 06f1aa4 + e7c61d3 commit a419130

21 files changed

Lines changed: 314 additions & 173 deletions

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ COPY --from=build /go/src/app/views ./views
2222
COPY --from=build /go/src/app/VCVerifier ./VCVerifier
2323
COPY --from=build /go/src/app/server.yaml ./server.yaml
2424

25+
ENV GIN_MODE=release
26+
2527
CMD ["./VCVerifier"]

config/config.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
package config
22

3+
import "github.com/fiware/VCVerifier/logging"
4+
35
// CONFIGURATION STRUCTURE FOR THE VERIFIER CONFIG
46

57
// general structure of the configuration file
68
type Configuration struct {
7-
Server Server `mapstructure:"server"`
8-
Verifier Verifier `mapstructure:"verifier"`
9-
Logging Logging `mapstructure:"logging"`
10-
ConfigRepo ConfigRepo `mapstructure:"configRepo"`
11-
M2M M2M `mapstructure:"m2m"`
12-
Elsi Elsi `mapstructure:"elsi"`
9+
Server Server `mapstructure:"server"`
10+
Verifier Verifier `mapstructure:"verifier"`
11+
Logging logging.LoggingConfig `mapstructure:"logging"`
12+
ConfigRepo ConfigRepo `mapstructure:"configRepo"`
13+
M2M M2M `mapstructure:"m2m"`
14+
Elsi Elsi `mapstructure:"elsi"`
1315
}
1416

1517
// general configuration to run the application
@@ -22,6 +24,15 @@ type Server struct {
2224
TemplateDir string `mapstructure:"templateDir" default:"views/"`
2325
// directory of static files to be provided, f.e. to be used inside the templates
2426
StaticDir string `mapstructure:"staticDir" default:"views/static/"`
27+
28+
// ReadTimeout is the maximum duration for reading the entire request, including the body.
29+
ReadTimeout int `mapstructure:"readTimeout" default:"5"`
30+
// WriteTimeout is the maximum duration before timing out writes of the response.
31+
WriteTimeout int `mapstructure:"writeTimeout" default:"10"`
32+
// IdleTimeout is the maximum amount of time to wait for the next request when keep-alives are enabled.
33+
IdleTimeout int `mapstructure:"idleTimeout" default:"120"`
34+
// ShutdownTimeout is the time allowed for active requests to finish during shutdown.
35+
ShutdownTimeout int `mapstructure:"shutdownTimeout" default:"5"`
2536
}
2637

2738
// configuration for M2M interaction
@@ -42,18 +53,6 @@ type M2M struct {
4253
KeyType string `mapstructure:"keyType" default:"RSAPS256"`
4354
}
4455

45-
// logging config
46-
type Logging struct {
47-
// loglevel to be used - can be DEBUG, INFO, WARN or ERROR
48-
Level string `mapstructure:"level" default:"INFO"`
49-
// should the logging in a structured json format
50-
JsonLogging bool `mapstructure:"jsonLogging" default:"true"`
51-
// should requests be logged
52-
LogRequests bool `mapstructure:"logRequests" default:"true"`
53-
// list of paths to be ignored on request logging(could be often called operational endpoints like f.e. metrics)
54-
PathsToSkip []string `mapstructure:"pathsToSkip"`
55-
}
56-
5756
// configuration specific to the functionality of the verifier
5857
type Verifier struct {
5958
// did to be used by the verifier

config/configClient_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ type MockHttpClient struct {
1717
Answer string
1818
}
1919

20+
var LOGGING_CONFIG = logging.LoggingConfig{
21+
Level: "DEBUG",
22+
JsonLogging: true,
23+
LogRequests: true,
24+
PathsToSkip: []string{},
25+
DisableCaller: false,
26+
}
27+
2028
func (mhc MockHttpClient) Get(url string) (resp *http.Response, err error) {
2129
return &http.Response{StatusCode: 200, Body: io.NopCloser(strings.NewReader(mhc.Answer))}, nil
2230
}
@@ -31,7 +39,7 @@ func readFile(filename string, t *testing.T) string {
3139

3240
func Test_getScope(t *testing.T) {
3341

34-
logging.Configure(true, "DEBUG", true, []string{})
42+
logging.Configure(LOGGING_CONFIG)
3543
type test struct {
3644
testName string
3745
testScope string

config/data/config_test.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ server:
22
port: 3000
33
staticDir: "views/static"
44
templateDir: "views/"
5-
5+
ReadTimeout: 100
6+
WriteTimeout: 200
7+
IdleTimeout: 300
8+
ShutdownTimeout: 400
69
logging:
710
level: "DEBUG"
811
jsonLogging: true
912
logRequests: true
1013
pathsToSkip: [/health]
14+
disableCaller: true
1115

1216
verifier:
1317
did: "did:key:somekey"
@@ -26,10 +30,10 @@ verifier:
2630
ssiKit:
2731
auditorURL: http://waltid:7003
2832

29-
m2m:
33+
m2m:
3034
authEnabled: false
3135
configRepo:
32-
services:
36+
services:
3337
- id: testService
3438
defaultOidcScope: someScope
3539
oidcScopes:
@@ -45,9 +49,8 @@ configRepo:
4549
id: my-pd
4650
input_descriptors:
4751
- id: my-descriptor
48-
constraints:
49-
fields:
52+
constraints:
53+
fields:
5054
- id: my-field
5155
path:
5256
- $.vc.my.claim
53-

config/provider_test.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ func Test_ReadConfig(t *testing.T) {
2323
args{"data/config_test.yaml"},
2424
Configuration{
2525
Server: Server{
26-
Port: 3000,
27-
TemplateDir: "views/",
28-
StaticDir: "views/static",
26+
Port: 3000,
27+
TemplateDir: "views/",
28+
StaticDir: "views/static",
29+
ReadTimeout: 100,
30+
WriteTimeout: 200,
31+
IdleTimeout: 300,
32+
ShutdownTimeout: 400,
2933
},
3034
Verifier: Verifier{
3135
Did: "did:key:somekey",
@@ -51,13 +55,14 @@ func Test_ReadConfig(t *testing.T) {
5155
KeyAlgorithm: "RS256",
5256
GenerateKey: true,
5357
SupportedModes: []string{"urlEncoded"},
54-
JwtExpiration: 30,
58+
JwtExpiration: 30,
5559
},
56-
Logging: Logging{
57-
Level: "DEBUG",
58-
JsonLogging: true,
59-
LogRequests: true,
60-
PathsToSkip: []string{"/health"},
60+
Logging: logging.LoggingConfig{
61+
Level: "DEBUG",
62+
JsonLogging: true,
63+
LogRequests: true,
64+
PathsToSkip: []string{"/health"},
65+
DisableCaller: true,
6166
},
6267
ConfigRepo: ConfigRepo{
6368
ConfigEndpoint: "",
@@ -106,8 +111,12 @@ func Test_ReadConfig(t *testing.T) {
106111
args{"data/empty_test.yaml"},
107112
Configuration{
108113
Server: Server{Port: 8080,
109-
TemplateDir: "views/",
110-
StaticDir: "views/static/",
114+
TemplateDir: "views/",
115+
StaticDir: "views/static/",
116+
ReadTimeout: 5,
117+
WriteTimeout: 10,
118+
IdleTimeout: 120,
119+
ShutdownTimeout: 5,
111120
},
112121
Verifier: Verifier{Did: "",
113122
TirAddress: "",
@@ -120,11 +129,12 @@ func Test_ReadConfig(t *testing.T) {
120129
SupportedModes: []string{"urlEncoded"},
121130
JwtExpiration: 30,
122131
},
123-
Logging: Logging{
124-
Level: "INFO",
125-
JsonLogging: true,
126-
LogRequests: true,
127-
PathsToSkip: nil,
132+
Logging: logging.LoggingConfig{
133+
Level: "INFO",
134+
JsonLogging: true,
135+
LogRequests: true,
136+
PathsToSkip: nil,
137+
DisableCaller: false,
128138
},
129139
M2M: M2M{AuthEnabled: false, VerificationMethod: "JsonWebKey2020", SignatureType: "JsonWebSignature2020", KeyType: "RSAPS256"},
130140
ConfigRepo: ConfigRepo{UpdateInterval: 30},

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ require (
8585
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
8686
go.opentelemetry.io/otel v1.10.0 // indirect
8787
go.opentelemetry.io/otel/trace v1.10.0 // indirect
88+
go.uber.org/multierr v1.11.0 // indirect
89+
go.uber.org/zap v1.27.1 // indirect
8890
golang.org/x/sync v0.13.0 // indirect
8991
golang.org/x/term v0.31.0 // indirect
9092
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
@@ -111,7 +113,6 @@ require (
111113
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
112114
github.com/penglongli/gin-metrics v0.1.10
113115
github.com/procyon-projects/chrono v1.1.2
114-
github.com/sirupsen/logrus v1.9.3
115116
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
116117
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
117118
github.com/ugorji/go/codec v1.2.11 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,10 @@ go.opentelemetry.io/otel v1.10.0 h1:Y7DTJMR6zs1xkS/upamJYk0SxxN4C9AqRd77jmZnyY4=
488488
go.opentelemetry.io/otel v1.10.0/go.mod h1:NbvWjCthWHKBEUMpf0/v8ZRZlni86PpGFEMA9pnQSnQ=
489489
go.opentelemetry.io/otel/trace v1.10.0 h1:npQMbR8o7mum8uF95yFbOEJffhs1sbCOfDh8zAJiH5E=
490490
go.opentelemetry.io/otel/trace v1.10.0/go.mod h1:Sij3YYczqAdz+EhmGhE6TpTxUO5/F/AzrK+kxfGqySM=
491+
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
492+
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
493+
go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc=
494+
go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
491495
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
492496
golang.org/x/arch v0.5.0 h1:jpGode6huXQxcskEIpOCvrU+tzo81b6+oFLUYXWtH/Y=
493497
golang.org/x/arch v0.5.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=

0 commit comments

Comments
 (0)