Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/fluent-bit/http_server/flb_hs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <fluent-bit/flb_info.h>
#include <fluent-bit/flb_config.h>
#include <fluent-bit/flb_network.h>
#include <fluent-bit/flb_pthread.h>
#include <fluent-bit/flb_sds.h>
#include <fluent-bit/http_server/flb_http_server.h>
#include <monkey/mk_core.h>
Expand All @@ -32,6 +33,7 @@
* by end-points.
*/
struct flb_hs_buf {
pthread_mutex_t lock;
int users;
int pending_free;
flb_sds_t data;
Expand Down Expand Up @@ -81,6 +83,7 @@ struct flb_hs {
struct flb_config *config;
struct mk_list routes;
struct mk_list health_metrics;
pthread_mutex_t health_metrics_lock;
struct flb_health_check_metrics_counter health_counter;

struct flb_hs_buf metrics;
Expand All @@ -102,6 +105,8 @@ int flb_hs_push_storage_metrics(struct flb_hs *hs, void *data, size_t size);
int flb_hs_destroy(struct flb_hs *ctx);
int flb_hs_start(struct flb_hs *hs);
void flb_hs_cmt_buffer_destroy(void *data);
int flb_hs_buf_acquire(struct flb_hs_buf *buffer, int require_data,
int require_raw_data);
void flb_hs_buf_release(struct flb_hs_buf *buffer, void (*raw_free)(void *));
int flb_hs_register_endpoint(struct flb_hs *hs,
const char *path,
Expand Down
5 changes: 5 additions & 0 deletions src/http_server/api/v1/health.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ int flb_hs_health_state_get(struct flb_hs *hs, struct flb_hs_health_state *state
}

memset(state, 0, sizeof(struct flb_hs_health_state));
pthread_mutex_lock(&hs->health_metrics_lock);

state->error_limit = hs->health_counter.error_limit;
state->retry_failure_limit = hs->health_counter.retry_failure_limit;
state->period_limit = hs->health_counter.period_limit;

if (mk_list_is_empty(&hs->health_metrics) == 0) {
state->healthy = FLB_TRUE;
pthread_mutex_unlock(&hs->health_metrics_lock);
return 0;
}

Expand All @@ -79,10 +82,12 @@ int flb_hs_health_state_get(struct flb_hs *hs, struct flb_hs_health_state *state
if (state->errors > hs->health_counter.error_limit ||
state->retries_failed > hs->health_counter.retry_failure_limit) {
state->healthy = FLB_FALSE;
pthread_mutex_unlock(&hs->health_metrics_lock);
return 0;
}

state->healthy = FLB_TRUE;
pthread_mutex_unlock(&hs->health_metrics_lock);

return 0;
}
Expand Down
8 changes: 2 additions & 6 deletions src/http_server/api/v1/metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@
/* Return the newest metrics buffer */
static struct flb_hs_buf *metrics_get_latest(struct flb_hs *hs)
{
if (hs->metrics.data == NULL || hs->metrics.raw_data == NULL) {
if (flb_hs_buf_acquire(&hs->metrics, FLB_TRUE, FLB_TRUE) != 0) {
return NULL;
}

return &hs->metrics;
}

Expand Down Expand Up @@ -159,9 +160,6 @@ static int cb_metrics_prometheus(struct flb_hs *hs,
return flb_http_response_commit(response);
}

/* ref count */
buf->users++;

/* Compose outgoing buffer string */
sds = flb_sds_create_size(1024);
if (!sds) {
Expand Down Expand Up @@ -416,8 +414,6 @@ static int cb_metrics(struct flb_hs *hs,
return flb_http_response_commit(response);
}

buf->users++;

flb_hs_response_set_payload(response, 200,
FLB_HS_CONTENT_TYPE_JSON,
buf->data, flb_sds_len(buf->data));
Expand Down
5 changes: 2 additions & 3 deletions src/http_server/api/v1/storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
/* Return the newest storage metrics buffer */
static struct flb_hs_buf *storage_metrics_get_latest(struct flb_hs *hs)
{
if (hs->storage_metrics.data == NULL) {
if (flb_hs_buf_acquire(&hs->storage_metrics, FLB_TRUE, FLB_FALSE) != 0) {
return NULL;
}

return &hs->storage_metrics;
}

Expand All @@ -51,8 +52,6 @@ static int cb_storage(struct flb_hs *hs,
return flb_http_response_commit(response);
}

buf->users++;

flb_hs_response_set_payload(response, 200,
FLB_HS_CONTENT_TYPE_JSON,
buf->data, flb_sds_len(buf->data));
Expand Down
5 changes: 2 additions & 3 deletions src/http_server/api/v2/metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@
/* Return the newest metrics buffer */
static struct flb_hs_buf *metrics_get_latest(struct flb_hs *hs)
{
if (hs->metrics_v2.raw_data == NULL) {
if (flb_hs_buf_acquire(&hs->metrics_v2, FLB_FALSE, FLB_TRUE) != 0) {
return NULL;
}

return &hs->metrics_v2;
}

Expand All @@ -59,7 +60,6 @@ static int cb_metrics_prometheus(struct flb_hs *hs,
return flb_http_response_commit(response);
}

buf->users++;
cmt = (struct cmt *) buf->raw_data;

/* convert CMetrics to text */
Expand Down Expand Up @@ -97,7 +97,6 @@ static int cb_metrics(struct flb_hs *hs,
return flb_http_response_commit(response);
}

buf->users++;
cmt = (struct cmt *) buf->raw_data;

/* convert CMetrics to text */
Expand Down
Loading
Loading