From 7835635a92f3a7499c4aa621e4acb3e6baec4322 Mon Sep 17 00:00:00 2001 From: shuaichen Date: Tue, 26 Nov 2024 16:53:23 -0800 Subject: [PATCH 1/2] out_stackdriver: return cached token when current_timestamp is less than cached_expiration. Signed-off-by: shuaichen --- plugins/out_stackdriver/stackdriver.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/out_stackdriver/stackdriver.c b/plugins/out_stackdriver/stackdriver.c index 903bffce98d..ba0e808957b 100644 --- a/plugins/out_stackdriver/stackdriver.c +++ b/plugins/out_stackdriver/stackdriver.c @@ -357,6 +357,7 @@ static flb_sds_t get_google_token(struct flb_stackdriver *ctx) int ret = 0; flb_sds_t output = NULL; time_t cached_expiration = 0; + time_t current_timestamp = 0; ret = pthread_mutex_trylock(&ctx->token_mutex); if (ret == EBUSY) { @@ -369,14 +370,16 @@ static flb_sds_t get_google_token(struct flb_stackdriver *ctx) */ output = oauth2_cache_to_token(); cached_expiration = oauth2_cache_get_expiration(); - if (time(NULL) >= cached_expiration) { + current_timestamp = time(NULL); + + if (current_timestamp < cached_expiration) { return output; } else { /* * Cached token is expired. Wait on lock to use up-to-date token * by either waiting for it to be refreshed or refresh it ourselves. */ - flb_plg_info(ctx->ins, "Cached token is expired. Waiting on lock."); + flb_plg_info(ctx->ins, "Cached token is expired, waiting on lock: current_timestamp=%lld, cached_expiration=%lld"); ret = pthread_mutex_lock(&ctx->token_mutex); } } From efd9944b9aa77a572e5c25e15e07ff4ad3f0d7ac Mon Sep 17 00:00:00 2001 From: Braydon Kains <93549768+braydonk@users.noreply.github.com> Date: Wed, 27 Nov 2024 08:45:26 -0500 Subject: [PATCH 2/2] stackdriver: revert log line change Signed-off-by: Braydon Kains <93549768+braydonk@users.noreply.github.com> --- plugins/out_stackdriver/stackdriver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/out_stackdriver/stackdriver.c b/plugins/out_stackdriver/stackdriver.c index ba0e808957b..99ef657a0b4 100644 --- a/plugins/out_stackdriver/stackdriver.c +++ b/plugins/out_stackdriver/stackdriver.c @@ -379,7 +379,7 @@ static flb_sds_t get_google_token(struct flb_stackdriver *ctx) * Cached token is expired. Wait on lock to use up-to-date token * by either waiting for it to be refreshed or refresh it ourselves. */ - flb_plg_info(ctx->ins, "Cached token is expired, waiting on lock: current_timestamp=%lld, cached_expiration=%lld"); + flb_plg_info(ctx->ins, "Cached token is expired. Waiting on lock."); ret = pthread_mutex_lock(&ctx->token_mutex); } }