@@ -58,8 +58,13 @@ func TestPubsub_Metrics(t *testing.T) {
5858 testutil .PromCounterHasValue (t , metrics , gatherCount , "coder_nats_pubsub_messages_total" , "normal" ) &&
5959 testutil .PromCounterHasValue (t , metrics , float64 (len (data ))+ latencyBytes , "coder_nats_pubsub_received_bytes_total" ) &&
6060 testutil .PromCounterHasValue (t , metrics , float64 (len (data ))+ latencyBytes , "coder_nats_pubsub_published_bytes_total" ) &&
61- testutil .PromGaugeAssertion (t , metrics , func (in float64 ) bool { return in > 0 }, "coder_nats_pubsub_send_latency_seconds" ) &&
62- testutil .PromGaugeAssertion (t , metrics , func (in float64 ) bool { return in > 0 }, "coder_nats_pubsub_receive_latency_seconds" ) &&
61+ // The latency gauges can be exactly 0 on Windows, whose monotonic
62+ // clock advances in coarse (up to 15.6ms) ticks; a sub-tick publish
63+ // measures a zero duration. An absent gauge reads as -1, so >= 0
64+ // still proves the gauge was gathered, and the measures_total/errs
65+ // counters below prove measurement ran and succeeded.
66+ testutil .PromGaugeAssertion (t , metrics , func (in float64 ) bool { return in >= 0 }, "coder_nats_pubsub_send_latency_seconds" ) &&
67+ testutil .PromGaugeAssertion (t , metrics , func (in float64 ) bool { return in >= 0 }, "coder_nats_pubsub_receive_latency_seconds" ) &&
6368 testutil .PromCounterHasValue (t , metrics , gatherCount , "coder_nats_pubsub_latency_measures_total" ) &&
6469 ! testutil .PromCounterGathered (t , metrics , "coder_nats_pubsub_latency_measure_errs_total" )
6570 }, testutil .WaitShort , testutil .IntervalFast )
@@ -95,8 +100,10 @@ func TestPubsub_Metrics(t *testing.T) {
95100 testutil .PromCounterHasValue (t , metrics , 1 , "coder_nats_pubsub_messages_total" , "colossal" ) &&
96101 testutil .PromCounterHasValue (t , metrics , float64 (colossalSize + len (data ))+ latencyBytes , "coder_nats_pubsub_received_bytes_total" ) &&
97102 testutil .PromCounterHasValue (t , metrics , float64 (colossalSize + len (data ))+ latencyBytes , "coder_nats_pubsub_published_bytes_total" ) &&
98- testutil .PromGaugeAssertion (t , metrics , func (in float64 ) bool { return in > 0 }, "coder_nats_pubsub_send_latency_seconds" ) &&
99- testutil .PromGaugeAssertion (t , metrics , func (in float64 ) bool { return in > 0 }, "coder_nats_pubsub_receive_latency_seconds" ) &&
103+ // Zero latency is accepted for coarse clocks; see the comment on
104+ // the first Eventually above.
105+ testutil .PromGaugeAssertion (t , metrics , func (in float64 ) bool { return in >= 0 }, "coder_nats_pubsub_send_latency_seconds" ) &&
106+ testutil .PromGaugeAssertion (t , metrics , func (in float64 ) bool { return in >= 0 }, "coder_nats_pubsub_receive_latency_seconds" ) &&
100107 testutil .PromCounterHasValue (t , metrics , gatherCount , "coder_nats_pubsub_latency_measures_total" ) &&
101108 ! testutil .PromCounterGathered (t , metrics , "coder_nats_pubsub_latency_measure_errs_total" )
102109 }, testutil .WaitShort , testutil .IntervalFast )
0 commit comments