Skip to content

Commit b769740

Browse files
authored
[AWSX] feat(lambda logs forwarder): Allow to opt-out from S3 tags enrichment (#946)
* [AWSX] feat(lambda logs forwarder): Allow to opt-out from S3 tags enrichment * Keep current behavior
1 parent fa5275e commit b769740

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

aws/logs_monitoring/caching/s3_tags_cache.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from botocore.exceptions import ClientError
23
from caching.base_tags_cache import BaseTagsCache
34
from caching.common import parse_get_resources_response_for_tags_by_arn
@@ -16,7 +17,8 @@ def __init__(self, prefix):
1617
)
1718

1819
def should_fetch_tags(self):
19-
return True
20+
# set it to true if we don't have the environment variable set to keep the default behavior
21+
return os.environ.get("DD_FETCH_S3_TAGS", "true").lower() == "true"
2022

2123
def build_tags_cache(self):
2224
"""Makes API calls to GetResources to get the live tags of the account's S3 buckets
@@ -56,6 +58,13 @@ def build_tags_cache(self):
5658
return tags_fetch_success, tags_by_arn_cache
5759

5860
def get(self, bucket_arn):
61+
if not self.should_fetch_tags():
62+
self.logger.debug(
63+
"Not fetching S3 tags because the env variable DD_FETCH_S3_TAGS is "
64+
"not set to true"
65+
)
66+
return []
67+
5968
if self._is_expired():
6069
send_forwarder_internal_metrics("local_s3_tags_cache_expired")
6170
self.logger.debug("Local cache expired, fetching cache from S3")

aws/logs_monitoring/steps/handlers/s3_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def _add_s3_tags_from_cache(self):
109109
self.metadata[DD_CUSTOM_TAGS] = (
110110
",".join(s3_tags)
111111
if not self.metadata[DD_CUSTOM_TAGS]
112-
else self.metadata[DD_CUSTOM_TAGS] + "," + ",".join(s3_tags)
112+
else ",".join(s3_tags) + "," + self.metadata[DD_CUSTOM_TAGS]
113113
)
114114

115115
def _extract_data(self):

aws/logs_monitoring/template.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ Parameters:
9696
- true
9797
- false
9898
Description: Let the forwarder fetch Step Functions tags using GetResources API calls and apply them to logs, metrics and traces. If set to true, permission tag:GetResources will be automatically added to the Lambda execution IAM role. The tags are cached in memory and S3 so that they'll only be fetched when the function cold starts or when the TTL (1 hour) expires. The forwarder increments the aws.lambda.enhanced.get_resources_api_calls metric for each API call made.
99+
DdFetchS3Tags:
100+
Type: String
101+
Default: true
102+
AllowedValues:
103+
- true
104+
- false
105+
Description: Let the forwarder fetch S3 buckets tags using GetResources API calls and apply them to S3 based logs. If set to true, permission tag:GetResources will be automatically added to the Lambda execution IAM role. The tags are cached in memory and S3 so that they'll only be fetched when the function cold starts or when the TTL (1 hour) expires. The forwarder increments the aws.lambda.enhanced.get_resources_api_calls metric for each API call made.
99106
DdUseTcp:
100107
Type: String
101108
Default: false
@@ -459,6 +466,7 @@ Resources:
459466
- SetDdFetchLambdaTags
460467
- !Ref DdFetchLambdaTags
461468
- !Ref AWS::NoValue
469+
DD_FETCH_S3_TAGS: !Ref DdFetchS3Tags
462470
DD_FETCH_LOG_GROUP_TAGS: !If
463471
- SetDdFetchLogGroupTags
464472
- !Ref DdFetchLogGroupTags
@@ -1036,6 +1044,7 @@ Metadata:
10361044
- DdFetchLambdaTags
10371045
- DdFetchLogGroupTags
10381046
- DdFetchStepFunctionsTags
1047+
- DdFetchS3Tags
10391048
- DdStepFunctionsTraceEnabled
10401049
- DdEnhancedMetrics
10411050
- TagsCacheTTLSeconds

0 commit comments

Comments
 (0)