Merge "[VOL-2738]Enable configuration of etcd v3 client options"
diff --git a/go.mod b/go.mod
index b506a7b..2adfb0f 100644
--- a/go.mod
+++ b/go.mod
@@ -10,7 +10,7 @@
github.com/imdario/mergo v0.3.7 // indirect
github.com/jessevdk/go-flags v1.4.0
github.com/jhump/protoreflect v1.5.0
- github.com/opencord/voltha-lib-go/v3 v3.0.23
+ github.com/opencord/voltha-lib-go/v3 v3.1.5
github.com/stretchr/testify v1.4.0
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 // indirect
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
diff --git a/go.sum b/go.sum
index 3d54b91..ce3c635 100644
--- a/go.sum
+++ b/go.sum
@@ -5,6 +5,7 @@
github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
+github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/Shopify/sarama v1.23.1/go.mod h1:XLH1GYJnLVE0XCr6KdJGVJRTwY30moWNJ4sERjXX6fs=
github.com/Shopify/sarama v1.25.0 h1:ch1ywjRLjfJtU+EaiJ+l0rWffQ6TRpyYmW4DX7Cb2SU=
github.com/Shopify/sarama v1.25.0/go.mod h1:y/CFFTO9eaMTNriwu/Q+W4eioLqiDMGkA1W+gmdfj8w=
@@ -24,6 +25,8 @@
github.com/boljen/go-bitmap v0.0.0-20151001105940-23cd2fb0ce7d/go.mod h1:f1iKL6ZhUWvbk7PdWVmOaak10o86cqMUYEmn1CZNGEI=
github.com/bsm/sarama-cluster v2.1.15+incompatible h1:RkV6WiNRnqEEbp81druK8zYhmnIgdOjqSVi0+9Cnl2A=
github.com/bsm/sarama-cluster v2.1.15+incompatible/go.mod h1:r7ao+4tTNXvWm+VRpRJchr2kQhqxgmAp2iEX5W96gMM=
+github.com/buraksezer/consistent v0.0.0-20191006190839-693edf70fd72/go.mod h1:OEE5igu/CDjGegM1Jn6ZMo7R6LlV/JChAkjfQQIRLpg=
+github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cevaris/ordered_map v0.0.0-20190319150403-3adeae072e73/go.mod h1:507vXsotcZop7NZfBWdhPmVeOse4ko2R7AagJYrpoEg=
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
@@ -226,10 +229,9 @@
github.com/onsi/gomega v0.0.0-20190113212917-5533ce8a0da3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.4.2 h1:3mYCb7aPxS/RU7TI1y4rkEn1oKmPRjNJLNEXgw7MH2I=
github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
-github.com/opencord/voltha-lib-go/v3 v3.0.23 h1:QJkosPdVm85AaLzVEk4umzcL7p2MmwukU9f83rZTIOU=
-github.com/opencord/voltha-lib-go/v3 v3.0.23/go.mod h1:QuAohPQ+InSw+8XgCFxnp4cpHWcxO2efVTtiBFUmuOY=
-github.com/opencord/voltha-protos/v3 v3.2.3 h1:Wv73mw1Ye0bCfyhOk5svgrlE2tLizHq6tQluoDq9Vg8=
-github.com/opencord/voltha-protos/v3 v3.2.3/go.mod h1:RIGHt7b80BHpHh3ceodknh0DxUjUHCWSbYbZqRx7Og0=
+github.com/opencord/voltha-lib-go/v3 v3.1.5 h1:Hci6ODHha76i+8jePcfV+W6moCakNA7sFsPSOG7EyIk=
+github.com/opencord/voltha-lib-go/v3 v3.1.5/go.mod h1:ad7C/5/09RcYvGQrxUH4AuOiO8OSQqGmCgEJNEpaag8=
+github.com/opencord/voltha-protos/v3 v3.3.0/go.mod h1:nl1ETp5Iw3avxOaKD8BJlYY5wYI4KeV95aT1pL63nto=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
@@ -274,6 +276,7 @@
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/soheilhy/cmux v0.1.4 h1:0HKaf1o97UwFjHH9o5XsHUOF+tqmdA7KEzXLpiyaw0E=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
+github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
diff --git a/internal/pkg/commands/loglevel.go b/internal/pkg/commands/loglevel.go
index acdc115..30e0cae 100644
--- a/internal/pkg/commands/loglevel.go
+++ b/internal/pkg/commands/loglevel.go
@@ -25,8 +25,6 @@
"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/log"
- "io/ioutil"
- "os"
"strings"
)
@@ -137,33 +135,7 @@
)
ProcessGlobalOptions()
- /*
- * TODO: VOL-2738
- * EVIL HACK ALERT
- * ===============
- * It would be nice if we could squelch all but fatal log messages from
- * the underlying libraries because as a CLI client we don't want a
- * bunch of logs and stack traces output and instead want to deal with
- * simple error propagation. To work around this, voltha-lib-go logging
- * is set to fatal and we redirect etcd client logging to a temp file.
- *
- * Replacing os.Stderr is used here as opposed to Dup2 because we want
- * low level panic to be displayed if they occurr. A temp file is used
- * as opposed to /dev/null because it can't be assumed that /dev/null
- * exists on all platforms and thus a temp file seems more portable.
- */
log.SetAllLogLevel(log.FatalLevel)
- saveStderr := os.Stderr
- if tmpStderr, err := ioutil.TempFile("", ""); err == nil {
- os.Stderr = tmpStderr
- defer func() {
- os.Stderr = saveStderr
- // Ignore errors on clean up because we can't do
- // anything anyway.
- _ = tmpStderr.Close()
- _ = os.Remove(tmpStderr.Name())
- }()
- }
if options.Args.Level != "" {
if _, err := log.StringToLogLevel(options.Args.Level); err != nil {
@@ -176,7 +148,7 @@
return fmt.Errorf(err.Error())
}
- client, err := kvstore.NewEtcdClient(GlobalConfig.KvStore, int(GlobalConfig.KvStoreConfig.Timeout.Seconds()))
+ client, err := kvstore.NewEtcdClient(GlobalConfig.KvStore, int(GlobalConfig.KvStoreConfig.Timeout.Seconds()), log.FatalLevel)
if err != nil {
return fmt.Errorf("Unable to create kvstore client %s", err)
}
@@ -235,35 +207,9 @@
)
ProcessGlobalOptions()
- /*
- * TODO: VOL-2738
- * EVIL HACK ALERT
- * ===============
- * It would be nice if we could squelch all but fatal log messages from
- * the underlying libraries because as a CLI client we don't want a
- * bunch of logs and stack traces output and instead want to deal with
- * simple error propagation. To work around this, voltha-lib-go logging
- * is set to fatal and we redirect etcd client logging to a temp file.
- *
- * Replacing os.Stderr is used here as opposed to Dup2 because we want
- * low level panic to be displayed if they occurr. A temp file is used
- * as opposed to /dev/null because it can't be assumed that /dev/null
- * exists on all platforms and thus a temp file seems more portable.
- */
log.SetAllLogLevel(log.FatalLevel)
- saveStderr := os.Stderr
- if tmpStderr, err := ioutil.TempFile("", ""); err == nil {
- os.Stderr = tmpStderr
- defer func() {
- os.Stderr = saveStderr
- // Ignore errors on clean up because we can't do
- // anything anyway.
- _ = tmpStderr.Close()
- _ = os.Remove(tmpStderr.Name())
- }()
- }
- client, err := kvstore.NewEtcdClient(GlobalConfig.KvStore, int(GlobalConfig.KvStoreConfig.Timeout.Seconds()))
+ client, err := kvstore.NewEtcdClient(GlobalConfig.KvStore, int(GlobalConfig.KvStoreConfig.Timeout.Seconds()), log.FatalLevel)
if err != nil {
return fmt.Errorf("Unable to create kvstore client %s", err)
}
@@ -339,40 +285,14 @@
)
ProcessGlobalOptions()
- /*
- * TODO: VOL-2738
- * EVIL HACK ALERT
- * ===============
- * It would be nice if we could squelch all but fatal log messages from
- * the underlying libraries because as a CLI client we don't want a
- * bunch of logs and stack traces output and instead want to deal with
- * simple error propagation. To work around this, voltha-lib-go logging
- * is set to fatal and we redirect etcd client logging to a temp file.
- *
- * Replacing os.Stderr is used here as opposed to Dup2 because we want
- * low level panic to be displayed if they occurr. A temp file is used
- * as opposed to /dev/null because it can't be assumed that /dev/null
- * exists on all platforms and thus a temp file seems more portable.
- */
log.SetAllLogLevel(log.FatalLevel)
- saveStderr := os.Stderr
- if tmpStderr, err := ioutil.TempFile("", ""); err == nil {
- os.Stderr = tmpStderr
- defer func() {
- os.Stderr = saveStderr
- // Ignore errors on clean up because we can't do
- // anything anyway.
- _ = tmpStderr.Close()
- _ = os.Remove(tmpStderr.Name())
- }()
- }
logLevelConfig, err = processComponentListArgs(options.Args.Component)
if err != nil {
return fmt.Errorf("%s", err)
}
- client, err := kvstore.NewEtcdClient(GlobalConfig.KvStore, int(GlobalConfig.KvStoreConfig.Timeout.Seconds()))
+ client, err := kvstore.NewEtcdClient(GlobalConfig.KvStore, int(GlobalConfig.KvStoreConfig.Timeout.Seconds()), log.FatalLevel)
if err != nil {
return fmt.Errorf("Unable to create kvstore client %s", err)
}
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/common.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/common.go
new file mode 100644
index 0000000..37e05fd
--- /dev/null
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/common.go
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2020-present Open Networking Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package config
+
+import (
+ "github.com/opencord/voltha-lib-go/v3/pkg/log"
+)
+
+var logger log.Logger
+
+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": "config"})
+ if err != nil {
+ panic(err)
+ }
+}
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/configmanager.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/configmanager.go
index 441c488..0dafc7a 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/configmanager.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/configmanager.go
@@ -24,13 +24,6 @@
"strings"
)
-func init() {
- _, err := log.AddPackage(log.JSON, log.FatalLevel, nil)
- if err != nil {
- log.Errorw("unable-to-register-package-to-the-log-map", log.Fields{"error": err})
- }
-}
-
const (
defaultkvStoreConfigPath = "config"
kvStoreDataPathPrefix = "service/voltha"
@@ -43,11 +36,12 @@
const (
ConfigTypeLogLevel ConfigType = iota
+ ConfigTypeMetadata
ConfigTypeKafka
)
func (c ConfigType) String() string {
- return [...]string{"loglevel", "kafka"}[c]
+ return [...]string{"loglevel", "metadata", "kafka"}[c]
}
// ChangeEvent represents the event recieved from watch
@@ -70,10 +64,10 @@
ConfigAttribute string
}
-// ConfigManager is a wrapper over backend to maintain Configuration of voltha components
+// ConfigManager is a wrapper over Backend to maintain Configuration of voltha components
// in kvstore based persistent storage
type ConfigManager struct {
- backend *db.Backend
+ Backend *db.Backend
KvStoreConfigPrefix string
}
@@ -102,7 +96,7 @@
return &ConfigManager{
KvStoreConfigPrefix: defaultkvStoreConfigPath,
- backend: &db.Backend{
+ Backend: &db.Backend{
Client: kvClient,
StoreType: kvStoreType,
Host: kvStoreHost,
@@ -115,12 +109,12 @@
// RetrieveComponentList list the component Names for which loglevel is stored in kvstore
func (c *ConfigManager) RetrieveComponentList(ctx context.Context, configType ConfigType) ([]string, error) {
- data, err := c.backend.List(ctx, c.KvStoreConfigPrefix)
+ data, err := c.Backend.List(ctx, c.KvStoreConfigPrefix)
if err != nil {
return nil, err
}
- // Looping through the data recieved from the backend for config
+ // Looping through the data recieved from the Backend for config
// Trimming and Splitting the required key and value from data and storing as componentName,PackageName and Level
// For Example, recieved key would be <Backend Prefix Path>/<Config Prefix>/<Component Name>/<Config Type>/default and value \"DEBUG\"
// Then in default will be stored as PackageName,componentName as <Component Name> and DEBUG will be stored as value in List struct
@@ -171,31 +165,31 @@
func (c *ComponentConfig) MonitorForConfigChange(ctx context.Context) chan *ConfigChangeEvent {
key := c.makeConfigPath()
- log.Debugw("monitoring-for-config-change", log.Fields{"key": key})
+ logger.Debugw("monitoring-for-config-change", log.Fields{"key": key})
c.changeEventChan = make(chan *ConfigChangeEvent, 1)
- c.kvStoreEventChan = c.cManager.backend.CreateWatch(ctx, key, true)
+ c.kvStoreEventChan = c.cManager.Backend.CreateWatch(ctx, key, true)
go c.processKVStoreWatchEvents()
return c.changeEventChan
}
-// processKVStoreWatchEvents process event channel recieved from the backend for any ChangeType
+// processKVStoreWatchEvents process event channel recieved from the Backend for any ChangeType
// It checks for the EventType is valid or not.For the valid EventTypes creates ConfigChangeEvent and send it on channel
func (c *ComponentConfig) processKVStoreWatchEvents() {
ccKeyPrefix := c.makeConfigPath()
- log.Debugw("processing-kvstore-event-change", log.Fields{"key-prefix": ccKeyPrefix})
+ logger.Debugw("processing-kvstore-event-change", log.Fields{"key-prefix": ccKeyPrefix})
- ccPathPrefix := c.cManager.backend.PathPrefix + ccKeyPrefix + kvStorePathSeparator
+ ccPathPrefix := c.cManager.Backend.PathPrefix + ccKeyPrefix + kvStorePathSeparator
for watchResp := range c.kvStoreEventChan {
if watchResp.EventType == kvstore.CONNECTIONDOWN || watchResp.EventType == kvstore.UNKNOWN {
- log.Warnw("received-invalid-change-type-in-watch-channel-from-kvstore", log.Fields{"change-type": watchResp.EventType})
+ logger.Warnw("received-invalid-change-type-in-watch-channel-from-kvstore", log.Fields{"change-type": watchResp.EventType})
continue
}
@@ -215,9 +209,9 @@
func (c *ComponentConfig) Retrieve(ctx context.Context, configKey string) (string, error) {
key := c.makeConfigPath() + "/" + configKey
- log.Debugw("retrieving-config", log.Fields{"key": key})
+ logger.Debugw("retrieving-config", log.Fields{"key": key})
- if kvpair, err := c.cManager.backend.Get(ctx, key); err != nil {
+ if kvpair, err := c.cManager.Backend.Get(ctx, key); err != nil {
return "", err
} else {
if kvpair == nil {
@@ -225,7 +219,7 @@
}
value := strings.Trim(fmt.Sprintf("%s", kvpair.Value), "\"")
- log.Debugw("retrieved-config", log.Fields{"key": key, "value": value})
+ logger.Debugw("retrieved-config", log.Fields{"key": key, "value": value})
return value, nil
}
}
@@ -233,19 +227,19 @@
func (c *ComponentConfig) RetrieveAll(ctx context.Context) (map[string]string, error) {
key := c.makeConfigPath()
- log.Debugw("retreiving-list", log.Fields{"key": key})
+ logger.Debugw("retreiving-list", log.Fields{"key": key})
- data, err := c.cManager.backend.List(ctx, key)
+ data, err := c.cManager.Backend.List(ctx, key)
if err != nil {
return nil, err
}
- // Looping through the data recieved from the backend for the given key
+ // Looping through the data recieved from the Backend for the given key
// Trimming the required key and value from data and storing as key/value pair
// For Example, recieved key would be <Backend Prefix Path>/<Config Prefix>/<Component Name>/<Config Type>/default and value \"DEBUG\"
// Then in default will be stored as key and DEBUG will be stored as value in map[string]string
res := make(map[string]string)
- ccPathPrefix := c.cManager.backend.PathPrefix + kvStorePathSeparator + key + kvStorePathSeparator
+ ccPathPrefix := c.cManager.Backend.PathPrefix + kvStorePathSeparator + key + kvStorePathSeparator
for attr, val := range data {
res[strings.TrimPrefix(attr, ccPathPrefix)] = strings.Trim(fmt.Sprintf("%s", val.Value), "\"")
}
@@ -256,10 +250,10 @@
func (c *ComponentConfig) Save(ctx context.Context, configKey string, configValue string) error {
key := c.makeConfigPath() + "/" + configKey
- log.Debugw("saving-config", log.Fields{"key": key, "value": configValue})
+ logger.Debugw("saving-config", log.Fields{"key": key, "value": configValue})
//save the data for update config
- if err := c.cManager.backend.Put(ctx, key, configValue); err != nil {
+ if err := c.cManager.Backend.Put(ctx, key, configValue); err != nil {
return err
}
return nil
@@ -269,9 +263,9 @@
//construct key using makeConfigPath
key := c.makeConfigPath() + "/" + configKey
- log.Debugw("deleting-config", log.Fields{"key": key})
+ logger.Debugw("deleting-config", log.Fields{"key": key})
//delete the config
- if err := c.cManager.backend.Delete(ctx, key); err != nil {
+ if err := c.cManager.Backend.Delete(ctx, key); err != nil {
return err
}
return nil
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/logcontroller.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/logcontroller.go
index 65927e6..b00569f 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/logcontroller.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/config/logcontroller.go
@@ -15,7 +15,7 @@
*/
// Package Config provides dynamic logging configuration for specific Voltha component with loglevel lookup
-// from etcd kvstore implemented using backend.
+// from etcd kvstore implemented using Backend.
// Any Voltha component can start utilizing dynamic logging by starting goroutine of StartLogLevelConfigProcessing after
// starting kvClient for the component.
@@ -28,13 +28,15 @@
"errors"
"github.com/opencord/voltha-lib-go/v3/pkg/log"
"os"
+ "sort"
"strings"
)
const (
- defaultLogLevelKey = "default" // kvstore key containing default loglevel
- globalConfigRootNode = "global" // Root Node in kvstore containing global config
- initialGlobalDefaultLogLevelValue = "WARN" // Hard-coded Global Default loglevel pushed at PoD startup
+ defaultLogLevelKey = "default" // kvstore key containing default loglevel
+ globalConfigRootNode = "global" // Root Node in kvstore containing global config
+ initialGlobalDefaultLogLevelValue = "WARN" // Hard-coded Global Default loglevel pushed at PoD startup
+ logPackagesListKey = "log_package_list" // kvstore key containing list of allowed log packages
)
// ComponentLogController represents a Configuration for Logging Config of specific Voltha component type
@@ -51,7 +53,7 @@
func NewComponentLogController(cm *ConfigManager) (*ComponentLogController, error) {
- log.Debug("creating-new-component-log-controller")
+ logger.Debug("creating-new-component-log-controller")
componentName := os.Getenv("COMPONENT_NAME")
if componentName == "" {
return nil, errors.New("Unable to retrieve PoD Component Name from Runtime env")
@@ -80,18 +82,20 @@
func StartLogLevelConfigProcessing(cm *ConfigManager, ctx context.Context) {
cc, err := NewComponentLogController(cm)
if err != nil {
- log.Errorw("unable-to-construct-component-log-controller-instance-for-log-config-monitoring", log.Fields{"error": err})
+ logger.Errorw("unable-to-construct-component-log-controller-instance-for-log-config-monitoring", log.Fields{"error": err})
return
}
cc.GlobalConfig = cm.InitComponentConfig(globalConfigRootNode, ConfigTypeLogLevel)
- log.Debugw("global-log-config", log.Fields{"cc-global-config": cc.GlobalConfig})
+ logger.Debugw("global-log-config", log.Fields{"cc-global-config": cc.GlobalConfig})
cc.componentNameConfig = cm.InitComponentConfig(cc.ComponentName, ConfigTypeLogLevel)
- log.Debugw("component-log-config", log.Fields{"cc-component-name-config": cc.componentNameConfig})
+ logger.Debugw("component-log-config", log.Fields{"cc-component-name-config": cc.componentNameConfig})
cc.persistInitialDefaultLogConfigs(ctx)
+ cc.persistRegisteredLogPackageList(ctx)
+
cc.processLogConfig(ctx)
}
@@ -101,38 +105,60 @@
_, err := c.GlobalConfig.Retrieve(ctx, defaultLogLevelKey)
if err != nil {
- log.Debugw("failed-to-retrieve-global-default-log-config-at-startup", log.Fields{"error": err})
+ logger.Debugw("failed-to-retrieve-global-default-log-config-at-startup", log.Fields{"error": err})
err = c.GlobalConfig.Save(ctx, defaultLogLevelKey, initialGlobalDefaultLogLevelValue)
if err != nil {
- log.Errorw("failed-to-persist-global-default-log-config-at-startup", log.Fields{"error": err, "loglevel": initialGlobalDefaultLogLevelValue})
+ logger.Errorw("failed-to-persist-global-default-log-config-at-startup", log.Fields{"error": err, "loglevel": initialGlobalDefaultLogLevelValue})
}
}
_, err = c.componentNameConfig.Retrieve(ctx, defaultLogLevelKey)
if err != nil {
- log.Debugw("failed-to-retrieve-component-default-log-config-at-startup", log.Fields{"error": err})
+ logger.Debugw("failed-to-retrieve-component-default-log-config-at-startup", log.Fields{"error": err})
err = c.componentNameConfig.Save(ctx, defaultLogLevelKey, c.initialLogLevel)
if err != nil {
- log.Errorw("failed-to-persist-component-default-log-config-at-startup", log.Fields{"error": err, "loglevel": c.initialLogLevel})
+ logger.Errorw("failed-to-persist-component-default-log-config-at-startup", log.Fields{"error": err, "loglevel": c.initialLogLevel})
}
}
}
+// Method to save list of all registered packages for component into config kvstore. A single string
+// is constructed with comma-separated package names in sorted order and persisted
+func (c *ComponentLogController) persistRegisteredLogPackageList(ctx context.Context) {
+
+ componentMetadataConfig := c.configManager.InitComponentConfig(c.ComponentName, ConfigTypeMetadata)
+ logger.Debugw("component-metadata-config", log.Fields{"component-metadata-config": componentMetadataConfig})
+
+ packageList := log.GetPackageNames()
+ packageList = append(packageList, defaultLogLevelKey)
+ sort.Strings(packageList)
+
+ packageNames, err := json.Marshal(packageList)
+ if err != nil {
+ logger.Errorw("failed-to-marshal-log-package-list-for-storage", log.Fields{"error": err, "packageList": packageList})
+ return
+ }
+
+ if err := componentMetadataConfig.Save(ctx, logPackagesListKey, string(packageNames)); err != nil {
+ logger.Errorw("failed-to-persist-component-registered-log-package-list-at-startup", log.Fields{"error": err, "packageNames": packageNames})
+ }
+}
+
// ProcessLogConfig will first load and apply log config and then start waiting on component config and global config
-// channels for any changes. Event channel will be recieved from backend for valid change type
-// Then data for componentn log config and global log config will be retrieved from backend and stored in updatedLogConfig in precedence order
+// channels for any changes. Event channel will be recieved from Backend for valid change type
+// Then data for componentn log config and global log config will be retrieved from Backend and stored in updatedLogConfig in precedence order
// If any changes in updatedLogConfig will be applied on component
func (c *ComponentLogController) processLogConfig(ctx context.Context) {
// Load and apply Log Config for first time
initialLogConfig, err := c.buildUpdatedLogConfig(ctx)
if err != nil {
- log.Warnw("unable-to-load-log-config-at-startup", log.Fields{"error": err})
+ logger.Warnw("unable-to-load-log-config-at-startup", log.Fields{"error": err})
} else {
if err := c.loadAndApplyLogConfig(initialLogConfig); err != nil {
- log.Warnw("unable-to-apply-log-config-at-startup", log.Fields{"error": err})
+ logger.Warnw("unable-to-apply-log-config-at-startup", log.Fields{"error": err})
}
}
@@ -148,18 +174,18 @@
case configEvent = <-componentConfigEventChan:
}
- log.Debugw("processing-log-config-change", log.Fields{"ChangeType": configEvent.ChangeType, "Package": configEvent.ConfigAttribute})
+ logger.Debugw("processing-log-config-change", log.Fields{"ChangeType": configEvent.ChangeType, "Package": configEvent.ConfigAttribute})
updatedLogConfig, err := c.buildUpdatedLogConfig(ctx)
if err != nil {
- log.Warnw("unable-to-fetch-updated-log-config", log.Fields{"error": err})
+ logger.Warnw("unable-to-fetch-updated-log-config", log.Fields{"error": err})
continue
}
- log.Debugw("applying-updated-log-config", log.Fields{"updated-log-config": updatedLogConfig})
+ logger.Debugw("applying-updated-log-config", log.Fields{"updated-log-config": updatedLogConfig})
if err := c.loadAndApplyLogConfig(updatedLogConfig); err != nil {
- log.Warnw("unable-to-load-and-apply-log-config", log.Fields{"error": err})
+ logger.Warnw("unable-to-load-and-apply-log-config", log.Fields{"error": err})
}
}
@@ -178,7 +204,7 @@
for _, packageName := range log.GetPackageNames() {
level, err := log.GetPackageLogLevel(packageName)
if err != nil {
- log.Warnw("unable-to-fetch-current-active-loglevel-for-package-name", log.Fields{"package-name": packageName, "error": err})
+ logger.Warnw("unable-to-fetch-current-active-loglevel-for-package-name", log.Fields{"package-name": packageName, "error": err})
continue
}
@@ -187,7 +213,7 @@
}
}
- log.Debugw("retreived-log-levels-from-zap-logger", log.Fields{"loglevels": loglevels})
+ logger.Debugw("retreived-log-levels-from-zap-logger", log.Fields{"loglevels": loglevels})
return loglevels
}
@@ -202,16 +228,16 @@
// Handle edge cases when global default loglevel is deleted directly from etcd or set to a invalid value
// We should use hard-coded initial default value in such cases
if globalDefaultLogLevel == "" {
- log.Warn("global-default-loglevel-not-found-in-config-store")
+ logger.Warn("global-default-loglevel-not-found-in-config-store")
globalDefaultLogLevel = initialGlobalDefaultLogLevelValue
}
if _, err := log.StringToLogLevel(globalDefaultLogLevel); err != nil {
- log.Warnw("unsupported-loglevel-config-defined-at-global-default", log.Fields{"log-level": globalDefaultLogLevel})
+ logger.Warnw("unsupported-loglevel-config-defined-at-global-default", log.Fields{"log-level": globalDefaultLogLevel})
globalDefaultLogLevel = initialGlobalDefaultLogLevelValue
}
- log.Debugw("retrieved-global-default-loglevel", log.Fields{"level": globalDefaultLogLevel})
+ logger.Debugw("retrieved-global-default-loglevel", log.Fields{"level": globalDefaultLogLevel})
return globalDefaultLogLevel, nil
}
@@ -225,7 +251,7 @@
effectiveDefaultLogLevel := ""
for logConfigKey, logConfigValue := range componentLogConfig {
if _, err := log.StringToLogLevel(logConfigValue); err != nil || logConfigKey == "" {
- log.Warnw("unsupported-loglevel-config-defined-at-component-context", log.Fields{"package-name": logConfigKey, "log-level": logConfigValue})
+ logger.Warnw("unsupported-loglevel-config-defined-at-component-context", log.Fields{"package-name": logConfigKey, "log-level": logConfigValue})
delete(componentLogConfig, logConfigKey)
} else {
if logConfigKey == defaultLogLevelKey {
@@ -242,12 +268,12 @@
componentLogConfig[defaultLogLevelKey] = effectiveDefaultLogLevel
- log.Debugw("retrieved-component-log-config", log.Fields{"component-log-level": componentLogConfig})
+ logger.Debugw("retrieved-component-log-config", log.Fields{"component-log-level": componentLogConfig})
return componentLogConfig, nil
}
-// buildUpdatedLogConfig retrieve the global logConfig and component logConfig from backend
+// buildUpdatedLogConfig retrieve the global logConfig and component logConfig from Backend
// component logConfig stores the log config with precedence order
// For example, If the global logConfig is set and component logConfig is set only for specific package then
// component logConfig is stored with global logConfig and component logConfig of specific package
@@ -256,7 +282,7 @@
func (c *ComponentLogController) buildUpdatedLogConfig(ctx context.Context) (map[string]string, error) {
globalLogLevel, err := c.getGlobalLogConfig(ctx)
if err != nil {
- log.Errorw("unable-to-retrieve-global-log-config", log.Fields{"err": err})
+ logger.Errorw("unable-to-retrieve-global-log-config", log.Fields{"err": err})
}
componentLogConfig, err := c.getComponentLogConfig(ctx, globalLogLevel)
@@ -286,7 +312,7 @@
UpdateLogLevels(logConfig)
c.logHash = currentLogHash
} else {
- log.Debug("effective-loglevel-config-same-as-currently-active")
+ logger.Debug("effective-loglevel-config-same-as-currently-active")
}
return nil
@@ -313,7 +339,7 @@
// Log warnings for all invalid packages for which log config has been set
for key, value := range updatedLogLevels {
if _, exist := activeLogLevels[key]; !exist {
- log.Warnw("ignoring-loglevel-set-for-invalid-package", log.Fields{"package": key, "log-level": value})
+ logger.Warnw("ignoring-loglevel-set-for-invalid-package", log.Fields{"package": key, "log-level": value})
}
}
@@ -330,11 +356,11 @@
// If no changed log levels are found, just return. It may happen on configuration of a invalid package
if len(changedLogLevels) == 0 {
- log.Debug("no-change-in-effective-loglevel-config")
+ logger.Debug("no-change-in-effective-loglevel-config")
return
}
- log.Debugw("applying-log-level-for-modified-packages", log.Fields{"changed-log-levels": changedLogLevels})
+ logger.Debugw("applying-log-level-for-modified-packages", log.Fields{"changed-log-levels": changedLogLevels})
for key, level := range changedLogLevels {
if key == defaultLogLevelKey {
if l, err := log.StringToLogLevel(level); err == nil {
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go
index faa86ed..55fda64 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/backend.go
@@ -82,7 +82,7 @@
case "consul":
return kvstore.NewConsulClient(address, timeout)
case "etcd":
- return kvstore.NewEtcdClient(address, timeout)
+ return kvstore.NewEtcdClient(address, timeout, log.WarnLevel)
}
return nil, errors.New("unsupported-kv-store")
}
@@ -222,7 +222,7 @@
defer b.Unlock()
formattedPath := b.makePath(key)
- logger.Debugw("putting-key", log.Fields{"key": key, "value": value, "path": formattedPath})
+ logger.Debugw("putting-key", log.Fields{"key": key, "path": formattedPath})
err := b.Client.Put(ctx, formattedPath, value)
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/common.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/common.go
index a5a79ae..1cf2e1c 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/common.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/common.go
@@ -19,16 +19,12 @@
"github.com/opencord/voltha-lib-go/v3/pkg/log"
)
-const (
- logLevel = log.ErrorLevel
-)
-
var logger log.Logger
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, logLevel, log.Fields{"pkg": "db"})
+ logger, err = log.AddPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "db"})
if err != nil {
panic(err)
}
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/common.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/common.go
index 2d2a6a6..aa7aeb0 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/common.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/common.go
@@ -19,16 +19,12 @@
"github.com/opencord/voltha-lib-go/v3/pkg/log"
)
-const (
- logLevel = log.ErrorLevel
-)
-
var logger log.Logger
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, logLevel, log.Fields{"pkg": "kvstore"})
+ logger, err = log.AddPackage(log.JSON, log.ErrorLevel, log.Fields{"pkg": "kvstore"})
if err != nil {
panic(err)
}
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go
index d38f0f6..90158bc 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore/etcdclient.go
@@ -39,12 +39,14 @@
}
// NewEtcdClient returns a new client for the Etcd KV store
-func NewEtcdClient(addr string, timeout int) (*EtcdClient, error) {
+func NewEtcdClient(addr string, timeout int, level log.LogLevel) (*EtcdClient, error) {
duration := GetDuration(timeout)
+ logconfig := log.ConstructZapConfig(log.JSON, level, log.Fields{})
c, err := v3Client.New(v3Client.Config{
Endpoints: []string{addr},
DialTimeout: duration,
+ LogConfig: &logconfig,
})
if err != nil {
logger.Error(err)
diff --git a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/log/log.go b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/log/log.go
index 47fa3fb..6b7087f 100644
--- a/vendor/github.com/opencord/voltha-lib-go/v3/pkg/log/log.go
+++ b/vendor/github.com/opencord/voltha-lib-go/v3/pkg/log/log.go
@@ -232,6 +232,10 @@
}
}
+func ConstructZapConfig(outputType string, level LogLevel, fields Fields) zp.Config {
+ return getDefaultConfig(outputType, level, fields)
+}
+
// SetLogger needs to be invoked before the logger API can be invoked. This function
// initialize the default logger (zap's sugaredlogger)
func SetDefaultLogger(outputType string, level LogLevel, defaultFields Fields) (Logger, error) {
@@ -499,11 +503,11 @@
}
func getPackageLevelSugaredLogger() *zp.SugaredLogger {
- pkgName, fileName, funcName, line := getCallerInfo()
+ pkgName, _, _, _ := getCallerInfo()
if _, exist := loggers[pkgName]; exist {
- return loggers[pkgName].log.With("caller", fmt.Sprintf("%s.%s:%d", fileName, funcName, line))
+ return loggers[pkgName].log
}
- return defaultLogger.log.With("caller", fmt.Sprintf("%s.%s:%d", fileName, funcName, line))
+ return defaultLogger.log
}
func getPackageLevelLogger() Logger {
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 6ed5711..45eeee3 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -90,7 +90,7 @@
github.com/modern-go/concurrent
# github.com/modern-go/reflect2 v1.0.1
github.com/modern-go/reflect2
-# github.com/opencord/voltha-lib-go/v3 v3.0.23
+# github.com/opencord/voltha-lib-go/v3 v3.1.5
github.com/opencord/voltha-lib-go/v3/pkg/config
github.com/opencord/voltha-lib-go/v3/pkg/db
github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore