VOL-3677 - move to v4 of protos and lib
Change-Id: Ie9d215f69b798dbf2b879d8e7d041c0d671f84c0
diff --git a/cmd/openonu-adapter/common.go b/cmd/openonu-adapter/common.go
index 7507288..9c871ef 100644
--- a/cmd/openonu-adapter/common.go
+++ b/cmd/openonu-adapter/common.go
@@ -18,15 +18,15 @@
package main
import (
- "github.com/opencord/voltha-lib-go/v3/pkg/log"
+ "github.com/opencord/voltha-lib-go/v4/pkg/log"
)
-var logger log.Logger
+var logger log.CLogger
func init() {
// Setup this package so that it's log level can be modified at run time
var err error
- logger, err = log.AddPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "main"})
+ logger, err = log.RegisterPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "main"})
// previously log.DebugLevel was set !?
if err != nil {
panic(err)
diff --git a/cmd/openonu-adapter/main.go b/cmd/openonu-adapter/main.go
index df7c327..e82c155 100644
--- a/cmd/openonu-adapter/main.go
+++ b/cmd/openonu-adapter/main.go
@@ -28,17 +28,17 @@
"syscall"
"time"
- "github.com/opencord/voltha-lib-go/v3/pkg/adapters"
- "github.com/opencord/voltha-lib-go/v3/pkg/adapters/adapterif"
- com "github.com/opencord/voltha-lib-go/v3/pkg/adapters/common"
- conf "github.com/opencord/voltha-lib-go/v3/pkg/config"
- "github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore"
- "github.com/opencord/voltha-lib-go/v3/pkg/kafka"
- "github.com/opencord/voltha-lib-go/v3/pkg/log"
- "github.com/opencord/voltha-lib-go/v3/pkg/probe"
- "github.com/opencord/voltha-lib-go/v3/pkg/version"
- ic "github.com/opencord/voltha-protos/v3/go/inter_container"
- "github.com/opencord/voltha-protos/v3/go/voltha"
+ "github.com/opencord/voltha-lib-go/v4/pkg/adapters"
+ "github.com/opencord/voltha-lib-go/v4/pkg/adapters/adapterif"
+ com "github.com/opencord/voltha-lib-go/v4/pkg/adapters/common"
+ conf "github.com/opencord/voltha-lib-go/v4/pkg/config"
+ "github.com/opencord/voltha-lib-go/v4/pkg/db/kvstore"
+ "github.com/opencord/voltha-lib-go/v4/pkg/kafka"
+ "github.com/opencord/voltha-lib-go/v4/pkg/log"
+ "github.com/opencord/voltha-lib-go/v4/pkg/probe"
+ "github.com/opencord/voltha-lib-go/v4/pkg/version"
+ ic "github.com/opencord/voltha-protos/v4/go/inter_container"
+ "github.com/opencord/voltha-protos/v4/go/voltha"
"github.com/opencord/voltha-openonu-adapter-go/internal/pkg/config"
ac "github.com/opencord/voltha-openonu-adapter-go/internal/pkg/onuadaptercore"
@@ -71,7 +71,7 @@
}
func (a *adapter) start(ctx context.Context) error {
- logger.Info("Starting Core Adapter components")
+ logger.Info(ctx, "Starting Core Adapter components")
var err error
var p *probe.Probe
@@ -79,6 +79,7 @@
if _, ok := value.(*probe.Probe); ok {
p = value.(*probe.Probe)
p.RegisterService(
+ ctx,
"message-bus",
"kv-store",
"container-proxy",
@@ -89,42 +90,42 @@
}
// Setup KV Client
- logger.Debugw("create-kv-client", log.Fields{"kvstore": a.config.KVStoreType})
- if err = a.setKVClient(); err != nil {
- logger.Fatalw("error-setting-kv-client", log.Fields{"error": err})
+ logger.Debugw(ctx, "create-kv-client", log.Fields{"kvstore": a.config.KVStoreType})
+ if err = a.setKVClient(ctx); err != nil {
+ logger.Fatalw(ctx, "error-setting-kv-client", log.Fields{"error": err})
}
if p != nil {
- p.UpdateStatus("kv-store", probe.ServiceStatusRunning)
+ p.UpdateStatus(ctx, "kv-store", probe.ServiceStatusRunning)
}
// Setup Log Config
/* address config update acc. to [VOL-2736] */
addr := a.config.KVStoreHost + ":" + strconv.Itoa(a.config.KVStorePort)
- cm := conf.NewConfigManager(a.kvClient, a.config.KVStoreType, addr, a.config.KVStoreTimeout)
+ cm := conf.NewConfigManager(ctx, a.kvClient, a.config.KVStoreType, addr, a.config.KVStoreTimeout)
go conf.StartLogLevelConfigProcessing(cm, ctx)
// Setup Kafka Client
- if a.kafkaClient, err = newKafkaClient("sarama", a.config.KafkaAdapterHost, a.config.KafkaAdapterPort); err != nil {
- logger.Fatalw("Unsupported-common-client", log.Fields{"error": err})
+ if a.kafkaClient, err = newKafkaClient(ctx, "sarama", a.config.KafkaAdapterHost, a.config.KafkaAdapterPort); err != nil {
+ logger.Fatalw(ctx, "Unsupported-common-client", log.Fields{"error": err})
}
if p != nil {
- p.UpdateStatus("message-bus", probe.ServiceStatusRunning)
+ p.UpdateStatus(ctx, "message-bus", probe.ServiceStatusRunning)
}
// Start the common InterContainer Proxy - retries as per program arguments or indefinitely per default
if a.kip, err = a.startInterContainerProxy(ctx, a.config.KafkaReconnectRetries); err != nil {
- logger.Fatalw("error-starting-inter-container-proxy", log.Fields{"error": err})
+ logger.Fatalw(ctx, "error-starting-inter-container-proxy", log.Fields{"error": err})
//aborting the complete processing here (does notmake sense after set Retry number [else use -1 for infinite])
return err
}
// Create the core proxy to handle requests to the Core
- a.coreProxy = com.NewCoreProxy(a.kip, a.config.Topic, a.config.CoreTopic)
+ a.coreProxy = com.NewCoreProxy(ctx, a.kip, a.config.Topic, a.config.CoreTopic)
- logger.Debugw("create adapter proxy", log.Fields{"OltTopic": a.config.OltTopic, "CoreTopic": a.config.CoreTopic})
- a.adapterProxy = com.NewAdapterProxy(a.kip, a.config.OltTopic, a.config.CoreTopic, cm.Backend)
+ logger.Debugw(ctx, "create adapter proxy", log.Fields{"OltTopic": a.config.OltTopic, "CoreTopic": a.config.CoreTopic})
+ a.adapterProxy = com.NewAdapterProxy(ctx, a.kip, a.config.CoreTopic, cm.Backend)
// Create the event proxy to post events to KAFKA
a.eventProxy = com.NewEventProxy(com.MsgClient(a.kafkaClient), com.MsgTopic(kafka.Topic{Name: a.config.EventTopic}))
@@ -132,17 +133,17 @@
// Create the open ONU interface adapter
if a.iAdapter, err = a.startVolthaInterfaceAdapter(ctx, a.kip, a.coreProxy, a.adapterProxy, a.eventProxy,
a.config, cm); err != nil {
- logger.Fatalw("error-starting-volthaInterfaceAdapter for OpenOnt", log.Fields{"error": err})
+ logger.Fatalw(ctx, "error-starting-volthaInterfaceAdapter for OpenOnt", log.Fields{"error": err})
}
// Register the core request handler
if err = a.setupRequestHandler(ctx, a.instanceID, a.iAdapter); err != nil {
- logger.Fatalw("error-setting-core-request-handler", log.Fields{"error": err})
+ logger.Fatalw(ctx, "error-setting-core-request-handler", log.Fields{"error": err})
}
// Register this adapter to the Core - retries indefinitely
if err = a.registerWithCore(ctx, -1); err != nil {
- logger.Fatalw("error-registering-with-core", log.Fields{"error": err})
+ logger.Fatalw(ctx, "error-registering-with-core", log.Fields{"error": err})
}
// check the readiness and liveliness and update the probe status
@@ -161,34 +162,34 @@
if a.kvClient != nil {
// Release all reservations
if err := a.kvClient.ReleaseAllReservations(ctx); err != nil {
- logger.Infow("fail-to-release-all-reservations", log.Fields{"error": err})
+ logger.Infow(ctx, "fail-to-release-all-reservations", log.Fields{"error": err})
}
// Close the DB connection
- a.kvClient.Close()
+ a.kvClient.Close(ctx)
}
if a.kip != nil {
- a.kip.Stop()
+ a.kip.Stop(ctx)
}
}
// #############################################
// Adapter Utility methods ##### begin #########
-func newKVClient(storeType, address string, timeout time.Duration) (kvstore.Client, error) {
- logger.Infow("kv-store-type", log.Fields{"store": storeType})
+func newKVClient(ctx context.Context, storeType, address string, timeout time.Duration) (kvstore.Client, error) {
+ logger.Infow(ctx, "kv-store-type", log.Fields{"store": storeType})
switch storeType {
case "consul":
- return kvstore.NewConsulClient(address, timeout)
+ return kvstore.NewConsulClient(ctx, address, timeout)
case "etcd":
- return kvstore.NewEtcdClient(address, timeout, log.FatalLevel)
+ return kvstore.NewEtcdClient(ctx, address, timeout, log.FatalLevel)
}
return nil, errors.New("unsupported-kv-store")
}
-func newKafkaClient(clientType, host string, port int) (kafka.Client, error) {
+func newKafkaClient(ctx context.Context, clientType, host string, port int) (kafka.Client, error) {
- logger.Infow("common-client-type", log.Fields{"client": clientType})
+ logger.Infow(ctx, "common-client-type", log.Fields{"client": clientType})
/* address config update acc. to [VOL-2736] */
addr := host + ":" + strconv.Itoa(port)
@@ -206,12 +207,12 @@
return nil, errors.New("unsupported-client-type")
}
-func (a *adapter) setKVClient() error {
+func (a *adapter) setKVClient(ctx context.Context) error {
addr := a.config.KVStoreHost + ":" + strconv.Itoa(a.config.KVStorePort)
- client, err := newKVClient(a.config.KVStoreType, addr, a.config.KVStoreTimeout)
+ client, err := newKVClient(ctx, a.config.KVStoreType, addr, a.config.KVStoreTimeout)
if err != nil {
a.kvClient = nil
- logger.Errorw("error-starting-KVClient", log.Fields{"error": err})
+ logger.Errorw(ctx, "error-starting-KVClient", log.Fields{"error": err})
return err
}
a.kvClient = client
@@ -219,7 +220,7 @@
}
func (a *adapter) startInterContainerProxy(ctx context.Context, retries int) (kafka.InterContainerProxy, error) {
- logger.Infow("starting-intercontainer-messaging-proxy", log.Fields{"host": a.config.KafkaAdapterHost,
+ logger.Infow(ctx, "starting-intercontainer-messaging-proxy", log.Fields{"host": a.config.KafkaAdapterHost,
"port": a.config.KafkaAdapterPort, "topic": a.config.Topic})
var err error
/* address config update acc. to [VOL-2736] */
@@ -230,8 +231,8 @@
kafka.DefaultTopic(&kafka.Topic{Name: a.config.Topic}))
count := 0
for {
- if err = kip.Start(); err != nil {
- logger.Warnw("error-starting-messaging-proxy", log.Fields{"error": err, "retry": retries, "count": count})
+ if err = kip.Start(ctx); err != nil {
+ logger.Warnw(ctx, "error-starting-messaging-proxy", log.Fields{"error": err, "retry": retries, "count": count})
if retries == count {
return nil, err
}
@@ -243,7 +244,7 @@
}
}
probe.UpdateStatusFromContext(ctx, "container-proxy", probe.ServiceStatusRunning)
- logger.Info("common-messaging-proxy-created")
+ logger.Info(ctx, "common-messaging-proxy-created")
return kip, nil
}
@@ -254,30 +255,30 @@
sAcONU := ac.NewOpenONUAC(ctx, a.kip, cp, ap, ep, a.kvClient, cfg, cm)
if err = sAcONU.Start(ctx); err != nil {
- logger.Fatalw("error-starting-OpenOnuAdapterCore", log.Fields{"error": err})
+ logger.Fatalw(ctx, "error-starting-OpenOnuAdapterCore", log.Fields{"error": err})
return nil, err
}
- logger.Info("open-ont-OpenOnuAdapterCore-started")
+ logger.Info(ctx, "open-ont-OpenOnuAdapterCore-started")
return sAcONU, nil
}
func (a *adapter) setupRequestHandler(ctx context.Context, coreInstanceID string, iadapter adapters.IAdapter) error {
- logger.Info("setting-request-handler")
+ logger.Info(ctx, "setting-request-handler")
requestProxy := com.NewRequestHandlerProxy(coreInstanceID, iadapter, a.coreProxy)
- if err := a.kip.SubscribeWithRequestHandlerInterface(kafka.Topic{Name: a.config.Topic}, requestProxy); err != nil {
- logger.Errorw("request-handler-setup-failed", log.Fields{"error": err})
+ if err := a.kip.SubscribeWithRequestHandlerInterface(ctx, kafka.Topic{Name: a.config.Topic}, requestProxy); err != nil {
+ logger.Errorw(ctx, "request-handler-setup-failed", log.Fields{"error": err})
return err
}
probe.UpdateStatusFromContext(ctx, "core-request-handler", probe.ServiceStatusRunning)
- logger.Info("request-handler-setup-done")
+ logger.Info(ctx, "request-handler-setup-done")
return nil
}
func (a *adapter) registerWithCore(ctx context.Context, retries int) error {
adapterID := fmt.Sprintf("brcm_openomci_onu_%d", a.config.CurrentReplica)
- logger.Infow("registering-with-core", log.Fields{
+ logger.Infow(ctx, "registering-with-core", log.Fields{
"adapterID": adapterID,
"currentReplica": a.config.CurrentReplica,
"totalReplicas": a.config.TotalReplicas,
@@ -302,7 +303,7 @@
count := 0
for {
if err := a.coreProxy.RegisterAdapter(context.TODO(), adapterDescription, deviceTypes); err != nil {
- logger.Warnw("registering-with-core-failed", log.Fields{"error": err})
+ logger.Warnw(ctx, "registering-with-core-failed", log.Fields{"error": err})
if retries == count {
return err
}
@@ -314,7 +315,7 @@
}
}
probe.UpdateStatusFromContext(ctx, "register-with-core", probe.ServiceStatusRunning)
- logger.Info("registered-with-core")
+ logger.Info(ctx, "registered-with-core")
return nil
}
@@ -360,7 +361,7 @@
}
case <-timeoutTimer.C:
// Check the status of the kv-store
- logger.Info("kv-store liveliness-recheck")
+ logger.Info(ctx, "kv-store liveliness-recheck")
if a.kvClient.IsConnectionUp(ctx) {
kvStoreChannel <- true
} else {
@@ -375,8 +376,8 @@
and update the status in the probe.
*/
func (a *adapter) checkKafkaReadiness(ctx context.Context) {
- livelinessChannel := a.kafkaClient.EnableLivenessChannel(true)
- healthinessChannel := a.kafkaClient.EnableHealthinessChannel(true)
+ livelinessChannel := a.kafkaClient.EnableLivenessChannel(ctx, true)
+ healthinessChannel := a.kafkaClient.EnableHealthinessChannel(ctx, true)
timeout := a.config.LiveProbeInterval
for {
timeoutTimer := time.NewTimer(timeout)
@@ -385,7 +386,7 @@
case healthiness := <-healthinessChannel:
if !healthiness {
// logger.Fatal will call os.Exit(1) to terminate
- logger.Fatal("Kafka service has become unhealthy")
+ logger.Fatal(ctx, "Kafka service has become unhealthy")
}
case liveliness := <-livelinessChannel:
if !liveliness {
@@ -402,13 +403,13 @@
<-timeoutTimer.C
}
case <-timeoutTimer.C:
- logger.Info("kafka-proxy-liveness-recheck")
+ logger.Info(ctx, "kafka-proxy-liveness-recheck")
// send the liveness probe in a goroutine; we don't want to deadlock ourselves as
// the liveness probe may wait (and block) writing to our channel.
- err := a.kafkaClient.SendLiveness()
+ err := a.kafkaClient.SendLiveness(ctx)
if err != nil {
// Catch possible error case if sending liveness after Sarama has been stopped.
- logger.Warnw("error-kafka-send-liveness", log.Fields{"error": err})
+ logger.Warnw(ctx, "error-kafka-send-liveness", log.Fields{"error": err})
}
}
}
@@ -417,13 +418,13 @@
// Adapter Utility methods ##### end #########
// #############################################
-func getVerifiedCodeVersion() string {
+func getVerifiedCodeVersion(ctx context.Context) string {
if version.VersionInfo.Version == "unknown-version" {
content, err := ioutil.ReadFile("VERSION")
if err == nil {
return (string(content))
}
- logger.Error("'VERSION'-file not readable")
+ logger.Error(ctx, "'VERSION'-file not readable")
}
return version.VersionInfo.Version
}
@@ -458,7 +459,7 @@
go func() {
select {
case <-ctx.Done():
- logger.Infow("Adapter run aborted due to internal errors", log.Fields{"context": "done"})
+ logger.Infow(ctx, "Adapter run aborted due to internal errors", log.Fields{"context": "done"})
exitChannel <- 2
case s := <-signalChannel:
switch s {
@@ -466,10 +467,10 @@
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT:
- logger.Infow("closing-signal-received", log.Fields{"signal": s})
+ logger.Infow(ctx, "closing-signal-received", log.Fields{"signal": s})
exitChannel <- 0
default:
- logger.Infow("unexpected-signal-received", log.Fields{"signal": s})
+ logger.Infow(ctx, "unexpected-signal-received", log.Fields{"signal": s})
exitChannel <- 1
}
}
@@ -481,31 +482,33 @@
func main() {
start := time.Now()
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
cf := config.NewAdapterFlags()
- defaultAppName := cf.InstanceID + "_" + getVerifiedCodeVersion()
+ defaultAppName := cf.InstanceID + "_" + getVerifiedCodeVersion(ctx)
cf.ParseCommandArguments()
// Setup logging
logLevel, err := log.StringToLogLevel(cf.LogLevel)
if err != nil {
- logger.Fatalf("Cannot setup logging, %s", err)
+ logger.Fatalf(ctx, "Cannot setup logging, %s", err)
}
// Setup default logger - applies for packages that do not have specific logger set
if _, err := log.SetDefaultLogger(log.JSON, logLevel, log.Fields{"instanceId": cf.InstanceID}); err != nil {
- log.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
+ logger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging")
}
// Update all loggers (provisioned via init) with a common field
if err := log.UpdateAllLoggers(log.Fields{"instanceId": cf.InstanceID}); err != nil {
- logger.With(log.Fields{"error": err}).Fatal("Cannot setup logging")
+ logger.With(log.Fields{"error": err}).Fatal(ctx, "Cannot setup logging")
}
log.SetAllLogLevel(logLevel)
- realMain() //fatal on httpListen(0,6060) ...
+ realMain(ctx) //fatal on httpListen(0,6060) ...
defer func() {
_ = log.CleanUp()
@@ -515,30 +518,34 @@
printVersion(defaultAppName)
return
}
- logger.Infow("config", log.Fields{"StartName": defaultAppName})
- logger.Infow("config", log.Fields{"BuildVersion": version.VersionInfo.String(" ")})
- logger.Infow("config", log.Fields{"Arguments": os.Args[1:]})
+ logger.Infow(ctx, "config", log.Fields{"StartName": defaultAppName})
+ logger.Infow(ctx, "config", log.Fields{"BuildVersion": version.VersionInfo.String(" ")})
+ logger.Infow(ctx, "config", log.Fields{"Arguments": os.Args[1:]})
// Print banner if specified
if cf.Banner {
printBanner()
}
- logger.Infow("config", log.Fields{"config": *cf})
-
- ctx, cancel := context.WithCancel(context.Background())
- defer cancel()
+ logger.Infow(ctx, "config", log.Fields{"config": *cf})
ad := newAdapter(cf)
p := &probe.Probe{}
- logger.Infow("resources", log.Fields{"Context": ctx, "Adapter": ad.instanceID, "ProbeCoreState": p.GetStatus("register-with-core")})
+ logger.Infow(ctx, "resources", log.Fields{"Context": ctx, "Adapter": ad.instanceID, "ProbeCoreState": p.GetStatus("register-with-core")})
- go p.ListenAndServe(fmt.Sprintf("%s:%d", ad.config.ProbeHost, ad.config.ProbePort))
- logger.Infow("probeState", log.Fields{"ProbeCoreState": p.GetStatus("register-with-core")})
+ go p.ListenAndServe(ctx, fmt.Sprintf("%s:%d", ad.config.ProbeHost, ad.config.ProbePort))
+ logger.Infow(ctx, "probeState", log.Fields{"ProbeCoreState": p.GetStatus("register-with-core")})
probeCtx := context.WithValue(ctx, probe.ProbeContextKey, p)
+ closer, err := log.GetGlobalLFM().InitTracingAndLogCorrelation(cf.TraceEnabled, cf.TraceAgentAddress, cf.LogCorrelationEnabled)
+ if err != nil {
+ logger.Warnw(ctx, "unable-to-initialize-tracing-and-log-correlation-module", log.Fields{"error": err})
+ } else {
+ defer log.TerminateTracing(closer)
+ }
+
go func() {
err := ad.start(probeCtx)
// If this operation returns an error
@@ -549,12 +556,12 @@
}()
code := waitForExit(ctx)
- logger.Infow("received-a-closing-signal", log.Fields{"code": code})
+ logger.Infow(ctx, "received-a-closing-signal", log.Fields{"code": code})
// Cleanup before leaving
ad.stop(ctx)
elapsed := time.Since(start)
- logger.Infow("run-time", log.Fields{"Name": "openadapter", "time": elapsed / time.Microsecond})
- //logger.Infow("run-time", log.Fields{"instanceId": ad.config.InstanceID, "time": elapsed / time.Second})
+ logger.Infow(ctx, "run-time", log.Fields{"Name": "openadapter", "time": elapsed / time.Microsecond})
+ //logger.Infow(ctx,"run-time", log.Fields{"instanceId": ad.config.InstanceID, "time": elapsed / time.Second})
}
diff --git a/cmd/openonu-adapter/release.go b/cmd/openonu-adapter/release.go
index a8fb220..50a286f 100644
--- a/cmd/openonu-adapter/release.go
+++ b/cmd/openonu-adapter/release.go
@@ -19,6 +19,8 @@
//Package main invokes the application
package main
-func realMain() {
- logger.Infoln("NOT PROFILING")
+import "context"
+
+func realMain(ctx context.Context) {
+ logger.Infoln(ctx, "NOT PROFILING")
}