forked from quic-go/quic-go
http3: add the qlog event schema to trace header (#5383)
This commit is contained in:
15
http3/qlog/qlog_dir.go
Normal file
15
http3/qlog/qlog_dir.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package qlog
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
"github.com/quic-go/quic-go/qlog"
|
||||
"github.com/quic-go/quic-go/qlogwriter"
|
||||
)
|
||||
|
||||
const EventSchema = "urn:ietf:params:qlog:events:http3-12"
|
||||
|
||||
func DefaultConnectionTracer(ctx context.Context, isClient bool, connID quic.ConnectionID) qlogwriter.Trace {
|
||||
return qlog.DefaultConnectionTracerWithSchemas(ctx, isClient, connID, []string{qlog.EventSchema, EventSchema})
|
||||
}
|
||||
41
http3/qlog/qlog_dir_test.go
Normal file
41
http3/qlog/qlog_dir_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package qlog
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
"github.com/quic-go/quic-go/qlog"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestQLOGDIRSet(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
connID := quic.ConnectionIDFromBytes([]byte{1, 2, 3, 4})
|
||||
qlogDir := filepath.Join(tmpDir, "qlogs")
|
||||
t.Setenv("QLOGDIR", qlogDir)
|
||||
|
||||
tracer := DefaultConnectionTracer(context.Background(), true, connID)
|
||||
require.NotNil(t, tracer)
|
||||
|
||||
// adding and closing a producer makes the tracer close the file
|
||||
recorder := tracer.AddProducer()
|
||||
recorder.Close()
|
||||
|
||||
_, err := os.Stat(qlogDir)
|
||||
qlogDirCreated := !os.IsNotExist(err)
|
||||
require.True(t, qlogDirCreated)
|
||||
|
||||
entries, err := os.ReadDir(qlogDir)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, entries, 1)
|
||||
|
||||
data, err := os.ReadFile(filepath.Join(qlogDir, entries[0].Name()))
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Contains(t, string(data), EventSchema)
|
||||
require.Contains(t, string(data), qlog.EventSchema)
|
||||
}
|
||||
Reference in New Issue
Block a user