Skip to content

Commit

Permalink
fix: observe GRPC client
Browse files Browse the repository at this point in the history
Signed-off-by: gatici <gulsum.atici@canonical.com>
  • Loading branch information
gatici committed Oct 21, 2024
1 parent 11fefa4 commit ae7369b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/gin-gonic/gin v1.10.0
github.com/google/uuid v1.6.0
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
github.com/omec-project/config5g v1.5.1
github.com/omec-project/config5g v1.5.3
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 @@ -65,7 +65,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 @@ -81,8 +81,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.3 h1:FPetMFU1/BXGzihcoRHJm0q1vU1AnYyR4Tq1T1gyvUQ=
github.com/omec-project/config5g v1.5.3/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 @@ -151,8 +151,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
50 changes: 44 additions & 6 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/antihax/optional"
"github.com/gin-contrib/cors"
"github.com/omec-project/config5g/proto/client"
grpcClient "github.com/omec-project/config5g/proto/client"
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
"github.com/omec-project/openapi/Nnrf_NFDiscovery"
openapiLogger "github.com/omec-project/openapi/logger"
Expand Down Expand Up @@ -114,12 +114,13 @@ func (pcf *PCF) Initialize(c *cli.Context) error {
return err
}

roc := os.Getenv("MANAGED_BY_CONFIG_POD")
if roc == "true" {
if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" {
initLog.Infoln("MANAGED_BY_CONFIG_POD is true")
gClient := client.ConnectToConfigServer(factory.PcfConfig.Configuration.WebuiUri)
commChannel := gClient.PublishOnConfigChange(true)
go pcf.UpdateConfig(commChannel)
client, err := grpcClient.ConnectToConfigServer(factory.PcfConfig.Configuration.WebuiUri)
if err != nil {
go updateConfig(client, pcf)
}
return err
} else {
go func() {
initLog.Infoln("Use helm chart config ")
Expand All @@ -129,6 +130,43 @@ func (pcf *PCF) Initialize(c *cli.Context) error {
return nil
}

// updateConfig connects the config pod GRPC server and subscribes the config changes
// then updates PCF configuration
func updateConfig(client grpcClient.ConfClient, pcf *PCF) {
var stream protos.ConfigService_NetworkSliceSubscribeClient
var err error
var configChannel chan *protos.NetworkSliceResponse
for {
if client != nil {
stream, err = client.CheckGrpcConnectivity()
if err != nil {
initLog.Errorf("%v", err)
if stream != nil {
time.Sleep(time.Second * 30)
continue
} else {
err = client.GetConfigClientConn().Close()
if err != nil {
initLog.Debugf("failing ConfigClient is not closed properly: %+v", err)
}
client = nil
continue
}
}
if configChannel == nil {
configChannel = client.PublishOnConfigChange(true, stream)
go pcf.UpdateConfig(configChannel)
}
} else {
client, err = grpcClient.ConnectToConfigServer(factory.PcfConfig.Configuration.WebuiUri)
if err != nil {
initLog.Errorf("%+v", err)
}
continue
}
}
}

func (pcf *PCF) setLogLevel() {
if factory.PcfConfig.Logger == nil {
initLog.Warnln("PCF config without log level setting!!!")
Expand Down

0 comments on commit ae7369b

Please sign in to comment.