Skip to content

Commit 0590935

Browse files
committed
update cost estimate endpoint and handlers
1 parent 10cd57b commit 0590935

20 files changed

+1721
-1666
lines changed

api/docs.go

+307-303
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/swagger.json

+307-303
Large diffs are not rendered by default.

api/swagger.yaml

+235-241
Large diffs are not rendered by default.

cmd/cm-ant/main.go

+62-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
package main
22

33
import (
4-
"log"
4+
"fmt"
5+
56
"os"
67
"os/signal"
8+
"runtime"
9+
"strings"
710
"syscall"
11+
"time"
812

913
"github.com/cloud-barista/cm-ant/internal/app"
1014
"github.com/cloud-barista/cm-ant/internal/config"
1115
"github.com/cloud-barista/cm-ant/internal/utils"
16+
"github.com/rs/zerolog"
17+
"github.com/rs/zerolog/log"
1218
)
1319

1420
// InitRouter initializes the routing for CM-ANT API server.
@@ -17,55 +23,99 @@ import (
1723
// @version 0.2.2
1824
// @description CM-ANT REST API swagger document.
1925
// @basePath /ant
26+
27+
type CallerHook struct{}
28+
29+
func (h CallerHook) Run(e *zerolog.Event, level zerolog.Level, msg string) {
30+
if pc, file, line, ok := runtime.Caller(3); ok {
31+
shortFile := file[strings.LastIndex(file, "/")+1:]
32+
e.Str("file", fmt.Sprintf("%s:%d", shortFile, line))
33+
funcName := strings.Replace(runtime.FuncForPC(pc).Name(), "github.com/cloud-barista/", "", 1)
34+
e.Str("func", funcName)
35+
}
36+
}
37+
2038
func main() {
39+
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339}
40+
output.FormatLevel = func(i interface{}) string {
41+
level := strings.ToUpper(fmt.Sprintf("%s", i))
42+
switch level {
43+
case "DEBUG":
44+
return fmt.Sprintf("\033[36m| %-6s|\033[0m", level) // Cyan
45+
case "INFO":
46+
return fmt.Sprintf("\033[32m| %-6s|\033[0m", level) // Green
47+
case "WARN":
48+
return fmt.Sprintf("\033[33m| %-6s|\033[0m", level) // Yellow
49+
case "ERROR":
50+
return fmt.Sprintf("\033[31m| %-6s|\033[0m", level) // Red
51+
case "FATAL":
52+
return fmt.Sprintf("\033[35m| %-6s|\033[0m", level) // Magenta
53+
default:
54+
return fmt.Sprintf("| %-6s|", level) // Default color
55+
}
56+
}
57+
output.FormatMessage = func(i interface{}) string {
58+
if i == nil {
59+
return ""
60+
}
61+
return fmt.Sprintf("message: \033[1m%s\033[0m", i)
62+
}
63+
64+
output.FormatFieldName = func(i interface{}) string {
65+
return fmt.Sprintf("%s:", i)
66+
}
67+
output.FormatFieldValue = func(i interface{}) string {
68+
return fmt.Sprintf("\033[1m%s\033[0m", i)
69+
}
70+
71+
log.Logger = zerolog.New(output).With().Timestamp().Logger().Hook(CallerHook{})
2172

2273
err := utils.Script(utils.JoinRootPathWith("/script/install_required_utils.sh"), []string{})
2374
if err != nil {
24-
log.Fatal("required tool can not install")
75+
log.Fatal().Msg("required tool can not install")
2576
}
26-
utils.LogInfo("Starting CM-Ant server initialization...")
2777

2878
// Initialize the configuration for CM-Ant server
2979
err = config.InitConfig()
3080
if err != nil {
31-
log.Fatalf("[ERROR] CM-Ant server config error: %v", err)
81+
log.Fatal().Msgf("CM-Ant server config error: %v", err)
3282
}
3383

3484
// Create a new instance of the CM-Ant server
3585
s, err := app.NewAntServer()
3686
if err != nil {
37-
log.Fatalf("[ERROR] CM-Ant server creation error: %v", err)
87+
log.Fatal().Msgf("CM-Ant server creation error: %v", err)
3888
}
3989

4090
// Initialize the router for the CM-Ant server
4191
err = s.InitRouter()
4292
if err != nil {
43-
log.Fatalf("[ERROR] CM-Ant server init router error: %v", err)
93+
log.Fatal().Msgf("CM-Ant server init router error: %v", err)
4494
}
4595

46-
utils.LogInfo("CM-Ant server initialization completed successfully.")
96+
log.Info().Msgf("CM-Ant server initialization completed successfully.")
4797

4898
// Create a channel to listen for OS signals
4999
stop := make(chan os.Signal, 1)
50100
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
51101

52-
utils.LogInfo("Starting the CM-Ant server...")
102+
log.Info().Msgf("Starting the CM-Ant server...")
53103
go func() {
54104
if err := s.Start(); err != nil {
55-
log.Fatalf("[ERROR] CM-Ant start server error: %v", err)
105+
log.Fatal().Msgf("CM-Ant start server error: %v", err)
56106
}
57107
}()
58108

59-
utils.LogInfo("CM-Ant server started successfully. Waiting for termination signal...")
109+
log.Info().Msgf("CM-Ant server started successfully. Waiting for termination signal...")
60110

61111
// Wait for termination signal
62112
<-stop
63113

64-
utils.LogInfo("Shutting down CM-Ant server...")
114+
log.Info().Msgf("Shutting down CM-Ant server...")
65115

66116
// Perform any necessary cleanup actions here, such as closing connections or saving state.
67117
// Optionally wait for pending operations to complete gracefully.
68118

69-
utils.LogInfo("CM-Ant server stopped gracefully.")
119+
log.Info().Msgf("CM-Ant server stopped gracefully.")
70120
os.Exit(0)
71121
}

config.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ tumblebug:
1515

1616
cost:
1717
estimation:
18-
forecast:
19-
priceUpdateInterval: 7d
18+
updateInterval: "168h"
2019

2120
load:
2221
retry: 2
2322
jmeter:
2423
dir: "/opt/ant/jmeter"
2524
version: 5.6
2625

27-
logging:
26+
log:
2827
level: info
2928

3029
database:

docker-compose.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ services:
3232
restart: unless-stopped
3333

3434
ant-postgres:
35+
container_name: ant-postgres
3536
image: timescale/timescaledb:latest-pg16
3637
ports:
3738
- "5432:5432"
@@ -50,7 +51,7 @@ services:
5051
restart: unless-stopped
5152

5253
cb-tumblebug:
53-
image: cloudbaristaorg/cb-tumblebug:0.9.13
54+
image: cloudbaristaorg/cb-tumblebug:0.9.21
5455
container_name: cb-tumblebug
5556
platform: linux/amd64
5657
ports:
@@ -147,7 +148,7 @@ services:
147148
restart: unless-stopped
148149

149150
cb-spider:
150-
image: cloudbaristaorg/cb-spider:0.9.4
151+
image: cloudbaristaorg/cb-spider:0.9.8
151152
container_name: cb-spider
152153
platform: linux/amd64
153154
networks:

0 commit comments

Comments
 (0)