From 218b204e1b8e5f72e7ceac1d13448a8e6b8ee498 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 7 Feb 2021 19:26:12 +0800 Subject: [PATCH 1/2] qlog the quic-go version This only works when quic-go is used as a library. --- qlog/qlog.go | 19 +++++++++++++++++++ qlog/trace.go | 1 + 2 files changed, 20 insertions(+) diff --git a/qlog/qlog.go b/qlog/qlog.go index 993e979b..a53ceeac 100644 --- a/qlog/qlog.go +++ b/qlog/qlog.go @@ -6,6 +6,7 @@ import ( "io" "log" "net" + "runtime/debug" "sync" "time" @@ -17,6 +18,24 @@ import ( "github.com/francoispqt/gojay" ) +var quicGoVersion = "(devel)" + +func init() { + info, ok := debug.ReadBuildInfo() + if !ok { // no build info available. This happens when quic-go is not used as a library. + return + } + for _, d := range info.Deps { + if d.Path == "github.com/lucas-clemente/quic-go" { + quicGoVersion = d.Version + if d.Replace != nil { + quicGoVersion += " (replaced)" + } + break + } + } +} + const eventChanSize = 50 type tracer struct { diff --git a/qlog/trace.go b/qlog/trace.go index 4c299644..253ca270 100644 --- a/qlog/trace.go +++ b/qlog/trace.go @@ -17,6 +17,7 @@ func (l topLevel) MarshalJSONObject(enc *gojay.Encoder) { enc.StringKey("qlog_format", "NDJSON") enc.StringKey("qlog_version", "draft-02") enc.StringKeyOmitEmpty("title", "quic-go qlog") + enc.StringKey("code_version", quicGoVersion) enc.ObjectKey("trace", l.trace) } From 0437acd41da9b4425102f2c4f8390edea2b08b28 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 7 Feb 2021 19:57:42 +0800 Subject: [PATCH 2/2] set the qlogged quic-go version when building the interop runner image --- interop/Dockerfile | 4 ++-- qlog/qlog.go | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/interop/Dockerfile b/interop/Dockerfile index 76686d31..380aad37 100644 --- a/interop/Dockerfile +++ b/interop/Dockerfile @@ -19,8 +19,8 @@ RUN git clone https://github.com/lucas-clemente/quic-go && \ WORKDIR /quic-go RUN git rev-parse HEAD > commit.txt -RUN go build -o server interop/server/main.go && \ - go build -o client interop/client/main.go +RUN go build -o server -ldflags="-X github.com/lucas-clemente/quic-go/qlog.quicGoVersion=$(git describe --always --long --dirty)" interop/server/main.go +RUN go build -o client -ldflags="-X github.com/lucas-clemente/quic-go/qlog.quicGoVersion=$(git describe --always --long --dirty)" interop/client/main.go FROM martenseemann/quic-network-simulator-endpoint:latest diff --git a/qlog/qlog.go b/qlog/qlog.go index a53ceeac..d28700dd 100644 --- a/qlog/qlog.go +++ b/qlog/qlog.go @@ -18,9 +18,15 @@ import ( "github.com/francoispqt/gojay" ) +// Setting of this only works when quic-go is used as a library. +// When building a binary from this repository, the version can be set using the following go build flag: +// -ldflags="-X github.com/lucas-clemente/quic-go/qlog.quicGoVersion=foobar" var quicGoVersion = "(devel)" func init() { + if quicGoVersion != "(devel)" { // variable set by ldflags + return + } info, ok := debug.ReadBuildInfo() if !ok { // no build info available. This happens when quic-go is not used as a library. return @@ -29,7 +35,11 @@ func init() { if d.Path == "github.com/lucas-clemente/quic-go" { quicGoVersion = d.Version if d.Replace != nil { - quicGoVersion += " (replaced)" + if len(d.Replace.Version) > 0 { + quicGoVersion = d.Version + } else { + quicGoVersion += " (replaced)" + } } break }