Skip to content

Commit 2335100

Browse files
committed
feat(backend): refactor advance info
1 parent 45e7b23 commit 2335100

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

backend/modules/observability/domain/trace/entity/loop_span/span.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,11 @@ func (s *Span) ClipSpan() {
550550
}
551551

552552
func (s SpanList) Stat(ctx context.Context) (inputTokens, outputTokens int64, err error) {
553-
modelSpans := s.FilterModelSpans()
554-
for _, v := range modelSpans {
553+
filter := GetModelSpansFilter()
554+
for _, v := range s {
555+
if !filter.Satisfied(v) {
556+
continue
557+
}
555558
in, out, err := v.getTokens(ctx)
556559
if err != nil {
557560
return -1, -1, err
@@ -572,10 +575,7 @@ func (s SpanList) FilterSpans(f *FilterFields) SpanList {
572575
return ret
573576
}
574577

575-
func (s SpanList) FilterModelSpans() SpanList {
576-
if len(s) == 0 {
577-
return s
578-
}
578+
func GetModelSpansFilter() *FilterFields {
579579
modelFilter := &FilterFields{
580580
QueryAndOr: ptr.Of(QueryAndOrEnumOr),
581581
FilterFields: []*FilterField{
@@ -594,7 +594,7 @@ func (s SpanList) FilterModelSpans() SpanList {
594594
},
595595
},
596596
}
597-
return s.FilterSpans(modelFilter)
597+
return modelFilter
598598
}
599599

600600
func (s SpanList) SortByStartTime(desc bool) {

backend/modules/observability/domain/trace/entity/loop_span/span_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,14 @@ func TestSpanList_FilterModelSpans(t *testing.T) {
744744

745745
for _, tt := range tests {
746746
t.Run(tt.name, func(t *testing.T) {
747-
got := tt.spans.FilterModelSpans()
748-
assert.Equal(t, tt.want, len(got))
747+
f := GetModelSpansFilter()
748+
got := 0
749+
for _, span := range tt.spans {
750+
if f.Satisfied(span) {
751+
got++
752+
}
753+
}
754+
assert.Equal(t, tt.want, got)
749755
})
750756
}
751757
}

backend/modules/observability/domain/trace/service/trace_service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ func (r *TraceServiceImpl) GetTracesAdvanceInfo(ctx context.Context, req *GetTra
596596
loop_span.SpanFieldInput,
597597
loop_span.SpanFieldOutput,
598598
},
599+
Filters: loop_span.GetModelSpansFilter(),
599600
}
600601
st := time.Now()
601602
spans, err := r.traceRepo.GetTrace(ctx, qReq)

0 commit comments

Comments
 (0)