Skip to content

Commit

Permalink
update all default log to zero log
Browse files Browse the repository at this point in the history
  • Loading branch information
hippo-an committed Nov 14, 2024
1 parent 5fcbc6c commit b32ffc0
Show file tree
Hide file tree
Showing 23 changed files with 251 additions and 254 deletions.
6 changes: 3 additions & 3 deletions internal/app/estimate_cost_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/cloud-barista/cm-ant/internal/config"
"github.com/cloud-barista/cm-ant/internal/core/common/constant"
"github.com/cloud-barista/cm-ant/internal/core/cost"
"github.com/cloud-barista/cm-ant/internal/utils"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
)

// @Id UpdateAndGetEstimateCost
Expand Down Expand Up @@ -74,12 +74,12 @@ func (a *AntServer) updateAndGetEstimateCost(c echo.Context) error {
splitedCommonImage := strings.Split(ci, delim)

if len(splitedCommonSpec) != 3 {
utils.LogErrorf("common spec format is not correct; image: %s; spec: %s", ci, cs)
log.Error().Msgf("common spec format is not correct; image: %s; spec: %s", ci, cs)
return errorResponseJson(http.StatusBadRequest, fmt.Sprintf("common spec format is not correct; image: %s; spec: %s", ci, cs))
}

if len(splitedCommonImage) == 3 && (splitedCommonImage[0] != splitedCommonSpec[0] || splitedCommonImage[1] != splitedCommonSpec[1]) {
utils.LogErrorf("common image and spec recommendation is wrong; image: %s; spec: %s", ci, cs)
log.Error().Msgf("common image and spec recommendation is wrong; image: %s; spec: %s", ci, cs)
return errorResponseJson(http.StatusBadRequest, fmt.Sprintf("common image and spec recommendation is wrong; image: %s; spec: %s", ci, cs))
}

Expand Down
13 changes: 6 additions & 7 deletions internal/app/evaluate_performance_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/cloud-barista/cm-ant/internal/core/common/constant"
"github.com/cloud-barista/cm-ant/internal/core/load"
"github.com/cloud-barista/cm-ant/internal/utils"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -74,20 +73,20 @@ func (s *AntServer) getAllLoadGeneratorInstallInfo(c echo.Context) error {
func (s *AntServer) installLoadGenerator(c echo.Context) error {
var req InstallLoadGeneratorReq

utils.LogInfo("Received request to install load generator")
log.Info().Msg("Received request to install load generator")

if err := c.Bind(&req); err != nil {
utils.LogError("Failed to bind request:", err)
log.Error().Msgf("Failed to bind request:", err)
return errorResponseJson(http.StatusBadRequest, "load generator installation info is not correct.")
}

if req.InstallLocation == "" ||
(req.InstallLocation != constant.Remote && req.InstallLocation != constant.Local) {
utils.LogError("Invalid install location:", req.InstallLocation)
log.Error().Msgf("Invalid install location:", req.InstallLocation)
return errorResponseJson(http.StatusBadRequest, "available install locations are remote or local.")
}

utils.LogInfo("Calling service layer to install load generator")
log.Info().Msgf("Calling service layer to install load generator")

// call service layer install load generator
param := load.InstallLoadGeneratorParam{
Expand All @@ -97,11 +96,11 @@ func (s *AntServer) installLoadGenerator(c echo.Context) error {
result, err := s.services.loadService.InstallLoadGenerator(param)

if err != nil {
utils.LogError("Error installing load generator:", err)
log.Error().Msgf("Error installing load generator:", err)
return errorResponseJson(http.StatusBadRequest, err.Error())
}

utils.LogInfo("Load generator installed successfully")
log.Info().Msg("Load generator installed successfully")

return successResponseJson(
c,
Expand Down
3 changes: 1 addition & 2 deletions internal/app/middlewares.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/labstack/echo/v4/middleware"

"github.com/cloud-barista/cm-ant/internal/utils"
"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
)
Expand All @@ -34,7 +33,7 @@ func setMiddleware(e *echo.Echo) {
Skipper: middleware.DefaultSkipper,
ErrorMessage: "request timeout",
OnTimeoutRouteErrorHandler: func(err error, c echo.Context) {
utils.LogInfo(c.Path())
log.Info().Msg(c.Path())
},
Timeout: 3000 * time.Second,
},
Expand Down
29 changes: 15 additions & 14 deletions internal/core/cost/cost_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/cloud-barista/cm-ant/internal/infra/outbound/spider"
"github.com/cloud-barista/cm-ant/internal/infra/outbound/tumblebug"
"github.com/cloud-barista/cm-ant/internal/utils"
"github.com/rs/zerolog/log"
)

type CostCollector interface {
Expand Down Expand Up @@ -136,7 +137,7 @@ func (a *AwsCostExplorerBaristaCostCollector) GetCostInfos(ctx context.Context,

serviceFilterValue, resourceIdFilterValue, err := a.generateFilterValue(param.CostResources, param.AwsAdditionalInfo)
if err != nil {
utils.LogError("parsing service and resource id for filtering cost explorer value")
log.Error().Msgf("parsing service and resource id for filtering cost explorer value")
return nil, err
}

Expand Down Expand Up @@ -216,51 +217,51 @@ func (a *AwsCostExplorerBaristaCostCollector) GetCostInfos(ctx context.Context,

if err != nil {
if errors.Is(err, spider.ErrSpiderCostResultEmpty) {
utils.LogError("error from spider: ", err)
log.Error().Msgf("error from spider: ", err)
return nil, ErrCostResultEmpty
}
return nil, err
}

if res == nil || res.ResultsByTime == nil || len(res.ResultsByTime) == 0 {
utils.LogError("cost result is empty: ")
log.Error().Msgf("cost result is empty: ")
return nil, ErrCostResultEmpty
}

var costInfos = make([]EstimateForecastCostInfo, 0)
for _, result := range res.ResultsByTime {
if result.Groups == nil {
utils.LogError("groups is nil; it must not be nil")
log.Error().Msgf("groups is nil; it must not be nil")
return nil, ErrCostResultFormatInvalid
}

if result.TimePeriod == nil || result.TimePeriod.Start == nil || result.TimePeriod.End == nil {
utils.LogError("time period is nil; it must not be nil")
log.Error().Msgf("time period is nil; it must not be nil")
return nil, ErrCostResultFormatInvalid
}

for _, group := range result.Groups {

if group == nil {
utils.LogError("sinble group is nil; it must not be nil")
log.Error().Msgf("sinble group is nil; it must not be nil")
continue
}

category := utils.NilSafeStr(group.Keys[0])
awsService := constant.AwsService(category)
resourceType, ok := serviceToResourceType[awsService]
if !ok {
utils.LogErrorf("service : %s does not exist; category: %s", awsService, category)
log.Error().Msgf("service : %s does not exist; category: %s", awsService, category)
continue
}
mt, ok := group.Metrics[metrics]
if !ok {
utils.LogError("matric value does not exist:", metrics)
log.Error().Msgf("matric value does not exist:", metrics)
continue
}
cost, err := strconv.ParseFloat(utils.NilSafeStr(mt.Amount), 64)
if err != nil {
utils.LogError("cost parsing error:", mt.Amount)
log.Error().Msgf("cost parsing error:", mt.Amount)
continue
}
unit := utils.NilSafeStr(mt.Unit)
Expand All @@ -274,13 +275,13 @@ func (a *AwsCostExplorerBaristaCostCollector) GetCostInfos(ctx context.Context,

startDate, err := time.Parse(time.RFC3339, utils.NilSafeStr(result.TimePeriod.Start))
if err != nil {
utils.LogError("start date parsing error:", result.TimePeriod.Start)
log.Error().Msgf("start date parsing error:", result.TimePeriod.Start)
continue
}

endDate, err := time.Parse(time.RFC3339, utils.NilSafeStr(result.TimePeriod.End))
if err != nil {
utils.LogError("end date parsing error to ")
log.Error().Msgf("end date parsing error to ")
continue
}

Expand Down Expand Up @@ -328,7 +329,7 @@ func (a *AwsCostExplorerBaristaCostCollector) UpdateEstimateForecastCost(ctx con
mci, err := a.tc.GetMciWithContext(ctx, param.NsId, param.MciId)

if err != nil {
utils.LogError("error while get mci from tumblebug; ", err)
log.Error().Msgf("error while get mci from tumblebug; ", err)
return res, err
}

Expand All @@ -353,7 +354,7 @@ func (a *AwsCostExplorerBaristaCostCollector) UpdateEstimateForecastCost(ctx con
pn := mci.ConnectionConfig.ProviderName

if pn == "" || !strings.EqualFold(strings.ToLower(pn), "aws") {
utils.LogWarnf("CSP: %s, does not support yet", pn)
log.Warn().Msgf("CSP: %s, does not support yet", pn)
continue
}

Expand All @@ -376,7 +377,7 @@ func (a *AwsCostExplorerBaristaCostCollector) UpdateEstimateForecastCost(ctx con
infos, err := a.GetCostInfos(ctx, arg)

if err != nil {
utils.LogError("error while get cost info from spider;", err)
log.Error().Msgf("error while get cost info from spider;", err)
return res, fmt.Errorf("error from get cost infos +%w", err)
}

Expand Down
12 changes: 6 additions & 6 deletions internal/core/cost/price_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/cloud-barista/cm-ant/internal/core/common/constant"
"github.com/cloud-barista/cm-ant/internal/infra/outbound/spider"
"github.com/cloud-barista/cm-ant/internal/utils"
"github.com/rs/zerolog/log"
)

type PriceCollector interface {
Expand Down Expand Up @@ -137,23 +137,23 @@ func (s *SpiderPriceCollector) FetchPriceInfos(ctx context.Context, param Recomm
currency = s.parseCurrency(policy.Currency)
convertedPrice, err := strconv.ParseFloat(policy.Price, 64)
if err != nil {
utils.LogWarnf("not allowed for error; %s", err)
log.Warn().Msgf("not allowed for error; %s", err)
continue
}

if convertedPrice == float64(0) {
utils.LogWarn("not allowed for empty price")
log.Warn().Msg("not allowed for empty price")
continue
}
price = s.naChecker(policy.Price)

if price == "" {
utils.LogWarn("not allowed for empty price")
log.Warn().Msg("not allowed for empty price")
continue
}

if strings.Contains(strings.ToLower(priceDescription), "dedicated") {
utils.LogWarnf("not allowed for dedicated instance hour; %s", priceDescription)
log.Warn().Msgf("not allowed for dedicated instance hour; %s", priceDescription)
continue
}

Expand Down Expand Up @@ -259,7 +259,7 @@ func (s *SpiderPriceCollector) splitMemory(input string) (string, constant.Memor

number, err := strconv.ParseFloat(strings.TrimSpace(numberPart), 64)
if err != nil {
utils.LogErrorf("error while split memory : %s", err.Error())
log.Error().Msgf("error while split memory : %s", err.Error())
return "", ""
}

Expand Down
9 changes: 4 additions & 5 deletions internal/core/cost/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

"github.com/cloud-barista/cm-ant/internal/core/common/constant"
"github.com/cloud-barista/cm-ant/internal/utils"
"github.com/rs/zerolog/log"
)

Expand Down Expand Up @@ -299,14 +298,14 @@ func (c *CostService) UpdateEstimateForecastCost(param UpdateEstimateForecastCos
for _, costInfo := range r {
u, i, err := c.costRepo.UpsertCostInfo(ctx, costInfo)
if err != nil {
utils.LogErrorf("upsert error: %+v", costInfo)
log.Error().Msgf("upsert error: %+v", costInfo)
}

updatedCount += u
insertedCount += i
}

utils.LogInfof("updated count: %d; inserted count : %d", updatedCount, insertedCount)
log.Info().Msgf("updated count: %d; inserted count : %d", updatedCount, insertedCount)

updateEstimateForecastCostInfoResult.UpdatedDataCount = updatedCount
updateEstimateForecastCostInfoResult.InsertedDataCount = insertedCount
Expand Down Expand Up @@ -356,13 +355,13 @@ func (c *CostService) UpdateEstimateForecastCostRaw(param UpdateEstimateForecast
for _, costInfo := range r {
u, i, err := c.costRepo.UpsertCostInfo(ctx, costInfo)
if err != nil {
utils.LogErrorf("upsert error: %+v", costInfo)
log.Error().Msgf("upsert error: %+v", costInfo)
}

updatedCount += u
insertedCount += i
}
utils.LogInfof("updated count: %d; inserted count : %d", updatedCount, insertedCount)
log.Info().Msgf("updated count: %d; inserted count : %d", updatedCount, insertedCount)

updateCostInfoResult.UpdatedDataCount = updatedCount
updateCostInfoResult.InsertedDataCount = insertedCount
Expand Down
4 changes: 2 additions & 2 deletions internal/core/load/jmx_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"fmt"
"html"
"io"
"log"
"net/url"
"strings"
"text/template"

"github.com/cloud-barista/cm-ant/internal/utils"
"github.com/rs/zerolog/log"
)

type jmxTemplateData struct {
Expand Down Expand Up @@ -205,7 +205,7 @@ func httpReqParseToJmx(httpReqs []RunLoadTestHttpParam) (string, error) {
var buf bytes.Buffer
err = tmpl.Execute(&buf, jmxHttpTemplateData)
if err != nil {
log.Fatalf("Error executing template: %s", err)
log.Error().Msgf("Error executing template: %s", err)
}
builder.WriteString(buf.String())
}
Expand Down
Loading

0 comments on commit b32ffc0

Please sign in to comment.