Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up logging and update golangci file #340

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# SPDX-FileCopyrightText: 2024 Intel Corporation
# SPDX-FileCopyrightText: 2021 Open Networking Foundation <info@opennetworking.org>
# Copyright 2019 free5GC.org
#
# SPDX-License-Identifier: Apache-2.0
#

# This file contains all available configuration options
# with their default values.
Expand All @@ -28,19 +27,6 @@ run:
# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-files:
- "api_.*\\.go$"
- "model_.*\\.go$"
- "routers.go"
- "client.go"
- "configuration.go"
- "nas.go"
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand All @@ -56,7 +42,7 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number
formats: colored-line-number
# print lines of code with issue, default is true
print-issued-lines: true
# print linter name in the end of issue text, default is true
Expand Down Expand Up @@ -139,10 +125,14 @@ linters-settings:
# minimal confidence for issues, default is 0.8
min-confidence: 0.8
gomnd:
settings:
mnd:
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks: argument,case,condition,operation,return,assign
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks:
- argument
- case
- condition
- operation
- return
- assign
gomodguard:
allowed:
modules: # List of allowed modules
Expand All @@ -160,8 +150,6 @@ linters-settings:
# version: "< 1.1.0" # Version constraint, see https://github.com/Masterminds/semver#basic-comparisons
# reason: "testing if blocked version constraint works." # Reason why the version constraint exists. (Optional)
govet:
# report about shadowed variables
check-shadowing: true
# settings per analyzer
settings:
printf: # analyzer name, run `go tool vet help` to see all analyzers
Expand Down Expand Up @@ -207,8 +195,6 @@ linters-settings:
whitespace:
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
gci:
local-prefixes: "bitbucket.org"
misspell:
#locale: US
ignore-words:
Expand Down Expand Up @@ -263,9 +249,9 @@ linters:
- dogsled
# - bodyclose
- asciicheck
#- stylecheck
# - stylecheck
- unparam
# - wsl
# - wsl

#disable-all: false
fast: true
Expand Down
17 changes: 12 additions & 5 deletions callback/api_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ import (
func HTTPSmPolicyUpdateNotification(c *gin.Context) {
var request models.SmPolicyNotification

reqBody, _ := c.GetRawData()
reqBody, err := c.GetRawData()
if err != nil {
logger.PduSessLog.Errorf("error: %v", err)
}

err := openapi.Deserialize(&request, reqBody, c.ContentType())
err = openapi.Deserialize(&request, reqBody, c.ContentType())
if err != nil {
logger.PduSessLog.Errorln("deserialize request failed")
}
Expand All @@ -46,7 +49,7 @@ func HTTPSmPolicyUpdateNotification(c *gin.Context) {
smContextRef := reqWrapper.Params["smContextRef"]
logger.PduSessLog.Infof("HTTPSmPolicyUpdateNotification received for UUID = %v", smContextRef)

txn := transaction.NewTransaction(reqWrapper.Body.(models.SmPolicyNotification), nil, svcmsgtypes.SmfMsgType(svcmsgtypes.SmPolicyUpdateNotification))
txn := transaction.NewTransaction(reqWrapper.Body.(models.SmPolicyNotification), nil, svcmsgtypes.SmPolicyUpdateNotification)
txn.CtxtKey = smContextRef
go txn.StartTxnLifeCycle(fsm.SmfTxnFsmHandle)
<-txn.Status // wait for txn to complete at SMF
Expand All @@ -61,7 +64,11 @@ func HTTPSmPolicyUpdateNotification(c *gin.Context) {
if err != nil {
logger.PduSessLog.Errorln(err)
}
c.Writer.Write(resBody)
_, err = c.Writer.Write(resBody)
if err != nil {
logger.PduSessLog.Errorf("error: %v", err)
}

c.Status(HTTPResponse.Status)
}

Expand All @@ -80,7 +87,7 @@ func N1N2FailureNotification(c *gin.Context) {
req.Params["smContextRef"] = c.Params.ByName("smContextRef")

smContextRef := req.Params["smContextRef"]
txn := transaction.NewTransaction(req.Body.(models.N1N2MsgTxfrFailureNotification), nil, svcmsgtypes.SmfMsgType(svcmsgtypes.N1N2MessageTransferFailureNotification))
txn := transaction.NewTransaction(req.Body.(models.N1N2MsgTxfrFailureNotification), nil, svcmsgtypes.N1N2MessageTransferFailureNotification)
txn.CtxtKey = smContextRef
go txn.StartTxnLifeCycle(fsm.SmfTxnFsmHandle)
<-txn.Status
Expand Down
33 changes: 23 additions & 10 deletions pdusession/api_individual_sm_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,30 @@ import (
mi "github.com/omec-project/util/metricinfo"
)

var (
multipartRelated string = "multipart/related"
applicationJson string = "application/json"
)

// HTTPReleaseSmContext - Release SM Context
func HTTPReleaseSmContext(c *gin.Context) {
var err error
logger.PduSessLog.Infoln("receive Release SM Context Request")
stats.IncrementN11MsgStats(smf_context.SMF_Self().NfInstanceID, string(svcmsgtypes.ReleaseSmContext), "In", "", "")
stats.PublishMsgEvent(mi.Smf_msg_type_pdu_sess_release_req)
err = stats.PublishMsgEvent(mi.Smf_msg_type_pdu_sess_release_req)
if err != nil {
logger.PduSessLog.Errorf("error: %v", err)
return
}

var request models.ReleaseSmContextRequest
request.JsonData = new(models.SmContextReleaseData)

s := strings.Split(c.GetHeader("Content-Type"), ";")
var err error
switch s[0] {
case "application/json":
case applicationJson:
err = c.ShouldBindJSON(request.JsonData)
case "multipart/related":
case multipartRelated:
err = c.ShouldBindWith(&request, openapi.MultipartRelatedBinding{})
}
if err != nil {
Expand All @@ -65,7 +74,7 @@ func HTTPReleaseSmContext(c *gin.Context) {
req.Params["smContextRef"] = c.Params.ByName("smContextRef")

smContextRef := req.Params["smContextRef"]
txn := transaction.NewTransaction(req.Body.(models.ReleaseSmContextRequest), nil, svcmsgtypes.SmfMsgType(svcmsgtypes.ReleaseSmContext))
txn := transaction.NewTransaction(req.Body.(models.ReleaseSmContextRequest), nil, svcmsgtypes.ReleaseSmContext)
txn.CtxtKey = smContextRef
go txn.StartTxnLifeCycle(fsm.SmfTxnFsmHandle)
<-txn.Status
Expand All @@ -84,19 +93,23 @@ func RetrieveSmContext(c *gin.Context) {

// HTTPUpdateSmContext - Update SM Context
func HTTPUpdateSmContext(c *gin.Context) {
var err error
logger.PduSessLog.Infoln("receive Update SM Context Request")
stats.IncrementN11MsgStats(smf_context.SMF_Self().NfInstanceID, string(svcmsgtypes.UpdateSmContext), "In", "", "")
stats.PublishMsgEvent(mi.Smf_msg_type_pdu_sess_modify_req)
err = stats.PublishMsgEvent(mi.Smf_msg_type_pdu_sess_modify_req)
if err != nil {
logger.PduSessLog.Errorf("error: %v", err)
return
}

var request models.UpdateSmContextRequest
request.JsonData = new(models.SmContextUpdateData)

s := strings.Split(c.GetHeader("Content-Type"), ";")
var err error
switch s[0] {
case "application/json":
case applicationJson:
err = c.ShouldBindJSON(request.JsonData)
case "multipart/related":
case multipartRelated:
err = c.ShouldBindWith(&request, openapi.MultipartRelatedBinding{})
}
if err != nil {
Expand All @@ -119,7 +132,7 @@ func HTTPUpdateSmContext(c *gin.Context) {

smContextRef := req.Params["smContextRef"]

txn := transaction.NewTransaction(req.Body.(models.UpdateSmContextRequest), nil, svcmsgtypes.SmfMsgType(svcmsgtypes.UpdateSmContext))
txn := transaction.NewTransaction(req.Body.(models.UpdateSmContextRequest), nil, svcmsgtypes.UpdateSmContext)
txn.CtxtKey = smContextRef
go txn.StartTxnLifeCycle(fsm.SmfTxnFsmHandle)
<-txn.Status
Expand Down
12 changes: 8 additions & 4 deletions pdusession/api_sm_contexts_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ import (
// HTTPPostSmContexts - Create SM Context
func HTTPPostSmContexts(c *gin.Context) {
logger.PduSessLog.Infoln("receive create SM Context Request")
var err error
var request models.PostSmContextsRequest
stats.IncrementN11MsgStats(smf_context.SMF_Self().NfInstanceID, string(svcmsgtypes.CreateSmContext), "In", "", "")
stats.PublishMsgEvent(mi.Smf_msg_type_pdu_sess_create_req)
err = stats.PublishMsgEvent(mi.Smf_msg_type_pdu_sess_create_req)
if err != nil {
logger.PduSessLog.Errorf("error: %v", err)
return
}

request.JsonData = new(models.SmContextCreateData)

s := strings.Split(c.GetHeader("Content-Type"), ";")
var err error
switch s[0] {
case "application/json":
err = c.ShouldBindJSON(request.JsonData)
Expand All @@ -62,7 +66,7 @@ func HTTPPostSmContexts(c *gin.Context) {
}

req := httpwrapper.NewRequest(c.Request, request)
txn := transaction.NewTransaction(req.Body.(models.PostSmContextsRequest), nil, svcmsgtypes.SmfMsgType(svcmsgtypes.CreateSmContext))
txn := transaction.NewTransaction(req.Body.(models.PostSmContextsRequest), nil, svcmsgtypes.CreateSmContext)

go txn.StartTxnLifeCycle(fsm.SmfTxnFsmHandle)
<-txn.Status // wait for txn to complete at SMF
Expand Down Expand Up @@ -95,7 +99,7 @@ func HTTPPostSmContexts(c *gin.Context) {
go func(smContext *smf_context.SMContext) {
var txn *transaction.Transaction
if HTTPResponse.Status == http.StatusCreated {
txn = transaction.NewTransaction(nil, nil, svcmsgtypes.SmfMsgType(svcmsgtypes.PfcpSessCreate))
txn = transaction.NewTransaction(nil, nil, svcmsgtypes.PfcpSessCreate)
txn.Ctxt = smContext
go txn.StartTxnLifeCycle(fsm.SmfTxnFsmHandle)
<-txn.Status
Expand Down
Loading