Skip to content

Commit 818b18c

Browse files
committed
Feedback (temporary -- will squash into above)
Signed-off-by: Alec Holmes <[email protected]>
1 parent a48e7ab commit 818b18c

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

src/flb_log.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ int flb_log_set_file(struct flb_config *config, char *out)
486486
struct flb_log_metrics *flb_log_metrics_create()
487487
{
488488
struct flb_log_metrics *metrics;
489-
int i;
489+
int log_message_type;
490490
const char *message_type_str;
491491
uint64_t ts;
492492
int ret;
@@ -498,8 +498,8 @@ struct flb_log_metrics *flb_log_metrics_create()
498498
}
499499

500500
metrics->cmt = cmt_create();
501-
if (!metrics->cmt) {
502-
flb_free(metrics);
501+
if (metrics->cmt == NULL) {
502+
flb_log_metrics_destroy(metrics);
503503
return NULL;
504504
}
505505

@@ -510,18 +510,14 @@ struct flb_log_metrics *flb_log_metrics_create()
510510
"Total number of logs",
511511
1, (char *[]) {"message_type"});
512512
if (metrics->logs_total_counter == NULL) {
513-
cmt_destroy(metrics->cmt);
514-
flb_free(metrics);
513+
flb_log_metrics_destroy(metrics);
515514
return NULL;
516515
}
517516

518-
/*
519-
* Initialize counters for all log message types to 0.
520-
* This assumes types are contiguous starting at 1 (FLB_LOG_ERROR).
521-
*/
517+
/* Initialize counters for log message types to 0. */
522518
ts = cfl_time_now();
523-
for (i = 1; ; i++) {
524-
message_type_str = flb_log_message_type_str(i);
519+
for (log_message_type = FLB_LOG_ERROR; log_message_type <= FLB_LOG_TRACE; log_message_type++) {
520+
message_type_str = flb_log_message_type_str(log_message_type);
525521
if (!message_type_str) {
526522
break;
527523
}
@@ -531,9 +527,7 @@ struct flb_log_metrics *flb_log_metrics_create()
531527
0,
532528
1, (char *[]) {message_type_str});
533529
if (ret == -1) {
534-
cmt_counter_destroy(metrics->logs_total_counter);
535-
cmt_destroy(metrics->cmt);
536-
flb_free(metrics);
530+
flb_log_metrics_destroy(metrics);
537531
return NULL;
538532
}
539533
}
@@ -544,9 +538,12 @@ struct flb_log_metrics *flb_log_metrics_create()
544538
/* Frees the metrics instance and its associated resources. */
545539
void flb_log_metrics_destroy(struct flb_log_metrics *metrics)
546540
{
547-
cmt_counter_destroy(metrics->logs_total_counter);
548-
cmt_destroy(metrics->cmt);
549-
flb_free(metrics);
541+
if (metrics != NULL && metrics->cmt != NULL) {
542+
cmt_destroy(metrics->cmt);
543+
}
544+
if (metrics != NULL) {
545+
flb_free(metrics);
546+
}
550547
}
551548

552549

@@ -832,7 +829,7 @@ void flb_log_print(int type, const char *file, int line, const char *fmt, ...)
832829
ts,
833830
1, (char *[]) {msg_type_str});
834831
if (ret == -1) {
835-
// Not using flb_log_debug to avoid recursing into this same function.
832+
/* Not using flb_log_debug to avoid recursing into this same function. */
836833
fprintf(stderr,
837834
"[log] failed to increment log total counter for message type '%s' (error=%d)\n",
838835
msg_type_str, ret);

src/flb_metrics_exporter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ struct cmt *flb_me_get_cmetrics(struct flb_config *ctx)
301301

302302
if (ctx->log != NULL) {
303303
ret = cmt_cat(cmt, ctx->log->metrics->cmt);
304-
if (ret == -1) {
305-
flb_error("[metrics exporter] could not append global log_metrics_ctx");
304+
if (ret != 0) {
305+
flb_error("[metrics exporter] could not append global log metrics");
306306
cmt_destroy(cmt);
307307
return NULL;
308308
}

0 commit comments

Comments
 (0)