aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Multanen <eric.w.multanen@intel.com>2020-09-10 23:47:04 +0000
committerGerrit Code Review <gerrit@onap.org>2020-09-10 23:47:04 +0000
commit172bebb96ce3ef47f5514c5f7a9a2b70d583f31c (patch)
tree514b4c834e01da0a064536bd8f68ee6ed83c35b9
parentdae8d6f81bf346b3e63d939081b80c269e925e50 (diff)
parent4759e43ff7f29727477b0d928047bf5ca283cef1 (diff)
Merge "Add log level support for orchestrator"
-rw-r--r--README.md3
-rw-r--r--src/orchestrator/config.json16
-rw-r--r--src/orchestrator/pkg/infra/config/config.go3
-rw-r--r--src/orchestrator/pkg/infra/logutils/logger.go11
-rw-r--r--src/orchestrator/utils/helm/helm.go13
-rw-r--r--src/orchestrator/utils/utils.go26
6 files changed, 50 insertions, 22 deletions
diff --git a/README.md b/README.md
index 4e380ef3..8aeed383 100644
--- a/README.md
+++ b/README.md
@@ -35,3 +35,6 @@ Steps:
* Run the plugin:
* `cd k8s/deployments && ./start.sh`
+# Troubleshooting
+
+* Logs can be set as "warn" or "info" in the config.json file of the orchestrator directory. By default the log level is set as "warn".
diff --git a/src/orchestrator/config.json b/src/orchestrator/config.json
new file mode 100644
index 00000000..1acd835d
--- /dev/null
+++ b/src/orchestrator/config.json
@@ -0,0 +1,16 @@
+{
+ "ca-file": "ca.cert",
+ "server-cert": "server.cert",
+ "server-key": "server.key",
+ "password": "",
+ "database-ip": "172.31.0.2",
+ "database-type": "mongo",
+ "plugin-dir": "plugins",
+ "etcd-ip": "127.0.0.1",
+ "etcd-cert": "",
+ "etcd-key": "",
+ "etcd-ca-file": "",
+ "service-port": "9015",
+ "log-level": "warn"
+
+}
diff --git a/src/orchestrator/pkg/infra/config/config.go b/src/orchestrator/pkg/infra/config/config.go
index fca8bfbd..43191489 100644
--- a/src/orchestrator/pkg/infra/config/config.go
+++ b/src/orchestrator/pkg/infra/config/config.go
@@ -44,6 +44,7 @@ type Configuration struct {
GrpcServerNameOverride string `json:"grpc-server-name-override"`
ServicePort string `json:"service-port"`
KubernetesLabelName string `json:"kubernetes-label-name"`
+ LogLevel string `json:"log-level"`
}
// Config is the structure that stores the configuration
@@ -98,6 +99,8 @@ func defaultConfiguration() *Configuration {
GrpcServerNameOverride: "",
ServicePort: "9015",
KubernetesLabelName: "orchestrator.io/rb-instance-id",
+ LogLevel: "warn",
+
}
}
diff --git a/src/orchestrator/pkg/infra/logutils/logger.go b/src/orchestrator/pkg/infra/logutils/logger.go
index 2e8f9969..209114a3 100644
--- a/src/orchestrator/pkg/infra/logutils/logger.go
+++ b/src/orchestrator/pkg/infra/logutils/logger.go
@@ -2,6 +2,9 @@ package logutils
import (
log "github.com/sirupsen/logrus"
+ "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/config"
+ "strings"
+
)
//Fields is type that will be used by the calling function
@@ -10,6 +13,13 @@ type Fields map[string]interface{}
func init() {
// Log as JSON instead of the default ASCII formatter.
log.SetFormatter(&log.JSONFormatter{})
+ if strings.EqualFold(config.GetConfiguration().LogLevel, "warn") {
+ log.SetLevel(log.WarnLevel)
+
+ }
+ if strings.EqualFold(config.GetConfiguration().LogLevel, "info") {
+ log.SetLevel(log.InfoLevel)
+ }
}
// Error uses the fields provided and logs
@@ -26,3 +36,4 @@ func Warn(msg string, fields Fields) {
func Info(msg string, fields Fields) {
log.WithFields(log.Fields(fields)).Info(msg)
}
+
diff --git a/src/orchestrator/utils/helm/helm.go b/src/orchestrator/utils/helm/helm.go
index 80cdfe5a..3f8b6e9e 100644
--- a/src/orchestrator/utils/helm/helm.go
+++ b/src/orchestrator/utils/helm/helm.go
@@ -21,7 +21,7 @@ import (
utils "github.com/onap/multicloud-k8s/src/orchestrator/utils"
pkgerrors "github.com/pkg/errors"
- "log"
+
"fmt"
"io/ioutil"
@@ -43,6 +43,8 @@ import (
"k8s.io/helm/pkg/renderutil"
"k8s.io/helm/pkg/tiller"
"k8s.io/helm/pkg/timeconv"
+ logger "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
+
)
//KubernetesResourceTemplate - Represents the template that is used to create a particular
@@ -174,7 +176,8 @@ func (h *TemplateClient) GenerateKubernetesArtifacts(inputPath string, valueFile
if err != nil {
return retData, pkgerrors.Wrap(err, "Got error creating temp dir")
}
- log.Printf("The o/p dir:: %s ", outputDir)
+ logger.Info(":: The o/p dir:: ", logger.Fields{"OutPutDirectory ":outputDir})
+
if namespace == "" {
namespace = "default"
@@ -302,20 +305,20 @@ func (h *TemplateClient) Resolve(appContent []byte, appProfileContent []byte, ov
if err != nil {
return sortedTemplates, pkgerrors.Wrap(err, "Extracting appContent")
}
- log.Printf("The chartBasePath :: %s", chartBasePath)
+ logger.Info("The chartBasePath ::", logger.Fields{"chartBasePath":chartBasePath})
//prPath is the tmp path where the appProfileContent is extracted.
prPath, err := utils.ExtractTarBall(bytes.NewBuffer(appProfileContent))
if err != nil {
return sortedTemplates, pkgerrors.Wrap(err, "Extracting Profile Content")
}
- log.Printf("The profile path:: %s", prPath)
+ logger.Info("The profile path:: ", logger.Fields{"Profile Path":prPath})
prYamlClient, err := ProcessProfileYaml(prPath, h.manifestName)
if err != nil {
return sortedTemplates, pkgerrors.Wrap(err, "Processing Profile Manifest")
}
- log.Println("Got the profileYamlClient..")
+ logger.Info("Got the profileYamlClient..", logger.Fields{})
err = prYamlClient.CopyConfigurationOverrides(chartBasePath)
if err != nil {
diff --git a/src/orchestrator/utils/utils.go b/src/orchestrator/utils/utils.go
index 22ce903b..b591ccb5 100644
--- a/src/orchestrator/utils/utils.go
+++ b/src/orchestrator/utils/utils.go
@@ -23,13 +23,14 @@ import (
"io"
"io/ioutil"
- "log"
"os"
"path"
"path/filepath"
pkgerrors "github.com/pkg/errors"
yaml "gopkg.in/yaml.v3"
+ log "github.com/onap/multicloud-k8s/src/orchestrator/pkg/infra/logutils"
+
)
// ListYamlStruct is applied when the kind is list
@@ -69,15 +70,15 @@ type YamlStruct struct {
func (y YamlStruct) isValid() bool {
if y.APIVersion == "" {
- log.Printf("apiVersion is missing in manifest file")
+ log.Info("apiVersion is missing in manifest file", log.Fields{})
return false
}
if y.Kind == "" {
- log.Printf("kind is missing in manifest file")
+ log.Info("kind is missing in manifest file", log.Fields{})
return false
}
if y.Metadata.Name == "" {
- log.Printf("metadata.name is missing in manifest file")
+ log.Info("metadata.name is missing in manifest file", log.Fields{})
return false
}
return true
@@ -107,13 +108,14 @@ func ExtractYamlParameters(f string) (YamlStruct, error) {
li := strings.LastIndex(filename, "/")
fn := string(filename[li+1:])
yamlStruct.Metadata.Name = fn
- log.Printf("Setting the metadata name as :: %s", fn)
+ log.Info("Setting the metadata", log.Fields{"MetaDataName":fn})
}
if yamlStruct.isValid() {
- log.Printf("YAML parameters for file ::%s \n %v", f, yamlStruct)
+ log.Info(":: YAML parameters ::", log.Fields{"fileName": f, "yamlStruct":yamlStruct})
+
return yamlStruct, nil
}
- log.Printf("YAML file ::%s has errors", f)
+ log.Info("YAML file has errors", log.Fields{"fileName": f})
return YamlStruct{}, pkgerrors.Errorf("Cant extract parameters from yaml file :: %s", filename)
}
@@ -204,13 +206,3 @@ func EnsureDirectory(f string) error {
}
return os.MkdirAll(base, 0755)
}
-
-// func main() {
-// filename := "./test.yaml"
-// yamlStruct, err := ExtractYamlParameters(filename)
-// if err!=nil {
-// log.Print(err)
-// }
-// fmt.Printf("%s+%s", yamlStruct.Metadata.Name, yamlStruct.Kind)
-// fmt.Printf("%v", yamlStruct)
-// }