50
50
#include "cloudwatch_api.h"
51
51
52
52
#define ERR_CODE_ALREADY_EXISTS "ResourceAlreadyExistsException"
53
- #define ERR_CODE_INVALID_SEQUENCE_TOKEN "InvalidSequenceTokenException"
54
53
#define ERR_CODE_NOT_FOUND "ResourceNotFoundException"
55
- #define ERR_CODE_DATA_ALREADY_ACCEPTED "DataAlreadyAcceptedException"
56
54
57
55
#define AMZN_REQUEST_ID_HEADER "x-amzn-RequestId"
58
56
@@ -229,23 +227,6 @@ static int init_put_payload(struct flb_cloudwatch *ctx, struct cw_flush *buf,
229
227
goto error ;
230
228
}
231
229
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
-
249
230
if (!try_to_write (buf -> out_buf , offset , buf -> out_buf_size ,
250
231
"\"logEvents\":[" , 13 )) {
251
232
goto error ;
@@ -493,9 +474,6 @@ void reset_flush_buf(struct flb_cloudwatch *ctx, struct cw_flush *buf) {
493
474
if (buf -> current_stream != NULL ) {
494
475
buf -> data_size += strlen (buf -> current_stream -> name );
495
476
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
- }
499
477
}
500
478
}
501
479
@@ -1153,7 +1131,6 @@ static int set_log_group_retention(struct flb_cloudwatch *ctx, struct log_stream
1153
1131
struct flb_aws_client * cw_client ;
1154
1132
flb_sds_t body ;
1155
1133
flb_sds_t tmp ;
1156
- flb_sds_t error ;
1157
1134
1158
1135
flb_plg_info (ctx -> ins , "Setting retention policy on log group %s to %dd" , stream -> group , ctx -> log_retention_days );
1159
1136
@@ -1196,17 +1173,9 @@ static int set_log_group_retention(struct flb_cloudwatch *ctx, struct log_stream
1196
1173
1197
1174
/* Check error */
1198
1175
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 );
1210
1179
}
1211
1180
}
1212
1181
@@ -1287,8 +1256,8 @@ int create_log_group(struct flb_cloudwatch *ctx, struct log_stream *stream)
1287
1256
flb_sds_destroy (error );
1288
1257
}
1289
1258
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 );
1292
1261
}
1293
1262
}
1294
1263
}
@@ -1402,8 +1371,8 @@ int create_log_stream(struct flb_cloudwatch *ctx, struct log_stream *stream,
1402
1371
flb_sds_destroy (error );
1403
1372
}
1404
1373
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 );
1407
1376
}
1408
1377
}
1409
1378
}
@@ -1417,8 +1386,7 @@ int create_log_stream(struct flb_cloudwatch *ctx, struct log_stream *stream,
1417
1386
}
1418
1387
1419
1388
/*
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
1422
1390
*/
1423
1391
int put_log_events (struct flb_cloudwatch * ctx , struct cw_flush * buf ,
1424
1392
struct log_stream * stream , size_t payload_size )
@@ -1427,7 +1395,6 @@ int put_log_events(struct flb_cloudwatch *ctx, struct cw_flush *buf,
1427
1395
struct flb_http_client * c = NULL ;
1428
1396
struct flb_aws_client * cw_client ;
1429
1397
flb_sds_t tmp ;
1430
- flb_sds_t error ;
1431
1398
int num_headers = 1 ;
1432
1399
int retry = FLB_TRUE ;
1433
1400
@@ -1460,8 +1427,7 @@ int put_log_events(struct flb_cloudwatch *ctx, struct cw_flush *buf,
1460
1427
if (c -> resp .data == NULL || c -> resp .data_len == 0 || strstr (c -> resp .data , AMZN_REQUEST_ID_HEADER ) == NULL ) {
1461
1428
/* code was 200, but response is invalid, treat as failure */
1462
1429
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 );
1465
1431
}
1466
1432
flb_http_client_destroy (c );
1467
1433
@@ -1474,73 +1440,15 @@ int put_log_events(struct flb_cloudwatch *ctx, struct cw_flush *buf,
1474
1440
AMZN_REQUEST_ID_HEADER );
1475
1441
return -1 ;
1476
1442
}
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
- }
1498
1443
1499
1444
flb_http_client_destroy (c );
1500
1445
return 0 ;
1501
1446
}
1502
1447
1503
1448
/* Check error */
1504
1449
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 );
1544
1452
}
1545
1453
}
1546
1454
0 commit comments