Skip to content

Conversation

hectorhdzg
Copy link
Member

@hectorhdzg hectorhdzg commented Mar 25, 2020

E2E verification for span creation using psycopg2 and dbapi integrations

@hectorhdzg hectorhdzg requested a review from a team March 25, 2020 20:12
@hectorhdzg hectorhdzg added ext needs reviewers PRs with this label are ready for review and needs people to review to move forward. tests labels Mar 25, 2020
@hectorhdzg hectorhdzg changed the title Adding functional tests for pysopg2 integration Adding functional tests for psycopg2 integration Mar 25, 2020
@codecov-io
Copy link

codecov-io commented Mar 27, 2020

Codecov Report

Merging #528 into master will increase coverage by 0.41%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #528      +/-   ##
==========================================
+ Coverage   88.97%   89.38%   +0.41%     
==========================================
  Files          43       43              
  Lines        2213     2195      -18     
  Branches      248      250       +2     
==========================================
- Hits         1969     1962       -7     
+ Misses        173      161      -12     
- Partials       71       72       +1     
Impacted Files Coverage Δ
...ntelemetry-api/src/opentelemetry/trace/__init__.py 83.12% <0.00%> (-2.51%) ⬇️
...ry-ext-wsgi/src/opentelemetry/ext/wsgi/__init__.py 67.56% <0.00%> (-0.58%) ⬇️
...lemetry-sdk/src/opentelemetry/sdk/util/__init__.py 85.54% <0.00%> (-0.35%) ⬇️
...ts/src/opentelemetry/ext/http_requests/__init__.py 89.18% <0.00%> (-0.29%) ⬇️
...src/opentelemetry/ext/opentracing_shim/__init__.py 95.86% <0.00%> (-0.17%) ⬇️
...xt-jaeger/src/opentelemetry/ext/jaeger/__init__.py 86.39% <0.00%> (-0.16%) ⬇️
...emetry-sdk/src/opentelemetry/sdk/trace/__init__.py 92.46% <0.00%> (-0.06%) ⬇️
.../src/opentelemetry/sdk/metrics/export/aggregate.py 100.00% <0.00%> (ø)
...xt-zipkin/src/opentelemetry/ext/zipkin/__init__.py 84.41% <0.00%> (ø)
...opentelemetry/sdk/context/propagation/b3_format.py 87.27% <0.00%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b6a52d...0cb2bb4. Read the comment docs.

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a few comments about the error handling patterns and reducing them. Can you look through those? After we discuss I can change to approve: the code overall looks great.

cls._connection.close()

@fixture(autouse=True)
def connect_to_db(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it feels a little weird to me to have a mix of pytest fixtures, and of the standard setup/teardown unittest pattern.

Can we normalize to one or the other? I think given the current precedent on unittest-style, that would be preferable.

since it's autouse, I figure it can be added to the setup/teardown method.

Or, I'm ok with just moving the class level fixtures like cursor to pytest fixtures as well. @c24t for his thoughts, since he's been arguing against pytest fixtures in our codebase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def connect_to_db(self):
if self._connection is None:
# Try to connect to DB
for i in range(5):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this retry logic? seems like even if we need it, 5 retries is a lot of times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DB will take sometime to startup in docker, maybe having less retries and more wait time?, it could take like 15 or 20 seconds to be ready to receive connections

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to fail immediately in the tests and replace docker-compose -up with a script that does the same and blocks until the container can accept connections. If possible I think it's a good idea to avoid sleeping at all in tests, and between this and #526 we're looking at adding up to a minute of idle time to an already-slow test suite.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a python script to check DB connections, so tests will not have any sleep but there will be initial script check for all tests, this will improve waiting if something goes wrong with docker setup and test will fail quickly

with self._tracer.start_as_current_span("rootSpan"):
try:
self._cursor.callproc("test", ())
except Exception as err:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this exception need to be caught? seems like it's fine to let it raise up.

Even if it's unrelated to our code, exceptions are a separate code path that we should exercise explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stored procedure doesn't exist so callproc will fail but Span will be created, I want to avoid as much pre setup as possible for this tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want an assertRaises here instead then, the tests generally shouldn't print anything.

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comments to #526. I've got reservations about the autouse fixture and sleeping/retrying in unit tests, but we can address that in another PR. The only blocking comment here is about the printed exception.

with self._tracer.start_as_current_span("rootSpan"):
try:
self._cursor.callproc("test", ())
except Exception as err:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want an assertRaises here instead then, the tests generally shouldn't print anything.

def connect_to_db(self):
if self._connection is None:
# Try to connect to DB
for i in range(5):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is to fail immediately in the tests and replace docker-compose -up with a script that does the same and blocks until the container can accept connections. If possible I think it's a good idea to avoid sleeping at all in tests, and between this and #526 we're looking at adding up to a minute of idle time to an already-slow test suite.

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for refactoring out the pytest! (Although I personally would love full pytest).

I still think there's some improvement in the connectivity checks that should be addressed, or else it'll provide incomplete information to others if it fails. Once that's fixed up I'll switch to approved.

Thanks for focusing on this!

def check_docker_services_availability():
try:
print("Checking Postgres availability")
check_postgres_connection()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should mongo availability also be checked?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MongoDB have been super fast to be available, will add the logic just to be safe in case this changes.

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all the feedback @hectorhdzg, no more blocking comments from me.

Copy link
Member

@toumorokoshi toumorokoshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for addressing that!

@toumorokoshi toumorokoshi merged commit 08b100f into open-telemetry:master Apr 9, 2020
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reviewers PRs with this label are ready for review and needs people to review to move forward. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants