Skip to content

Commit

Permalink
rename xoptest.Request.Trace -> Bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
muir committed Oct 3, 2022
1 parent 1429107 commit 0e5de30
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 74 deletions.
6 changes: 0 additions & 6 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

# required before ready to use in production

- misc

- remame xoptest.Request.Trace to Bundle

- repo

- create xop org, move repo there
Expand All @@ -13,8 +9,6 @@

- actually feed xopotel traces into Jaeger

- drop rest/ or finish it

- documentation

- propogation (add to README)
Expand Down
24 changes: 12 additions & 12 deletions xopjson/jsonlogger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,21 @@ func newChecker(t *testing.T, tlog *xoptest.TestLogger, config checkConfig) *che
}
for i, span := range tlog.Spans {
if debugTspan {
t.Logf("recorded span: %s - %s", span.Trace.Trace.SpanID().String(), span.Name)
t.Logf("recorded span: %s - %s", span.Bundle.Trace.SpanID().String(), span.Name)
}
_, ok := c.spanIndex[span.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span id %s", span.Trace.Trace.SpanID().String())
c.spanIndex[span.Trace.Trace.SpanID().String()] = i
_, ok := c.spanIndex[span.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span id %s", span.Bundle.Trace.SpanID().String())
c.spanIndex[span.Bundle.Trace.SpanID().String()] = i
}
for i, request := range tlog.Requests {
if debugTspan {
t.Logf("recorded request: %s - %s", request.Trace.Trace.SpanID().String(), request.Name)
t.Logf("recorded request: %s - %s", request.Bundle.Trace.SpanID().String(), request.Name)
}
_, ok := c.spanIndex[request.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span/request id %s", request.Trace.Trace.SpanID().String())
_, ok = c.requestIndex[request.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate request id %s", request.Trace.Trace.SpanID().String())
c.requestIndex[request.Trace.Trace.SpanID().String()] = i
_, ok := c.spanIndex[request.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span/request id %s", request.Bundle.Trace.SpanID().String())
_, ok = c.requestIndex[request.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate request id %s", request.Bundle.Trace.SpanID().String())
c.requestIndex[request.Bundle.Trace.SpanID().String()] = i
}
for spanID, versions := range c.sequencing {
if c.config.minVersions == c.config.maxVersions {
Expand Down Expand Up @@ -291,7 +291,7 @@ func (c *checker) check(t *testing.T, data string) {
}
}
for _, span := range c.tlog.Spans {
spanAttributes := c.accumulatedSpans[span.Trace.Trace.SpanID().String()]
spanAttributes := c.accumulatedSpans[span.Bundle.Trace.SpanID().String()]
if len(span.Metadata) != 0 || len(spanAttributes) != 0 {
if c.config.hasAttributesObject {
t.Logf("comparing metadata: %+v vs %+v", span.Metadata, spanAttributes)
Expand All @@ -302,7 +302,7 @@ func (c *checker) check(t *testing.T, data string) {
}
}
for _, span := range c.tlog.Requests {
spanAttributes := c.accumulatedSpans[span.Trace.Trace.SpanID().String()]
spanAttributes := c.accumulatedSpans[span.Bundle.Trace.SpanID().String()]
if len(span.Metadata) != 0 || len(spanAttributes) != 0 {
if c.config.hasAttributesObject {
t.Logf("comparing metadata: %+v vs %+v", span.Metadata, spanAttributes)
Expand Down
24 changes: 12 additions & 12 deletions xopmiddle/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,30 +187,30 @@ func TestHandlerFuncMiddleware(t *testing.T) {

require.Equal(t, 1, len(tLog.Requests), "one request")
request := tLog.Requests[0]
assert.Equal(t, hc.expectParentTrace, request.Trace.ParentTrace.TraceID().String(), "parent traceID")
assert.Equal(t, hc.expectParentSpan, request.Trace.ParentTrace.SpanID().String(), "parent spanID")
assert.Equal(t, "00", request.Trace.ParentTrace.Version().String(), "parent version")
assert.Equal(t, hc.expectParentFlags, request.Trace.ParentTrace.Flags().String(), "parent flags")
assert.Equal(t, hc.expectParentTrace, request.Bundle.ParentTrace.TraceID().String(), "parent traceID")
assert.Equal(t, hc.expectParentSpan, request.Bundle.ParentTrace.SpanID().String(), "parent spanID")
assert.Equal(t, "00", request.Bundle.ParentTrace.Version().String(), "parent version")
assert.Equal(t, hc.expectParentFlags, request.Bundle.ParentTrace.Flags().String(), "parent flags")

if hc.expectTrace == "" {
hc.expectTrace = hc.expectParentTrace
}

if hc.expectTrace == "random" {
assert.False(t, request.Trace.Trace.TraceID().IsZero(), "trace traceID zero")
assert.False(t, request.Bundle.Trace.TraceID().IsZero(), "trace traceID zero")
} else {
assert.Equal(t, hc.expectTrace, request.Trace.Trace.TraceID().String(), "trace traceID")
assert.Equal(t, hc.expectTrace, request.Bundle.Trace.TraceID().String(), "trace traceID")
}
if hc.expectSpan != "" {
assert.Equal(t, hc.expectSpan, request.Trace.Trace.SpanID().String(), "trace spanID")
assert.Equal(t, hc.expectSpan, request.Bundle.Trace.SpanID().String(), "trace spanID")
} else {
assert.False(t, request.Trace.Trace.SpanID().IsZero(), "trace spanID is zero")
assert.NotEqual(t, hc.expectParentSpan, request.Trace.Trace.SpanID().String(), "trace spanID")
assert.False(t, request.Bundle.Trace.SpanID().IsZero(), "trace spanID is zero")
assert.NotEqual(t, hc.expectParentSpan, request.Bundle.Trace.SpanID().String(), "trace spanID")
}
assert.Equal(t, "00", request.Trace.Trace.Version().String(), "trace version")
assert.Equal(t, hc.expectFlags, request.Trace.Trace.Flags().String(), "trace flags")
assert.Equal(t, "00", request.Bundle.Trace.Version().String(), "trace version")
assert.Equal(t, hc.expectFlags, request.Bundle.Trace.Flags().String(), "trace flags")

assert.Equal(t, request.Trace.Trace.String(), w.Header().Get("traceresponse"), "trace response header")
assert.Equal(t, request.Bundle.Trace.String(), w.Header().Get("traceresponse"), "trace response header")
})
}
})
Expand Down
24 changes: 12 additions & 12 deletions xopotel/otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,21 @@ func newChecker(t *testing.T, tlog *xoptest.TestLogger, spansNotIntTest []string
}
for i, span := range tlog.Spans {
if debugTspan {
t.Logf("recorded span: %s - %s", span.Trace.Trace.SpanID().String(), span.Name)
t.Logf("recorded span: %s - %s", span.Bundle.Trace.SpanID().String(), span.Name)
}
_, ok := c.spanIndex[span.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span id %s", span.Trace.Trace.SpanID().String())
c.spanIndex[span.Trace.Trace.SpanID().String()] = i
_, ok := c.spanIndex[span.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span id %s", span.Bundle.Trace.SpanID().String())
c.spanIndex[span.Bundle.Trace.SpanID().String()] = i
}
for i, request := range tlog.Requests {
if debugTspan {
t.Logf("recorded request: %s - %s", request.Trace.Trace.SpanID().String(), request.Name)
t.Logf("recorded request: %s - %s", request.Bundle.Trace.SpanID().String(), request.Name)
}
_, ok := c.spanIndex[request.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span/request id %s", request.Trace.Trace.SpanID().String())
_, ok = c.requestIndex[request.Trace.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate request id %s", request.Trace.Trace.SpanID().String())
c.requestIndex[request.Trace.Trace.SpanID().String()] = i
_, ok := c.spanIndex[request.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate span/request id %s", request.Bundle.Trace.SpanID().String())
_, ok = c.requestIndex[request.Bundle.Trace.SpanID().String()]
assert.Falsef(t, ok, "duplicate request id %s", request.Bundle.Trace.SpanID().String())
c.requestIndex[request.Bundle.Trace.SpanID().String()] = i
}
return c
}
Expand All @@ -279,13 +279,13 @@ func (c *checker) check(t *testing.T, data string) {
}
}
for _, span := range c.tlog.Spans {
spanAttributes := c.accumulatedSpans[span.Trace.Trace.SpanID().String()]
spanAttributes := c.accumulatedSpans[span.Bundle.Trace.SpanID().String()]
if len(span.Metadata) != 0 || len(spanAttributes.data) != 0 {
compareData(t, span.Metadata, span.MetadataType, "xoptest.Metadata", spanAttributes.data, "xoptel.span.generic", true)
}
}
for _, span := range c.tlog.Requests {
spanAttributes := c.accumulatedSpans[span.Trace.Trace.SpanID().String()]
spanAttributes := c.accumulatedSpans[span.Bundle.Trace.SpanID().String()]
if len(span.Metadata) != 0 || len(spanAttributes.data) != 0 {
compareData(t, span.Metadata, span.MetadataType, "xoptest.Metadata", spanAttributes.data, "xopotel.span.generic", true)
}
Expand Down
2 changes: 1 addition & 1 deletion xopresty/resty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestXopResty(t *testing.T) {
assert.NoError(t, err, "Get")
assert.True(t, called, "handler called")

text := "T1.1.1: traceresponse http.remote_trace=" + farSideSpan.Trace.Trace.String()
text := "T1.1.1: traceresponse http.remote_trace=" + farSideSpan.Bundle.Trace.String()
assert.Equalf(t, 1, tLog.CountLines(xoptest.TextContains(text)), "count lines with '%s'", text)

for _, text := range tc.expectedText {
Expand Down
26 changes: 13 additions & 13 deletions xoptest/testlogger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions xoptest/testlogger.zzzgo
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type Span struct {
lock sync.Mutex
testLogger *TestLogger
RequestNum int // sequence of requests with the same traceID
Trace trace.Bundle
Bundle trace.Bundle
IsRequest bool
Parent *Span
Spans []*Span
Expand Down Expand Up @@ -163,13 +163,13 @@ func (log *TestLogger) ReferencesKept() bool { return true }
func (log *TestLogger) SetErrorReporter(func(error)) {}

// Request is a required method for xopbase.Logger
func (log *TestLogger) Request(ctx context.Context, ts time.Time, span trace.Bundle, name string) xopbase.Request {
func (log *TestLogger) Request(ctx context.Context, ts time.Time, bundle trace.Bundle, name string) xopbase.Request {
log.lock.Lock()
defer log.lock.Unlock()
s := &Span{
testLogger: log,
IsRequest: true,
Trace: span,
Bundle: bundle,
StartTime: ts,
Name: name,
Metadata: make(map[string]interface{}),
Expand All @@ -188,13 +188,13 @@ func (log *TestLogger) Request(ctx context.Context, ts time.Time, span trace.Bun

// must hold a lock to call setShortRequest
func (span *Span) setShortRequest() {
ts := span.Trace.Trace.GetTraceID().String()
ts := span.Bundle.Trace.GetTraceID().String()
if ti, ok := span.testLogger.traceMap[ts]; ok {
ti.requestCount++
span.RequestNum = ti.requestCount
ti.spans[span.Trace.Trace.SpanID().String()] = span
ti.spans[span.Bundle.Trace.SpanID().String()] = span
span.Short = fmt.Sprintf("T%d.%d", ti.traceNum, ti.requestCount)
span.testLogger.t.Log("Start request " + span.Short + "=" + span.Trace.Trace.String() + " " + span.Name)
span.testLogger.t.Log("Start request " + span.Short + "=" + span.Bundle.Trace.String() + " " + span.Name)
return
}
span.testLogger.traceCount++
Expand All @@ -203,21 +203,21 @@ func (span *Span) setShortRequest() {
requestCount: 1,
traceNum: span.testLogger.traceCount,
spans: map[string]*Span{
span.Trace.Trace.SpanID().String(): span,
span.Bundle.Trace.SpanID().String(): span,
},
}
span.Short = fmt.Sprintf("T%d.%d", span.testLogger.traceCount, 1)
span.testLogger.t.Log("Start request " + span.Short + "=" + span.Trace.Trace.String() + " " + span.Name)
span.testLogger.t.Log("Start request " + span.Short + "=" + span.Bundle.Trace.String() + " " + span.Name)
}

// must hold a lock to call setShortSpan
func (span *Span) setShortSpan() {
ts := span.Trace.Trace.GetTraceID().String()
ts := span.Bundle.Trace.GetTraceID().String()
ti := span.testLogger.traceMap[ts]
span.RequestNum = span.Parent.RequestNum
ti.spans[span.Trace.Trace.SpanID().String()] = span
ti.spans[span.Bundle.Trace.SpanID().String()] = span
span.Short = fmt.Sprintf("T%d.%d%s", ti.traceNum, span.RequestNum, span.SequenceCode)
span.testLogger.t.Log("Start span " + span.Short + "=" + span.Trace.Trace.String() + " " + span.Name)
span.testLogger.t.Log("Start span " + span.Short + "=" + span.Bundle.Trace.String() + " " + span.Name)
}

// Done is a required method for xopbase.Span
Expand Down Expand Up @@ -263,14 +263,14 @@ func (span *Span) ID() string { return span.testLogger.id }
func (span *Span) SetErrorReporter(func(error)) {}

// Span is a required method for xopbase.Span
func (span *Span) Span(ctx context.Context, ts time.Time, traceSpan trace.Bundle, name string, spanSequenceCode string) xopbase.Span {
func (span *Span) Span(ctx context.Context, ts time.Time, bundle trace.Bundle, name string, spanSequenceCode string) xopbase.Span {
span.testLogger.lock.Lock()
defer span.testLogger.lock.Unlock()
span.lock.Lock()
defer span.lock.Unlock()
n := &Span{
testLogger: span.testLogger,
Trace: traceSpan,
Bundle: bundle,
StartTime: ts,
Name: name,
Metadata: make(map[string]interface{}),
Expand Down
10 changes: 5 additions & 5 deletions xoptest/xoptestutil/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ func DumpEvents(t testing.TB, tlog *xoptest.TestLogger) {
case xoptest.LineEvent:
o = append(o, fmt.Sprintf("line: %s", event.Line.Text))
case xoptest.SpanStart:
o = append(o, fmt.Sprintf("spanstart: %s", event.Span.Trace.Trace.SpanID().String()))
o = append(o, fmt.Sprintf("spanstart: %s", event.Span.Bundle.Trace.SpanID().String()))
case xoptest.SpanDone:
o = append(o, fmt.Sprintf("spandone: %s", event.Span.Trace.Trace.SpanID().String()))
o = append(o, fmt.Sprintf("spandone: %s", event.Span.Bundle.Trace.SpanID().String()))

case xoptest.RequestStart:
o = append(o, fmt.Sprintf("requeststart: %s", event.Span.Trace.Trace.SpanID().String()))
o = append(o, fmt.Sprintf("requeststart: %s", event.Span.Bundle.Trace.SpanID().String()))
case xoptest.RequestDone:
o = append(o, fmt.Sprintf("requestdone: %s", event.Span.Trace.Trace.SpanID().String()))
o = append(o, fmt.Sprintf("requestdone: %s", event.Span.Bundle.Trace.SpanID().String()))
case xoptest.FlushEvent:
o = append(o, "Flush!")
case xoptest.CustomEvent:
o = append(o, "Custom: "+event.Msg)
case xoptest.MetadataSet:
o = append(o, fmt.Sprintf("Metadata on %s: %s", event.Span.Trace.Trace.SpanID().String(), event.Msg))
o = append(o, fmt.Sprintf("Metadata on %s: %s", event.Span.Bundle.Trace.SpanID().String(), event.Msg))
default:
o = append(o, "unknown event")
}
Expand Down

0 comments on commit 0e5de30

Please sign in to comment.