waterfall.go
waterfall.go - Overview
This file contains functions related to generating waterfall diagrams (also known as trace timelines) from trace data. It includes functionalities for merging intervals, finding selected spans, and traversing traces to extract the necessary information for visualization.
Detailed Documentation
SPAN_LIMIT_PER_REQUEST_FOR_WATERFALL float64
var (
SPAN_LIMIT_PER_REQUEST_FOR_WATERFALL float64 = 500
)
- Purpose: Defines a constant for limiting the number of spans in a waterfall diagram request.
SPAN_LIMIT_PER_REQUEST_FOR_WATERFALL
: Maximum number of spans to include in a waterfall diagram request.
Interval
struct
type Interval struct {
StartTime uint64
Duration uint64
Service string
}
- Purpose: Represents a time interval for a service.
StartTime
: Start time of the interval (Unix nanoseconds).Duration
: Duration of the interval (nanoseconds).Service
: Name of the service.
mergeIntervals(intervals []Interval) []Interval
func mergeIntervals(intervals []Interval) []Interval { ... }
- Purpose: Merges overlapping intervals into non-overlapping intervals.
- Parameters:
intervals
: Slice ofInterval
structs to merge.
- Returns: A slice of merged
Interval
structs.
- Parameters:
ContainsWaterfallSpan(slice []*model.Span, item *model.Span) bool
func ContainsWaterfallSpan(slice []*model.Span, item *model.Span) bool { ... }
- Purpose: Checks if a
model.Span
exists in a slice ofmodel.Span
pointers.- Parameters:
slice
: Slice of*model.Span
to search within.item
:*model.Span
to search for.
- Returns:
true
if the item is found in the slice,false
otherwise.
- Parameters:
findIndexForSelectedSpanFromPreOrder(spans []*model.Span, selectedSpanId string) int
func findIndexForSelectedSpanFromPreOrder(spans []*model.Span, selectedSpanId string) int { ... }
- Purpose: Finds the index of a selected span ID within a pre-order traversal of spans.
- Parameters:
spans
: Slice of*model.Span
representing the pre-order traversal.selectedSpanId
: The SpanID to search for.
- Returns: The index of the selected span, or -1 if not found.
- Parameters:
getPathFromRootToSelectedSpanId(node *model.Span, selectedSpanId string, uncollapsedSpans []string, isSelectedSpanIDUnCollapsed bool) (bool, []string)
func getPathFromRootToSelectedSpanId(node *model.Span, selectedSpanId string, uncollapsedSpans []string, isSelectedSpanIDUnCollapsed bool) (bool, []string) { ... }
- Purpose: Recursively finds the path (list of SpanIDs) from the root span to the selected span.
- Parameters:
node
: The current*model.Span
being traversed.selectedSpanId
: The SpanID to search for.uncollapsedSpans
: A slice of uncollapsed span IDsisSelectedSpanIDUnCollapsed
: Flag if selected span id is uncollapsed or not.
- Returns:
bool
:true
if the selected span is found in the subtree of the current node,false
otherwise.[]string
: Slice of SpanIDs representing the path from the root to the selected span.
- Parameters:
traverseTrace(span *model.Span, uncollapsedSpans []string, level uint64, isPartOfPreOrder bool, hasSibling bool, selectedSpanId string) []*model.Span
func traverseTrace(span *model.Span, uncollapsedSpans []string, level uint64, isPartOfPreOrder bool, hasSibling bool, selectedSpanId string) []*model.Span { ... }
- Purpose: Performs a traversal of the trace tree, building a pre-order traversal list and calculating subtree node counts.
- Parameters:
span
: The current*model.Span
being traversed.uncollapsedSpans
: Slice of SpanIDs that should not be collapsed.level
: The level of the current span in the trace tree.isPartOfPreOrder
: Boolean indicating whether the current span is part of the pre-order traversal.hasSibling
: Boolean indicating whether the current span has a sibling.selectedSpanId
: selected span id if any, else empty string.
- Returns: A slice of
*model.Span
representing the pre-order traversal of the trace.
- Parameters:
CalculateServiceTime(serviceIntervals map[string][]Interval) map[string]uint64
func CalculateServiceTime(serviceIntervals map[string][]Interval) map[string]uint64 { ... }
- Purpose: Calculates the total time spent in each service based on the provided intervals.
- Parameters:
serviceIntervals
: A map where keys are service names and values are slices ofInterval
structs.
- Returns: A map where keys are service names and values are the total time spent in that service (nanoseconds).
- Parameters:
GetSelectedSpans(uncollapsedSpans []string, selectedSpanID string, traceRoots []*model.Span, spanIdToSpanNodeMap map[string]*model.Span, isSelectedSpanIDUnCollapsed bool) ([]*model.Span, []string, string, string)
func GetSelectedSpans(uncollapsedSpans []string, selectedSpanID string, traceRoots []*model.Span, spanIdToSpanNodeMap map[string]*model.Span, isSelectedSpanIDUnCollapsed bool) ([]*model.Span, []string, string, string) { ... }
- Purpose: Retrieves a limited set of spans for a waterfall diagram request, focusing on spans around a selected span.
- Parameters:
uncollapsedSpans
: Slice of SpanIDs that should not be collapsed.selectedSpanID
: The ID of the selected span (if any).traceRoots
: Slice of root spans (*model.Span
) for the traces.spanIdToSpanNodeMap
: Map of SpanID to*model.Span
for quick lookup.isSelectedSpanIDUnCollapsed
: Flag if selected span id is uncollapsed or not.
- Returns:
[]*model.Span
: Slice of selected*model.Span
for the waterfall diagram.[]string
: Updated uncollapsedSpans slice.string
: Root service name.string
: Root service entrypoint.
- Parameters:
Include in Getting Started: NO