Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stackdriver: Add latency metric for write log entries HTTP request. #9182

Merged
merged 1 commit into from
Aug 13, 2024
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
11 changes: 11 additions & 0 deletions plugins/out_stackdriver/stackdriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2829,6 +2829,9 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk,
struct flb_connection *u_conn;
struct flb_http_client *c;
int compressed = FLB_FALSE;
uint64_t write_entries_start = 0;
uint64_t write_entries_end = 0;
float write_entries_latency = 0.0;
#ifdef FLB_HAVE_METRICS
char *name = (char *) flb_output_name(ctx->ins);
uint64_t ts = cfl_time_now();
Expand Down Expand Up @@ -2923,9 +2926,14 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk,
flb_http_set_content_encoding_gzip(c);
}

write_entries_start = cfl_time_now();

/* Send HTTP request */
ret = flb_http_do(c, &b_sent);

write_entries_end = cfl_time_now();
write_entries_latency = (float)(write_entries_end - write_entries_start) / 1000000000.0;

/* validate response */
if (ret != 0) {
flb_plg_warn(ctx->ins, "http_do=%i", ret);
Expand Down Expand Up @@ -2994,6 +3002,9 @@ static void cb_stackdriver_flush(struct flb_event_chunk *event_chunk,
#ifdef FLB_HAVE_METRICS
if (ret_code == FLB_OK) {
cmt_counter_inc(ctx->cmt_successful_requests, ts, 1, (char *[]) {name});
if (write_entries_latency > 0.0) {
cmt_histogram_observe(ctx->cmt_write_entries_latency, ts, write_entries_latency, 1, (char *[]) {name});
}
add_record_metrics(ctx, ts, (int) event_chunk->total_events, 200, 0);

/* OLD api */
Expand Down
3 changes: 3 additions & 0 deletions plugins/out_stackdriver/stackdriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <fluent-bit/flb_regex.h>
#include <fluent-bit/flb_metrics.h>

#include <cmetrics/cmt_histogram.h>

/* refresh token every 50 minutes */
#define FLB_STD_TOKEN_REFRESH 3000

Expand Down Expand Up @@ -218,6 +220,7 @@ struct flb_stackdriver {
struct cmt_counter *cmt_requests_total;
struct cmt_counter *cmt_proc_records_total;
struct cmt_counter *cmt_retried_records_total;
struct cmt_histogram *cmt_write_entries_latency;
#endif

/* plugin instance */
Expand Down
15 changes: 13 additions & 2 deletions plugins/out_stackdriver/stackdriver_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ struct flb_stackdriver *flb_stackdriver_conf_create(struct flb_output_instance *
const char *backwards_compatible_env_var;
struct flb_stackdriver *ctx;
size_t http_request_key_size;
struct cmt_histogram_buckets *buckets;

/* Allocate config context */
ctx = flb_calloc(1, sizeof(struct flb_stackdriver));
Expand Down Expand Up @@ -559,6 +560,16 @@ struct flb_stackdriver *flb_stackdriver_conf_create(struct flb_output_instance *
"Total number of retried records.",
2, (char *[]) {"status", "name"});

buckets = cmt_histogram_buckets_create(7, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0);
ctx->cmt_write_entries_latency = cmt_histogram_create(ins->cmt,
"fluentbit",
"stackdriver",
"write_entries_latency",
"Latency of Cloud Logging WriteLogEntries HTTP request.",
buckets,
1, (char *[]) {"name"});


/* OLD api */
flb_metrics_add(FLB_STACKDRIVER_SUCCESSFUL_REQUESTS,
"stackdriver_successful_requests", ctx->ins->metrics);
Expand Down Expand Up @@ -599,7 +610,7 @@ int flb_stackdriver_conf_destroy(struct flb_stackdriver *ctx)
}
flb_free(ctx->creds);
}

if (ctx->env) {
if (ctx->env->creds_file) {
flb_sds_destroy(ctx->env->creds_file);
Expand All @@ -620,7 +631,7 @@ int flb_stackdriver_conf_destroy(struct flb_stackdriver *ctx)
if (ctx->metadata_server) {
flb_sds_destroy(ctx->metadata_server);
}

if (ctx->resource_type == RESOURCE_TYPE_K8S){
flb_sds_destroy(ctx->namespace_name);
flb_sds_destroy(ctx->pod_name);
Expand Down
Loading