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

run integration tests with qlog and metrics on CircleCI #2677

Merged
merged 1 commit into from
Jul 22, 2020
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
name: "Run self integration tests with race detector"
command: ginkgo -race -v -randomizeAllSpecs -trace integrationtests/self
- run:
name: "Run self integration tests with qlog"
command: ginkgo -v -randomizeAllSpecs -trace integrationtests/self -- -qlog
name: "Run self integration tests with qlog and metrics"
command: ginkgo -v -randomizeAllSpecs -trace integrationtests/self -- -qlog -metrics
go114:
<<: *test
interop-build:
Expand Down
56 changes: 36 additions & 20 deletions integrationtests/self/self_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/internal/utils"
"github.com/lucas-clemente/quic-go/logging"
"github.com/lucas-clemente/quic-go/metrics"
"github.com/lucas-clemente/quic-go/qlog"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -82,34 +83,25 @@ func (b *syncedBuffer) Reset() {
}

var (
logFileName string // the log file set in the ginkgo flags
logBufOnce sync.Once
logBuf *syncedBuffer
enableQlog bool
logFileName string // the log file set in the ginkgo flags
logBufOnce sync.Once
logBuf *syncedBuffer
enableQlog bool
enableMetrics bool

tlsConfig *tls.Config
tlsConfigLongChain *tls.Config
tlsClientConfig *tls.Config

tracer = qlog.NewTracer(func(p logging.Perspective, connectionID []byte) io.WriteCloser {
role := "server"
if p == logging.PerspectiveClient {
role = "client"
}
filename := fmt.Sprintf("log_%x_%s.qlog", connectionID, role)
fmt.Fprintf(GinkgoWriter, "Creating %s.\n", filename)
f, err := os.Create(filename)
Expect(err).ToNot(HaveOccurred())
bw := bufio.NewWriter(f)
return utils.NewBufferedWriteCloser(bw, f)
})
tracer logging.Tracer
)

// read the logfile command line flag
// to set call ginkgo -- -logfile=log.txt
func init() {
flag.StringVar(&logFileName, "logfile", "", "log file")
flag.BoolVar(&enableQlog, "qlog", false, "enable qlog")
// metrics won't be accessible anywhere, but it's useful to exercise the code
flag.BoolVar(&enableMetrics, "metrics", false, "enable metrics")

ca, caPrivateKey, err := generateCA()
if err != nil {
Expand Down Expand Up @@ -138,6 +130,33 @@ func init() {
RootCAs: root,
NextProtos: []string{alpn},
}

var qlogTracer, metricsTracer logging.Tracer
if enableQlog {
qlogTracer = qlog.NewTracer(func(p logging.Perspective, connectionID []byte) io.WriteCloser {
role := "server"
if p == logging.PerspectiveClient {
role = "client"
}
filename := fmt.Sprintf("log_%x_%s.qlog", connectionID, role)
fmt.Fprintf(GinkgoWriter, "Creating %s.\n", filename)
f, err := os.Create(filename)
Expect(err).ToNot(HaveOccurred())
bw := bufio.NewWriter(f)
return utils.NewBufferedWriteCloser(bw, f)
})
}
if enableMetrics {
metricsTracer = metrics.NewTracer()
}

if enableQlog && enableMetrics {
tracer = logging.NewMultiplexedTracer(qlogTracer, metricsTracer)
} else if enableQlog {
tracer = qlogTracer
} else if enableMetrics {
tracer = metricsTracer
}
}

func generateCA() (*x509.Certificate, *rsa.PrivateKey, error) {
Expand Down Expand Up @@ -263,9 +282,6 @@ func getQuicConfig(conf *quic.Config) *quic.Config {
} else {
conf = conf.Clone()
}
if !enableQlog {
return conf
}
conf.Tracer = tracer
return conf
}
Expand Down