Skip to content

Commit 6eb39e3

Browse files
authored
fix: observe grpc client (#160)
* fix: observe grpc client Signed-off-by: gatici <[email protected]> * fix: logging typo Signed-off-by: gatici <[email protected]> * fix: merge conflicts Signed-off-by: gatici <[email protected]> * refactor: reorganize the methods Signed-off-by: gatici <[email protected]> * chore: organize manageGrpcClient method Signed-off-by: gatici <[email protected]> * refactor managegrpcclient Signed-off-by: gatici <[email protected]> * removing spots in the logs Signed-off-by: gatici <[email protected]> --------- Signed-off-by: gatici <[email protected]>
1 parent 36a62ed commit 6eb39e3

File tree

4 files changed

+63
-13
lines changed

4 files changed

+63
-13
lines changed

VERSION

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

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/antihax/optional v1.0.0
77
github.com/gin-gonic/gin v1.10.0
88
github.com/google/uuid v1.6.0
9-
github.com/omec-project/config5g v1.5.1
9+
github.com/omec-project/config5g v1.5.4
1010
github.com/omec-project/openapi v1.3.1
1111
github.com/omec-project/util v1.2.3
1212
github.com/prometheus/client_golang v1.20.5
@@ -61,7 +61,7 @@ require (
6161
golang.org/x/text v0.19.0 // indirect
6262
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
6363
google.golang.org/grpc v1.67.1 // indirect
64-
google.golang.org/protobuf v1.34.2 // indirect
64+
google.golang.org/protobuf v1.35.1 // indirect
6565
gopkg.in/h2non/gock.v1 v1.1.2 // indirect
6666
gopkg.in/yaml.v3 v3.0.1 // indirect
6767
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
7474
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
7575
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
7676
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
77-
github.com/omec-project/config5g v1.5.1 h1:JaVgr76tnjJIb7Uoesv5a9GI72NdOXtCvfukj0/ONio=
78-
github.com/omec-project/config5g v1.5.1/go.mod h1:o04ZdwGcM7tbGjuT5t/WzYSKLXOSnFl6vH7b6BGAspU=
77+
github.com/omec-project/config5g v1.5.4 h1:5JMw5Fsr5qyLZpQi3IZQaQPj78QJMFQXDVS3QDMOY9Y=
78+
github.com/omec-project/config5g v1.5.4/go.mod h1:HOvQtmi79f8cw35AiFHWHDoCTuZbXfMjeFJWgtPbwaI=
7979
github.com/omec-project/openapi v1.3.1 h1:NCteMRdMtWnMhf1CXYduuLgeu8fEhc/7XO1CiE7fN3Y=
8080
github.com/omec-project/openapi v1.3.1/go.mod h1:cR6Iharp2TLOzEmskQ/EdCVFZnpKh0zTvUSSuyXAYLE=
8181
github.com/omec-project/util v1.2.3 h1:h32ZYFT99+fB9VPp1CQUIKwrSP6RtX+PbFDcqmEHmn0=
@@ -141,8 +141,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:
141141
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
142142
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
143143
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
144-
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
145-
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
144+
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
145+
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
146146
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
147147
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
148148
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

service/init.go

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"syscall"
1818
"time"
1919

20-
"github.com/omec-project/config5g/proto/client"
20+
grpcClient "github.com/omec-project/config5g/proto/client"
2121
protos "github.com/omec-project/config5g/proto/sdcoreConfig"
2222
"github.com/omec-project/openapi/models"
2323
nrfCache "github.com/omec-project/openapi/nrfcache"
@@ -101,21 +101,71 @@ func (udm *UDM) Initialize(c *cli.Context) error {
101101
return err
102102
}
103103

104-
roc := os.Getenv("MANAGED_BY_CONFIG_POD")
105-
if roc == "true" {
104+
if os.Getenv("MANAGED_BY_CONFIG_POD") == "true" {
106105
logger.InitLog.Infoln("MANAGED_BY_CONFIG_POD is true")
107-
commChannel := client.ConfigWatcher(factory.UdmConfig.Configuration.WebuiUri)
108-
go udm.updateConfig(commChannel)
106+
go manageGrpcClient(factory.UdmConfig.Configuration.WebuiUri, udm)
109107
} else {
110108
go func() {
111-
logger.InitLog.Infoln("use helm chart config")
109+
logger.InitLog.Infoln("use helm chart config ")
112110
ConfigPodTrigger <- true
113111
}()
114112
}
115113

116114
return nil
117115
}
118116

117+
// manageGrpcClient connects the config pod GRPC server and subscribes the config changes.
118+
// Then it updates UDM configuration.
119+
func manageGrpcClient(webuiUri string, udm *UDM) {
120+
var configChannel chan *protos.NetworkSliceResponse
121+
var client grpcClient.ConfClient
122+
var stream protos.ConfigService_NetworkSliceSubscribeClient
123+
var err error
124+
count := 0
125+
for {
126+
if client != nil {
127+
if client.CheckGrpcConnectivity() != "ready" {
128+
time.Sleep(time.Second * 30)
129+
count++
130+
if count > 5 {
131+
err = client.GetConfigClientConn().Close()
132+
if err != nil {
133+
logger.InitLog.Infof("failing ConfigClient is not closed properly: %+v", err)
134+
}
135+
client = nil
136+
count = 0
137+
}
138+
logger.InitLog.Infoln("checking the connectivity readiness")
139+
continue
140+
}
141+
142+
if stream == nil {
143+
stream, err = client.SubscribeToConfigServer()
144+
if err != nil {
145+
logger.InitLog.Infof("failing SubscribeToConfigServer: %+v", err)
146+
continue
147+
}
148+
}
149+
150+
if configChannel == nil {
151+
configChannel = client.PublishOnConfigChange(true, stream)
152+
logger.InitLog.Infoln("PublishOnConfigChange is triggered")
153+
go udm.updateConfig(configChannel)
154+
logger.InitLog.Infoln("UDM updateConfig is triggered")
155+
}
156+
} else {
157+
client, err = grpcClient.ConnectToConfigServer(webuiUri)
158+
stream = nil
159+
configChannel = nil
160+
logger.InitLog.Infoln("connecting to config server")
161+
if err != nil {
162+
logger.InitLog.Errorf("%+v", err)
163+
}
164+
continue
165+
}
166+
}
167+
}
168+
119169
func (udm *UDM) setLogLevel() {
120170
if factory.UdmConfig.Logger == nil {
121171
logger.InitLog.Warnln("UDM config without log level setting")

0 commit comments

Comments
 (0)