Code Room
Code reviewMediumcr-g267
Subject Empty inputLevel Mid–Senior~15 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this Python code that summarizes latency once per scrape interval.

`scrape` runs on a fixed timer regardless of whether any traffic arrived in the window.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewpython
def avg_latency(samples):    total = 0    for s in samples:        total += s.latency_ms    return total / len(samples) def scrape(window):    samples = collect(window)          # whatever arrived this interval    avg = avg_latency(samples)    emit_gauge("latency.avg_ms", avg)    return avg
Run or narrate your approach, then ask the coach.