Skip to content

Commit

Permalink
Package caching
Browse files Browse the repository at this point in the history
  • Loading branch information
ge0Aja committed Feb 26, 2024
1 parent fca42eb commit 6f9efe1
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 42 deletions.
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import boto3

from base_tags_cache import (
from caching.base_tags_cache import (
BaseTagsCache,
logger,
sanitize_aws_tag_string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from botocore.exceptions import ClientError

from base_tags_cache import (
from caching.base_tags_cache import (
GET_RESOURCES_LAMBDA_FILTER,
BaseTagsCache,
logger,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from botocore.exceptions import ClientError

from base_tags_cache import (
from caching.base_tags_cache import (
BaseTagsCache,
logger,
parse_get_resources_response_for_tags_by_arn,
Expand Down
2 changes: 1 addition & 1 deletion aws/logs_monitoring/enhanced_lambda_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import re
import datetime
from time import time
from lambda_cache import LambdaTagsCache
from caching.lambda_cache import LambdaTagsCache

ENHANCED_METRICS_NAMESPACE_PREFIX = "aws.lambda.enhanced"

Expand Down
4 changes: 2 additions & 2 deletions aws/logs_monitoring/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
get_lambda_function_name_from_logstream_name,
is_lambda_customized_log_group,
)
from step_functions_cache import StepFunctionsTagsCache
from cloudwatch_log_group_cache import CloudwatchLogGroupTagsCache
from caching.step_functions_cache import StepFunctionsTagsCache
from caching.cloudwatch_log_group_cache import CloudwatchLogGroupTagsCache
from telemetry import (
DD_FORWARDER_TELEMETRY_NAMESPACE_PREFIX,
get_forwarder_telemetry_tags,
Expand Down
2 changes: 1 addition & 1 deletion aws/logs_monitoring/tests/test_cloudtrail_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class TestS3CloudwatchParsing(unittest.TestCase):
def setUp(self):
self.maxDiff = 9000

@patch("base_tags_cache.boto3")
@patch("caching.base_tags_cache.boto3")
@patch("parsing.boto3")
@patch("lambda_function.boto3")
def test_s3_cloudtrail_pasing_and_enrichment(
Expand Down
54 changes: 27 additions & 27 deletions aws/logs_monitoring/tests/test_enhanced_lambda_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
create_out_of_memory_enhanced_metric,
)

from base_tags_cache import (
from caching.base_tags_cache import (
sanitize_aws_tag_string,
parse_get_resources_response_for_tags_by_arn,
get_dd_tag_string_from_aws_dict,
)
from lambda_cache import LambdaTagsCache
from caching.lambda_cache import LambdaTagsCache


class TestEnhancedLambdaMetrics(unittest.TestCase):
Expand Down Expand Up @@ -313,8 +313,8 @@ def test_create_out_of_memory_enhanced_metric(self):
success_message = "Success!"
self.assertEqual(len(create_out_of_memory_enhanced_metric(success_message)), 0)

@patch("base_tags_cache.send_forwarder_internal_metrics")
@patch("lambda_cache.LambdaTagsCache.get_cache_from_s3")
@patch("caching.base_tags_cache.send_forwarder_internal_metrics")
@patch("caching.lambda_cache.LambdaTagsCache.get_cache_from_s3")
def test_generate_enhanced_lambda_metrics(
self, mock_get_s3_cache, mock_forward_metrics
):
Expand Down Expand Up @@ -411,8 +411,8 @@ def test_generate_enhanced_lambda_metrics(

del os.environ["DD_FETCH_LAMBDA_TAGS"]

@patch("base_tags_cache.send_forwarder_internal_metrics")
@patch("lambda_cache.LambdaTagsCache.get_cache_from_s3")
@patch("caching.base_tags_cache.send_forwarder_internal_metrics")
@patch("caching.lambda_cache.LambdaTagsCache.get_cache_from_s3")
def test_generate_enhanced_lambda_metrics_with_tags(
self, mock_get_s3_cache, mock_forward_metrics
):
Expand Down Expand Up @@ -524,8 +524,8 @@ def test_generate_enhanced_lambda_metrics_with_tags(

del os.environ["DD_FETCH_LAMBDA_TAGS"]

@patch("base_tags_cache.send_forwarder_internal_metrics")
@patch("lambda_cache.LambdaTagsCache.get_cache_from_s3")
@patch("caching.base_tags_cache.send_forwarder_internal_metrics")
@patch("caching.lambda_cache.LambdaTagsCache.get_cache_from_s3")
def test_generate_enhanced_lambda_metrics_once_with_missing_arn(
self, mock_get_s3_cache, mock_forward_metrics
):
Expand Down Expand Up @@ -560,8 +560,8 @@ def test_generate_enhanced_lambda_metrics_once_with_missing_arn(

del os.environ["DD_FETCH_LAMBDA_TAGS"]

@patch("base_tags_cache.send_forwarder_internal_metrics")
@patch("lambda_cache.LambdaTagsCache.get_cache_from_s3")
@patch("caching.base_tags_cache.send_forwarder_internal_metrics")
@patch("caching.lambda_cache.LambdaTagsCache.get_cache_from_s3")
def test_generate_enhanced_lambda_metrics_refresh_on_new_arn(
self, mock_get_s3_cache, mock_forward_metrics
):
Expand Down Expand Up @@ -603,12 +603,12 @@ def test_generate_enhanced_lambda_metrics_refresh_on_new_arn(

del os.environ["DD_FETCH_LAMBDA_TAGS"]

@patch("lambda_cache.LambdaTagsCache.release_s3_cache_lock")
@patch("lambda_cache.LambdaTagsCache.acquire_s3_cache_lock")
@patch("lambda_cache.LambdaTagsCache.write_cache_to_s3")
@patch("lambda_cache.LambdaTagsCache.build_tags_cache")
@patch("lambda_cache.send_forwarder_internal_metrics")
@patch("lambda_cache.LambdaTagsCache.get_cache_from_s3")
@patch("caching.lambda_cache.LambdaTagsCache.release_s3_cache_lock")
@patch("caching.lambda_cache.LambdaTagsCache.acquire_s3_cache_lock")
@patch("caching.lambda_cache.LambdaTagsCache.write_cache_to_s3")
@patch("caching.lambda_cache.LambdaTagsCache.build_tags_cache")
@patch("caching.lambda_cache.send_forwarder_internal_metrics")
@patch("caching.lambda_cache.LambdaTagsCache.get_cache_from_s3")
def test_generate_enhanced_lambda_metrics_refresh_s3_cache(
self,
mock_get_s3_cache,
Expand Down Expand Up @@ -664,13 +664,13 @@ def test_generate_enhanced_lambda_metrics_refresh_s3_cache(

del os.environ["DD_FETCH_LAMBDA_TAGS"]

@patch("lambda_cache.LambdaTagsCache.release_s3_cache_lock")
@patch("lambda_cache.LambdaTagsCache.acquire_s3_cache_lock")
@patch("lambda_cache.resource_tagging_client")
@patch("lambda_cache.LambdaTagsCache.write_cache_to_s3")
@patch("lambda_cache.parse_get_resources_response_for_tags_by_arn")
@patch("lambda_cache.send_forwarder_internal_metrics")
@patch("lambda_cache.LambdaTagsCache.get_cache_from_s3")
@patch("caching.lambda_cache.LambdaTagsCache.release_s3_cache_lock")
@patch("caching.lambda_cache.LambdaTagsCache.acquire_s3_cache_lock")
@patch("caching.lambda_cache.resource_tagging_client")
@patch("caching.lambda_cache.LambdaTagsCache.write_cache_to_s3")
@patch("caching.lambda_cache.parse_get_resources_response_for_tags_by_arn")
@patch("caching.lambda_cache.send_forwarder_internal_metrics")
@patch("caching.lambda_cache.LambdaTagsCache.get_cache_from_s3")
def test_generate_enhanced_lambda_metrics_client_error(
self,
mock_get_s3_cache,
Expand Down Expand Up @@ -724,8 +724,8 @@ def test_generate_enhanced_lambda_metrics_client_error(

del os.environ["DD_FETCH_LAMBDA_TAGS"]

@patch("base_tags_cache.send_forwarder_internal_metrics")
@patch("lambda_cache.LambdaTagsCache.get_cache_from_s3")
@patch("caching.base_tags_cache.send_forwarder_internal_metrics")
@patch("caching.lambda_cache.LambdaTagsCache.get_cache_from_s3")
def test_generate_enhanced_lambda_metrics_timeout(
self, mock_get_s3_cache, mock_forward_metrics
):
Expand Down Expand Up @@ -782,8 +782,8 @@ def test_generate_enhanced_lambda_metrics_timeout(
)
del os.environ["DD_FETCH_LAMBDA_TAGS"]

@patch("base_tags_cache.send_forwarder_internal_metrics")
@patch("lambda_cache.LambdaTagsCache.get_cache_from_s3")
@patch("caching.base_tags_cache.send_forwarder_internal_metrics")
@patch("caching.lambda_cache.LambdaTagsCache.get_cache_from_s3")
def test_generate_enhanced_lambda_metrics_out_of_memory(
self, mock_get_s3_cache, mock_forward_metrics
):
Expand Down
12 changes: 6 additions & 6 deletions aws/logs_monitoring/tests/test_lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_datadog_forwarder(self, mock_get_s3_cache):

del os.environ["DD_FETCH_LAMBDA_TAGS"]

@patch("cloudwatch_log_group_cache.CloudwatchLogGroupTagsCache.get")
@patch("caching.cloudwatch_log_group_cache.CloudwatchLogGroupTagsCache.get")
def test_setting_service_tag_from_log_group_cache(self, cw_logs_tags_get):
reload(sys.modules["settings"])
reload(sys.modules["parsing"])
Expand All @@ -159,7 +159,7 @@ def test_setting_service_tag_from_log_group_cache(self, cw_logs_tags_get):
self.assertEqual(log["service"], "log_group_service")

@patch.dict(os.environ, {"DD_TAGS": "service:dd_tag_service"}, clear=True)
@patch("cloudwatch_log_group_cache.CloudwatchLogGroupTagsCache.get")
@patch("caching.cloudwatch_log_group_cache.CloudwatchLogGroupTagsCache.get")
def test_service_override_from_dd_tags(self, cw_logs_tags_get):
reload(sys.modules["settings"])
reload(sys.modules["parsing"])
Expand All @@ -179,8 +179,8 @@ def test_service_override_from_dd_tags(self, cw_logs_tags_get):
for log in logs:
self.assertEqual(log["service"], "dd_tag_service")

@patch("lambda_cache.LambdaTagsCache.get")
@patch("cloudwatch_log_group_cache.CloudwatchLogGroupTagsCache.get")
@patch("caching.lambda_cache.LambdaTagsCache.get")
@patch("caching.cloudwatch_log_group_cache.CloudwatchLogGroupTagsCache.get")
def test_overrding_service_tag_from_lambda_cache(
self, lambda_tags_get, cw_logs_tags_get
):
Expand All @@ -203,8 +203,8 @@ def test_overrding_service_tag_from_lambda_cache(
self.assertEqual(log["service"], "lambda_service")

@patch.dict(os.environ, {"DD_TAGS": "service:dd_tag_service"}, clear=True)
@patch("lambda_cache.LambdaTagsCache.get")
@patch("cloudwatch_log_group_cache.CloudwatchLogGroupTagsCache.get")
@patch("caching.lambda_cache.LambdaTagsCache.get")
@patch("caching.cloudwatch_log_group_cache.CloudwatchLogGroupTagsCache.get")
def test_overrding_service_tag_from_lambda_cache_when_dd_tags_is_set(
self, lambda_tags_get, cw_logs_tags_get
):
Expand Down
4 changes: 2 additions & 2 deletions aws/logs_monitoring/tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class TestAWSLogsHandler(unittest.TestCase):
@patch("parsing.CloudwatchLogGroupTagsCache.release_s3_cache_lock")
@patch("parsing.CloudwatchLogGroupTagsCache.acquire_s3_cache_lock")
@patch("parsing.CloudwatchLogGroupTagsCache.write_cache_to_s3")
@patch("base_tags_cache.send_forwarder_internal_metrics")
@patch("caching.base_tags_cache.send_forwarder_internal_metrics")
@patch("parsing.CloudwatchLogGroupTagsCache.get_cache_from_s3")
def test_awslogs_handler_rds_postgresql(
self,
Expand Down Expand Up @@ -456,7 +456,7 @@ def test_awslogs_handler_rds_postgresql(
@patch("parsing.StepFunctionsTagsCache.release_s3_cache_lock")
@patch("parsing.StepFunctionsTagsCache.acquire_s3_cache_lock")
@patch("parsing.StepFunctionsTagsCache.write_cache_to_s3")
@patch("base_tags_cache.send_forwarder_internal_metrics")
@patch("caching.base_tags_cache.send_forwarder_internal_metrics")
@patch("parsing.StepFunctionsTagsCache.get_cache_from_s3")
def test_awslogs_handler_step_functions_tags_added_properly(
self,
Expand Down

0 comments on commit 6f9efe1

Please sign in to comment.