Skip to content

Commit 1791e05

Browse files
committed
add wavy distribution with 3 sine wave cycles
1 parent c407726 commit 1791e05

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

scripts/seed-traces/seed-traces-bulk.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -382,17 +382,27 @@ async function loadTraceSamples(): Promise<OTELTrace[]> {
382382
}
383383

384384
function generateTimestamp(index: number, total: number): Date {
385-
// Scatter timestamps evenly across the configured time range
385+
// Scatter timestamps with a wavy pattern across the configured time range
386386
const now = Date.now();
387387
const startTime = now - timeRangeDays * 24 * 60 * 60 * 1000;
388388
const timeRange = now - startTime;
389389

390-
// Distribute evenly across the range with some randomness
390+
// Use inverse CDF of a wave-modulated distribution for wavy density
391+
// More traces during "peaks", fewer during "valleys"
391392
const position = index / Math.max(1, total - 1);
392-
const baseTime = startTime + timeRange * position;
393393

394-
// Add some jitter (~30 minutes) to avoid all traces being at exact intervals
395-
const jitter = (Math.random() - 0.5) * 2 * 30 * 60 * 1000; // ~30 minutes
394+
// Create wavy pattern using sine waves
395+
// Multiple overlapping waves for a more natural look
396+
const waves = 3; // Number of wave cycles
397+
const wavePhase = position * Math.PI * 2 * waves;
398+
const waveModulation = Math.sin(wavePhase) * 0.15; // 15% amplitude
399+
400+
// Apply modulation while keeping within [0, 1] bounds
401+
const modulatedPosition = Math.max(0, Math.min(1, position + waveModulation));
402+
const baseTime = startTime + timeRange * modulatedPosition;
403+
404+
// Add some jitter (~15 minutes) to avoid all traces being at exact intervals
405+
const jitter = (Math.random() - 0.5) * 2 * 15 * 60 * 1000; // ~15 minutes
396406

397407
return new Date(baseTime + jitter);
398408
}
@@ -433,9 +443,7 @@ async function executeClickHouseQuery(query: string) {
433443
}
434444

435445
async function seedTraces() {
436-
console.log('Resolving target ID...');
437446
const targetId = await resolveTargetId(targetSlug, authUrl, authToken);
438-
console.log(`Resolved target ID: ${targetId}`);
439447

440448
console.log('Loading trace samples...');
441449
const traceSamples = await loadTraceSamples();
@@ -511,15 +519,22 @@ async function seedTraces() {
511519
`Processing chunk ${chunkIndex + 1}/${numChunks}: duplicating ${duplicatesInChunk.toLocaleString()} times...`,
512520
);
513521

522+
// Wave parameters for wavy distribution
523+
const waveCount = 3; // Number of wave cycles across the time range
524+
const waveAmplitude = 0.15; // 15% amplitude
525+
514526
const duplicateQuery = `
515527
INSERT INTO otel_traces
516528
SELECT
517-
-- Adjust timestamp: distribute evenly across configured time range
529+
-- Adjust timestamp: distribute with wavy pattern across configured time range
518530
toDateTime64(
519-
${startTime / 1000} +
520-
((((dense_rank() OVER (ORDER BY original_traces.TraceId, dup_index) - 1) + ${globalTraceOffset}) * ${timeRange / 1000 / totalTraces}) +
531+
${startTime / 1000} + (
532+
-- Base position with wave modulation for wavy density pattern
533+
(((dense_rank() OVER (ORDER BY original_traces.TraceId, dup_index) - 1) + ${globalTraceOffset}) / ${totalTraces}) +
534+
(sin((((dense_rank() OVER (ORDER BY original_traces.TraceId, dup_index) - 1) + ${globalTraceOffset}) / ${totalTraces}) * ${Math.PI * 2 * waveCount}) * ${waveAmplitude})
535+
) * ${timeRange / 1000} +
521536
((toUnixTimestamp64Milli(original_traces.Timestamp) - toUnixTimestamp64Milli(min(original_traces.Timestamp) OVER (PARTITION BY original_traces.TraceId))) / 1000) +
522-
((sipHash64(original_traces.TraceId, dup_index) % 3600) - 1800)), -- Add ~30 min jitter (deterministic per trace)
537+
((sipHash64(original_traces.TraceId, dup_index) % 1800) - 900), -- Add ~15 min jitter (deterministic per trace)
523538
9, 'UTC'
524539
) AS Timestamp,
525540

0 commit comments

Comments
 (0)