Skip to content

Commit

Permalink
Replace logrus wth zap logger (#115)
Browse files Browse the repository at this point in the history
Signed-off-by: Arrobo, Gabriel <[email protected]>
  • Loading branch information
gab-arrobo authored Oct 3, 2024
1 parent c1ecaab commit 0a62253
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 117 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2-dev
1.2.0
14 changes: 7 additions & 7 deletions cmd/pfcpsim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

pb "github.com/omec-project/pfcpsim/api"
"github.com/omec-project/pfcpsim/internal/pfcpsim"
"github.com/omec-project/pfcpsim/logger"
"github.com/pborman/getopt/v2"
log "github.com/sirupsen/logrus"
"google.golang.org/grpc"
)

Expand All @@ -25,7 +25,7 @@ const (
func startServer(apiDoneChannel chan bool, iFace string, port string, group *sync.WaitGroup) {
lis, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%v", port))
if err != nil {
log.Fatalf("API gRPC Server failed to listen: %v", err)
logger.PfcpsimLog.Fatalf("api gRPC Server failed to listen: %v", err)
}

grpcServer := grpc.NewServer()
Expand All @@ -34,17 +34,17 @@ func startServer(apiDoneChannel chan bool, iFace string, port string, group *syn

go func() {
if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("Failed to listed: %v", err)
logger.PfcpsimLog.Fatalf("failed to listed: %v", err)
}
}()

log.Infof("Server listening on port %v", port)
logger.PfcpsimLog.Infoln("server listening on port", port)

x := <-apiDoneChannel
if x {
// if the API channel is closed, stop the gRPC pfcpsim
grpcServer.Stop()
log.Warnf("Stopping API gRPC pfcpsim")
logger.PfcpsimLog.Warnln("stopping API gRPC pfcpsim")
}

group.Done()
Expand Down Expand Up @@ -80,11 +80,11 @@ func main() {
wg.Add(1)

go startServer(doneChannel, *iFaceName, *port, &wg)
log.Debugf("Started API gRPC Service")
logger.PfcpsimLog.Debugln("started API gRPC Service")

wg.Wait()

defer func() {
log.Info("PFCP Simulator shutting down")
logger.PfcpsimLog.Infoln("pfcp Simulator shutting down")
}()
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ require (
github.com/golang/protobuf v1.5.4
github.com/jessevdk/go-flags v1.6.1
github.com/pborman/getopt/v2 v2.1.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/wmnsk/go-pfcp v0.0.24
go.uber.org/zap v1.27.0
google.golang.org/grpc v1.67.0
google.golang.org/protobuf v1.34.2
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
Expand Down
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
github.com/c-robinson/iplib v1.0.8 h1:exDRViDyL9UBLcfmlxxkY5odWX5092nPsQIykHXhIn4=
github.com/c-robinson/iplib v1.0.8/go.mod h1:i3LuuFL1hRT5gFpBRnEydzw8R6yhGkF4szNDIbF8pgo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
Expand All @@ -13,17 +12,18 @@ github.com/pborman/getopt/v2 v2.1.0 h1:eNfR+r+dWLdWmV8g5OlpyrTYHkhVNxHBdN2cCrJmO
github.com/pborman/getopt/v2 v2.1.0/go.mod h1:4NtW75ny4eBw9fO1bhtNdYTlZKYX5/tBLtsOpwKIKd0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/wmnsk/go-pfcp v0.0.24 h1:sv4F3U/IphsPUMXMkTJW877CRvXZ1sF5onWHGBvxx/A=
github.com/wmnsk/go-pfcp v0.0.24/go.mod h1:8EUVvOzlz25wkUs9D8STNAs5zGyIo5xEUpHQOUZ/iSg=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
Expand All @@ -36,6 +36,5 @@ google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6h
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
6 changes: 3 additions & 3 deletions internal/pfcpctl/commands/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package commands
import (
pb "github.com/omec-project/pfcpsim/api"
"github.com/omec-project/pfcpsim/internal/pfcpctl/config"
log "github.com/sirupsen/logrus"
"github.com/omec-project/pfcpsim/logger"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand All @@ -17,7 +17,7 @@ func connect() pb.PFCPSimClient {
// Create an insecure gRPC Channel
connection, err := grpc.NewClient(config.GlobalConfig.Server, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("Error dialing %v: %v", config.GlobalConfig.Server, err)
logger.PfcpsimLog.Fatalf("error dialing %v: %v", config.GlobalConfig.Server, err)
}

return pb.NewPFCPSimClient(connection)
Expand All @@ -27,7 +27,7 @@ func disconnect() {
if conn != nil {
err := conn.Close()
if err != nil {
log.Warnln(err)
logger.PfcpsimLog.Warnln(err)
}
}
}
16 changes: 8 additions & 8 deletions internal/pfcpctl/commands/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/jessevdk/go-flags"
pb "github.com/omec-project/pfcpsim/api"
log "github.com/sirupsen/logrus"
"github.com/omec-project/pfcpsim/logger"
)

type (
Expand All @@ -29,7 +29,7 @@ type serviceOptions struct {
func RegisterServiceCommands(parser *flags.Parser) {
_, err := parser.AddCommand("service", "configure pfcpsim", "Command to configure pfcpsim", &serviceOptions{})
if err != nil {
log.Warnln(err)
logger.PfcpsimLog.Warnln(err)
}
}

Expand All @@ -43,10 +43,10 @@ func (c *configureRemoteAddresses) Execute(args []string) error {
RemotePeerAddress: c.RemotePeerAddress,
})
if err != nil {
log.Fatalf("Error while configuring remote addresses: %v", err)
logger.PfcpsimLog.Fatalf("error while configuring remote addresses: %v", err)
}

log.Info(res.Message)
logger.PfcpsimLog.Infoln(res.Message)

return nil
}
Expand All @@ -58,10 +58,10 @@ func (c *associate) Execute(args []string) error {

res, err := client.Associate(context.Background(), &pb.EmptyRequest{})
if err != nil {
log.Fatalf("Error while associating: %v", err)
logger.PfcpsimLog.Fatalf("error while associating: %v", err)
}

log.Infof("%s", res.Message)
logger.PfcpsimLog.Infoln(res.Message)

return nil
}
Expand All @@ -73,10 +73,10 @@ func (c *disassociate) Execute(args []string) error {

res, err := client.Disassociate(context.Background(), &pb.EmptyRequest{})
if err != nil {
log.Fatalf("Error while disassociating: %v", err)
logger.PfcpsimLog.Fatalf("error while disassociating: %v", err)
}

log.Infof("%s", res.Message)
logger.PfcpsimLog.Infoln(res.Message)

return nil
}
22 changes: 11 additions & 11 deletions internal/pfcpctl/commands/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/jessevdk/go-flags"
pb "github.com/omec-project/pfcpsim/api"
log "github.com/sirupsen/logrus"
"github.com/omec-project/pfcpsim/logger"
)

type commonArgs struct {
Expand All @@ -22,11 +22,11 @@ type commonArgs struct {

func (a *commonArgs) validate() {
if a.BaseID <= 0 {
log.Fatalf("BaseID cannot be 0 or a negative number.")
logger.PfcpsimLog.Fatalln("baseID cannot be 0 or a negative number")
}

if a.Count <= 0 {
log.Fatalf("Count cannot be 0 or a negative number.")
logger.PfcpsimLog.Fatalln("count cannot be 0 or a negative number")
}
}

Expand Down Expand Up @@ -64,13 +64,13 @@ func RegisterSessionCommands(parser *flags.Parser) {
&SessionOptions{},
)
if err != nil {
log.Warnln(err)
logger.PfcpsimLog.Warnln(err)
}
}

func (s *sessionCreate) Execute(args []string) error {
if s.Args.QFI > 64 {
log.Fatalf("QFI cannot be greater than 64. Provided QFI: %v", s.Args.QFI)
logger.PfcpsimLog.Fatalf("qfi cannot be greater than 64. Provided qfi: %v", s.Args.QFI)
}

client := connect()
Expand All @@ -88,10 +88,10 @@ func (s *sessionCreate) Execute(args []string) error {
Qfi: int32(s.Args.QFI),
})
if err != nil {
log.Fatalf("Error while creating sessions: %v", err)
logger.PfcpsimLog.Fatalf("error while creating sessions: %v", err)
}

log.Infof("%s", res.Message)
logger.PfcpsimLog.Infoln(res.Message)

return nil
}
Expand All @@ -113,10 +113,10 @@ func (s *sessionModify) Execute(args []string) error {
AppFilters: s.Args.AppFilterString,
})
if err != nil {
log.Fatalf("Error while modifying sessions: %v", err)
logger.PfcpsimLog.Fatalf("error while modifying sessions: %v", err)
}

log.Infof("%s", res.Message)
logger.PfcpsimLog.Infof(res.Message)

return nil
}
Expand All @@ -133,10 +133,10 @@ func (s *sessionDelete) Execute(args []string) error {
BaseID: int32(s.Args.BaseID),
})
if err != nil {
log.Fatalf("Error while deleting sessions: %v", err)
logger.PfcpsimLog.Fatalf("error while deleting sessions: %v", err)
}

log.Infof("%s", res.Message)
logger.PfcpsimLog.Infoln(res.Message)

return nil
}
6 changes: 3 additions & 3 deletions internal/pfcpctl/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net"
"os"

log "github.com/sirupsen/logrus"
"github.com/omec-project/pfcpsim/logger"
)

const (
Expand Down Expand Up @@ -40,7 +40,7 @@ func ProcessGlobalOptions() {

// Generate error messages for required settings
if GlobalConfig.Server == "" {
log.Fatal("Server is not set. Please use the -s option")
logger.PfcpsimLog.Fatalln("server is not set. Please use the -s option")
}

// Try to resolve hostname if provided for the server
Expand All @@ -50,5 +50,5 @@ func ProcessGlobalOptions() {
}
}

log.Debugf("ServerAddress: %v", GlobalOptions.Server)
logger.PfcpsimLog.Debugf("serverAddress: %v", GlobalOptions.Server)
}
25 changes: 11 additions & 14 deletions internal/pfcpsim/export/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (

"github.com/c-robinson/iplib"
"github.com/omec-project/pfcpsim/internal/pfcpsim"
"github.com/omec-project/pfcpsim/logger"
sim "github.com/omec-project/pfcpsim/pkg/pfcpsim"
"github.com/omec-project/pfcpsim/pkg/pfcpsim/session"
log "github.com/sirupsen/logrus"
ieLib "github.com/wmnsk/go-pfcp/ie"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -120,8 +120,8 @@ func (c *PfcpSimCfg) CreateSession(baseID int,

lastUEAddr, _, err := net.ParseCIDR(uePool)
if err != nil {
errMsg := fmt.Sprintf(" Could not parse Address Pool: %v", err)
log.Error(errMsg)
errMsg := fmt.Sprintf("Could not parse Address Pool: %v", err)
logger.PfcpsimLog.Errorln(errMsg)

return status.Error(codes.Aborted, errMsg)
}
Expand Down Expand Up @@ -159,7 +159,7 @@ func (c *PfcpSimCfg) CreateSession(baseID int,
return status.Error(codes.Aborted, err.Error())
}

log.Infof("Successfully parsed application filter. SDF Filter: %v", SDFFilter)
logger.PfcpsimLog.Infof("successfully parsed application filter. SDF Filter: %v", SDFFilter)

uplinkPdrID := ID
downlinkPdrID := ID + 1
Expand Down Expand Up @@ -283,8 +283,7 @@ func (c *PfcpSimCfg) CreateSession(baseID int,
sim.InsertSession(i, sess)
}

infoMsg := fmt.Sprintf("%v sessions were established using %v as baseID ", count, baseID)
log.Info(infoMsg)
logger.PfcpsimLog.Infof("%d sessions were established using %d as baseID", count, baseID)

return nil
}
Expand Down Expand Up @@ -337,7 +336,7 @@ func (c *PfcpSimCfg) ModifySession(baseID int,
sess, ok := sim.GetSession(i)
if !ok {
errMsg := fmt.Sprintf("Could not retrieve session with index %v", i)
log.Error(errMsg)
logger.PfcpsimLog.Errorln(errMsg)

return status.Error(codes.Internal, errMsg)
}
Expand All @@ -348,8 +347,7 @@ func (c *PfcpSimCfg) ModifySession(baseID int,
}
}

infoMsg := fmt.Sprintf("%v sessions were modified", count)
log.Info(infoMsg)
logger.PfcpsimLog.Infof("%v sessions were modified", count)

return nil
}
Expand All @@ -359,7 +357,7 @@ func (c *PfcpSimCfg) DeleteSession(baseID int) error {

if sim.GetActiveSessionNum() < count {
err := sim.NewNotEnoughSessionsError()
log.Error(err)
logger.PfcpsimLog.Error(err)

return status.Error(codes.Aborted, err.Error())
}
Expand All @@ -368,22 +366,21 @@ func (c *PfcpSimCfg) DeleteSession(baseID int) error {
sess, ok := sim.GetSession(i)
if !ok {
errMsg := "Session was nil. Check baseID"
log.Error(errMsg)
logger.PfcpsimLog.Errorln(errMsg)

return status.Error(codes.Aborted, errMsg)
}

err := c.sim.DeleteSession(sess)
if err != nil {
log.Error(err.Error())
logger.PfcpsimLog.Errorln(err.Error())
return status.Error(codes.Aborted, err.Error())
}
// remove from activeSessions
sim.RemoveSession(i)
}

infoMsg := fmt.Sprintf("%v sessions deleted; activeSessions: %v", count, sim.GetActiveSessionNum())
log.Info(infoMsg)
logger.PfcpsimLog.Infof("%v sessions deleted; activeSessions: %v", count, sim.GetActiveSessionNum())

return nil
}
Loading

0 comments on commit 0a62253

Please sign in to comment.