Skip to content

Commit

Permalink
feat: show important information after manager-api started (apache#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
starsz committed Nov 29, 2020
1 parent 67b0bfb commit 741d346
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
12 changes: 12 additions & 0 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -65,6 +75,8 @@ func main() {
}
}()

printInfo()

sig := <-quit
log.Infof("The Manager API server receive %s and start shutting down", sig.String())

Expand Down
32 changes: 31 additions & 1 deletion api/test/shell/cli_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#

set -ex
VERSION=$(cat ./VERSION)

clean_up() {
git checkout conf/conf.yaml
Expand All @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 741d346

Please sign in to comment.