Skip to content

Commit aa033e7

Browse files
out_azure_kusto: Close OAuth handles in case of failure
Signed-off-by: ag-ramachandran <[email protected]>
1 parent 2d3b233 commit aa033e7

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

plugins/out_azure_kusto/azure_kusto.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int azure_kusto_get_msi_token(struct flb_azure_kusto *ctx)
4545
/* Retrieve access token */
4646
token = flb_azure_msiauth_token_get(ctx->o);
4747
if (!token) {
48-
flb_plg_error(ctx->ins, "error retrieving oauth2 access token");
48+
flb_plg_error(ctx->ins, "error retrieving oauth2 access token (MSI access token is NULL)");
4949
return -1;
5050
}
5151

@@ -99,11 +99,16 @@ static int azure_kusto_get_service_principal_token(struct flb_azure_kusto *ctx)
9999
flb_plg_error(ctx->ins, "error appending oauth2 params");
100100
return -1;
101101
}
102+
/* Enable OAuth2 for token retrieval */
103+
ctx->o->cfg.enabled = FLB_TRUE;
102104

103105
/* Retrieve access token */
104106
char *token = flb_oauth2_token_get(ctx->o);
105107
if (!token) {
106-
flb_plg_error(ctx->ins, "error retrieving oauth2 access token");
108+
flb_plg_error(ctx->ins, "error retrieving oauth2 access token - "
109+
"check Fluent Bit logs for '[oauth2]' errors "
110+
"(common causes: connection failure to '%s', invalid credentials, "
111+
"or malformed response)", ctx->oauth_url ? ctx->oauth_url : "unknown");
107112
return -1;
108113
}
109114

@@ -117,7 +122,6 @@ flb_sds_t get_azure_kusto_token(struct flb_azure_kusto *ctx)
117122
flb_sds_t output = NULL;
118123

119124
if (pthread_mutex_lock(&ctx->token_mutex)) {
120-
flb_plg_error(ctx->ins, "error locking mutex");
121125
return NULL;
122126
}
123127

@@ -933,15 +937,20 @@ static int cb_azure_kusto_init(struct flb_output_instance *ins, struct flb_confi
933937
* Create upstream context for Kusto Ingestion endpoint
934938
*/
935939
ctx->u = flb_upstream_create_url(config, ctx->ingestion_endpoint, io_flags, ins->tls);
940+
if (!ctx->u) {
941+
flb_plg_error(ctx->ins, "upstream creation failed");
942+
pthread_mutex_destroy(&ctx->resources_mutex);
943+
pthread_mutex_destroy(&ctx->token_mutex);
944+
pthread_mutex_destroy(&ctx->blob_mutex);
945+
flb_azure_kusto_conf_destroy(ctx);
946+
return -1;
947+
}
948+
936949
if (ctx->buffering_enabled == FLB_TRUE){
937950
flb_stream_disable_flags(&ctx->u->base, FLB_IO_ASYNC);
938951
ctx->u->base.net.io_timeout = ctx->io_timeout;
939952
ctx->has_old_buffers = azure_kusto_store_has_data(ctx);
940953
}
941-
if (!ctx->u) {
942-
flb_plg_error(ctx->ins, "upstream creation failed");
943-
return -1;
944-
}
945954

946955
flb_plg_debug(ctx->ins, "async flag is %d", flb_stream_is_async(&ctx->u->base));
947956

@@ -950,6 +959,11 @@ static int cb_azure_kusto_init(struct flb_output_instance *ins, struct flb_confi
950959
flb_oauth2_create(ctx->config, ctx->oauth_url, FLB_AZURE_KUSTO_TOKEN_REFRESH);
951960
if (!ctx->o) {
952961
flb_plg_error(ctx->ins, "cannot create oauth2 context");
962+
flb_upstream_destroy(ctx->u);
963+
pthread_mutex_destroy(&ctx->resources_mutex);
964+
pthread_mutex_destroy(&ctx->token_mutex);
965+
pthread_mutex_destroy(&ctx->blob_mutex);
966+
flb_azure_kusto_conf_destroy(ctx);
953967
return -1;
954968
}
955969
flb_output_upstream_set(ctx->u, ins);

0 commit comments

Comments
 (0)