Skip to content

Commit

Permalink
http_server/health: Implement throughput health check
Browse files Browse the repository at this point in the history
Move struct definitions to header.

Signed-off-by: Thiago Padilha <[email protected]>
  • Loading branch information
tchrono committed Jul 22, 2022
1 parent 5178cca commit a9b0cfb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 29 deletions.
34 changes: 5 additions & 29 deletions src/http_server/api/v1/health.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,11 @@

#include "health.h"

/*
* in/out records sample at a certain timestamp.
*/
struct flb_hs_throughput_sample {
uint64_t in_records;
uint64_t out_records;
uint64_t timestamp_seconds;
};

/* ring buffer + helper functions for storing samples */
struct flb_hs_throughput_samples {
struct flb_hs_throughput_sample *items;
int size;
int count;
int insert;
};
struct flb_hs_throughput_state throughput_check_state = {0};

struct flb_health_check_metrics_counter *metrics_counter;

pthread_key_t hs_health_key;

static struct flb_hs_throughput_sample *samples_add(
struct flb_hs_throughput_samples *samples)
Expand Down Expand Up @@ -81,19 +70,6 @@ static struct flb_hs_throughput_sample *samples_get(
return samples->items + samples_translate_index(samples, index);
}

struct {
int enabled;
struct mk_list *input_plugins;
struct mk_list *output_plugins;
double out_in_ratio_threshold;

struct flb_hs_throughput_samples samples;
bool healthy;
} throughput_check_state = {0};

struct flb_health_check_metrics_counter *metrics_counter;

pthread_key_t hs_health_key;

static struct mk_list *hs_health_key_create()
{
Expand Down
28 changes: 28 additions & 0 deletions src/http_server/api/v1/health.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,34 @@ struct flb_hs_hc_buf {
struct mk_list _head;
};

/*
* in/out records sample at a certain timestamp.
*/
struct flb_hs_throughput_sample {
uint64_t in_records;
uint64_t out_records;
uint64_t timestamp_seconds;
};

/* ring buffer + helper functions for storing samples */
struct flb_hs_throughput_samples {
struct flb_hs_throughput_sample *items;
int size;
int count;
int insert;
};

/* throughput health check state */
struct flb_hs_throughput_state {
int enabled;
struct mk_list *input_plugins;
struct mk_list *output_plugins;
double out_in_ratio_threshold;

struct flb_hs_throughput_samples samples;
int healthy;
};

/* health endpoint*/
int api_v1_health(struct flb_hs *hs);

Expand Down

0 comments on commit a9b0cfb

Please sign in to comment.