Skip to content

Commit cd82c37

Browse files
out_cloudwatch_logs: Added StorageResolution support for EMF
Signed-off-by: Devin Stafford <[email protected]>
1 parent 455fc22 commit cd82c37

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

plugins/out_cloudwatch_logs/cloudwatch_api.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ int pack_emf_payload(struct flb_cloudwatch *ctx,
750750
mk_list_foreach_safe(metric_head, metric_temp, flb_intermediate_metrics) {
751751
an_item = mk_list_entry(metric_head, struct flb_intermediate_metric, _head);
752752
if (should_add_to_emf(an_item) == 1) {
753-
msgpack_pack_map(&mp_pck, 2);
753+
msgpack_pack_map(&mp_pck, 3);
754754
msgpack_pack_str(&mp_pck, 4);
755755
msgpack_pack_str_body(&mp_pck, "Name", 4);
756756
msgpack_pack_object(&mp_pck, an_item->key);
@@ -759,6 +759,9 @@ int pack_emf_payload(struct flb_cloudwatch *ctx,
759759
msgpack_pack_str(&mp_pck, strlen(an_item->metric_unit));
760760
msgpack_pack_str_body(&mp_pck, an_item->metric_unit,
761761
strlen(an_item->metric_unit));
762+
msgpack_pack_str(&mp_pck, 17);
763+
msgpack_pack_str_body(&mp_pck, "StorageResolution", 17);
764+
msgpack_pack_int(&mp_pck, ctx->metric_storage_resolution);
762765
}
763766
}
764767

plugins/out_cloudwatch_logs/cloudwatch_logs.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,19 +195,26 @@ static int cb_cloudwatch_init(struct flb_output_instance *ins,
195195
}
196196

197197
tmp = flb_output_get_property("metric_namespace", ins);
198-
if (tmp)
199-
{
198+
if (tmp) {
200199
flb_plg_info(ctx->ins, "Metric Namespace=%s", tmp);
201200
ctx->metric_namespace = flb_sds_create(tmp);
202201
}
203202

204203
tmp = flb_output_get_property("metric_dimensions", ins);
205-
if (tmp)
206-
{
204+
if (tmp) {
207205
flb_plg_info(ctx->ins, "Metric Dimensions=%s", tmp);
208206
ctx->metric_dimensions = flb_utils_split(tmp, ';', 256);
209207
}
210208

209+
tmp = flb_output_get_property("metric_storage_resolution", ins);
210+
if (tmp) {
211+
flb_plg_info(ctx->ins, "Metric Storage Resolution=%s", tmp);
212+
ctx->metric_storage_resolution = atoi(tmp);
213+
} else {
214+
/* Default to 60s storage resolution as does CloudWatch if not specified */
215+
ctx->metric_storage_resolution = 60;
216+
}
217+
211218
ctx->create_group = FLB_FALSE;
212219
tmp = flb_output_get_property("auto_create_group", ins);
213220
if (tmp) {
@@ -676,6 +683,12 @@ static struct flb_config_map config_map[] = {
676683
"is 'd1,d2;d3', we will consider it as [[d1, d2],[d3]]."
677684
},
678685

686+
{
687+
FLB_CONFIG_MAP_STR, "metric_storage_resolution", NULL,
688+
0, FLB_FALSE, 0,
689+
"Metric storage resolution for CloudWatch EMF logs"
690+
},
691+
679692
{
680693
FLB_CONFIG_MAP_STR, "profile", NULL,
681694
0, FLB_TRUE, offsetof(struct flb_cloudwatch, profile),

plugins/out_cloudwatch_logs/cloudwatch_logs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ struct flb_cloudwatch {
157157
is 'd1,d2;d3', we will consider it as [[d1, d2],[d3]]*/
158158
struct mk_list *metric_dimensions;
159159

160+
int metric_storage_resolution;
161+
160162
/* Plugin output instance reference */
161163
struct flb_output_instance *ins;
162164
};

0 commit comments

Comments
 (0)