@@ -197,11 +197,8 @@ static int build_headers(struct flb_http_client *c, struct flb_oci_logan *ctx,
197
197
flb_sds_t encoded_uri = NULL ;
198
198
flb_sds_t signature = NULL ;
199
199
flb_sds_t auth_header_str = NULL ;
200
-
201
200
flb_sds_t tmp_ref = NULL ;
202
-
203
201
size_t tmp_len = 0 ;
204
-
205
202
unsigned char sha256_buf [32 ] = { 0 };
206
203
207
204
tmp_sds = flb_sds_create_size (512 );
@@ -576,6 +573,7 @@ static int cb_oci_logan_init(struct flb_output_instance *ins,
576
573
struct flb_config * config , void * data )
577
574
{
578
575
struct flb_oci_logan * ctx ;
576
+
579
577
ctx = flb_oci_logan_conf_create (ins , config );
580
578
if (!ctx ) {
581
579
flb_plg_error (ins , "cannot initialize plugin" );
@@ -663,29 +661,33 @@ static flb_sds_t compose_uri(struct flb_oci_logan *ctx,
663
661
return full_uri ;
664
662
}
665
663
666
- // Checks if the current security token needs refresh(expires within 5min)
664
+ /* Checks if the current security token needs refresh(expires within 5min) */
667
665
static int token_needs_refresh (struct flb_oci_logan * ctx )
668
666
{
669
- time_t now = time ( NULL ) ;
667
+ time_t now ;
670
668
669
+ now = time (NULL );
671
670
return (ctx -> security_token .expires_at - now ) < 300 ;
672
671
}
673
672
674
- // Refreshes the security token if it's close to expiration
673
+ /* Refreshes the security token if it's close to expiration */
675
674
static int refresh_security_token_if_needed (struct flb_oci_logan * ctx )
676
675
{
676
+ flb_sds_t json_payload ;
677
+ flb_sds_t response ;
678
+
677
679
if (!token_needs_refresh (ctx )) {
678
680
return 0 ;
679
681
}
680
682
681
- flb_sds_t json_payload = create_federation_payload (ctx );
683
+ json_payload = create_federation_payload (ctx );
682
684
if (!json_payload ) {
683
685
flb_plg_error (ctx -> ins ,
684
686
"failed to create federation payload for token refresh" );
685
687
return -1 ;
686
688
}
687
689
688
- flb_sds_t response = sign_and_send_federation_request (ctx , json_payload );
690
+ response = sign_and_send_federation_request (ctx , json_payload );
689
691
flb_sds_destroy (json_payload );
690
692
691
693
if (!response ) {
@@ -722,9 +724,10 @@ static flb_sds_t sign_oci_request_with_security_token_for_logging(struct
722
724
unsigned char * b64_out = NULL ;
723
725
size_t sig_len = 0 ;
724
726
BIO * bio = NULL ;
727
+ size_t b64_size , olen ;
725
728
EVP_PKEY * pkey = NULL ;
726
729
EVP_MD_CTX * md_ctx = NULL ;
727
-
730
+ const char * headers_list ;
728
731
729
732
string_to_sign = flb_sds_create_size (2048 );
730
733
if (!string_to_sign ) {
@@ -784,8 +787,8 @@ static flb_sds_t sign_oci_request_with_security_token_for_logging(struct
784
787
goto cleanup ;
785
788
}
786
789
787
- size_t b64_size = ((sig_len + 2 ) / 3 ) * 4 + 1 ;
788
- size_t olen = 0 ;
790
+ b64_size = ((sig_len + 2 ) / 3 ) * 4 + 1 ;
791
+ olen = 0 ;
789
792
b64_out = flb_malloc (b64_size );
790
793
if (!b64_out ) {
791
794
goto cleanup ;
@@ -801,7 +804,7 @@ static flb_sds_t sign_oci_request_with_security_token_for_logging(struct
801
804
goto cleanup ;
802
805
}
803
806
804
- const char * headers_list = payload && payload_size > 0 ?
807
+ headers_list = payload && payload_size > 0 ?
805
808
"date (request-target) host x-content-sha256 content-type content-length"
806
809
: "date (request-target) host x-content-sha256 content-length" ;
807
810
@@ -878,7 +881,8 @@ struct flb_http_client *create_oci_signed_request_for_logging(struct
878
881
char date_buf [128 ];
879
882
time_t now ;
880
883
struct tm * tm_info ;
881
-
884
+ size_t date_len ;
885
+ const char * user_agent ;
882
886
883
887
if (refresh_security_token_if_needed (ctx ) < 0 ) {
884
888
flb_plg_error (ctx -> ins , "refresh_security_token_if_needed failed " );
@@ -897,7 +901,7 @@ struct flb_http_client *create_oci_signed_request_for_logging(struct
897
901
return NULL ;
898
902
}
899
903
900
- size_t date_len =
904
+ date_len =
901
905
strftime (date_buf , sizeof (date_buf ) - 1 , "%a, %d %b %Y %H:%M:%S GMT" ,
902
906
tm_info );
903
907
if (date_len == 0 ) {
@@ -941,7 +945,7 @@ struct flb_http_client *create_oci_signed_request_for_logging(struct
941
945
942
946
flb_http_add_header (client , "opc-retry-token" , 15 , content_sha256 ,
943
947
strlen (content_sha256 ));
944
- const char * user_agent = "fluent-bit-oci-plugin/1.0" ;
948
+ user_agent = "fluent-bit-oci-plugin/1.0" ;
945
949
flb_http_add_header (client , "User-Agent" , 10 , user_agent ,
946
950
strlen (user_agent ));
947
951
@@ -981,19 +985,22 @@ static void dump_payload_to_file(struct flb_oci_logan *ctx, flb_sds_t payload,
981
985
{
982
986
char hash_in_hex [66 ];
983
987
char filename [1024 ];
988
+ char * content_sha256 ;
989
+ int i ;
990
+ size_t payload_size ;
991
+ FILE * fp ;
984
992
985
993
if (!ctx -> payload_files_location ) {
986
994
flb_plg_error (ctx -> ins ,
987
995
"directory path for dumping should be specified" );
988
996
return ;
989
997
}
990
- size_t payload_size = flb_sds_len (payload );
991
- char * content_sha256 =
992
- calculate_content_sha256_b64 (payload , payload_size );
998
+ payload_size = flb_sds_len (payload );
999
+ content_sha256 = calculate_content_sha256_b64 (payload , payload_size );
993
1000
if (!content_sha256 ) {
994
1001
return ;
995
1002
}
996
- int i ;
1003
+
997
1004
for (i = 0 ; i < SHA256_DIGEST_LENGTH ; i ++ ) {
998
1005
sprintf (hash_in_hex + (i * 2 ), "%02x" , content_sha256 [i ]);
999
1006
}
@@ -1007,7 +1014,7 @@ static void dump_payload_to_file(struct flb_oci_logan *ctx, flb_sds_t payload,
1007
1014
return ;
1008
1015
}
1009
1016
1010
- FILE * fp = fopen (filename , "w" );
1017
+ fp = fopen (filename , "w" );
1011
1018
if (!fp ) {
1012
1019
flb_plg_error (ctx -> ins , "cant open file -> %s" , filename );
1013
1020
flb_free (content_sha256 );
@@ -1031,6 +1038,7 @@ static int flush_to_endpoint(struct flb_oci_logan *ctx,
1031
1038
flb_sds_t full_uri ;
1032
1039
struct flb_http_client * c = NULL ;
1033
1040
struct flb_connection * u_conn ;
1041
+ bool should_retry ;
1034
1042
1035
1043
if (!payload ) {
1036
1044
return FLB_ERROR ;
@@ -1053,7 +1061,7 @@ static int flush_to_endpoint(struct flb_oci_logan *ctx,
1053
1061
flb_sds_destroy (full_uri );
1054
1062
return FLB_ERROR ;
1055
1063
}
1056
- bool should_retry = 0 ;
1064
+ should_retry = 0 ;
1057
1065
if (strcmp (ctx -> auth_type , "instance_principal" ) == 0 ) {
1058
1066
c = create_oci_signed_request_for_logging (ctx , u_conn ,
1059
1067
full_uri ,
@@ -1346,6 +1354,8 @@ static void pack_oci_fields(msgpack_packer *packer, struct flb_oci_logan *ctx,
1346
1354
static int check_metadata_dot_notation (msgpack_object key ,
1347
1355
char * * metadata_key )
1348
1356
{
1357
+ int meta_key_start , meta_key_len ;
1358
+
1349
1359
if (key .type != MSGPACK_OBJECT_STR ) {
1350
1360
return FLB_FALSE ;
1351
1361
}
@@ -1363,8 +1373,8 @@ static int check_metadata_dot_notation(msgpack_object key,
1363
1373
if (key .via .str .ptr [FLB_OCI_METADATA_KEY_SIZE ] != '.' ) {
1364
1374
return FLB_FALSE ;
1365
1375
}
1366
- int meta_key_start = FLB_OCI_METADATA_KEY_SIZE + 1 ;
1367
- int meta_key_len = key .via .str .size - meta_key_start ;
1376
+ meta_key_start = FLB_OCI_METADATA_KEY_SIZE + 1 ;
1377
+ meta_key_len = key .via .str .size - meta_key_start ;
1368
1378
if (meta_key_len <= 0 ) {
1369
1379
return FLB_FALSE ;
1370
1380
}
@@ -1406,11 +1416,16 @@ static int get_and_pack_oci_fields_from_record(msgpack_packer *packer,
1406
1416
const char * log_path_value = NULL ;
1407
1417
int log_path_len = 0 ;
1408
1418
1409
- //handling metadata
1419
+ char tz_str [256 ];
1420
+ int tz_len ;
1410
1421
struct mk_list dot_metadata_list ;
1411
1422
struct metadata_obj * dot_meta_obj ;
1412
1423
char * dot_meta_key ;
1413
1424
int has_dot_metadata = 0 ;
1425
+ int total_meta_fields ;
1426
+ struct mk_list * head ;
1427
+ struct mk_list * tmp ;
1428
+ int j ;
1414
1429
1415
1430
mk_list_init (& dot_metadata_list );
1416
1431
@@ -1620,8 +1635,7 @@ static int get_and_pack_oci_fields_from_record(msgpack_packer *packer,
1620
1635
}
1621
1636
1622
1637
if (log_timezone ) {
1623
- char tz_str [256 ];
1624
- int tz_len = log_timezone -> via .str .size ;
1638
+ tz_len = log_timezone -> via .str .size ;
1625
1639
if (tz_len >= sizeof (tz_str )) {
1626
1640
tz_len = sizeof (tz_str ) - 1 ;
1627
1641
}
@@ -1649,7 +1663,7 @@ static int get_and_pack_oci_fields_from_record(msgpack_packer *packer,
1649
1663
msgpack_pack_str_body (packer , FLB_OCI_LOG_METADATA ,
1650
1664
FLB_OCI_LOG_METADATA_SIZE );
1651
1665
1652
- int total_meta_fields = 0 ;
1666
+ total_meta_fields = 0 ;
1653
1667
if (metadata ) {
1654
1668
total_meta_fields += metadata -> via .map .size ;
1655
1669
}
@@ -1660,15 +1674,13 @@ static int get_and_pack_oci_fields_from_record(msgpack_packer *packer,
1660
1674
msgpack_pack_map (packer , total_meta_fields );
1661
1675
1662
1676
if (metadata ) {
1663
- int j ;
1664
1677
for (j = 0 ; j < metadata -> via .map .size ; j ++ ) {
1665
1678
msgpack_pack_object (packer , metadata -> via .map .ptr [j ].key );
1666
1679
msgpack_pack_object (packer , metadata -> via .map .ptr [j ].val );
1667
1680
}
1668
1681
}
1669
1682
1670
1683
if (has_dot_metadata ) {
1671
- struct mk_list * head ;
1672
1684
mk_list_foreach (head , & dot_metadata_list ) {
1673
1685
dot_meta_obj =
1674
1686
mk_list_entry (head , struct metadata_obj , _head );
@@ -1698,8 +1710,6 @@ static int get_and_pack_oci_fields_from_record(msgpack_packer *packer,
1698
1710
}
1699
1711
}
1700
1712
if (has_dot_metadata ) {
1701
- struct mk_list * tmp ;
1702
- struct mk_list * head ;
1703
1713
mk_list_foreach_safe (head , tmp , & dot_metadata_list ) {
1704
1714
dot_meta_obj = mk_list_entry (head , struct metadata_obj , _head );
1705
1715
if (dot_meta_obj -> key )
@@ -1729,6 +1739,9 @@ static int send_batch_with_count(struct flb_oci_logan *ctx,
1729
1739
msgpack_object map ;
1730
1740
char * tag ;
1731
1741
int tag_len ;
1742
+ int skip ;
1743
+ int packed_records ;
1744
+ int map_size ;
1732
1745
1733
1746
tag = event_chunk -> tag ;
1734
1747
tag_len = ((event_chunk -> tag ) ? flb_sds_len (event_chunk -> tag ) : 0 );
@@ -1753,7 +1766,6 @@ static int send_batch_with_count(struct flb_oci_logan *ctx,
1753
1766
log_set_id = ctx -> oci_la_log_set_id ;
1754
1767
}
1755
1768
else {
1756
- int skip ;
1757
1769
for (skip = 0 ; skip < start_record ; skip ++ ) {
1758
1770
if (flb_log_event_decoder_next (& log_decoder , & log_event ) !=
1759
1771
FLB_EVENT_DECODER_SUCCESS ) {
@@ -1803,14 +1815,14 @@ static int send_batch_with_count(struct flb_oci_logan *ctx,
1803
1815
current_record ++ ;
1804
1816
}
1805
1817
1806
- int packed_records = 0 ;
1818
+ packed_records = 0 ;
1807
1819
while (packed_records < record_count &&
1808
1820
flb_log_event_decoder_next (& log_decoder ,
1809
1821
& log_event ) ==
1810
1822
FLB_EVENT_DECODER_SUCCESS ) {
1811
1823
1812
1824
map = * log_event .body ;
1813
- int map_size = map .via .map .size ;
1825
+ map_size = map .via .map .size ;
1814
1826
1815
1827
/* lookupfor message or log field */
1816
1828
msg = -1 ;
@@ -1851,9 +1863,8 @@ static int send_batch_with_count(struct flb_oci_logan *ctx,
1851
1863
1852
1864
flb_log_event_decoder_destroy (& log_decoder );
1853
1865
1854
- out_buf =
1855
- flb_msgpack_raw_to_json_sds (mp_sbuf .data , mp_sbuf .size ,
1856
- config -> json_escape_unicode );
1866
+ out_buf = flb_msgpack_raw_to_json_sds (mp_sbuf .data , mp_sbuf .size ,
1867
+ config -> json_escape_unicode );
1857
1868
flb_plg_debug (ctx -> ins , "out->buf [%s]" , out_buf );
1858
1869
msgpack_sbuffer_destroy (& mp_sbuf );
1859
1870
@@ -1887,6 +1898,9 @@ static int total_flush(struct flb_event_chunk *event_chunk,
1887
1898
size_t estimated_total_size = 0 ;
1888
1899
flb_sds_t log_group_id = NULL ;
1889
1900
flb_sds_t log_set_id = NULL ;
1901
+ int batches_needed , records_per_batch , start_record , remaining_records ,
1902
+ batch_size ;
1903
+ msgpack_object map ;
1890
1904
1891
1905
/* intialize decoder for counting record and estimate size */
1892
1906
ret = flb_log_event_decoder_init (& log_decoder , (char * ) event_chunk -> data ,
@@ -1899,7 +1913,7 @@ static int total_flush(struct flb_event_chunk *event_chunk,
1899
1913
1900
1914
while (flb_log_event_decoder_next (& log_decoder , & log_event ) ==
1901
1915
FLB_EVENT_DECODER_SUCCESS ) {
1902
- msgpack_object map = * log_event .body ;
1916
+ map = * log_event .body ;
1903
1917
1904
1918
for (i = 0 ; i < map .via .map .size ; i ++ ) {
1905
1919
if (map .via .map .ptr [i ].val .type == MSGPACK_OBJECT_STR ) {
@@ -1926,12 +1940,13 @@ static int total_flush(struct flb_event_chunk *event_chunk,
1926
1940
}
1927
1941
1928
1942
/* calculate batching parameters */
1929
- int batches_needed = (estimated_total_size + MAX_PAYLOAD_SIZE_BYTES - 1 ) / MAX_PAYLOAD_SIZE_BYTES ;
1943
+ batches_needed = (estimated_total_size + MAX_PAYLOAD_SIZE_BYTES -
1944
+ 1 ) / MAX_PAYLOAD_SIZE_BYTES ;
1930
1945
if (batches_needed < 1 ) {
1931
1946
batches_needed = 1 ;
1932
1947
}
1933
-
1934
- int records_per_batch = (total_records + batches_needed - 1 ) / batches_needed ;
1948
+
1949
+ records_per_batch = (total_records + batches_needed - 1 ) / batches_needed ;
1935
1950
if (records_per_batch < 1 ) {
1936
1951
records_per_batch = 1 ;
1937
1952
}
@@ -1941,13 +1956,13 @@ static int total_flush(struct flb_event_chunk *event_chunk,
1941
1956
batches_needed , records_per_batch );
1942
1957
1943
1958
/* send data in batches */
1944
- int start_record = 0 ;
1945
- int remaining_records = total_records ;
1959
+ start_record = 0 ;
1960
+ remaining_records = total_records ;
1946
1961
1947
1962
while (remaining_records > 0 ) {
1948
- int batch_size =
1949
- ( remaining_records >
1950
- records_per_batch ) ? records_per_batch : remaining_records ;
1963
+ batch_size = ( remaining_records >
1964
+ records_per_batch ) ? records_per_batch :
1965
+ remaining_records ;
1951
1966
1952
1967
ret =
1953
1968
send_batch_with_count (ctx , event_chunk , start_record , batch_size ,
0 commit comments