diff --git a/Dockerfile b/Dockerfile index 9aad84a..48e6438 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ## Build -FROM golang:1.21.4-bookworm AS build +FROM golang:1.22-bookworm AS build COPY . /usr/src/troll/ diff --git a/README.md b/README.md index 04097ce..7862713 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Troll is a very simple webserver returning defined response with configurable de * 404 page dumping request to log * Generate 503 randomly (simulate errors) * Fill RAM with each request (simulate mem leaks) + * Ready delay for testing canary releases and readyness check ## Build @@ -58,17 +59,19 @@ env GOOS=target-OS GOARCH=target-architecture go build . troll -help -fail int - Returns 503. Set 1 - 10, where 10 = 100% error rate. + Returns 503. Set 1 - 10, where 10 = 100% error rate. -fill-ram int - Fill ram with each request. Set number in bytes. + Fill ram with each request. Set number in bytes. -name string - Define custom application name (default "troll") + Define custom application name (default "troll") + -ready-delay int + Simulate long application init (seconds). -root string - Define document root for serving files (default "./public") + Define document root for serving files (default "./public") -v2-path string - Define path to v2 api endpoint configuration yaml (default "./v2_api.yaml") + Define path to v2 api endpoint configuration yaml (default "./v2_api.yaml") -wait int - Minimal wait time before each request + Minimal wait time before each request ``` ## Config diff --git a/go.mod b/go.mod index 2954b19..e31f93d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module gitlab.com/theztd/troll -go 1.17 +go 1.22 require ( github.com/gin-contrib/requestid v0.0.5 diff --git a/go.sum b/go.sum index eba77d6..10ab883 100644 --- a/go.sum +++ b/go.sum @@ -243,7 +243,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= -github.com/ugorji/go v1.2.7 h1:qYhyWUUd6WbiM+C6JZAUkIJt/1WrjzNHY9+KCIjVqTo= github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= diff --git a/main.go b/main.go index 6b88922..dceac57 100644 --- a/main.go +++ b/main.go @@ -41,12 +41,24 @@ func main() { flag.StringVar(&V2_PATH, "v2-path", "./v2_api.yaml", "Define path to v2 api endpoint configuration yaml") flag.IntVar(&FAIL_FREQ, "fail", 0, "Returns 503. Set 1 - 10, where 10 = 100% error rate.") flag.IntVar(&FILL_RAM, "fill-ram", 0, "Fill ram with each request. Set number in bytes.") + flag.IntVar(&READY_DELAY, "ready-delay", 0, "Simulate long application init (seconds).") + flag.Parse() // it is better to be configurable via env ADDRESS = getEnv("ADDRESS", ":8080") LOG_LEVEL = getEnv("LOG_LEVEL", "info") + if READY_DELAY > 0 { + fmt.Printf("Application init") + for i := 0; i < READY_DELAY; i++ { + time.Sleep(time.Duration(1 * time.Second)) + fmt.Printf(".") + } + fmt.Printf(" DONE\n\n") + + } + // It is enought getRoutes() diff --git a/variables.go b/variables.go index 0701ac0..f17b916 100644 --- a/variables.go +++ b/variables.go @@ -9,7 +9,7 @@ import ( var router = gin.New() var m = ginmetrics.GetMonitor() -var VERSION string = "1.1.2" +var VERSION string = "1.2.0" var LOG_LEVEL string var NAME string var DOC_ROOT string @@ -18,3 +18,4 @@ var ADDRESS string var V2_PATH string var FAIL_FREQ int = 0 var FILL_RAM int = 0 +var READY_DELAY int = 0