Skip to content

Commit

Permalink
fix: observe GRPC client (#135)
Browse files Browse the repository at this point in the history
* fix: observer grpc client

Signed-off-by: gatici <[email protected]>

* chore: add fmt, lint and test options to make file

fix: linting errors

Signed-off-by: gatici <[email protected]>

* Move the implementation under service/Initialize method

Signed-off-by: gatici <[email protected]>

* update config5g version

Signed-off-by: gatici <[email protected]>

* removing spots

Signed-off-by: gatici <[email protected]>

* adding a blank line

Signed-off-by: gatici <[email protected]>

* move MANAGED_BY_CONFIG_POD env clauses under service/init.go

Signed-off-by: gatici <[email protected]>

* revert back Configured variable to factory

Signed-off-by: gatici <[email protected]>

* change the order of execution

Signed-off-by: gatici <[email protected]>

---------

Signed-off-by: gatici <[email protected]>
  • Loading branch information
gatici authored Oct 28, 2024
1 parent 3658baf commit 22c48ce
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 24 deletions.
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,22 @@ docker-push:
for target in $(DOCKER_TARGETS); do \
docker push ${DOCKER_REGISTRY}${DOCKER_REPOSITORY}5gc-$$target:${DOCKER_TAG}; \
done

.coverage:
rm -rf $(CURDIR)/.coverage
mkdir -p $(CURDIR)/.coverage

test: .coverage
docker run --rm -v $(CURDIR):/nssf -w /nssf golang:latest \
go test \
-failfast \
-coverprofile=.coverage/coverage-unit.txt \
-covermode=atomic \
-v \
./ ./...

fmt:
@go fmt ./...

golint:
@docker run --rm -v $(CURDIR):/app -w /app golangci/golangci-lint:latest golangci-lint run -v --config /app/.golangci.yml
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.1-dev
1.5.1
2 changes: 1 addition & 1 deletion factory/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func init() {
ConfigPodTrigger = make(chan bool)
}

func (c *Config) updateConfig(commChannel chan *protos.NetworkSliceResponse) bool {
func (c *Config) UpdateConfig(commChannel chan *protos.NetworkSliceResponse) bool {
var minConfig bool
for rsp := range commChannel {
logger.GrpcLog.Infoln("Received updateConfig in the nssf app : ", rsp)
Expand Down
14 changes: 0 additions & 14 deletions factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"os"
"sync"

"github.com/omec-project/config5g/proto/client"
"github.com/omec-project/nssf/logger"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -43,20 +42,7 @@ func InitConfigFactory(f string) error {
if NssfConfig.Configuration.WebuiUri == "" {
NssfConfig.Configuration.WebuiUri = "webui:9876"
}
roc := os.Getenv("MANAGED_BY_CONFIG_POD")
if roc == "true" {
logger.CfgLog.Infoln("MANAGED_BY_CONFIG_POD is true")
commChannel := client.ConfigWatcher(NssfConfig.Configuration.WebuiUri)
go NssfConfig.updateConfig(commChannel)
} else {
go func() {
logger.CfgLog.Infoln("Use helm chart config ")
ConfigPodTrigger <- true
}()
}
Configured = true
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/evanphx/json-patch v5.9.0+incompatible
github.com/gin-gonic/gin v1.10.0
github.com/google/uuid v1.6.0
github.com/omec-project/config5g v1.5.1
github.com/omec-project/config5g v1.5.4
github.com/omec-project/openapi v1.3.1
github.com/omec-project/util v1.2.3
github.com/prometheus/client_golang v1.20.5
Expand Down Expand Up @@ -62,7 +62,7 @@ require (
golang.org/x/text v0.19.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.34.2 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/h2non/gock.v1 v1.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/omec-project/config5g v1.5.1 h1:JaVgr76tnjJIb7Uoesv5a9GI72NdOXtCvfukj0/ONio=
github.com/omec-project/config5g v1.5.1/go.mod h1:o04ZdwGcM7tbGjuT5t/WzYSKLXOSnFl6vH7b6BGAspU=
github.com/omec-project/config5g v1.5.4 h1:5JMw5Fsr5qyLZpQi3IZQaQPj78QJMFQXDVS3QDMOY9Y=
github.com/omec-project/config5g v1.5.4/go.mod h1:HOvQtmi79f8cw35AiFHWHDoCTuZbXfMjeFJWgtPbwaI=
github.com/omec-project/openapi v1.3.1 h1:NCteMRdMtWnMhf1CXYduuLgeu8fEhc/7XO1CiE7fN3Y=
github.com/omec-project/openapi v1.3.1/go.mod h1:cR6Iharp2TLOzEmskQ/EdCVFZnpKh0zTvUSSuyXAYLE=
github.com/omec-project/util v1.2.3 h1:h32ZYFT99+fB9VPp1CQUIKwrSP6RtX+PbFDcqmEHmn0=
Expand Down Expand Up @@ -143,8 +143,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
67 changes: 65 additions & 2 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"syscall"
"time"

grpcClient "github.com/omec-project/config5g/proto/client"
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
"github.com/omec-project/nssf/consumer"
"github.com/omec-project/nssf/context"
"github.com/omec-project/nssf/factory"
Expand Down Expand Up @@ -84,17 +86,78 @@ func (nssf *NSSF) Initialize(c *cli.Context) error {
}
}

context.InitNssfContext()

nssf.setLogLevel()

if err := factory.CheckConfigVersion(); err != nil {
return err
}

if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" {
logger.InitLog.Infoln("MANAGED_BY_CONFIG_POD is true")
go manageGrpcClient(factory.NssfConfig.Configuration.WebuiUri)
} else {
go func() {
logger.CfgLog.Infoln("use helm chart config")
factory.ConfigPodTrigger <- true
}()
}
factory.Configured = true
context.InitNssfContext()
return nil
}

// manageGrpcClient connects the config pod GRPC server and subscribes the config changes.
// Then it updates NSSF configuration.
func manageGrpcClient(webuiUri string) {
var configChannel chan *protos.NetworkSliceResponse
var client grpcClient.ConfClient
var stream protos.ConfigService_NetworkSliceSubscribeClient
var err error
count := 0
for {
if client != nil {
if client.CheckGrpcConnectivity() != "ready" {
time.Sleep(time.Second * 30)
count++
if count > 5 {
err = client.GetConfigClientConn().Close()
if err != nil {
logger.InitLog.Infof("failing ConfigClient is not closed properly: %+v", err)
}
client = nil
count = 0
}
logger.InitLog.Infoln("checking the connectivity readiness")
continue
}

if stream == nil {
stream, err = client.SubscribeToConfigServer()
if err != nil {
logger.InitLog.Infof("failing SubscribeToConfigServer: %+v", err)
continue
}
}

if configChannel == nil {
configChannel = client.PublishOnConfigChange(true, stream)
logger.InitLog.Infoln("PublishOnConfigChange is triggered")
go factory.NssfConfig.UpdateConfig(configChannel)
logger.InitLog.Infoln("NSSF updateConfig is triggered")
}
} else {
client, err = grpcClient.ConnectToConfigServer(webuiUri)
stream = nil
configChannel = nil
logger.InitLog.Infoln("connecting to config server")
if err != nil {
logger.InitLog.Errorf("%+v", err)
}
continue
}
}
}

func (nssf *NSSF) setLogLevel() {
if factory.NssfConfig.Logger == nil {
logger.InitLog.Warnln("NSSF config without log level setting")
Expand Down

0 comments on commit 22c48ce

Please sign in to comment.