Skip to content

Commit a362323

Browse files
Copilotalexisjcarr
andcommitted
Fix bug: Exclude hosts with missing or 404 HTTP check status
The bug was that when HTTP check results were missing from the map (value = 0), hosts were incorrectly included in lag calculations. Fixed by checking for both StatusNotFound (404) AND zero (missing map entry). - Updated aggregateMySQLProbes to check: httpStatus == StatusNotFound || httpStatus == 0 - Added test case TestAggregateMySQLProbesWithMissingHttpChecks to validate fix - All existing tests pass Co-authored-by: alexisjcarr <34029816+alexisjcarr@users.noreply.github.com>
1 parent 8c8b9ec commit a362323

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

pkg/throttle/mysql.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ func aggregateMySQLProbes(
2121
// so it's safe to iterate it
2222
probeValues := []float64{}
2323
for _, probe := range *probes {
24-
if clusterInstanceHttpChecksMap[mysql.MySQLHttpCheckHashKey(clusterName, &probe.Key)] == http.StatusNotFound {
24+
httpStatus := clusterInstanceHttpChecksMap[mysql.MySQLHttpCheckHashKey(clusterName, &probe.Key)]
25+
if httpStatus == http.StatusNotFound || httpStatus == 0 {
2526
continue
2627
}
2728
instanceMetricResult, ok := instanceResultsMap[mysql.GetClusterInstanceKey(clusterName, &probe.Key)]

pkg/throttle/mysql_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,34 @@ func TestAggregateMySQLProbesWithHttpChecks(t *testing.T) {
265265
test.S(t).ExpectNotNil(err)
266266
}
267267
}
268+
269+
func TestAggregateMySQLProbesWithMissingHttpChecks(t *testing.T) {
270+
clusterName := "c0"
271+
k1 := mysql.GetClusterInstanceKey(clusterName, &key1)
272+
k2 := mysql.GetClusterInstanceKey(clusterName, &key2)
273+
k3 := mysql.GetClusterInstanceKey(clusterName, &key3)
274+
275+
results := mysql.InstanceMetricResultMap{
276+
k1: base.NewSimpleMetricResult(1.2),
277+
k2: base.NewSimpleMetricResult(2.5),
278+
k3: base.NewSimpleMetricResult(0.3),
279+
}
280+
281+
// Test with missing HTTP check entry (will return 0 from map)
282+
checksWithMissing := mysql.ClusterInstanceHttpCheckResultMap{
283+
mysql.MySQLHttpCheckHashKey(clusterName, &key1): http.StatusOK,
284+
mysql.MySQLHttpCheckHashKey(clusterName, &key3): http.StatusOK,
285+
// key2 is missing - should be excluded
286+
}
287+
288+
var probeSet mysql.Probes = map[mysql.InstanceKey](*mysql.Probe){}
289+
for ck := range results {
290+
probeSet[ck.Key] = &mysql.Probe{Key: ck.Key}
291+
}
292+
293+
metric := aggregateMySQLProbes(&probeSet, clusterName, results, checksWithMissing, 0, false, 0)
294+
val, err := metric.Get()
295+
test.S(t).ExpectNil(err)
296+
// key2 (2.5) should be excluded due to missing HTTP check, worst should be 1.2
297+
test.S(t).ExpectEquals(val, 1.2)
298+
}

0 commit comments

Comments
 (0)