Skip to content

Commit

Permalink
out_cloudwatch_logs: useful print stmts for log class
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley Pettit <wppttt@amazon.com>
  • Loading branch information
PettitWesley committed May 16, 2024
1 parent c35ef67 commit 1426fc8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions plugins/out_cloudwatch_logs/cloudwatch_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ int create_log_group(struct flb_cloudwatch *ctx, struct log_stream *stream)
}

/* construct CreateLogGroup request body */
if (ctx->log_group_class_type == LOG_CLASS_DEFAULT) {
if (ctx->log_group_class_type == LOG_CLASS_DEFAULT_TYPE) {
tmp = flb_sds_printf(&body, "{\"logGroupName\":\"%s\"}", stream->group);
if (!tmp) {
flb_sds_destroy(body);
Expand Down Expand Up @@ -1239,7 +1239,8 @@ int create_log_group(struct flb_cloudwatch *ctx, struct log_stream *stream)

if (c->resp.status == 200) {
/* success */
flb_plg_info(ctx->ins, "Created log group %s", stream->group);
flb_plg_info(ctx->ins, "Created log group %s with storage class %s",
stream->group, ctx->log_group_class);
flb_sds_destroy(body);
flb_http_client_destroy(c);
ret = set_log_group_retention(ctx, stream);
Expand Down
10 changes: 7 additions & 3 deletions plugins/out_cloudwatch_logs/cloudwatch_logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,22 @@ static int validate_log_group_class(struct flb_cloudwatch *ctx)
}

if (ctx->log_group_class == NULL || strlen(ctx->log_group_class) == 0) {
ctx->log_group_class_type = LOG_CLASS_DEFAULT;
} else if (strcmp(ctx->log_group_class, LOG_CLASS_STANDARD) == 0) {
ctx->log_group_class_type = LOG_CLASS_DEFAULT_TYPE;
ctx->log_group_class = LOG_CLASS_STANDARD;
return 0;
} else if (strncmp(ctx->log_group_class, LOG_CLASS_STANDARD, LOG_CLASS_STANDARD_LEN) == 0) {
flb_plg_debug(ctx->ins, "Using explicitly configured `log_group_class %s`, which is the default log class.", ctx->log_group_class);
ctx->log_group_class_type = LOG_CLASS_STANDARD_TYPE;
return 0;
} else if (strcmp(ctx->log_group_class, LOG_CLASS_INFREQUENT_ACCESS) == 0) {
} else if (strncmp(ctx->log_group_class, LOG_CLASS_INFREQUENT_ACCESS, LOG_CLASS_INFREQUENT_ACCESS_LEN) == 0) {
flb_plg_warn(ctx->ins, "Configured `log_group_class %s` will only apply to log groups created by Fluent Bit. "
"Look for the `Created log group` info level message emitted when a group does not already exist and is created.", ctx->log_group_class);
ctx->log_group_class_type = LOG_CLASS_INFREQUENT_ACCESS_TYPE;
return 0;
}

flb_plg_error(ctx->ins, "The valid values for log_group_class are {%s, %s}. Invalid input was %s", LOG_CLASS_STANDARD, LOG_CLASS_INFREQUENT_ACCESS, ctx->log_group_class);

return -1;
}

Expand Down
4 changes: 3 additions & 1 deletion plugins/out_cloudwatch_logs/cloudwatch_logs.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
#include <fluent-bit/record_accessor/flb_ra_parser.h>

#define LOG_CLASS_STANDARD "STANDARD"
#define LOG_CLASS_STANDARD_LEN 8
#define LOG_CLASS_INFREQUENT_ACCESS "INFREQUENT_ACCESS"
#define LOG_CLASS_INFREQUENT_ACCESS_LEN 17
/* log_group_class not configured; do not send the logGroupClass field in request */
#define LOG_CLASS_DEFAULT 0
#define LOG_CLASS_DEFAULT_TYPE 0
/* send configured & validated string in request */
#define LOG_CLASS_STANDARD_TYPE 1
#define LOG_CLASS_INFREQUENT_ACCESS_TYPE 2
Expand Down

0 comments on commit 1426fc8

Please sign in to comment.