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

filled out rest of psycopg 3 plugin #168

Merged
merged 2 commits into from
Oct 21, 2021
Merged

Conversation

tom-pytel
Copy link
Contributor

A copy of psycopg2 to psycopg 3 was not enough since some interface stuff changed, this PR adds those changes:

  • Removed Cursor.callproc()
  • Added Cursor.stream()
  • Hook Connection.connect()
  • Instrumented AsyncConnection and AsyncCursor (which is the main point of psycopg 3 I think :)
  • Still needs a test, will add simple script to convert to test if anyone is up for it, @Superskyyy ?

@tom-pytel
Copy link
Contributor Author

Simple test script:

#!/usr/bin/env python

from skywalking import agent
agent.start()

import asyncio
import psycopg

# with psycopg.connect('postgresql://root:root@localhost:15432/admin') as conn:
with psycopg.Connection.connect('postgresql://root:root@localhost:5432/admin') as conn:
    with conn.cursor() as cur:
        sql = "select * from user where user = %s"

        cur.execute(sql, ("root",))
        print(cur.fetchall())

        cur.executemany(sql, (("root",), ("root",)))
        print(cur.fetchall())

        for res in cur.stream(sql, ("root",)):
            print(res)

async def main():
    async with await psycopg.AsyncConnection.connect('postgresql://root:root@localhost:5432/admin') as aconn:
        async with aconn.cursor() as acur:
            sql = "select * from user where user = %s"

            await acur.execute(sql, ("root",))
            print(await acur.fetchall())

            await acur.executemany(sql, (("root",), ("root",)))
            print(await acur.fetchall())

            async for res in acur.stream(sql, ("root",)):
                print(res)

asyncio.run(main())

from time import sleep; sleep(1)  # BUG? Agent is supposed to flush pending segments on exit so this should not be needed, but it is.

@tom-pytel tom-pytel added the enhancement New feature or request label Oct 20, 2021
@tom-pytel tom-pytel added this to the 1.0.0 milestone Oct 20, 2021
@tom-pytel
Copy link
Contributor Author

BTW, @kezhenxu94, this is good for merge, just missing the the test which @Superskyyy gave thumbs up so will probably add along with celery test in a different PR.

@kezhenxu94 kezhenxu94 merged commit 4ef2b67 into apache:master Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants