Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

botocore: bump moto to latest #2605

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ importlib-metadata==6.11.0
iniconfig==2.0.0
Jinja2==3.1.4
jmespath==1.0.1
MarkupSafe==2.0.1
moto==3.1.19
MarkupSafe==2.1.5
moto==5.0.9
packaging==24.0
pluggy==1.5.0
py-cpuinfo==9.0.0
Expand All @@ -31,7 +31,7 @@ six==1.16.0
tomli==2.0.1
typing_extensions==4.9.0
urllib3==1.26.18
Werkzeug==2.1.2
Werkzeug==3.0.3
wrapt==1.16.0
xmltodict==0.13.0
zipp==3.17.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from unittest import mock

import botocore.session
from moto import mock_dynamodb2 # pylint: disable=import-error
from moto import mock_aws # pylint: disable=import-error

from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
from opentelemetry.instrumentation.botocore.extensions.dynamodb import (
Expand Down Expand Up @@ -184,7 +184,7 @@ def assert_extension_item_col_metrics(self, operation: str):
)
self.assert_item_col_metrics(span)

@mock_dynamodb2
@mock_aws
def test_batch_get_item(self):
table_name1 = "test_table1"
table_name2 = "test_table2"
Expand All @@ -203,7 +203,7 @@ def test_batch_get_item(self):
self.assert_table_names(span, table_name1, table_name2)
self.assert_consumed_capacity(span, table_name1, table_name2)

@mock_dynamodb2
@mock_aws
def test_batch_write_item(self):
table_name1 = "test_table1"
table_name2 = "test_table2"
Expand All @@ -224,7 +224,7 @@ def test_batch_write_item(self):
self.assert_consumed_capacity(span, table_name1, table_name2)
self.assert_item_col_metrics(span)

@mock_dynamodb2
@mock_aws
def test_create_table(self):
local_sec_idx = {
"IndexName": "local_sec_idx",
Expand Down Expand Up @@ -268,7 +268,7 @@ def test_create_table(self):
)
self.assert_provisioned_read_cap(span, 42)

@mock_dynamodb2
@mock_aws
def test_delete_item(self):
self._create_prepared_table()

Expand Down Expand Up @@ -297,7 +297,7 @@ def test_delete_item_consumed_capacity(self):
def test_delete_item_item_collection_metrics(self):
self.assert_extension_item_col_metrics("DeleteItem")

@mock_dynamodb2
@mock_aws
def test_delete_table(self):
self._create_prepared_table()

Expand All @@ -306,7 +306,7 @@ def test_delete_table(self):
span = self.assert_span("DeleteTable")
self.assert_table_names(span, self.default_table_name)

@mock_dynamodb2
@mock_aws
def test_describe_table(self):
self._create_prepared_table()

Expand All @@ -315,15 +315,31 @@ def test_describe_table(self):
span = self.assert_span("DescribeTable")
self.assert_table_names(span, self.default_table_name)

@mock_dynamodb2
def test_get_item(self):
@mock_aws
def test_get_item_expression(self):
self._create_prepared_table()

self.client.get_item(
TableName=self.default_table_name,
Key={"id": {"S": "1"}},
ConsistentRead=True,
ProjectionExpression="PE",
ReturnConsumedCapacity="TOTAL",
)

span = self.assert_span("GetItem")
self.assert_table_names(span, self.default_table_name)
self.assert_consistent_read(span, True)
self.assert_consumed_capacity(span, self.default_table_name)

@mock_aws
def test_get_item_non_expression(self):
self._create_prepared_table()

self.client.get_item(
TableName=self.default_table_name,
Key={"id": {"S": "1"}},
ConsistentRead=True,
AttributesToGet=["id"],
ProjectionExpression="PE",
ReturnConsumedCapacity="TOTAL",
)
Expand All @@ -334,7 +350,7 @@ def test_get_item(self):
self.assert_projection(span, "PE")
self.assert_consumed_capacity(span, self.default_table_name)

@mock_dynamodb2
@mock_aws
def test_list_tables(self):
self._create_table(TableName="my_table")
self._create_prepared_table()
Expand All @@ -351,7 +367,7 @@ def test_list_tables(self):
)
self.assertEqual(5, span.attributes[SpanAttributes.AWS_DYNAMODB_LIMIT])

@mock_dynamodb2
@mock_aws
def test_put_item(self):
table = "test_table"
self._create_prepared_table(TableName=table)
Expand All @@ -372,7 +388,7 @@ def test_put_item(self):
def test_put_item_item_collection_metrics(self):
self.assert_extension_item_col_metrics("PutItem")

@mock_dynamodb2
@mock_aws
def test_query(self):
self._create_prepared_table()

Expand Down Expand Up @@ -407,7 +423,7 @@ def test_query(self):
self.assert_select(span, "ALL_ATTRIBUTES")
self.assert_consumed_capacity(span, self.default_table_name)

@mock_dynamodb2
@mock_aws
def test_scan(self):
self._create_prepared_table()

Expand Down Expand Up @@ -444,7 +460,7 @@ def test_scan(self):
self.assert_select(span, "ALL_ATTRIBUTES")
self.assert_consumed_capacity(span, self.default_table_name)

@mock_dynamodb2
@mock_aws
def test_update_item(self):
self._create_prepared_table()

Expand All @@ -465,7 +481,7 @@ def test_update_item(self):
def test_update_item_item_collection_metrics(self):
self.assert_extension_item_col_metrics("UpdateItem")

@mock_dynamodb2
@mock_aws
def test_update_table(self):
self._create_prepared_table()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from unittest.mock import Mock, patch
from unittest.mock import ANY, Mock, patch

import botocore.session
from botocore.exceptions import ParamValidationError
from moto import ( # pylint: disable=import-error
mock_ec2,
mock_kinesis,
mock_kms,
mock_s3,
mock_sqs,
mock_sts,
mock_xray,
)
from moto import mock_aws # pylint: disable=import-error

from opentelemetry import trace as trace_api
from opentelemetry.instrumentation.botocore import BotocoreInstrumentor
Expand All @@ -39,7 +31,7 @@
from opentelemetry.test.test_base import TestBase
from opentelemetry.trace.span import format_span_id, format_trace_id

_REQUEST_ID_REGEX_MATCH = r"[A-Z0-9]{52}"
_REQUEST_ID_REGEX_MATCH = r"[A-Za-z0-9]{52}"


# pylint:disable=too-many-public-methods
Expand Down Expand Up @@ -102,7 +94,7 @@ def assert_span(
self.assertEqual(f"{service}.{operation}", span.name)
return span

@mock_ec2
@mock_aws
def test_traced_client(self):
ec2 = self._make_client("ec2")

Expand All @@ -111,7 +103,7 @@ def test_traced_client(self):
request_id = "fdcdcab1-ae5c-489e-9c33-4637c5dda355"
self.assert_span("EC2", "DescribeInstances", request_id=request_id)

@mock_ec2
@mock_aws
def test_not_recording(self):
mock_tracer = Mock()
mock_span = Mock()
Expand All @@ -126,7 +118,7 @@ def test_not_recording(self):
self.assertFalse(mock_span.set_attribute.called)
self.assertFalse(mock_span.set_status.called)

@mock_s3
@mock_aws
def test_exception(self):
s3 = self._make_client("s3")

Expand All @@ -149,14 +141,14 @@ def test_exception(self):
self.assertIn(SpanAttributes.EXCEPTION_TYPE, event.attributes)
self.assertIn(SpanAttributes.EXCEPTION_MESSAGE, event.attributes)

@mock_s3
@mock_aws
def test_s3_client(self):
s3 = self._make_client("s3")

s3.list_buckets()
self.assert_span("S3", "ListBuckets")

@mock_s3
@mock_aws
def test_s3_put(self):
s3 = self._make_client("s3")

Expand All @@ -174,7 +166,7 @@ def test_s3_put(self):
s3.get_object(Bucket="mybucket", Key="foo")
self.assert_span("S3", "GetObject", request_id=_REQUEST_ID_REGEX_MATCH)

@mock_sqs
@mock_aws
def test_sqs_client(self):
sqs = self._make_client("sqs")

Expand All @@ -184,7 +176,7 @@ def test_sqs_client(self):
"SQS", "ListQueues", request_id=_REQUEST_ID_REGEX_MATCH
)

@mock_sqs
@mock_aws
def test_sqs_send_message(self):
sqs = self._make_client("sqs")
test_queue_name = "test_queue_name"
Expand All @@ -205,14 +197,14 @@ def test_sqs_send_message(self):
attributes={"aws.queue_url": queue_url},
)

@mock_kinesis
@mock_aws
def test_kinesis_client(self):
kinesis = self._make_client("kinesis")

kinesis.list_streams()
self.assert_span("Kinesis", "ListStreams")

@mock_kinesis
@mock_aws
def test_unpatch(self):
kinesis = self._make_client("kinesis")

Expand All @@ -221,7 +213,7 @@ def test_unpatch(self):
kinesis.list_streams()
self.assertEqual(0, len(self.memory_exporter.get_finished_spans()))

@mock_ec2
@mock_aws
def test_uninstrument_does_not_inject_headers(self):
headers = {}

Expand All @@ -240,7 +232,7 @@ def intercept_headers(**kwargs):

self.assertNotIn(TRACE_HEADER_KEY, headers)

@mock_sqs
@mock_aws
def test_double_patch(self):
sqs = self._make_client("sqs")

Expand All @@ -252,31 +244,31 @@ def test_double_patch(self):
"SQS", "ListQueues", request_id=_REQUEST_ID_REGEX_MATCH
)

@mock_kms
@mock_aws
def test_kms_client(self):
kms = self._make_client("kms")

kms.list_keys(Limit=21)

span = self.assert_only_span()
expected = self._default_span_attributes("KMS", "ListKeys")
expected["aws.request_id"] = ANY
# check for exact attribute set to make sure not to leak any kms secrets
self.assertEqual(
self._default_span_attributes("KMS", "ListKeys"), span.attributes
)
self.assertEqual(expected, dict(span.attributes))

@mock_sts
@mock_aws
def test_sts_client(self):
sts = self._make_client("sts")

sts.get_caller_identity()

span = self.assert_only_span()
expected = self._default_span_attributes("STS", "GetCallerIdentity")
expected["aws.request_id"] = "c6104cbe-af31-11e0-8154-cbc7ccf896c7"
expected["aws.request_id"] = ANY
# check for exact attribute set to make sure not to leak any sts secrets
self.assertEqual(expected, span.attributes)
self.assertEqual(expected, dict(span.attributes))

@mock_ec2
@mock_aws
def test_propagator_injects_into_request(self):
headers = {}
previous_propagator = get_global_textmap()
Expand Down Expand Up @@ -316,7 +308,7 @@ def check_headers(**kwargs):
finally:
set_global_textmap(previous_propagator)

@mock_ec2
@mock_aws
def test_override_xray_propagator_injects_into_request(self):
headers = {}

Expand All @@ -335,23 +327,23 @@ def check_headers(**kwargs):
self.assertNotIn(MockTextMapPropagator.TRACE_ID_KEY, headers)
self.assertNotIn(MockTextMapPropagator.SPAN_ID_KEY, headers)

@mock_xray
@mock_aws
def test_suppress_instrumentation_xray_client(self):
xray_client = self._make_client("xray")
with suppress_instrumentation():
xray_client.put_trace_segments(TraceSegmentDocuments=["str1"])
xray_client.put_trace_segments(TraceSegmentDocuments=["str2"])
self.assertEqual(0, len(self.get_finished_spans()))

@mock_xray
@mock_aws
def test_suppress_http_instrumentation_xray_client(self):
xray_client = self._make_client("xray")
with suppress_http_instrumentation():
xray_client.put_trace_segments(TraceSegmentDocuments=["str1"])
xray_client.put_trace_segments(TraceSegmentDocuments=["str2"])
self.assertEqual(2, len(self.get_finished_spans()))

@mock_s3
@mock_aws
def test_request_hook(self):
request_hook_service_attribute_name = "request_hook.service_name"
request_hook_operation_attribute_name = "request_hook.operation_name"
Expand Down Expand Up @@ -386,7 +378,7 @@ def request_hook(span, service_name, operation_name, api_params):
},
)

@mock_s3
@mock_aws
def test_response_hook(self):
response_hook_service_attribute_name = "request_hook.service_name"
response_hook_operation_attribute_name = "response_hook.operation_name"
Expand Down
Loading