-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conti/add aws kinesis tests #2143
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ce55455
initial commit
wconti27 363563b
disable slow mac-os tests
wconti27 8e9b64b
fix kinesis
wconti27 afe16cb
Merge branch 'conti/add-aws-sns-testing' into conti/add-aws-kinesis-t…
wconti27 d8f68ac
enable kinesis service
wconti27 7d5e794
more debugging
wconti27 62b4942
wait until stream active
wconti27 3ef11bc
fix kinesis tests
wconti27 49f73a8
remove breakpoints
wconti27 5d8f96d
fix kinesis finding spans
wconti27 5b37436
change kinesis message to json string
wconti27 101d4c7
fix JS failures
wconti27 74c567d
Revert "fix JS failures"
wconti27 6d215de
Merge branch 'conti/add-aws-sns-testing' into conti/add-aws-kinesis-t…
wconti27 99d9ce8
Merge branch 'main' into conti/add-aws-kinesis-tests
wconti27 7320f91
fix reviewer comment
wconti27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
203 changes: 203 additions & 0 deletions
203
tests/integrations/crossed_integrations/test_kinesis.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
|
||
from tests.integrations.crossed_integrations.test_kafka import _python_buddy | ||
from utils import interfaces, scenarios, weblog, missing_feature, features | ||
from utils.tools import logger | ||
|
||
|
||
class _Test_Kinesis: | ||
"""Test Kinesis compatibility with inputted datadog tracer""" | ||
|
||
BUDDY_TO_WEBLOG_STREAM = None | ||
WEBLOG_TO_BUDDY_STREAM = None | ||
buddy = None | ||
buddy_interface = None | ||
|
||
@classmethod | ||
def get_span(cls, interface, span_kind, stream, operation): | ||
logger.debug(f"Trying to find traces with span kind: {span_kind} and stream: {stream} in {interface}") | ||
|
||
for data, trace in interface.get_traces(): | ||
for span in trace: | ||
if not span.get("meta"): | ||
continue | ||
|
||
if span["meta"].get("span.kind") not in span_kind: | ||
continue | ||
|
||
# we want to skip all the kafka spans | ||
if "aws.service" not in span["meta"] and "aws_service" not in span["meta"]: | ||
continue | ||
|
||
if ( | ||
"kinesis" not in span["meta"].get("aws.service", "").lower() | ||
and "kinesis" not in span["meta"].get("aws_service", "").lower() | ||
): | ||
continue | ||
|
||
if operation.lower() != span["meta"].get("aws.operation", "").lower(): | ||
continue | ||
|
||
if operation.lower() == "getrecords" and span["meta"].get("language", "") == "javascript": | ||
# for nodejs we propagate from aws.response span which does not have the stream included on the span. | ||
if span["resource"] != "aws.response": | ||
continue | ||
# elif stream != cls.get_stream_name(span): | ||
# continue | ||
|
||
logger.debug(f"span found in {data['log_filename']}:\n{json.dumps(span, indent=2)}") | ||
return span | ||
|
||
logger.debug("No span found") | ||
return None | ||
|
||
@staticmethod | ||
def get_stream(span) -> str | None: | ||
"""Extracts the stream from a span by trying various fields""" | ||
stream = span["meta"].get("streamname", None) # this is in nodejs, java, python | ||
|
||
if stream is None: | ||
if "aws.stream.url" in span["meta"]: | ||
stream = span["meta"]["aws.stream.url"].split("/")[-1] | ||
elif "messaging.url" in span["meta"]: | ||
stream = span["meta"]["messaging.url"].split("/")[-1] | ||
|
||
if stream is None: | ||
logger.error(f"could not extract stream from this span:\n{span}") | ||
|
||
return stream | ||
|
||
def setup_produce(self): | ||
""" | ||
send request A to weblog : this request will produce a Kinesis message | ||
send request B to library buddy, this request will consume Kinesis message | ||
""" | ||
|
||
self.production_response = weblog.get( | ||
"/kinesis/produce", params={"stream": self.WEBLOG_TO_BUDDY_STREAM}, timeout=61 | ||
) | ||
self.consume_response = self.buddy.get( | ||
"/kinesis/consume", params={"stream": self.WEBLOG_TO_BUDDY_STREAM, "timeout": 60}, timeout=61 | ||
) | ||
|
||
def test_produce(self): | ||
"""Check that a message produced to Kinesis is correctly ingested by a Datadog tracer""" | ||
|
||
assert self.production_response.status_code == 200 | ||
assert self.consume_response.status_code == 200 | ||
|
||
# The weblog is the producer, the buddy is the consumer | ||
self.validate_kinesis_spans( | ||
producer_interface=interfaces.library, | ||
consumer_interface=self.buddy_interface, | ||
stream=self.WEBLOG_TO_BUDDY_STREAM, | ||
) | ||
|
||
@missing_feature(library="golang", reason="Expected to fail, Golang does not propagate context") | ||
@missing_feature(library="ruby", reason="Expected to fail, Ruby does not propagate context") | ||
@missing_feature( | ||
library="java", reason="Expected to fail, Java defaults to using Xray headers to propagate context" | ||
) | ||
def test_produce_trace_equality(self): | ||
"""This test relies on the setup for produce, it currently cannot be run on its own""" | ||
producer_span = self.get_span( | ||
interfaces.library, | ||
span_kind=["producer", "client"], | ||
stream=self.WEBLOG_TO_BUDDY_STREAM, | ||
operation="PutRecord", | ||
) | ||
consumer_span = self.get_span( | ||
self.buddy_interface, | ||
span_kind=["consumer", "client", "server"], | ||
stream=self.WEBLOG_TO_BUDDY_STREAM, | ||
operation="GetRecords", | ||
) | ||
|
||
# Both producer and consumer spans should be part of the same trace | ||
# Different tracers can handle the exact propagation differently, so for now, this test avoids | ||
# asserting on direct parent/child relationships | ||
assert producer_span["trace_id"] == consumer_span["trace_id"] | ||
|
||
def setup_consume(self): | ||
""" | ||
send request A to library buddy : this request will produce a Kinesis message | ||
send request B to weblog, this request will consume Kinesis message | ||
|
||
request A: GET /library_buddy/produce_kinesis_message | ||
request B: GET /weblog/consume_kinesis_message | ||
""" | ||
|
||
self.production_response = self.buddy.get( | ||
"/kinesis/produce", params={"stream": self.BUDDY_TO_WEBLOG_STREAM}, timeout=61 | ||
) | ||
self.consume_response = weblog.get( | ||
"/kinesis/consume", params={"stream": self.BUDDY_TO_WEBLOG_STREAM, "timeout": 60}, timeout=61 | ||
) | ||
|
||
def test_consume(self): | ||
"""Check that a message by an app instrumented by a Datadog tracer is correctly ingested""" | ||
|
||
assert self.production_response.status_code == 200 | ||
assert self.consume_response.status_code == 200 | ||
|
||
# The buddy is the producer, the weblog is the consumer | ||
self.validate_kinesis_spans( | ||
producer_interface=self.buddy_interface, | ||
consumer_interface=interfaces.library, | ||
stream=self.BUDDY_TO_WEBLOG_STREAM, | ||
) | ||
|
||
@missing_feature(library="golang", reason="Expected to fail, Golang does not propagate context") | ||
@missing_feature(library="ruby", reason="Expected to fail, Ruby does not propagate context") | ||
def test_consume_trace_equality(self): | ||
"""This test relies on the setup for consume, it currently cannot be run on its own""" | ||
producer_span = self.get_span( | ||
self.buddy_interface, | ||
span_kind=["producer", "client"], | ||
stream=self.BUDDY_TO_WEBLOG_STREAM, | ||
operation="PutRecord", | ||
) | ||
consumer_span = self.get_span( | ||
interfaces.library, | ||
span_kind=["consumer", "client", "server"], | ||
stream=self.BUDDY_TO_WEBLOG_STREAM, | ||
operation="GetRecords", | ||
) | ||
|
||
# Both producer and consumer spans should be part of the same trace | ||
# Different tracers can handle the exact propagation differently, so for now, this test avoids | ||
# asserting on direct parent/child relationships | ||
assert producer_span["trace_id"] == consumer_span["trace_id"] | ||
|
||
def validate_kinesis_spans(self, producer_interface, consumer_interface, stream): | ||
""" | ||
Validates production/consumption of Kinesis message. | ||
It works the same for both test_produce and test_consume | ||
""" | ||
|
||
producer_span = self.get_span( | ||
producer_interface, span_kind=["producer", "client"], stream=stream, operation="PutRecord" | ||
) | ||
consumer_span = self.get_span( | ||
consumer_interface, span_kind=["consumer", "client", "server"], stream=stream, operation="GetRecords" | ||
) | ||
# check that both consumer and producer spans exists | ||
assert producer_span is not None | ||
assert consumer_span is not None | ||
|
||
# Assert that the consumer span is not the root | ||
assert "parent_id" in consumer_span, "parent_id is missing in consumer span" | ||
|
||
# returns both span for any custom check | ||
return producer_span, consumer_span | ||
|
||
|
||
@scenarios.crossed_tracing_libraries | ||
@features.aws_kinesis_span_creationcontext_propagation_via_message_attributes_with_dd_trace | ||
class Test_Kinesis_PROPAGATION_VIA_MESSAGE_ATTRIBUTES(_Test_Kinesis): | ||
buddy_interface = interfaces.python_buddy | ||
buddy = _python_buddy | ||
WEBLOG_TO_BUDDY_STREAM = "Test_Kinesis_propagation_via_message_attributes_weblog_to_buddy" | ||
BUDDY_TO_WEBLOG_STREAM = "Test_Kinesis_propagation_via_message_attributes_buddy_to_weblog" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing lot of flakiness on the python tracer, we removed this line a while ago.