From f44e3a143d6a86bd516e1911779cbbacae58b141 Mon Sep 17 00:00:00 2001 From: s0s01qp Date: Sat, 24 Jul 2021 10:37:11 +0530 Subject: [PATCH] changed flag usage to separate flag set and updated readme --- README.md | 70 ++++++++++++++++++++++++++++++++++++++++++-- commons/constants.go | 1 + flags/flags.go | 19 ++++++++---- 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a2da99a..8445c26 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ GO actuator configures the set of actuator endpoints for your application. It is compatible with [Fast HTTP](https://github.com/valyala/fasthttp), [GIN](https://github.com/gin-gonic/gin) and [NET/HTTP](https://pkg.go.dev/net/http). +## Project Versioning + +Go actuator uses [semantic versioning](http://semver.org/). API should not change between patch and minor releases. New minor versions may add additional features to the API. + ## Installation ```shell @@ -166,7 +170,7 @@ commitAuthor=$(git --no-pager show -s --format='%an <%ae>' "$commitId") gitUrl=$(git config --get remote.origin.url) userName=$(whoami) hostName=$(hostname) -go build -ldflags " -X github.com/sinhashubham95/info.BuildStamp=$buildStamp -X github.com/sinhashubham95/info.GitCommitID=$commitId -X github.com/sinhashubham95/info.GitPrimaryBranch=$2 -X github.com/sinhashubham95/info.GitURL=$gitUrl -X github.com/sinhashubham95/info.UserName=$userName -X github.com/sinhashubham95/info.HostName=$hostName -X \"github.com/sinhashubham95/info.GitCommitTime=$commitTime\" -X \"github.com/sinhashubham95/info.GitCommitAuthor=$commitAuthor\"" +go build -ldflags " -X github.com/sinhashubham95/go-actuator/core.BuildStamp=$buildStamp -X github.com/sinhashubham95/go-actuator/core.GitCommitID=$commitId -X github.com/sinhashubham95/go-actuator/core.GitPrimaryBranch=$2 -X github.com/sinhashubham95/go-actuator/core.GitURL=$gitUrl -X github.com/sinhashubham95/go-actuator/core.Username=$userName -X github.com/sinhashubham95/go-actuator/core.HostName=$hostName -X \"github.com/sinhashubham95/go-actuator/core.GitCommitTime=$commitTime\" -X \"github.com/sinhashubham95/go-actuator/core.GitCommitAuthor=$commitAuthor\"" ./${APPLICATION_NAME} -env=${ENVIRONMENT_NAME} -name=${APPLICATION_NAME} -port=${APPLICATION_PORT} -version=${APPLICATION_VERSION} ``` @@ -201,7 +205,50 @@ go build -ldflags " -X github.com/sinhashubham95/info.Buil This is used to get the runtime memory statistics for your application. You can find the definition of each of the fields [here](./models/memStats.go). ```json -{} +{ + "alloc": 2047816, + "totalAlloc": 2850832, + "sys": 73942024, + "lookups": 0, + "mAllocations": 15623, + "frees": 9223, + "heapAlloc": 2047816, + "heapSys": 66551808, + "heapIdle": 62832640, + "heapInUse": 3719168, + "heapReleased": 62570496, + "heapObjects": 6400, + "stackInUse": 557056, + "stackSys": 557056, + "mSpanInUse": 81056, + "mSpanSys": 81920, + "MCacheInUse": 19200, + "mCacheSys": 32768, + "buckHashSys": 1446250, + "gcSys": 4225056, + "otherSys": 1047166, + "nextGC": 4194304, + "lastGC": 1627102938524536000, + "pauseTotalNs": 35655, + "pauseNs": [ + 35655 + ], + "pauseEnd": [ + 1627102938524536000 + ], + "numGC": 1, + "numForcedGC": 0, + "gcCPUFraction": 0.000005360999257331059, + "enableGC": true, + "debugGC": false, + "BySize": [ + { + "Size": 0, + "MAllocations": 0, + "Frees": 0 + } + ] +} ``` ### Ping - `/actuator/ping` @@ -215,3 +262,22 @@ This is used to bring the application down. ### Thread dump - `/actuator/threadDump` This is used to get the trace of all the goroutines. + +```text +goroutine profile: total 1 +1 @ 0x103af45 0x10337fb 0x10688f5 0x10c4de5 0x10c58b5 0x10c5897 0x1117e0f 0x1124391 0x11355e8 0x113576f 0x12037a5 0x1203676 0x1217025 0x1217007 0x121db9a 0x121e5b5 0x106e3e1 +# 0x10688f4 internal/poll.runtime_pollWait+0x54 /Users/s0s01qp/go/go1.16.6/src/runtime/netpoll.go:222 +# 0x10c4de4 internal/poll.(*pollDesc).wait+0x44 /Users/s0s01qp/go/go1.16.6/src/internal/poll/fd_poll_runtime.go:87 +# 0x10c58b4 internal/poll.(*pollDesc).waitRead+0x1d4 /Users/s0s01qp/go/go1.16.6/src/internal/poll/fd_poll_runtime.go:92 +# 0x10c5896 internal/poll.(*FD).Read+0x1b6 /Users/s0s01qp/go/go1.16.6/src/internal/poll/fd_unix.go:166 +# 0x1117e0e net.(*netFD).Read+0x4e /Users/s0s01qp/go/go1.16.6/src/net/fd_posix.go:55 +# 0x1124390 net.(*conn).Read+0x90 /Users/s0s01qp/go/go1.16.6/src/net/net.go:183 +# 0x11355e7 bufio.(*Reader).fill+0x107 /Users/s0s01qp/go/go1.16.6/src/bufio/bufio.go:101 +# 0x113576e bufio.(*Reader).Peek+0x4e /Users/s0s01qp/go/go1.16.6/src/bufio/bufio.go:139 +# 0x12037a4 github.com/valyala/fasthttp.(*RequestHeader).tryRead+0x64 /Users/s0s01qp/go/pkg/mod/github.com/valyala/fasthttp@v1.28.0/header.go:1520 +# 0x1203675 github.com/valyala/fasthttp.(*RequestHeader).readLoop+0x55 /Users/s0s01qp/go/pkg/mod/github.com/valyala/fasthttp@v1.28.0/header.go:1506 +# 0x1217024 github.com/valyala/fasthttp.(*RequestHeader).Read+0x1ae4 /Users/s0s01qp/go/pkg/mod/github.com/valyala/fasthttp@v1.28.0/header.go:1497 +# 0x1217006 github.com/valyala/fasthttp.(*Server).serveConn+0x1ac6 /Users/s0s01qp/go/pkg/mod/github.com/valyala/fasthttp@v1.28.0/server.go:2112 +# 0x121db99 github.com/valyala/fasthttp.(*workerPool).workerFunc+0xb9 /Users/s0s01qp/go/pkg/mod/github.com/valyala/fasthttp@v1.28.0/workerpool.go:223 +# 0x121e5b4 github.com/valyala/fasthttp.(*workerPool).getCh.func1+0x34 /Users/s0s01qp/go/pkg/mod/github.com/valyala/fasthttp@v1.28.0/workerpool.go:195 +``` diff --git a/commons/constants.go b/commons/constants.go index 17ec1f4..f8ffa68 100644 --- a/commons/constants.go +++ b/commons/constants.go @@ -2,6 +2,7 @@ package commons // Common Constants const ( + ActuatorFlagSetName = "actuator-flag-set" Application = "app" Arch = "arch" BuildStamp = "buildStamp" diff --git a/flags/flags.go b/flags/flags.go index 782ffe6..44e9ab9 100644 --- a/flags/flags.go +++ b/flags/flags.go @@ -1,19 +1,26 @@ package flags import ( - "github.com/sinhashubham95/go-actuator/commons" flag "github.com/spf13/pflag" + "os" + + "github.com/sinhashubham95/go-actuator/commons" ) +var flagSet = flag.NewFlagSet(commons.ActuatorFlagSetName, flag.ContinueOnError) + var ( - env = flag.String(commons.Env, commons.EnvDefaultValue, commons.EnvUsage) - name = flag.String(commons.Name, commons.NameDefaultValue, commons.NameUsage) - port = flag.Int(commons.Port, commons.PortDefaultValue, commons.PortUsage) - version = flag.String(commons.Version, commons.VersionDefaultValue, commons.VersionUsage) + env = flagSet.String(commons.Env, commons.EnvDefaultValue, commons.EnvUsage) + name = flagSet.String(commons.Name, commons.NameDefaultValue, commons.NameUsage) + port = flagSet.Int(commons.Port, commons.PortDefaultValue, commons.PortUsage) + version = flagSet.String(commons.Version, commons.VersionDefaultValue, commons.VersionUsage) ) func init() { - flag.Parse() + err := flagSet.Parse(os.Args[1:]) + if err != nil { + return + } } // Env is the environment where the application is running