Skip to content

Commit f2936c8

Browse files
committed
perf: use limit=1 for resource attribute trace queries
fetchResourceAttrs only needs one span but was streaming the full result set from VictoriaTraces. Add limit=1 to the LogsQL query to avoid wasting bandwidth on long-lived instances with many spans.
1 parent bab7a5f commit f2936c8

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

test/e2e/benchmark/traces.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,38 @@ func (v *victoriaTraceProvider) fetchAllSpans(ctx context.Context, serviceName s
261261
}
262262

263263
// fetchResourceAttrs queries a single span and extracts OTEL resource attributes
264-
// from it. Returns nil if no spans are available.
264+
// from it. Uses limit=1 to avoid streaming the full span set on long-lived
265+
// instances. Returns nil if no spans are available.
265266
func (v *victoriaTraceProvider) fetchResourceAttrs(ctx context.Context, serviceName string) *resourceAttrs {
266-
scanner, body, err := v.fetchLogStream(ctx, serviceName)
267+
end := time.Now()
268+
query := fmt.Sprintf(`_stream:{resource_attr:service.name="%s"}`, serviceName)
269+
baseURL := strings.TrimRight(v.queryURL, "/")
270+
url := fmt.Sprintf("%s/select/logsql/query?query=%s&start=%s&end=%s&limit=1",
271+
baseURL,
272+
neturl.QueryEscape(query),
273+
v.startTime.Format(time.RFC3339Nano),
274+
end.Format(time.RFC3339Nano))
275+
276+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
277+
if err != nil {
278+
v.t.Logf("warning: failed to create resource attrs request: %v", err)
279+
return nil
280+
}
281+
282+
resp, err := http.DefaultClient.Do(req)
267283
if err != nil {
268284
v.t.Logf("warning: failed to fetch resource attrs: %v", err)
269285
return nil
270286
}
271-
defer body.Close()
287+
defer resp.Body.Close()
272288

289+
if resp.StatusCode != http.StatusOK {
290+
v.t.Logf("warning: unexpected status %d fetching resource attrs", resp.StatusCode)
291+
return nil
292+
}
293+
294+
scanner := bufio.NewScanner(resp.Body)
295+
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
273296
for scanner.Scan() {
274297
line := scanner.Bytes()
275298
if len(line) == 0 {

0 commit comments

Comments
 (0)