Unverified Commit bc26003c authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Remove legacy trace tuples and inline sample validation

Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent 3cea9e0c
......@@ -81,7 +81,7 @@ pub struct TraceSpanInfo {
/// Average corrected duration across spans in the group.
pub avg_corrected_duration: Option<i64>,
/// Raw span ID of the group's example span, whose `cpuDuration`,
/// `correctedDuration` and `memorySamples` are the ones reported here.
/// `correctedDuration`, `memorySummary` and `sampleSeries` are reported here.
/// First in execution order — *not* the largest, so it can badly understate
/// a group's allocations. Use `heaviestSpanId` for those.
pub first_span_id: Option<String>,
......@@ -91,8 +91,9 @@ pub struct TraceSpanInfo {
/// Total bytes allocated by this span and all its children.
///
/// For aggregated groups this is the group total, unlike `cpuDuration`,
/// `correctedDuration` and `memorySamples`, which describe the example span
/// only. Every allocation field below follows this field, not those.
/// `correctedDuration`, `memorySummary` and `sampleSeries`, which describe
/// the example span only. Every allocation field below follows this field,
/// not those.
pub allocations: i64,
/// Total bytes deallocated by this span and all its children.
/// Group total for aggregated spans.
......@@ -130,28 +131,19 @@ pub struct TraceSpanInfo {
/// Number of allocation operations by this span itself, excluding children.
/// Group total for aggregated spans.
pub self_allocation_count: i64,
/// Process samples recorded while this span (or its example span, for
/// aggregated groups) was live.
/// Summary of TurboMalloc readings while this span (or its example span,
/// for aggregated groups) was live; absent when its range holds none.
///
/// **Process-wide, not per-span.** One global series is sliced by the
/// span's time range, so spans that overlap in time report identical values
/// no matter what each allocated. Rank concurrent work by the allocation
/// fields instead.
///
/// Each entry is `[ts_offset_from_span_start_in_ticks, bytes, pressure,
/// footprint, active_worker_threads]`: `bytes` is TurboMalloc memory usage,
/// `pressure` is the memory-pressure byte (0 = no pressure, higher = more
/// pressure), `footprint` is the process memory footprint (RSS) in bytes
/// (0 = not reported by the platform), and `active_worker_threads` counts
/// non-parked Tokio scheduler workers. `100 ticks = 1 µs`. Capped and
/// downsampled by the store.
pub memory_samples: Vec<Vec<i64>>,
/// Summary of `memorySamples`; absent when the span's range holds none.
/// Unlike the allocation counters these are absolute live-heap readings, so
/// span's time range, so overlapping ranges report the same readings no
/// matter what each allocated. Rank concurrent work by allocation fields;
/// `peak` is the figure to quote for memory actually in use.
///
/// Computed from at most 200 temporary peak-memory rows, independently
/// of whether or how many sample values are requested.
pub memory_summary: Option<TraceMemorySummary>,
/// Requested value arrays; absent unless `samples` was supplied.
/// MCP flattens this internal object and omits the legacy tuples above.
/// MCP flattens this internal object to the four optional value arrays.
pub sample_series: Option<TraceSpanSampleSeries>,
/// Descendants of this span, populated only when `depth > 1`.
pub children: Vec<TraceSpanInfo>,
......@@ -159,6 +151,8 @@ pub struct TraceSpanInfo {
/// Requested process/global value series. Captured memory/pressure/workers
/// are grouped by recorded timestamps; concurrency uses equal-time segments.
/// Memory is TurboMalloc live bytes, pressure is the recorded pressure byte,
/// and workers are non-parked Tokio scheduler workers (not the blocking pool).
#[napi(object)]
pub struct TraceSpanSampleSeries {
pub memory_samples: Vec<i64>,
......@@ -234,19 +228,7 @@ fn convert_span(s: turbopack_trace_server::SpanInfo) -> TraceSpanInfo {
self_deallocations: s.self_deallocations as i64,
self_persistent_allocations: s.self_persistent_allocations as i64,
self_allocation_count: s.self_allocation_count as i64,
memory_samples: s
.memory_samples
.into_iter()
.map(|(ts, mem, pressure, footprint, workers)| {
vec![
ts,
mem as i64,
pressure as i64,
footprint as i64,
workers as i64,
]
})
.collect(),
memory_summary: s.memory_summary.map(|m| TraceMemorySummary {
count: m.count as u32,
start: m.start as i64,
......
......@@ -36,7 +36,6 @@ import type {
import type { NextBuildOptions } from '../cli/next-build.js'
import type { NextTypegenOptions } from '../cli/next-typegen.js'
import type { NextPostBuildOptions } from '../cli/next-post-build.js'
import { parseTraceSampleCount } from '../cli/internal/query-trace'
import { ensureProfilesDir } from '../lib/profiles-dir'
import type { NextRequestInsightsOptions } from '../cli/next-request-insights.js'
......@@ -858,7 +857,15 @@ internal
new Option(
'--samples <N>',
'Include up to N memory, pressure, active Tokio worker, and concurrency values per span. Omit for summaries only; 0 returns empty arrays.'
).argParser(parseTraceSampleCount)
).argParser((value: string) => {
const count = Number(value)
if (!/^\d+$/.test(value) || !Number.isSafeInteger(count) || count < 0) {
throw new InvalidArgumentError(
'Sample count must be a nonnegative safe integer.'
)
}
return count
})
)
.addHelpText('after', ({ command }) => {
const port = (command.opts() as { port?: number }).port ?? 5748
......
......@@ -886,7 +886,7 @@ export interface TraceSpanInfo {
avgCorrectedDuration?: number
/**
* Raw span ID of the group's example span, whose `cpuDuration`,
* `correctedDuration` and `memorySamples` are the ones reported here.
* `correctedDuration`, `memorySummary` and `sampleSeries` are reported here.
* First in execution order — *not* the largest, so it can badly understate
* a group's allocations. Use `heaviestSpanId` for those.
*/
......@@ -900,8 +900,9 @@ export interface TraceSpanInfo {
* Total bytes allocated by this span and all its children.
*
* For aggregated groups this is the group total, unlike `cpuDuration`,
* `correctedDuration` and `memorySamples`, which describe the example span
* only. Every allocation field below follows this field, not those.
* `correctedDuration`, `memorySummary` and `sampleSeries`, which describe
* the example span only. Every allocation field below follows this field,
* not those.
*/
allocations: number
/**
......@@ -955,32 +956,21 @@ export interface TraceSpanInfo {
*/
selfAllocationCount: number
/**
* Process samples recorded while this span (or its example span, for
* aggregated groups) was live.
* Summary of TurboMalloc readings while this span (or its example span,
* for aggregated groups) was live; absent when its range holds none.
*
* **Process-wide, not per-span.** One global series is sliced by the
* span's time range, so spans that overlap in time report identical values
* no matter what each allocated. Rank concurrent work by the allocation
* fields instead.
*
* Each entry is `[ts_offset_from_span_start_in_ticks, bytes, pressure,
* footprint, active_worker_threads]`: `bytes` is TurboMalloc memory usage,
* `pressure` is the memory-pressure byte (0 = no pressure, higher = more
* pressure), `footprint` is the process memory footprint (RSS) in bytes
* (0 = not reported by the platform), and `active_worker_threads` counts
* non-parked Tokio scheduler workers. `100 ticks = 1 µs`. Capped and
* downsampled by the store.
*/
memorySamples: Array<Array<number>>
/**
* Summary of `memorySamples`; absent when the span's range holds none.
* Unlike the allocation counters these are absolute live-heap readings, so
* span's time range, so overlapping ranges report the same readings no
* matter what each allocated. Rank concurrent work by allocation fields;
* `peak` is the figure to quote for memory actually in use.
*
* Computed from at most 200 temporary peak-memory rows, independently
* of whether or how many sample values are requested.
*/
memorySummary?: TraceMemorySummary
/**
* Requested value arrays; absent unless `samples` was supplied.
* MCP flattens this internal object and omits the legacy tuples above.
* MCP flattens this internal object to the four optional value arrays.
*/
sampleSeries?: TraceSpanSampleSeries
/** Descendants of this span, populated only when `depth > 1`. */
......@@ -990,6 +980,8 @@ export interface TraceSpanInfo {
/**
* Requested process/global value series. Captured memory/pressure/workers
* are grouped by recorded timestamps; concurrency uses equal-time segments.
* Memory is TurboMalloc live bytes, pressure is the recorded pressure byte,
* and workers are non-parked Tokio scheduler workers (not the blocking pool).
*/
export interface TraceSpanSampleSeries {
memorySamples: Array<number>
......
......@@ -8,20 +8,8 @@
* Usage: next internal query-trace [options]
*/
import { InvalidArgumentError } from 'next/dist/compiled/commander'
const DEFAULT_MCP_PORT = 5748 // Keep in sync with turbo-trace-server.ts
export function parseTraceSampleCount(value: string): number {
const count = Number(value)
if (!/^\d+$/.test(value) || !Number.isSafeInteger(count) || count < 0) {
throw new InvalidArgumentError(
'Sample count must be a nonnegative safe integer.'
)
}
return count
}
interface QueryTraceOptions {
port: number | undefined
parent: string | undefined
......
import type {
TraceMemorySummary,
TraceSpanInfo,
TraceSpanSampleSeries,
} from '../../build/swc/generated-native'
/** Public MCP shape: summaries always, value arrays only on explicit request. */
type JsonSpanInfo = Omit<
TraceSpanInfo,
'memorySamples' | 'sampleSeries' | 'children'
> &
type JsonSpanInfo = Omit<TraceSpanInfo, 'sampleSeries' | 'children'> &
Partial<TraceSpanSampleSeries> & { children: JsonSpanInfo[] }
export function serializeTraceSpan(span: TraceSpanInfo): JsonSpanInfo {
const { memorySamples: _summaryRows, sampleSeries, children, ...info } = span
const { sampleSeries, children, ...info } = span
return {
...info,
...sampleSeries,
......@@ -19,6 +17,20 @@ export function serializeTraceSpan(span: TraceSpanInfo): JsonSpanInfo {
}
}
export function renderMemorySummary(
summary: TraceMemorySummary | undefined,
formatBytes: (bytes: number) => string
): string | null {
if (!summary) return null
const delta = summary.end - summary.start
const deltaSign = delta >= 0 ? '+' : '-'
return (
`samples=${summary.count}, peak=${formatBytes(summary.peak)}, min=${formatBytes(summary.min)}, ` +
`start=${formatBytes(summary.start)}, end=${formatBytes(summary.end)}, ` +
`Δ=${deltaSign}${formatBytes(Math.abs(delta))}, maxPressure=${summary.maxPressure}`
)
}
export function renderSampleSeriesMarkdown(
series: TraceSpanSampleSeries | undefined,
formatBytes: (bytes: number) => string
......
......@@ -3,6 +3,7 @@ import z from 'next/dist/compiled/zod'
import { loadBindings } from '../../build/swc'
import type { TraceSpanInfo } from '../../build/swc/generated-native'
import {
renderMemorySummary,
renderSampleSeriesMarkdown,
serializeTraceSpan,
} from './trace-query-result'
......@@ -85,26 +86,6 @@ function renderAllocationsMarkdown(span: TraceSpanInfo): string {
return md
}
function summarizeMemorySamples(span: TraceSpanInfo): string | null {
const summary = span.memorySummary
if (!summary) return null
const delta = summary.end - summary.start
const deltaSign = delta >= 0 ? '+' : '-'
const workers = span.memorySamples.map((s) => s[4])
// Footprint is 0 when the platform does not report it.
const footprintSummary =
summary.maxFootprint > 0
? `, maxFootprint=${formatBytes(summary.maxFootprint)}`
: ''
return (
`samples=${summary.count}, peak=${formatBytes(summary.peak)}, min=${formatBytes(summary.min)}, ` +
`start=${formatBytes(summary.start)}, end=${formatBytes(summary.end)}, ` +
`Δ=${deltaSign}${formatBytes(Math.abs(delta))}, maxPressure=${summary.maxPressure}` +
footprintSummary +
`, activeWorkerThreads=${Math.min(...workers)}–${Math.max(...workers)}`
)
}
/**
* Render a single span (or aggregated span group) as a markdown section.
*
......@@ -159,9 +140,9 @@ function renderSpanMarkdown(
md += renderAllocationsMarkdown(span)
}
const memSummary = summarizeMemorySamples(span)
const memSummary = renderMemorySummary(span.memorySummary, formatBytes)
if (memSummary) {
md += `\n**Process samples (TurboMalloc live bytes, memory pressure, memory footprint, active Tokio workers):** ${memSummary}\n`
md += `\n**Process samples (TurboMalloc live bytes, memory pressure, memory footprint):** ${memSummary}\n`
}
md += renderSampleSeriesMarkdown(span.sampleSeries, formatBytes)
......
import { execFile } from 'child_process'
import { createServer } from 'http'
import { promisify } from 'util'
import type { TraceSpanInfo } from 'next/dist/build/swc/generated-native'
import { queryTraceCli } from 'next/dist/cli/internal/query-trace'
import {
parseTraceSampleCount,
queryTraceCli,
} from 'next/dist/cli/internal/query-trace'
import {
renderMemorySummary,
renderSampleSeriesMarkdown,
serializeTraceSpan,
} from 'next/dist/cli/internal/trace-query-result'
......@@ -33,7 +34,6 @@ function span(overrides: Partial<TraceSpanInfo> = {}): TraceSpanInfo {
selfDeallocations: 0,
selfPersistentAllocations: 0,
selfAllocationCount: 0,
memorySamples: [[0, 1024, 7, 2]],
memorySummary: {
count: 1,
start: 1024,
......@@ -69,6 +69,53 @@ const options = {
describe('query-trace samples', () => {
const originalFetch = global.fetch
const execFileAsync = promisify(execFile)
const server = createServer(async (request, response) => {
const chunks: Buffer[] = []
for await (const chunk of request) chunks.push(Buffer.from(chunk))
const rpc = JSON.parse(Buffer.concat(chunks).toString())
response.writeHead(200, { 'Content-Type': 'text/event-stream' })
response.end(
`data: ${JSON.stringify({
result: {
content: [
{ type: 'text', text: JSON.stringify(rpc.params.arguments) },
],
},
})}\n`
)
})
let port: number
beforeAll(async () => {
await new Promise<void>((resolve, reject) => {
server.once('error', reject)
server.listen(0, '127.0.0.1', resolve)
})
const address = server.address()
if (!address || typeof address === 'string') throw new Error('No TCP port')
port = address.port
})
afterAll(async () => {
await new Promise<void>((resolve, reject) => {
server.close((error) => (error ? reject(error) : resolve()))
})
})
function runCommand(value: string) {
return execFileAsync(
process.execPath,
[
require.resolve('next/dist/bin/next'),
'internal',
'query-trace',
'--port',
String(port),
'--json',
'--samples',
value,
],
{ timeout: 15000 }
)
}
afterEach(() => {
jest.restoreAllMocks()
global.fetch = originalFetch
......@@ -76,8 +123,12 @@ describe('query-trace samples', () => {
it.each(['0', '1', '300', String(Number.MAX_SAFE_INTEGER)])(
'accepts count %s',
(value) => {
expect(parseTraceSampleCount(value)).toBe(Number(value))
async (value) => {
const { stdout } = await runCommand(value)
expect(JSON.parse(stdout)).toMatchObject({
outputType: 'json',
samples: Number(value),
})
}
)
......@@ -91,10 +142,11 @@ describe('query-trace samples', () => {
'1e2',
' 2 ',
'9007199254740992',
])('rejects count %s', (value) => {
expect(() => parseTraceSampleCount(value)).toThrow(
'nonnegative safe integer'
)
])('rejects count %s', async (value) => {
await expect(runCommand(value)).rejects.toMatchObject({
code: 1,
stderr: expect.stringContaining('nonnegative safe integer'),
})
})
it.each([undefined, 0, 1, 300])(
......@@ -130,7 +182,7 @@ describe('query-trace samples', () => {
}
})
it('flattens requested value arrays recursively rather than exposing legacy tuples', () => {
it('flattens the only native sample-series fields recursively', () => {
const result = serializeTraceSpan(
span({
sampleSeries: series,
......@@ -159,6 +211,21 @@ describe('query-trace samples', () => {
})
})
it('prints independent memory and pressure summaries without worker bounds', () => {
const summary = renderMemorySummary(
span().memorySummary,
(value) => `${value / 1024} KB`
)
expect(summary).toBe(
'samples=1, peak=1 KB, min=1 KB, start=1 KB, end=1 KB, Δ=+0 KB, maxPressure=7'
)
expect(summary).not.toContain('activeWorkerThreads')
})
it('omits the memory summary when no readings are available', () => {
expect(renderMemorySummary(undefined, String)).toBeNull()
})
it('prints readable units and explains independent sample grids', () => {
const md = renderSampleSeriesMarkdown(
series,
......
......@@ -48,7 +48,7 @@ mod viewer;
)]
type FxIndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasherDefault<FxHasher>>;
/// Maximum number of process sample rows used for legacy query summaries.
/// Maximum number of process sample rows used for independent query summaries.
const MAX_MEMORY_SUMMARY_SAMPLES: usize = 200;
/// Starts the trace server on a background thread and returns the store
......@@ -131,6 +131,8 @@ pub struct QueryOptions {
/// Requested value series for a span's elapsed range. Captured samples and
/// equal-duration concurrency segments do not share a timestamp grid.
/// Memory is TurboMalloc live bytes, pressure is the recorded pressure byte,
/// and workers are non-parked Tokio scheduler workers (not the blocking pool).
pub struct SpanSampleSeries {
pub memory_samples: Vec<u64>,
pub memory_pressure_samples: Vec<u8>,
......@@ -180,7 +182,7 @@ pub struct SpanInfo {
/// Average corrected_duration across all spans in the group.
pub avg_corrected_duration: Option<u64>,
/// Raw span ID of the group's example span, whose `cpu_duration`,
/// `corrected_duration` and `memory_samples` are the ones reported above.
/// `corrected_duration`, `memory_summary` and `sample_series` are reported here.
/// First in execution order — *not* the largest, so it can badly understate
/// a group's allocations. Use `heaviest_span_id` for those.
pub first_span_id: Option<String>,
......@@ -190,8 +192,9 @@ pub struct SpanInfo {
/// Total bytes allocated by this span and all its children.
///
/// For aggregated groups this is the group total, unlike `cpu_duration`,
/// `corrected_duration` and `memory_samples`, which describe the example
/// span only. Every allocation field below follows this field, not those.
/// `corrected_duration`, `memory_summary` and `sample_series`, which describe
/// the example span only. Every allocation field below follows this field,
/// not those.
pub allocations: u64,
/// Total bytes deallocated by this span and all its children.
/// Group total for aggregated spans.
......@@ -230,30 +233,21 @@ pub struct SpanInfo {
/// Number of allocation operations by this span itself, excluding children.
/// Group total for aggregated spans.
pub self_allocation_count: u64,
/// Process samples recorded while this span (or its example span, for
/// aggregated groups) was live.
/// Summary of TurboMalloc readings while this span (or its example span,
/// for aggregated groups) was live. `None` when its range holds none.
///
/// **Process-wide, not per-span.** There is one global sample series, and a
/// span's samples are just the slice covering its time range, so spans that
/// overlap in time report identical values no matter what each allocated.
/// Rank concurrent work by the allocation fields; use these for absolute
/// memory over a span that dominates its window.
/// **Process-wide, not per-span.** One global series is sliced by the
/// span's time range, so overlapping ranges report the same readings no
/// matter what each allocated. Rank concurrent work by allocation fields;
/// use this summary for absolute memory over a span dominating its window.
///
/// Each tuple is `(ts_offset_from_span_start_in_ticks, bytes, pressure,
/// footprint, active_worker_threads)`. `bytes` is TurboMalloc memory
/// usage; `pressure` is the memory-pressure byte (0 = no pressure, higher
/// = more pressure); `footprint` is the process memory footprint (RSS) in
/// bytes (0 = not reported by the platform); and `active_worker_threads`
/// counts non-parked Tokio scheduler workers. `100 ticks = 1 µs`. The
/// offset is within the span.
///
/// The query caller caps the series at `MAX_MEMORY_SUMMARY_SAMPLES`; groups
/// retain the peak-memory timestamp/value and independent pressure,
/// footprint and worker maxima.
pub memory_samples: Vec<(i64, u64, u8, u64, u64)>,
/// Summary of `memory_samples`. `None` when the span's range holds none.
/// The query caller summarizes at most `MAX_MEMORY_SUMMARY_SAMPLES`
/// temporary rows, selecting each group's peak-memory row and independent
/// pressure, footprint and worker maxima. This is independent of whether
/// or how many sample values are requested.
pub memory_summary: Option<MemorySummary>,
/// Opt-in series independent of the legacy, 200-row summary inputs above.
/// Opt-in process/global value series for this span's elapsed range
/// (the example span's range for aggregated groups).
pub sample_series: Option<SpanSampleSeries>,
/// Descendants of this span, populated only when `QueryOptions::depth` is
/// greater than 1. Sorted and aggregated the same way as this level.
......@@ -285,7 +279,7 @@ pub struct MemorySummary {
impl MemorySummary {
/// Summarize a sample series, or `None` if it is empty.
fn from_samples(samples: &[(i64, u64, u8, u64, u64)]) -> Option<Self> {
fn from_samples(samples: &[(Timestamp, u64, u8, u64, u64)]) -> Option<Self> {
let (_, first_bytes, first_pressure, first_footprint, _) = *samples.first()?;
let mut summary = MemorySummary {
count: samples.len(),
......@@ -520,16 +514,13 @@ fn sort_spans(items: &mut [Located<SpanRef<'_>>], sort: SortMode) {
}
}
/// Memory samples recorded while `span` was live, offset from its start.
fn memory_samples_for(store: &store::Store, span: &SpanRef<'_>) -> Vec<(i64, u64, u8, u64, u64)> {
let span_start = *span.start() as i64;
store
.memory_samples_for_range_with_ts(span.start(), span.end(), MAX_MEMORY_SUMMARY_SAMPLES)
.into_iter()
.map(|(ts, mem, pressure, footprint, workers)| {
((*ts as i64) - span_start, mem, pressure, footprint, workers)
})
.collect()
/// Summarize temporary process rows independently of requested sample values.
fn memory_summary_for(store: &store::Store, span: &SpanRef<'_>) -> Option<MemorySummary> {
MemorySummary::from_samples(&store.memory_samples_for_range_with_ts(
span.start(),
span.end(),
MAX_MEMORY_SUMMARY_SAMPLES,
))
}
fn sample_series_for(store: &store::Store, span: &SpanRef<'_>, limit: usize) -> SpanSampleSeries {
......@@ -566,8 +557,7 @@ fn build_graph_span_info(
.max_by_key(|span| span.total_persistent_allocations())
.map(|span| span.index.to_string());
let memory_samples = memory_samples_for(store, &first);
let memory_summary = MemorySummary::from_samples(&memory_samples);
let memory_summary = memory_summary_for(store, &first);
let children = if depth > 1 {
let mut located_children: Vec<_> = graph_children(&graph)
......@@ -618,7 +608,6 @@ fn build_graph_span_info(
self_deallocations: graph.self_deallocations(),
self_persistent_allocations: graph.self_persistent_allocations(),
self_allocation_count: graph.self_allocation_count(),
memory_samples,
memory_summary,
sample_series: samples.map(|limit| sample_series_for(store, &first, limit)),
children,
......@@ -637,8 +626,7 @@ fn build_raw_span_info(
let Located { item: span, id } = located;
let (cat, title) = span.nice_name();
let memory_samples = memory_samples_for(store, &span);
let memory_summary = MemorySummary::from_samples(&memory_samples);
let memory_summary = memory_summary_for(store, &span);
let children = if depth > 1 {
let mut located_children: Vec<_> = span
......@@ -684,7 +672,6 @@ fn build_raw_span_info(
self_deallocations: span.self_deallocations(),
self_persistent_allocations: span.self_persistent_allocations(),
self_allocation_count: span.self_allocation_count(),
memory_samples,
memory_summary,
sample_series: samples.map(|limit| sample_series_for(store, &span, limit)),
children,
......@@ -1453,9 +1440,9 @@ mod tests {
#[test]
fn memory_summary_reports_peak_not_last() {
let samples = [
(0i64, 100u64, 0u8, 5000u64, 2u64),
(1, 900, 3, 4000, 1),
(2, 200, 1, 7000, 3),
(Timestamp::from_micros(0), 100, 0, 5000, 2),
(Timestamp::from_micros(1), 900, 3, 4000, 1),
(Timestamp::from_micros(2), 200, 1, 7000, 3),
];
let summary = MemorySummary::from_samples(&samples).expect("samples present");
assert_eq!(summary.count, 3);
......
......@@ -64,7 +64,10 @@ fn reads_active_workers_and_exposes_them_in_span_queries() {
assert_eq!(samples[0].3, 5555);
assert_eq!(samples[0].4, 2);
for aggregated in [false, true] {
for (aggregated, limit) in [false, true]
.into_iter()
.flat_map(|aggregated| [None, Some(0), Some(1)].map(|limit| (aggregated, limit)))
{
let result = query_spans(
&store,
QueryOptions {
......@@ -76,14 +79,36 @@ fn reads_active_workers_and_exposes_them_in_span_queries() {
depth: 1,
page: 1,
page_size: None,
samples: None,
samples: limit,
},
);
assert_eq!(result.spans.len(), 1);
assert_eq!(
result.spans[0].memory_samples,
vec![(1000, 1234, 7, 5555, 2)]
);
let span = &result.spans[0];
let summary = span.memory_summary.expect("summary remains available");
assert_eq!(summary.count, 1);
assert_eq!(summary.start, 1234);
assert_eq!(summary.end, 1234);
assert_eq!(summary.min, 1234);
assert_eq!(summary.peak, 1234);
assert_eq!(summary.max_pressure, 7);
assert_eq!(summary.max_footprint, 5555);
match limit {
None => assert!(span.sample_series.is_none()),
Some(limit) => {
let series = span.sample_series.as_ref().unwrap();
if limit == 0 {
assert!(series.memory_samples.is_empty());
assert!(series.memory_pressure_samples.is_empty());
assert!(series.active_worker_threads_samples.is_empty());
assert!(series.concurrency_samples.is_empty());
} else {
assert_eq!(series.memory_samples, vec![1234]);
assert_eq!(series.memory_pressure_samples, vec![7]);
assert_eq!(series.active_worker_threads_samples, vec![2]);
assert_eq!(series.concurrency_samples, vec![1.0]);
}
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment