5050#include "cloudwatch_api.h"
5151
5252#define ERR_CODE_ALREADY_EXISTS "ResourceAlreadyExistsException"
53- #define ERR_CODE_INVALID_SEQUENCE_TOKEN "InvalidSequenceTokenException"
5453#define ERR_CODE_NOT_FOUND "ResourceNotFoundException"
55- #define ERR_CODE_DATA_ALREADY_ACCEPTED "DataAlreadyAcceptedException"
5654
5755#define AMZN_REQUEST_ID_HEADER "x-amzn-RequestId"
5856
@@ -229,23 +227,6 @@ static int init_put_payload(struct flb_cloudwatch *ctx, struct cw_flush *buf,
229227 goto error ;
230228 }
231229
232- if (stream -> sequence_token ) {
233- if (!try_to_write (buf -> out_buf , offset , buf -> out_buf_size ,
234- "\"sequenceToken\":\"" , 17 )) {
235- goto error ;
236- }
237-
238- if (!try_to_write (buf -> out_buf , offset , buf -> out_buf_size ,
239- stream -> sequence_token , 0 )) {
240- goto error ;
241- }
242-
243- if (!try_to_write (buf -> out_buf , offset , buf -> out_buf_size ,
244- "\"," , 2 )) {
245- goto error ;
246- }
247- }
248-
249230 if (!try_to_write (buf -> out_buf , offset , buf -> out_buf_size ,
250231 "\"logEvents\":[" , 13 )) {
251232 goto error ;
@@ -493,9 +474,6 @@ void reset_flush_buf(struct flb_cloudwatch *ctx, struct cw_flush *buf) {
493474 if (buf -> current_stream != NULL ) {
494475 buf -> data_size += strlen (buf -> current_stream -> name );
495476 buf -> data_size += strlen (buf -> current_stream -> group );
496- if (buf -> current_stream -> sequence_token ) {
497- buf -> data_size += strlen (buf -> current_stream -> sequence_token );
498- }
499477 }
500478}
501479
@@ -1153,7 +1131,6 @@ static int set_log_group_retention(struct flb_cloudwatch *ctx, struct log_stream
11531131 struct flb_aws_client * cw_client ;
11541132 flb_sds_t body ;
11551133 flb_sds_t tmp ;
1156- flb_sds_t error ;
11571134
11581135 flb_plg_info (ctx -> ins , "Setting retention policy on log group %s to %dd" , stream -> group , ctx -> log_retention_days );
11591136
@@ -1196,17 +1173,9 @@ static int set_log_group_retention(struct flb_cloudwatch *ctx, struct log_stream
11961173
11971174 /* Check error */
11981175 if (c -> resp .payload_size > 0 ) {
1199- error = flb_aws_error (c -> resp .payload , c -> resp .payload_size );
1200- if (error != NULL ) {
1201- /* some other error occurred; notify user */
1202- flb_aws_print_error (c -> resp .payload , c -> resp .payload_size ,
1203- "PutRetentionPolicy" , ctx -> ins );
1204- flb_sds_destroy (error );
1205- }
1206- else {
1207- /* error can not be parsed, print raw response to debug */
1208- flb_plg_debug (ctx -> ins , "Raw response: %s" , c -> resp .payload );
1209- }
1176+ /* some error occurred; notify user */
1177+ flb_aws_print_error (c -> resp .payload , c -> resp .payload_size ,
1178+ "PutRetentionPolicy" , ctx -> ins );
12101179 }
12111180 }
12121181
@@ -1287,8 +1256,8 @@ int create_log_group(struct flb_cloudwatch *ctx, struct log_stream *stream)
12871256 flb_sds_destroy (error );
12881257 }
12891258 else {
1290- /* error can not be parsed, print raw response to debug */
1291- flb_plg_debug (ctx -> ins , "Raw response: %s" , c -> resp .payload );
1259+ /* error can not be parsed, print raw response */
1260+ flb_plg_warn (ctx -> ins , "Raw response: %s" , c -> resp .payload );
12921261 }
12931262 }
12941263 }
@@ -1402,8 +1371,8 @@ int create_log_stream(struct flb_cloudwatch *ctx, struct log_stream *stream,
14021371 flb_sds_destroy (error );
14031372 }
14041373 else {
1405- /* error can not be parsed, print raw response to debug */
1406- flb_plg_debug (ctx -> ins , "Raw response: %s" , c -> resp .payload );
1374+ /* error can not be parsed, print raw response */
1375+ flb_plg_warn (ctx -> ins , "Raw response: %s" , c -> resp .payload );
14071376 }
14081377 }
14091378 }
@@ -1417,8 +1386,7 @@ int create_log_stream(struct flb_cloudwatch *ctx, struct log_stream *stream,
14171386}
14181387
14191388/*
1420- * Returns -1 on failure, 0 on success, and 1 for a sequence token error,
1421- * which means the caller can retry.
1389+ * Returns -1 on failure, 0 on success
14221390 */
14231391int put_log_events (struct flb_cloudwatch * ctx , struct cw_flush * buf ,
14241392 struct log_stream * stream , size_t payload_size )
@@ -1427,7 +1395,6 @@ int put_log_events(struct flb_cloudwatch *ctx, struct cw_flush *buf,
14271395 struct flb_http_client * c = NULL ;
14281396 struct flb_aws_client * cw_client ;
14291397 flb_sds_t tmp ;
1430- flb_sds_t error ;
14311398 int num_headers = 1 ;
14321399 int retry = FLB_TRUE ;
14331400
@@ -1460,8 +1427,7 @@ int put_log_events(struct flb_cloudwatch *ctx, struct cw_flush *buf,
14601427 if (c -> resp .data == NULL || c -> resp .data_len == 0 || strstr (c -> resp .data , AMZN_REQUEST_ID_HEADER ) == NULL ) {
14611428 /* code was 200, but response is invalid, treat as failure */
14621429 if (c -> resp .data != NULL ) {
1463- flb_plg_debug (ctx -> ins , "Could not find sequence token in "
1464- "response: response body is empty: full data: `%.*s`" , c -> resp .data_len , c -> resp .data );
1430+ flb_plg_debug (ctx -> ins , "Invalid response: full data: `%.*s`" , c -> resp .data_len , c -> resp .data );
14651431 }
14661432 flb_http_client_destroy (c );
14671433
@@ -1474,73 +1440,15 @@ int put_log_events(struct flb_cloudwatch *ctx, struct cw_flush *buf,
14741440 AMZN_REQUEST_ID_HEADER );
14751441 return -1 ;
14761442 }
1477-
1478-
1479- /* success */
1480- if (c -> resp .payload_size > 0 ) {
1481- flb_plg_debug (ctx -> ins , "Sent events to %s" , stream -> name );
1482- tmp = flb_json_get_val (c -> resp .payload , c -> resp .payload_size ,
1483- "nextSequenceToken" );
1484- if (tmp ) {
1485- if (stream -> sequence_token != NULL ) {
1486- flb_sds_destroy (stream -> sequence_token );
1487- }
1488- stream -> sequence_token = tmp ;
1489-
1490- flb_http_client_destroy (c );
1491- return 0 ;
1492- }
1493- else {
1494- flb_plg_error (ctx -> ins , "Could not find sequence token in "
1495- "response: %s" , c -> resp .payload );
1496- }
1497- }
14981443
14991444 flb_http_client_destroy (c );
15001445 return 0 ;
15011446 }
15021447
15031448 /* Check error */
15041449 if (c -> resp .payload_size > 0 ) {
1505- error = flb_aws_error (c -> resp .payload , c -> resp .payload_size );
1506- if (error != NULL ) {
1507- if (strcmp (error , ERR_CODE_INVALID_SEQUENCE_TOKEN ) == 0 ) {
1508- /*
1509- * This case will happen when we do not know the correct
1510- * sequence token; we can find it in the error response
1511- * and retry.
1512- */
1513- flb_plg_debug (ctx -> ins , "Sequence token was invalid, "
1514- "will retry" );
1515- tmp = flb_json_get_val (c -> resp .payload , c -> resp .payload_size ,
1516- "expectedSequenceToken" );
1517- if (tmp ) {
1518- if (stream -> sequence_token != NULL ) {
1519- flb_sds_destroy (stream -> sequence_token );
1520- }
1521- stream -> sequence_token = tmp ;
1522- flb_sds_destroy (error );
1523- flb_http_client_destroy (c );
1524- /* tell the caller to retry */
1525- return 1 ;
1526- }
1527- } else if (strcmp (error , ERR_CODE_DATA_ALREADY_ACCEPTED ) == 0 ) {
1528- /* not sure what causes this but it counts as success */
1529- flb_plg_info (ctx -> ins , "Got %s, a previous retry must have succeeded asychronously" , ERR_CODE_DATA_ALREADY_ACCEPTED );
1530- flb_sds_destroy (error );
1531- flb_http_client_destroy (c );
1532- /* success */
1533- return 0 ;
1534- }
1535- /* some other error occurred; notify user */
1536- flb_aws_print_error (c -> resp .payload , c -> resp .payload_size ,
1537- "PutLogEvents" , ctx -> ins );
1538- flb_sds_destroy (error );
1539- }
1540- else {
1541- /* error could not be parsed, print raw response to debug */
1542- flb_plg_debug (ctx -> ins , "Raw response: %s" , c -> resp .payload );
1543- }
1450+ flb_aws_print_error (c -> resp .payload , c -> resp .payload_size ,
1451+ "PutLogEvents" , ctx -> ins );
15441452 }
15451453 }
15461454
0 commit comments