Skip to content

Commit

Permalink
make selectable the timeline details view
Browse files Browse the repository at this point in the history
  • Loading branch information
ymtdzzz committed Mar 31, 2024
1 parent 40fe620 commit 9b6da0c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tuiexporter/internal/tui/component/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (p *TUIPages) createTracePage(store *telemetry.Store) *tview.Flex {

func (p *TUIPages) createTimelinePage() *tview.Flex {
page := tview.NewFlex().SetDirection(tview.FlexRow)
page.Box.SetTitle("Timeline").SetBorder(true)
page.Box.SetBorder(false)
page.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyEsc {
p.pages.SwitchToPage(PAGE_TRACES)
Expand Down
29 changes: 25 additions & 4 deletions tuiexporter/internal/tui/component/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/ymtdzzz/otel-tui/tuiexporter/internal/telemetry"
)

const TIMELINE_DETAILS_IDX = 1 // index of details in the base flex container

type spanTreeNode struct {
span *telemetry.SpanData
label string
Expand Down Expand Up @@ -65,6 +67,7 @@ func DrawTimeline(traceID string, cache *telemetry.TraceCache, setFocusFn func(p
SetBorders(true).
AddItem(title, 0, 0, 1, 1, 0, 0, false).
AddItem(timeline, 0, 1, 1, 1, 0, 0, false)
grid.SetTitle("Trace Timeline (t)").SetBorder(true)

var (
tvs []*tview.TextView
Expand All @@ -88,7 +91,7 @@ func DrawTimeline(traceID string, cache *telemetry.TraceCache, setFocusFn func(p
if totalRow > 0 {
currentRow := 0
setFocusFn(tvs[currentRow])
treeTitle := "Span Details"
treeTitle := "Details (d)"

grid.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
// FIXME: key 'j' and 'k' should be used to move the focus
Expand All @@ -100,7 +103,7 @@ func DrawTimeline(traceID string, cache *telemetry.TraceCache, setFocusFn func(p
setFocusFn(tvs[currentRow])

// update details
oldDetails := base.GetItem(1)
oldDetails := base.GetItem(TIMELINE_DETAILS_IDX)
base.RemoveItem(oldDetails)
details := getSpanInfoTree(nodes[currentRow].span, treeTitle)
base.AddItem(details, 0, 3, false)
Expand All @@ -113,7 +116,7 @@ func DrawTimeline(traceID string, cache *telemetry.TraceCache, setFocusFn func(p
details = getSpanInfoTree(nodes[currentRow].span, treeTitle)

// update details
oldDetails := base.GetItem(1)
oldDetails := base.GetItem(TIMELINE_DETAILS_IDX)
base.RemoveItem(oldDetails)
details := getSpanInfoTree(nodes[currentRow].span, treeTitle)
base.AddItem(details, 0, 3, false)
Expand All @@ -124,11 +127,25 @@ func DrawTimeline(traceID string, cache *telemetry.TraceCache, setFocusFn func(p
})
}

details.SetBorder(true).SetTitle("Span Details")
details.SetBorder(true).SetTitle("Details (d)")

base.AddItem(grid, 0, 7, true).
AddItem(details, 0, 3, false)

base.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
switch event.Rune() {
case 'd':
log.Printf("d key pressed")
setFocusFn(base.GetItem(TIMELINE_DETAILS_IDX))
return nil
case 't':
log.Printf("t key pressed")
setFocusFn(grid)
return nil
}
return event
})

return base, KeyMaps{
*tcell.NewEventKey(tcell.KeyUp, ' ', tcell.ModNone): "Move up",
*tcell.NewEventKey(tcell.KeyDown, ' ', tcell.ModNone): "Move down",
Expand Down Expand Up @@ -398,5 +415,9 @@ func getSpanInfoTree(span *telemetry.SpanData, title string) *tview.TreeView {
}
root.AddChild(links)

tree.SetSelectedFunc(func(node *tview.TreeNode) {
node.SetExpanded(!node.IsExpanded())
})

return tree
}
10 changes: 4 additions & 6 deletions tuiexporter/internal/tui/component/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,16 @@ func getTraceInfoTree(spans []*telemetry.SpanData) *tview.TreeView {
scopes := tview.NewTreeNode("Scopes")
for si := 0; si < rs.ScopeSpans().Len(); si++ {
ss := rs.ScopeSpans().At(si)
scope := tview.NewTreeNode(fmt.Sprintf("Scope %d", si))
scope := tview.NewTreeNode(ss.Scope().Name())
sschema := tview.NewTreeNode(fmt.Sprintf("schema url: %s", ss.SchemaUrl()))
scope.AddChild(sschema)

isc := tview.NewTreeNode("Instrumentation Scope")
isc.AddChild(tview.NewTreeNode(fmt.Sprintf("name: %s", ss.Scope().Name())))
isc.AddChild(tview.NewTreeNode(fmt.Sprintf("version: %s", ss.Scope().Version())))
isc.AddChild(tview.NewTreeNode(fmt.Sprintf("dropped attributes count: %d", ss.Scope().DroppedAttributesCount())))
scope.AddChild(tview.NewTreeNode(fmt.Sprintf("version: %s", ss.Scope().Version())))
scope.AddChild(tview.NewTreeNode(fmt.Sprintf("dropped attributes count: %d", ss.Scope().DroppedAttributesCount())))

attrs := tview.NewTreeNode("Attributes")
appendAttrsSorted(attrs, ss.Scope().Attributes().AsRaw())
isc.AddChild(attrs)
scope.AddChild(attrs)

scopes.AddChild(scope)
}
Expand Down
15 changes: 10 additions & 5 deletions tuiexporter/internal/tui/component/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestGetTraceInfoTree(t *testing.T) {
ResourceSpan: testdata.RSpans[1],
ScopeSpans: testdata.SSpans[2],
})
sw, sh := 55, 15
sw, sh := 55, 20
screen := tcell.NewSimulationScreen("")
screen.Init()
screen.SetSize(sw, sh)
Expand Down Expand Up @@ -172,10 +172,15 @@ func TestGetTraceInfoTree(t *testing.T) {
│ ├──resource index: %!s(int64=0)
│ └──service.name: test-service-1
└──Scopes
├──Scope 0
│ └──schema url:
└──Scope 1
└──schema url:
├──test-scope-1-1
│ ├──schema url:
│ ├──version: v0.0.1
│ ├──dropped attributes count: 2
│ └──Attributes
│ └──scope index: %!s(int64=0)
└──test-scope-1-2
├──schema url:
└──version: v0.0.1
`
assert.Equal(t, want, got.String())
}
Expand Down

0 comments on commit 9b6da0c

Please sign in to comment.