Skip to content

Commit f5b094a

Browse files
out_azure_blob: fixed review comments & windows build error
Signed-off-by: Tanmaya Panda <[email protected]>
1 parent 4e90ac1 commit f5b094a

File tree

3 files changed

+80
-107
lines changed

3 files changed

+80
-107
lines changed

plugins/out_azure_blob/azure_blob.c

Lines changed: 75 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,15 @@ void generate_random_string_blob(char *str, size_t length)
152152
{
153153
const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
154154
const size_t charset_size = sizeof(charset) - 1;
155+
size_t i;
156+
size_t index;
155157

156-
// Seed the random number generator with multiple sources of entropy
158+
/* Seed the random number generator with multiple sources of entropy */
157159
unsigned int seed = (unsigned int)(time(NULL) ^ clock() ^ getpid());
158160
srand(seed);
159161

160-
for (size_t i = 0; i < length; ++i) {
161-
size_t index = (size_t)rand() % charset_size;
162+
for (i = 0; i < length; ++i) {
163+
index = (size_t)rand() % charset_size;
162164
str[i] = charset[index];
163165
}
164166

@@ -182,7 +184,6 @@ static int create_blob(struct flb_azure_blob *ctx, char *name)
182184
ctx->u->base.flags &= ~(FLB_IO_ASYNC);
183185
ctx->u->base.net.io_timeout = ctx->io_timeout;
184186
}
185-
flb_plg_debug(ctx->ins, "create_blob -- async flag is %d", flb_stream_is_async(&ctx->u->base));
186187

187188
/* Get upstream connection */
188189
u_conn = flb_upstream_conn_get(ctx->u);
@@ -344,7 +345,6 @@ static int http_send_blob(struct flb_config *config, struct flb_azure_blob *ctx,
344345
ctx->u->base.flags &= ~(FLB_IO_ASYNC);
345346
ctx->u->base.net.io_timeout = ctx->io_timeout;
346347
}
347-
flb_plg_debug(ctx->ins, "send_blob -- async flag is %d", flb_stream_is_async(&ctx->u->base));
348348

349349
/* Get upstream connection */
350350
u_conn = flb_upstream_conn_get(ctx->u);
@@ -461,25 +461,33 @@ static int send_blob(struct flb_config *config,
461461
flb_sds_t ref_name = NULL;
462462
void *payload_buf = data;
463463
size_t payload_size = bytes;
464-
char generated_random_string[ctx->blob_uri_length + 1];
464+
char *generated_random_string;
465465

466466
ref_name = flb_sds_create_size(256);
467467
if (!ref_name) {
468468
return FLB_RETRY;
469469
}
470470

471+
/* Allocate memory for the random string dynamically */
472+
generated_random_string = flb_malloc(ctx->blob_uri_length + 1);
473+
if (!generated_random_string) {
474+
flb_errno();
475+
flb_plg_error(ctx->ins, "cannot allocate memory for random string");
476+
flb_sds_destroy(ref_name);
477+
return FLB_RETRY;
478+
}
479+
471480
if (blob_type == AZURE_BLOB_APPENDBLOB) {
472481
uri = azb_append_blob_uri(ctx, tag);
473482
}
474483
else if (blob_type == AZURE_BLOB_BLOCKBLOB) {
475-
generate_random_string_blob(generated_random_string, ctx->blob_uri_length); // Generate the random string
484+
generate_random_string_blob(generated_random_string, ctx->blob_uri_length); /* Generate the random string */
476485
if (event_type == FLB_EVENT_TYPE_LOGS) {
477486
block_id = azb_block_blob_id_logs(&ms);
478487
if (!block_id) {
479488
flb_plg_error(ctx->ins, "could not generate block id");
480-
489+
flb_free(generated_random_string);
481490
cfl_sds_destroy(ref_name);
482-
483491
return FLB_RETRY;
484492
}
485493
uri = azb_block_blob_uri(ctx, tag, block_id, ms, generated_random_string);
@@ -493,35 +501,14 @@ static int send_blob(struct flb_config *config,
493501
}
494502

495503
if (!uri) {
504+
flb_free(generated_random_string);
496505
if (block_id != NULL) {
497506
flb_free(block_id);
498507
}
499508
flb_sds_destroy(ref_name);
500509
return FLB_RETRY;
501510
}
502511

503-
/* Logs: Format the data (msgpack -> JSON) *//*
504-
if (event_type == FLB_EVENT_TYPE_LOGS) {
505-
ret = azure_blob_format(config, i_ins,
506-
ctx, NULL,
507-
FLB_EVENT_TYPE_LOGS,
508-
tag, tag_len,
509-
data, bytes,
510-
&payload_buf, &payload_size);
511-
if (ret != 0) {
512-
flb_sds_destroy(uri);
513-
if (block_id != NULL) {
514-
flb_free(block_id);
515-
}
516-
flb_sds_destroy(ref_name);
517-
return FLB_ERROR;
518-
}
519-
}
520-
else if (event_type == FLB_EVENT_TYPE_BLOBS) {
521-
payload_buf = data;
522-
payload_size = bytes;
523-
}*/
524-
525512
/* Map buffer */
526513
payload_buf = data;
527514
payload_size = bytes;
@@ -548,6 +535,7 @@ static int send_blob(struct flb_config *config,
548535
}
549536

550537
flb_sds_destroy(uri);
538+
flb_free(generated_random_string);
551539

552540
if (block_id != NULL) {
553541
flb_free(block_id);
@@ -568,7 +556,6 @@ static int create_container(struct flb_azure_blob *ctx, char *name)
568556
ctx->u->base.flags &= ~(FLB_IO_ASYNC);
569557
ctx->u->base.net.io_timeout = ctx->io_timeout;
570558
}
571-
flb_plg_debug(ctx->ins, "create_container -- async flag is %d", flb_stream_is_async(&ctx->u->base));
572559

573560
/* Get upstream connection */
574561
u_conn = flb_upstream_conn_get(ctx->u);
@@ -667,7 +654,6 @@ static int ensure_container(struct flb_azure_blob *ctx)
667654
ctx->u->base.flags &= ~(FLB_IO_ASYNC);
668655
ctx->u->base.net.io_timeout = ctx->io_timeout;
669656
}
670-
flb_plg_debug(ctx->ins, "ensure_container -- async flag is %d", flb_stream_is_async(&ctx->u->base));
671657

672658
/* Get upstream connection */
673659
u_conn = flb_upstream_conn_get(ctx->u);
@@ -1212,7 +1198,6 @@ static void cb_azure_blob_ingest(struct flb_config *config, void *data) {
12121198

12131199
/* Log entry point and container information */
12141200
flb_plg_debug(ctx->ins, "Running upload timer callback (cb_azure_blob_ingest)..");
1215-
flb_plg_debug(ctx->ins, "inside ctx : container name is %s", ctx->container_name);
12161201

12171202
/* Initialize jitter for retry mechanism */
12181203
srand(time(NULL));
@@ -1310,7 +1295,8 @@ static void cb_azure_blob_ingest(struct flb_config *config, void *data) {
13101295
ret = azure_blob_store_file_delete(ctx, file);
13111296
if (ret == 0) {
13121297
flb_plg_debug(ctx->ins, "cb_azure_blob_ingest :: deleted successfully ingested file %s", fsf->name);
1313-
} else {
1298+
}
1299+
else {
13141300
flb_plg_error(ctx->ins, "cb_azure_blob_ingest :: failed to delete ingested file %s", fsf->name);
13151301
if (file) {
13161302
azure_blob_store_file_unlock(file);
@@ -1331,7 +1317,8 @@ static void cb_azure_blob_ingest(struct flb_config *config, void *data) {
13311317
file->fsf->name);
13321318
if (ctx->delete_on_max_upload_error){
13331319
azure_blob_store_file_delete(ctx, file);
1334-
}else{
1320+
}
1321+
else {
13351322
azure_blob_store_file_inactive(ctx, file);
13361323
}
13371324
}
@@ -1378,7 +1365,8 @@ static int ingest_all_chunks(struct flb_azure_blob *ctx, struct flb_config *conf
13781365
(char *) fsf->meta_buf, ctx->scheduler_max_retries);
13791366
if (ctx->delete_on_max_upload_error){
13801367
azure_blob_store_file_delete(ctx, chunk);
1381-
} else{
1368+
}
1369+
else {
13821370
azure_blob_store_file_inactive(ctx, chunk);
13831371
}
13841372
continue;
@@ -1450,7 +1438,8 @@ static void flush_init(void *out_context, struct flb_config *config)
14501438
ctx->fs->root_path);
14511439
FLB_OUTPUT_RETURN(FLB_RETRY);
14521440
}
1453-
}else{
1441+
}
1442+
else {
14541443
flb_plg_debug(ctx->ins,
14551444
"Did not find any local buffered data from previous "
14561445
"executions to azure blob; buffer=%s",
@@ -1507,7 +1496,8 @@ static void cb_azure_blob_flush(struct flb_event_chunk *event_chunk,
15071496

15081497
if (ctx->unify_tag == FLB_TRUE) {
15091498
tag_name = flb_sds_create("fluentbit-buffer-file-unify-tag.log");
1510-
} else {
1499+
}
1500+
else {
15111501
tag_name = event_chunk->tag;
15121502
}
15131503
tag_len = flb_sds_len(tag_name);
@@ -1578,21 +1568,24 @@ static void cb_azure_blob_flush(struct flb_event_chunk *event_chunk,
15781568
flb_plg_debug(ctx->ins, "uploaded file %s successfully", upload_file->fsf->name);
15791569
azure_blob_store_file_delete(ctx, upload_file);
15801570
goto cleanup;
1581-
} else {
1571+
}
1572+
else {
15821573
flb_plg_error(ctx->ins, "error uploading file %s", upload_file->fsf->name);
15831574
if (upload_file) {
15841575
azure_blob_store_file_unlock(upload_file);
15851576
upload_file->failures += 1;
15861577
}
15871578
goto error;
15881579
}
1589-
} else {
1580+
}
1581+
else {
15901582
/* Buffer current chunk */
15911583
ret = azure_blob_store_buffer_put(ctx, upload_file, tag_name, tag_len, json, json_size);
15921584
if (ret == 0) {
15931585
flb_plg_debug(ctx->ins, "buffered chunk %s", event_chunk->tag);
15941586
goto cleanup;
1595-
} else {
1587+
}
1588+
else {
15961589
flb_plg_error(ctx->ins, "failed to buffer chunk %s", event_chunk->tag);
15971590
goto error;
15981591
}
@@ -1621,7 +1614,8 @@ static void cb_azure_blob_flush(struct flb_event_chunk *event_chunk,
16211614
flb_free(final_payload);
16221615
}
16231616
FLB_OUTPUT_RETURN(FLB_RETRY);
1624-
} else {
1617+
}
1618+
else {
16251619

16261620
/*
16271621
* Azure blob requires a container. The following function validate that the container exists,
@@ -1901,75 +1895,76 @@ static struct flb_config_map config_map[] = {
19011895
},
19021896

19031897
{
1904-
FLB_CONFIG_MAP_BOOL, "buffering_enabled", "false",
1905-
0, FLB_TRUE, offsetof(struct flb_azure_blob, buffering_enabled),
1906-
"Enable buffering into disk before ingesting into Azure Blob."
1898+
FLB_CONFIG_MAP_BOOL, "buffering_enabled", "false",
1899+
0, FLB_TRUE, offsetof(struct flb_azure_blob, buffering_enabled),
1900+
"Enable buffering into disk before ingesting into Azure Blob"
19071901
},
19081902

19091903
{
1910-
FLB_CONFIG_MAP_STR, "buffer_dir", "/tmp/fluent-bit/azure-blob/",
1911-
0, FLB_TRUE, offsetof(struct flb_azure_blob, buffer_dir),
1912-
"Specifies the location of directory where the buffered data will be stored."
1904+
FLB_CONFIG_MAP_STR, "buffer_dir", "/tmp/fluent-bit/azure-blob/",
1905+
0, FLB_TRUE, offsetof(struct flb_azure_blob, buffer_dir),
1906+
"Specifies the location of directory where the buffered data will be stored"
19131907
},
19141908

19151909
{
1916-
FLB_CONFIG_MAP_TIME, "upload_timeout", "30m",
1917-
0, FLB_TRUE, offsetof(struct flb_azure_blob, upload_timeout),
1918-
"Optionally specify a timeout for uploads. "
1919-
"Fluent Bit will start ingesting buffer files which have been created more than x minutes and haven't reached upload_file_size limit yet. "
1920-
" Default is 30m."
1910+
FLB_CONFIG_MAP_TIME, "upload_timeout", "30m",
1911+
0, FLB_TRUE, offsetof(struct flb_azure_blob, upload_timeout),
1912+
"Optionally specify a timeout for uploads. "
1913+
"Fluent Bit will start ingesting buffer files which have been created more than x minutes and haven't reached upload_file_size limit yet"
1914+
"Default is 30m."
19211915
},
19221916

19231917
{
1924-
FLB_CONFIG_MAP_SIZE, "upload_file_size", "200M",
1925-
0, FLB_TRUE, offsetof(struct flb_azure_blob, file_size),
1926-
"Specifies the size of files to be uploaded in MBs. Default is 200MB"
1918+
FLB_CONFIG_MAP_SIZE, "upload_file_size", "200M",
1919+
0, FLB_TRUE, offsetof(struct flb_azure_blob, file_size),
1920+
"Specifies the size of files to be uploaded in MBs. Default is 200MB"
19271921
},
19281922

19291923
{
1930-
FLB_CONFIG_MAP_STR, "azure_blob_buffer_key", "key",
1931-
0, FLB_TRUE, offsetof(struct flb_azure_blob, azure_blob_buffer_key),
1932-
"Set the azure blob buffer key which needs to be specified when using multiple instances of azure blob output plugin and buffering is enabled"
1924+
FLB_CONFIG_MAP_STR, "azure_blob_buffer_key", "key",
1925+
0, FLB_TRUE, offsetof(struct flb_azure_blob, azure_blob_buffer_key),
1926+
"Set the azure blob buffer key which needs to be specified when using multiple instances of azure blob output plugin and buffering is enabled"
19331927
},
19341928

19351929
{
1936-
FLB_CONFIG_MAP_SIZE, "store_dir_limit_size", "8G",
1937-
0, FLB_TRUE, offsetof(struct flb_azure_blob, store_dir_limit_size),
1938-
"Set the max size of the buffer directory. Default is 8GB"
1930+
FLB_CONFIG_MAP_SIZE, "store_dir_limit_size", "8G",
1931+
0, FLB_TRUE, offsetof(struct flb_azure_blob, store_dir_limit_size),
1932+
"Set the max size of the buffer directory. Default is 8GB"
19391933
},
19401934

19411935
{
1942-
FLB_CONFIG_MAP_BOOL, "buffer_file_delete_early", "false",
1943-
0, FLB_TRUE, offsetof(struct flb_azure_blob, buffer_file_delete_early),
1944-
"Whether to delete the buffered file early after successful blob creation. Default is false"
1936+
FLB_CONFIG_MAP_BOOL, "buffer_file_delete_early", "false",
1937+
0, FLB_TRUE, offsetof(struct flb_azure_blob, buffer_file_delete_early),
1938+
"Whether to delete the buffered file early after successful blob creation. Default is false"
19451939
},
19461940

1947-
{ FLB_CONFIG_MAP_INT, "blob_uri_length", "64",
1948-
0, FLB_TRUE, offsetof(struct flb_azure_blob, blob_uri_length),
1949-
"Set the length of generated blob uri before ingesting to Azure Kusto. Default is 64"
1941+
{
1942+
FLB_CONFIG_MAP_INT, "blob_uri_length", "64",
1943+
0, FLB_TRUE, offsetof(struct flb_azure_blob, blob_uri_length),
1944+
"Set the length of generated blob uri before ingesting to Azure Kusto. Default is 64"
19501945
},
19511946

19521947
{
1953-
FLB_CONFIG_MAP_BOOL, "unify_tag", "false",
1954-
0, FLB_TRUE, offsetof(struct flb_azure_blob, unify_tag),
1955-
"Whether to create a single buffer file when buffering mode is enabled. Default is false"
1948+
FLB_CONFIG_MAP_BOOL, "unify_tag", "false",
1949+
0, FLB_TRUE, offsetof(struct flb_azure_blob, unify_tag),
1950+
"Whether to create a single buffer file when buffering mode is enabled. Default is false"
19561951
},
19571952

19581953
{
1959-
FLB_CONFIG_MAP_INT, "scheduler_max_retries", "3",
1960-
0, FLB_TRUE, offsetof(struct flb_azure_blob, scheduler_max_retries),
1961-
"Maximum number of retries for the scheduler send blob. Default is 3"
1954+
FLB_CONFIG_MAP_INT, "scheduler_max_retries", "3",
1955+
0, FLB_TRUE, offsetof(struct flb_azure_blob, scheduler_max_retries),
1956+
"Maximum number of retries for the scheduler send blob. Default is 3"
19621957
},
19631958

19641959
{
1965-
FLB_CONFIG_MAP_BOOL, "delete_on_max_upload_error", "false",
1966-
0, FLB_TRUE, offsetof(struct flb_azure_blob, delete_on_max_upload_error),
1967-
"Whether to delete the buffer file on maximum upload errors. Default is false"
1960+
FLB_CONFIG_MAP_BOOL, "delete_on_max_upload_error", "false",
1961+
0, FLB_TRUE, offsetof(struct flb_azure_blob, delete_on_max_upload_error),
1962+
"Whether to delete the buffer file on maximum upload errors. Default is false"
19681963
},
19691964

19701965
{
1971-
FLB_CONFIG_MAP_TIME, "io_timeout", "60s",0, FLB_TRUE, offsetof(struct flb_azure_blob, io_timeout),
1972-
"HTTP IO timeout. Default is 60s"
1966+
FLB_CONFIG_MAP_TIME, "io_timeout", "60s",0, FLB_TRUE, offsetof(struct flb_azure_blob, io_timeout),
1967+
"HTTP IO timeout. Default is 60s"
19731968
},
19741969

19751970
/* EOF */

plugins/out_azure_blob/azure_blob_blockblob.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ int azb_block_blob_put_block_list(struct flb_azure_blob *ctx, flb_sds_t uri, flb
262262
ctx->u->base.flags &= ~(FLB_IO_ASYNC);
263263
ctx->u->base.net.io_timeout = ctx->io_timeout;
264264
}
265-
flb_plg_debug(ctx->ins, "azb_block_blob_put_block_list -- async flag is %d", flb_stream_is_async(&ctx->u->base));
266265

267266
/* Get upstream connection */
268267
u_conn = flb_upstream_conn_get(ctx->u);

0 commit comments

Comments
 (0)