Skip to content

Implement StatsCollector for basic metrics aggregation #11

@marr97

Description

@marr97

Description

Thread-safe component that collects per-request results and provides aggregated metrics snapshot.
Will be integrated with Engine later.

Tasks

  • StatsCollector class with
    • Thread-safe counters using LongAdder: totalRequests, successCount, errorCount
    • Latency tracking: min, max, totalLatency (for average)
    • record(int statusCode, long latencyMs) method
    • getSnapshot() method returning current aggregated metrics
    • reset() method for clearing state between tests
  • StatsSnapshot record/class with fields: totalRequests, successCount, errorCount, avgLatencyMs, minLatencyMs, maxLatencyMs
  • Unit tests, more info below

Unit tests

record

  • throws on negative status code
  • throws on status code below 100
  • throws on status code above 599
  • throws on negative latency
  • boundary: 200 is success, 199 is error, 299 is success, 300 is error
  • zero latency is valid

getSnapshot

  • before any records returns all zeros

record + getSnapshot

  • single success record counted correctly
  • single error record counted correctly
  • multiple records — all counters correct
  • average latency calculated correctly
  • min latency tracked correctly
  • max latency tracked correctly

record + getSnapshot + reset

  • records after reset are independent of previous state
  • 10 cycles with random count of records (1-10), random statusCode (100-599), random LatencyMs (0-999)
  • double reset is safe
  • snapshot taken before reset is not affected by reset

Thread safety

  • concurrent writes from multiple threads produce correct total count
  • 10 cycles, 5 threads, random records per thread (10-109), random statusCode (100-599), random latencyMs (0-999)

Metadata

Metadata

Labels

statsMetrics collection

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions