Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add logging support #389

Merged
merged 13 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
go-version: 1.22
- name: Unit Test
run: |
make test-all-backend
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
go-version: 1.22
- name: API Test
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
go-version: 1.22
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
env:
Expand All @@ -91,7 +91,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
go-version: 1.22
- name: Set output
id: vars
run: echo "tag=$(git describe --tags)" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -126,7 +126,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
go-version: 1.22
- name: Use Node.js
uses: actions/setup-node@v3
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
go-version: 1.22.2
- name: Use Node.js
uses: actions/setup-node@v3
with:
Expand All @@ -46,7 +46,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.20.x
go-version: 1.22.2
- name: Unit Test
run: |
make test-all-backend
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ COPY console/atest-ui .
RUN npm install --ignore-scripts --registry=https://registry.npmmirror.com
RUN npm run build-only

FROM docker.io/golang:1.20 AS builder
FROM docker.io/golang:1.22.2 AS builder

ARG VERSION
ARG GOPROXY
Expand Down
11 changes: 8 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"io"
"log"
"net/http"
"os"
"os/exec"
Expand All @@ -32,10 +31,12 @@ import (

"github.com/linuxsuren/api-testing/pkg/apispec"
"github.com/linuxsuren/api-testing/pkg/limit"
"github.com/linuxsuren/api-testing/pkg/logging"
"github.com/linuxsuren/api-testing/pkg/runner"
"github.com/linuxsuren/api-testing/pkg/runner/monitor"
"github.com/linuxsuren/api-testing/pkg/testing"
"github.com/linuxsuren/api-testing/pkg/util"

fakeruntime "github.com/linuxsuren/go-fake-runtime"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -71,6 +72,10 @@ type runOption struct {
loader testing.Loader
}

var (
runLogger = logging.DefaultLogger(logging.LogLevelInfo).WithName("run")
)

func newDefaultRunOption() *runOption {
return &runOption{
reporter: runner.NewMemoryTestReporter(nil, ""),
Expand Down Expand Up @@ -198,7 +203,7 @@ func (o *runOption) startMonitor() (err error) {
execer := fakeruntime.NewDefaultExecerWithContext(o.context)
go func(socketURL, plugin string) {
if err = execer.RunCommandWithIO(plugin, "", os.Stdout, os.Stderr, nil, "server", "--socket", socketURL); err != nil {
log.Printf("failed to start %s, error: %v", socketURL, err)
runLogger.Info("failed to start", "socketURL", socketURL, " error", err.Error())
yuluo-yx marked this conversation as resolved.
Show resolved Hide resolved
}
}(sockFile, monitorBin)

Expand Down Expand Up @@ -287,7 +292,7 @@ func (o *runOption) runSuiteWithDuration(loader testing.Loader) (err error) {
defer sem.Release(1)
defer wait.Done()
defer func() {
log.Println("routing end with", time.Since(now))
runLogger.Info("routing end with", "time", time.Since(now))
}()

dataContext := getDefaultContext()
Expand Down
19 changes: 12 additions & 7 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"context"
"errors"
"fmt"
"log"
"net"
"net/http"
"os"
Expand All @@ -37,13 +36,15 @@ import (
pprof "net/http/pprof"

"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/linuxsuren/api-testing/pkg/logging"
"github.com/linuxsuren/api-testing/pkg/oauth"
template "github.com/linuxsuren/api-testing/pkg/render"
"github.com/linuxsuren/api-testing/pkg/server"
"github.com/linuxsuren/api-testing/pkg/testing"
"github.com/linuxsuren/api-testing/pkg/testing/remote"
"github.com/linuxsuren/api-testing/pkg/util"
fakeruntime "github.com/linuxsuren/go-fake-runtime"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand All @@ -55,6 +56,10 @@ import (
"google.golang.org/grpc/reflection"
)

var (
serverLogger = logging.DefaultLogger(logging.LogLevelInfo).WithName("server")
)

func createServerCmd(execer fakeruntime.Execer, httpServer server.HTTPServer) (c *cobra.Command) {
opt := &serverOption{
httpServer: httpServer,
Expand Down Expand Up @@ -228,15 +233,15 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {
reflection.Register(gRPCServer)
}
server.RegisterRunnerServer(s, remoteServer)
log.Printf("gRPC server listening at %v", lis.Addr())
serverLogger.Info("gRPC server listening at", "addr", lis.Addr())
s.Serve(lis)
}()

go func() {
<-clean
log.Println("stopping the extensions")
serverLogger.Info("stopping the extensions")
storeExtMgr.StopAll()
log.Println("stopping the server")
serverLogger.Info("stopping the server")
_ = lis.Close()
_ = o.httpServer.Shutdown(ctx)
}()
Expand Down Expand Up @@ -280,8 +285,8 @@ func (o *serverOption) runE(cmd *cobra.Command, args []string) (err error) {

debugHandler(mux, remoteServer)
o.httpServer.WithHandler(mux)
log.Printf("HTTP server listening at %v", httplis.Addr())
log.Printf("Server is running.")
serverLogger.Info("HTTP server listening at", "addr", httplis.Addr())
serverLogger.Info("Server is running.")
err = o.httpServer.Serve(httplis)
err = util.IgnoreErrServerClosed(err)
}
Expand Down Expand Up @@ -354,7 +359,7 @@ func debugHandler(mux *runtime.ServeMux, remoteServer server.RunnerServer) {
sub := pathParams["sub"]
extName := r.URL.Query().Get("name")
if extName != "" && remoteServer != nil {
log.Println("get pprof of extension:", extName)
serverLogger.Info("get pprof of extension", "name", extName)

ctx := metadata.NewIncomingContext(r.Context(), metadata.New(map[string]string{
server.HeaderKeyStoreName: extName,
Expand Down
60 changes: 33 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/linuxsuren/api-testing

go 1.20
go 1.22.2

require (
github.com/Masterminds/sprig/v3 v3.2.3
Expand All @@ -10,6 +10,10 @@ require (
github.com/expr-lang/expr v1.15.6
github.com/flopp/go-findfont v0.1.0
github.com/ghodss/yaml v1.0.0
github.com/go-logr/logr v1.4.1
github.com/go-logr/zapr v1.3.0
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0
github.com/gorilla/mux v1.8.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0
github.com/h2non/gock v1.2.0
Expand All @@ -18,62 +22,64 @@ require (
github.com/linuxsuren/go-fake-runtime v0.0.4
github.com/linuxsuren/go-service v0.0.0-20231225060426-efabcd3a5161
github.com/linuxsuren/unstructured v0.0.1
github.com/prometheus/client_golang v1.16.0
github.com/prometheus/client_golang v1.19.0
github.com/signintech/gopdf v0.18.0
github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/tidwall/gjson v1.14.4
github.com/xeipuuv/gojsonschema v1.2.0
golang.org/x/oauth2 v0.14.0
golang.org/x/sync v0.3.0
google.golang.org/grpc v1.57.0
google.golang.org/protobuf v1.31.0
go.uber.org/zap v1.27.0
golang.org/x/oauth2 v0.18.0
golang.org/x/sync v0.6.0
google.golang.org/grpc v1.62.1
google.golang.org/protobuf v1.33.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect
github.com/cucumber/messages-go/v16 v16.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-memdb v1.3.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/huandu/xstrings v1.4.0 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.0 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.50.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sys v0.15.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading
Loading