Skip to content

Commit b92caec

Browse files
authored
fix: observe grpc client (#339)
* fix: observe grpc client Signed-off-by: gatici <[email protected]> * fix: correct the NF name in comment Signed-off-by: gatici <[email protected]> * chore: update version Signed-off-by: gatici <[email protected]> * refactor: move implementation under service Signed-off-by: gatici <[email protected]> * move if clause related to MANAGED_BY_CONFIG_POD env value to service/init.go Signed-off-by: gatici <[email protected]> * remove else clause and fix typos Signed-off-by: gatici <[email protected]> * update go.mod and go.sum Signed-off-by: gatici <[email protected]> --------- Signed-off-by: gatici <[email protected]>
1 parent 280b7bb commit b92caec

File tree

6 files changed

+74
-22
lines changed

6 files changed

+74
-22
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.6.2-dev
1+
1.6.2

factory/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (r *RoutingConfig) GetVersion() string {
237237
return ""
238238
}
239239

240-
func (c *Config) updateConfig(commChannel chan *protos.NetworkSliceResponse) bool {
240+
func (c *Config) UpdateConfig(commChannel chan *protos.NetworkSliceResponse) bool {
241241
for {
242242
rsp := <-commChannel
243243
logger.GrpcLog.Infof("received updateConfig in the smf app: %+v \n", rsp)

factory/factory.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"os"
1515
"sync"
1616

17-
"github.com/omec-project/config5g/proto/client"
1817
"github.com/omec-project/smf/logger"
1918
"gopkg.in/yaml.v2"
2019
)
@@ -26,7 +25,11 @@ var (
2625
SmfConfigSyncLock sync.Mutex
2726
)
2827

29-
// TODO: Support configuration update from REST api
28+
// InitConfigFactory gets the NrfConfig and subscribes the config pod.
29+
// This observes the GRPC client availability and connection status in a loop.
30+
// When the GRPC server pod is restarted, GRPC connection status stuck in idle.
31+
// If GRPC client does not exist, creates it. If client exists but GRPC connectivity is not ready,
32+
// then it closes the existing client start a new client.
3033
func InitConfigFactory(f string) error {
3134
if content, err := os.ReadFile(f); err != nil {
3235
return err
@@ -45,15 +48,7 @@ func InitConfigFactory(f string) error {
4548
enableKafka := true
4649
SmfConfig.Configuration.KafkaInfo.EnableKafka = &enableKafka
4750
}
48-
49-
roc := os.Getenv("MANAGED_BY_CONFIG_POD")
50-
if roc == "true" {
51-
gClient := client.ConnectToConfigServer(SmfConfig.Configuration.WebuiUri)
52-
commChannel := gClient.PublishOnConfigChange(false)
53-
go SmfConfig.updateConfig(commChannel)
54-
}
5551
}
56-
5752
return nil
5853
}
5954

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/google/uuid v1.6.0
99
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
1010
github.com/omec-project/aper v1.2.1
11-
github.com/omec-project/config5g v1.5.1
11+
github.com/omec-project/config5g v1.5.4
1212
github.com/omec-project/nas v1.4.2
1313
github.com/omec-project/ngap v1.3.0
1414
github.com/omec-project/openapi v1.3.1
@@ -79,7 +79,7 @@ require (
7979
golang.org/x/sys v0.26.0 // indirect
8080
golang.org/x/text v0.19.0 // indirect
8181
google.golang.org/grpc v1.67.1 // indirect
82-
google.golang.org/protobuf v1.34.2 // indirect
82+
google.golang.org/protobuf v1.35.1 // indirect
8383
gopkg.in/h2non/gock.v1 v1.1.2 // indirect
8484
gopkg.in/yaml.v3 v3.0.1 // indirect
8585
inet.af/netaddr v0.0.0-20220811202034-502d2d690317 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
225225
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
226226
github.com/omec-project/aper v1.2.1 h1:A4KhlTMta5mUA1DX2njOjOn0SuFi5WoWnSqdbRnl9Q8=
227227
github.com/omec-project/aper v1.2.1/go.mod h1:CbCZ0uNmcD3XA4YM6wBwpqP1PYtGAaC3RqLL4B5gG2U=
228-
github.com/omec-project/config5g v1.5.1 h1:JaVgr76tnjJIb7Uoesv5a9GI72NdOXtCvfukj0/ONio=
229-
github.com/omec-project/config5g v1.5.1/go.mod h1:o04ZdwGcM7tbGjuT5t/WzYSKLXOSnFl6vH7b6BGAspU=
228+
github.com/omec-project/config5g v1.5.4 h1:5JMw5Fsr5qyLZpQi3IZQaQPj78QJMFQXDVS3QDMOY9Y=
229+
github.com/omec-project/config5g v1.5.4/go.mod h1:HOvQtmi79f8cw35AiFHWHDoCTuZbXfMjeFJWgtPbwaI=
230230
github.com/omec-project/nas v1.4.2 h1:V+DKwxmxRrwMmpNQ3+kx7WQjqY1XqbWDIeQXWIof+Gk=
231231
github.com/omec-project/nas v1.4.2/go.mod h1:cAXzuNN0dVDXgwg2cbptQjwTKP4llXPV8jrU4LVp7H0=
232232
github.com/omec-project/ngap v1.3.0 h1:NuAc6GZRup6E3jg+fGTy8aR4VkOlB1mnkaaYr6OGmMc=
@@ -519,8 +519,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
519519
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
520520
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
521521
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
522-
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
523-
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
522+
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
523+
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
524524
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
525525
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
526526
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

service/init.go

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"time"
1919

2020
aperLogger "github.com/omec-project/aper/logger"
21+
grpcClient "github.com/omec-project/config5g/proto/client"
22+
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
2123
nasLogger "github.com/omec-project/nas/logger"
2224
ngapLogger "github.com/omec-project/ngap/logger"
2325
openapiLogger "github.com/omec-project/openapi/logger"
@@ -139,9 +141,65 @@ func (smf *SMF) Initialize(c *cli.Context) error {
139141
}()
140142
}
141143

144+
if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" {
145+
logger.InitLog.Infoln("MANAGED_BY_CONFIG_POD is true")
146+
go manageGrpcClient(factory.SmfConfig.Configuration.WebuiUri)
147+
}
142148
return nil
143149
}
144150

151+
// manageGrpcClient connects the config pod GRPC server and subscribes the config changes.
152+
// Then it updates SMF configuration.
153+
func manageGrpcClient(webuiUri string) {
154+
var configChannel chan *protos.NetworkSliceResponse
155+
var client grpcClient.ConfClient
156+
var stream protos.ConfigService_NetworkSliceSubscribeClient
157+
var err error
158+
count := 0
159+
for {
160+
if client != nil {
161+
if client.CheckGrpcConnectivity() != "ready" {
162+
time.Sleep(time.Second * 30)
163+
count++
164+
if count > 5 {
165+
err = client.GetConfigClientConn().Close()
166+
if err != nil {
167+
logger.InitLog.Infof("failing ConfigClient is not closed properly: %+v", err)
168+
}
169+
client = nil
170+
count = 0
171+
}
172+
logger.InitLog.Infoln("checking the connectivity readiness")
173+
continue
174+
}
175+
176+
if stream == nil {
177+
stream, err = client.SubscribeToConfigServer()
178+
if err != nil {
179+
logger.InitLog.Infof("failing SubscribeToConfigServer: %+v", err)
180+
continue
181+
}
182+
}
183+
184+
if configChannel == nil {
185+
configChannel = client.PublishOnConfigChange(true, stream)
186+
logger.InitLog.Infoln("PublishOnConfigChange is triggered")
187+
go factory.SmfConfig.UpdateConfig(configChannel)
188+
logger.InitLog.Infoln("SMF updateConfig is triggered")
189+
}
190+
} else {
191+
client, err = grpcClient.ConnectToConfigServer(webuiUri)
192+
stream = nil
193+
configChannel = nil
194+
logger.InitLog.Infoln("connecting to config server")
195+
if err != nil {
196+
logger.InitLog.Errorf("%+v", err)
197+
}
198+
continue
199+
}
200+
}
201+
}
202+
145203
func (smf *SMF) setLogLevel() {
146204
if factory.SmfConfig.Logger == nil {
147205
logger.InitLog.Warnln("SMF config without log level setting")
@@ -263,10 +321,9 @@ func (smf *SMF) Start() {
263321
context.InitSMFUERouting(&factory.UERoutingConfig)
264322

265323
// Wait for additional/updated config from config pod
266-
roc := os.Getenv("MANAGED_BY_CONFIG_POD")
267-
if roc == "true" {
268-
logger.InitLog.Infoln("configuration is managed by Config Pod")
269-
logger.InitLog.Infoln("waiting for initial configuration from config pod")
324+
if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" {
325+
logger.InitLog.Infof("configuration is managed by Config Pod")
326+
logger.InitLog.Infof("waiting for initial configuration from config pod")
270327

271328
// Main thread should be blocked for config update from ROC
272329
// Future config update from ROC can be handled via background go-routine.

0 commit comments

Comments
 (0)