Your question is Parse Counters and Flag Anomalies. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
At Datadog, performance counters are emitted as log lines in the format name=value. Write a function that parses a list of counter strings and flags anomalous counters based on recent history.
A line is valid only if it contains exactly one = and the value is a valid integer. Ignore invalid lines. For each counter name, keep the sequence of parsed values in input order. A counter value is considered anomalous if it is at least threshold greater than the average of the previous window_size valid values for the same counter. If fewer than window_size previous values exist for that counter, do not evaluate anomaly status for that occurrence.
Return a list of anomalies in the order they are detected. Each anomaly should be represented as [name, index, value], where index is the original position in the input list.
lines as a list of strings, window_size as an integer, threshold as an integer[counter_name, original_index, counter_value]def flag_counter_anomalies(lines, window_size, threshold):