Skip to content

Commit 968a2e1

Browse files
committed
fixup! http_server/health: Implement throughput health check
Address Leonardo review: Refactor to not use goto Signed-off-by: Thiago Padilha <[email protected]>
1 parent 0548505 commit 968a2e1

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/http_server/api/v1/health.c

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -332,30 +332,31 @@ static int check_throughput_health(uint64_t in_records,
332332
_head);
333333
}
334334

335-
if (last_sample &&
336-
in_records == last_sample->in_records &&
337-
out_records == last_sample->out_records) {
338-
flb_debug("[api/v1/health/throughput]: no changes since last check");
339-
/* don't collect another sample unless either in_records or out_records have
340-
* changed*/
341-
goto check;
342-
}
335+
if (!last_sample ||
336+
in_records != last_sample->in_records ||
337+
out_records != last_sample->out_records) {
338+
339+
sample = flb_malloc(sizeof(struct flb_hs_throughput_sample));
340+
341+
if (sample) {
342+
sample->timestamp_seconds = timestamp_seconds;
343+
sample->in_records = in_records;
344+
sample->out_records = out_records;
345+
mk_list_add(&sample->_head, sample_list);
346+
} else {
347+
flb_error("[api/v1/health/throughput]: failed to allocate sample");
348+
}
343349

344-
sample = flb_malloc(sizeof(struct flb_hs_throughput_sample));
345-
if (!sample) {
346-
flb_error("[api/v1/health/throughput]: failed to allocate sample");
347-
goto check;
350+
} else {
351+
/* don't collect another sample unless either in_records or out_records have
352+
* changed since last check */
353+
flb_debug("[api/v1/health/throughput]: no changes since last check");
348354
}
349355

350-
sample->timestamp_seconds = timestamp_seconds;
351-
sample->in_records = in_records;
352-
sample->out_records = out_records;
353-
mk_list_add(&sample->_head, sample_list);
354-
355-
check:
356356
flb_debug("[api/v1/health/throughput]: check samples start %d %f",
357357
sample_count,
358358
out_in_ratio_threshold);
359+
359360
healthy = false;
360361
mk_list_foreach_safe_r(head, tmp, sample_list) {
361362
entry = mk_list_entry(head, struct flb_hs_throughput_sample, _head);
@@ -379,6 +380,7 @@ static int check_throughput_health(uint64_t in_records,
379380
out_in_ratio,
380381
out_rate,
381382
in_rate);
383+
382384
if (healthy) {
383385
break;
384386
}
@@ -399,6 +401,7 @@ static int check_throughput_health(uint64_t in_records,
399401
rv = count < sample_count || healthy;
400402
flb_debug("checking throughput samples stop, result: %s",
401403
rv ? "healthy" :"unhealthy");
404+
402405
return rv;
403406
}
404407

0 commit comments

Comments
 (0)