From 741d346a69c47542895393af1c445b0f369d66d4 Mon Sep 17 00:00:00 2001 From: starsz Date: Sat, 28 Nov 2020 18:41:25 +0800 Subject: [PATCH] feat: show important information after manager-api started (#853) --- api/main.go | 12 ++++++++++++ api/test/shell/cli_test.sh | 32 +++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/api/main.go b/api/main.go index 336aac9230..4cd2c10b92 100644 --- a/api/main.go +++ b/api/main.go @@ -33,6 +33,16 @@ import ( "github.com/apisix/manager-api/log" ) +var Version string + +func printInfo() { + fmt.Fprint(os.Stdout, "The manager-api is running successfully!\n\n") + fmt.Fprintf(os.Stdout, "%-8s: %s\n", "Version", Version) + fmt.Fprintf(os.Stdout, "%-8s: %s:%d\n", "Listen", conf.ServerHost, conf.ServerPort) + fmt.Fprintf(os.Stdout, "%-8s: %s\n", "Loglevel", conf.ErrorLogLevel) + fmt.Fprintf(os.Stdout, "%-8s: %s\n\n", "Logfile", conf.ErrorLogPath) +} + func main() { if err := storage.InitETCDClient(conf.ETCDEndpoints); err != nil { @@ -65,6 +75,8 @@ func main() { } }() + printInfo() + sig := <-quit log.Infof("The Manager API server receive %s and start shutting down", sig.String()) diff --git a/api/test/shell/cli_test.sh b/api/test/shell/cli_test.sh index 8f142b1909..dd4bb2391c 100755 --- a/api/test/shell/cli_test.sh +++ b/api/test/shell/cli_test.sh @@ -18,6 +18,7 @@ # set -ex +VERSION=$(cat ./VERSION) clean_up() { git checkout conf/conf.yaml @@ -39,7 +40,7 @@ clean_logfile() { trap clean_up EXIT export GO111MODULE=on -go build -o ./manager-api . +go build -o ./manager-api -ldflags "-X main.Version=${VERSION}" . #default level: warn, path: logs/error.log @@ -93,3 +94,32 @@ if [[ `grep -c "INFO" ./error.log` -eq '0' ]]; then echo "failed: failed to write log on right level" exit 1 fi + +# test start info + +LOGLEVEL=$(cat conf/conf.yaml | awk '$1=="level:"{print $2}') +HOST=$(cat conf/conf.yaml | awk '$1=="host:"{print $2}') +PORT=$(cat conf/conf.yaml | awk '$1=="port:"{print $2}') +STDOUT=/tmp/manager-api +./manager-api &>/tmp/manager-api & +sleep 3 + +if [[ `grep -c "The manager-api is running successfully\!" ${STDOUT}` -ne '1' ]]; then + echo "failed: the manager server didn't show started info" + exit 1 +fi + +if [[ `grep -c "${VERSION}" ${STDOUT}` -ne '1' ]]; then + echo "failed: the manager server didn't show started info" + exit 1 +fi + +if [[ `grep -c "${LOGLEVEL}" ${STDOUT}` -ne '1' ]]; then + echo "failed: the manager server didn't show started info" + exit 1 +fi + +if [[ `grep -c "${HOST}:${PORT}" ${STDOUT}` -ne '1' ]]; then + echo "failed: the manager server didn't show started info" + exit 1 +fi