Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace all with Zerolog #1482

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/api/rest/server/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"

"github.com/cloud-barista/cb-tumblebug/src/core/common"
)
Expand All @@ -46,7 +47,7 @@ func RestInitConfig(c echo.Context) error {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
if err := Validate(c, []string{"configId"}); err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
return common.EndRequestWithLog(c, reqID, err, nil)
}

Expand All @@ -55,7 +56,7 @@ func RestInitConfig(c echo.Context) error {
err := fmt.Errorf("Failed to init the config " + c.Param("configId"))
return common.EndRequestWithLog(c, reqID, err, nil)
} else {
return SendMessage(c, http.StatusOK, "The config "+c.Param("configId")+" has been initialized.")
// return SendMessage(c, http.StatusOK, "The config "+c.Param("configId")+" has been initialized.")
content := map[string]string{"message": "The config " + c.Param("configId") + " has been initialized."}
return common.EndRequestWithLog(c, reqID, err, content)
}
Expand All @@ -78,7 +79,7 @@ func RestGetConfig(c echo.Context) error {
return c.JSON(http.StatusBadRequest, map[string]string{"message": idErr.Error()})
}
if err := Validate(c, []string{"configId"}); err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
return SendMessage(c, http.StatusBadRequest, err.Error())
}

Expand Down
3 changes: 0 additions & 3 deletions src/api/rest/server/common/utility.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/go-playground/validator/v10"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"

"github.com/cloud-barista/cb-tumblebug/src/core/common"
"github.com/cloud-barista/cb-tumblebug/src/core/mcis"
Expand Down Expand Up @@ -85,8 +84,6 @@ func RestGetHealth(c echo.Context) error {
okMessage := common.SimpleMsg{}
okMessage.Message = "API server of CB-Tumblebug is alive"

log.Debug().Msg("Inside of RestGetHealth() handler")

return c.JSON(http.StatusOK, &okMessage)
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/server/mcir/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func RestRegisterExistingResources(c echo.Context) error {

result, err := mcir.RegisterExistingResources(nsId, u.ConnectionName)
if err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusConflict, &mapA)
}
Expand Down
17 changes: 9 additions & 8 deletions src/api/rest/server/mcis/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cloud-barista/cb-tumblebug/src/core/common"
"github.com/cloud-barista/cb-tumblebug/src/core/mcis"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
)

// RestPostCluster godoc
Expand Down Expand Up @@ -52,7 +53,7 @@ func RestPostCluster(c echo.Context) error {
content, err := mcis.CreateCluster(nsId, u, optionFlag)

if err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}
Expand Down Expand Up @@ -111,7 +112,7 @@ func RestPostNodeGroup(c echo.Context) error {
content, err := mcis.AddNodeGroup(nsId, clusterId, u)

if err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}
Expand Down Expand Up @@ -141,7 +142,7 @@ func RestDeleteNodeGroup(c echo.Context) error {

res, err := mcis.RemoveNodeGroup(nsId, clusterId, nodeGroupName, forceFlag)
if err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}
Expand Down Expand Up @@ -185,7 +186,7 @@ func RestPutSetAutoscaling(c echo.Context) error {
content, err := mcis.SetAutoscaling(nsId, clusterId, nodeGroupName, u)

if err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}
Expand Down Expand Up @@ -222,7 +223,7 @@ func RestPutChangeAutoscaleSize(c echo.Context) error {
content, err := mcis.ChangeAutoscaleSize(nsId, clusterId, nodeGroupName, u)

if err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}
Expand Down Expand Up @@ -330,7 +331,7 @@ func RestDeleteCluster(c echo.Context) error {

res, err := mcis.DeleteCluster(nsId, clusterId, forceFlag)
if err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}
Expand Down Expand Up @@ -365,7 +366,7 @@ func RestDeleteAllCluster(c echo.Context) error {

output, err := mcis.DeleteAllCluster(nsId, subString, forceFlag)
if err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusConflict, &mapA)
}
Expand Down Expand Up @@ -400,7 +401,7 @@ func RestPutUpgradeCluster(c echo.Context) error {
content, err := mcis.UpgradeCluster(nsId, clusterId, u)

if err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}
Expand Down
3 changes: 2 additions & 1 deletion src/api/rest/server/mcis/manageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cloud-barista/cb-tumblebug/src/core/common"
"github.com/cloud-barista/cb-tumblebug/src/core/mcis"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
)

// JSONResult is a dummy struct for Swagger annotations.
Expand Down Expand Up @@ -316,7 +317,7 @@ func RestDelMcisVm(c echo.Context) error {

err := mcis.DelMcisVm(nsId, mcisId, vmId, option)
if err != nil {
common.CBLog.Error(err)
log.Error().Err(err).Msg("")
err := fmt.Errorf("Failed to delete the VM info")
return common.EndRequestWithLog(c, reqID, err, nil)
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/go-resty/resty/v2"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
)

// CacheItem is a struct to store cached item
Expand Down Expand Up @@ -345,7 +346,7 @@ func ForwardRequestToAny(reqPath string, method string, requestBody interface{})
)

if err != nil {
CBLog.Error(err)
log.Error().Err(err).Msg("")
return nil, err
}

Expand Down
18 changes: 10 additions & 8 deletions src/core/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"github.com/jedib0t/go-pretty/v6/table"

cbstore_utils "github.com/cloud-barista/cb-store/utils"

"github.com/rs/zerolog/log"
)

type CloudInfo struct {
Expand Down Expand Up @@ -188,7 +190,7 @@ func UpdateConfig(u *ConfigReq) (ConfigInfo, error) {
val, _ := json.Marshal(content)
err := CBStore.Put(key, string(val))
if err != nil {
CBLog.Error(err)
log.Error().Err(err).Msg("")
return content, err
}
keyValue, _ := CBStore.Get(key)
Expand All @@ -205,7 +207,7 @@ func UpdateGlobalVariable(id string) error {

configInfo, err := GetConfig(id)
if err != nil {
//CBLog.Error(err)
//log.Error().Err(err).Msg("")
return err
}

Expand Down Expand Up @@ -274,7 +276,7 @@ func InitConfig(id string) error {

CBStore.Delete(key)
// if err != nil {
// CBLog.Error(err)
// log.Error().Err(err).Msg("")
// return err
// }
}
Expand All @@ -296,7 +298,7 @@ func GetConfig(id string) (ConfigInfo, error) {

if err != nil {
temp := ConfigInfo{}
CBLog.Error(err)
log.Error().Err(err).Msg("")
return temp, err
}

Expand All @@ -305,15 +307,15 @@ func GetConfig(id string) (ConfigInfo, error) {

keyValue, err := CBStore.Get(key)
if err != nil {
//CBLog.Error(err)
//log.Error().Err(err).Msg("")
return res, err
}

fmt.Println("<" + keyValue.Key + "> " + keyValue.Value)

err = json.Unmarshal([]byte(keyValue.Value), &res)
if err != nil {
CBLog.Error(err)
log.Error().Err(err).Msg("")
return res, err
}
return res, nil
Expand All @@ -328,7 +330,7 @@ func ListConfig() ([]ConfigInfo, error) {
keyValue = cbstore_utils.GetChildList(keyValue, key)

if err != nil {
CBLog.Error(err)
log.Error().Err(err).Msg("")
return nil, err
}
if keyValue != nil {
Expand All @@ -337,7 +339,7 @@ func ListConfig() ([]ConfigInfo, error) {
tempObj := ConfigInfo{}
err = json.Unmarshal([]byte(v.Value), &tempObj)
if err != nil {
CBLog.Error(err)
log.Error().Err(err).Msg("")
return nil, err
}
res = append(res, tempObj)
Expand Down
Loading