Skip to content

Commit

Permalink
chore(mariadb): update tests to support mariadb>=1.1.0 (#3883)
Browse files Browse the repository at this point in the history
The latest version of mariadb client library requires a newer version of the C library in order to build.

This PR updates snapshot tests to account for newly supported db.rowcount for mariadb query spans.

This PR depends on #3884 to be merged and update our dev image first before this can pass.

This is a testing only fix, our integration continues to work fine for mariadb>=1.1.0, but our test suite was not setup for it.

Co-authored-by: Kyle Verhoog <kyle@verhoog.ca>
Co-authored-by: Munir Abdinur <munir.abdinur@datadoghq.com>
  • Loading branch information
3 people committed Jun 30, 2022
1 parent 2066030 commit 22746a3
Show file tree
Hide file tree
Showing 22 changed files with 466 additions and 104 deletions.
39 changes: 27 additions & 12 deletions tests/contrib/mariadb/test_mariadb.py
@@ -1,3 +1,5 @@
from typing import Tuple

import mariadb
import pytest

Expand All @@ -13,6 +15,17 @@
from tests.utils import snapshot


MARIADB_VERSION = mariadb.__version_info__ # type: Tuple[int, int, int, str, int]
SNAPSHOT_VARIANTS = {
"pre_1_1": MARIADB_VERSION < (1, 1, 0),
"post_1_1": MARIADB_VERSION
>= (
1,
1,
),
}


@pytest.fixture
def tracer():
tracer = DummyTracer()
Expand Down Expand Up @@ -71,6 +84,7 @@ def test_query_executemany(connection, tracer):
dummy_key VARCHAR(32) PRIMARY KEY,
dummy_value TEXT NOT NULL)"""
)
cursor.execute("DELETE FROM dummy")
tracer.enabled = True

stmt = "INSERT INTO dummy (dummy_key, dummy_value) VALUES (%s, %s)"
Expand Down Expand Up @@ -116,7 +130,7 @@ def test_analytics_default(connection, tracer):


@pytest.mark.subprocess(env=dict(DD_SERVICE="mysvc"))
@snapshot(async_mode=False)
@snapshot(async_mode=False, variants=SNAPSHOT_VARIANTS)
def test_user_specified_dd_service_snapshot():
"""
When a user specifies a service for the app
Expand All @@ -140,7 +154,7 @@ def test_user_specified_dd_service_snapshot():


@pytest.mark.subprocess(env=dict(DD_MARIADB_SERVICE="mysvc"))
@snapshot(async_mode=False)
@snapshot(async_mode=False, variants=SNAPSHOT_VARIANTS)
def test_user_specified_dd_mariadb_service_snapshot():
"""
When a user specifies a service for the app
Expand All @@ -163,7 +177,7 @@ def test_user_specified_dd_mariadb_service_snapshot():
tracer.shutdown()


@snapshot(include_tracer=True)
@snapshot(include_tracer=True, variants=SNAPSHOT_VARIANTS)
def test_simple_query_snapshot(tracer):
with get_connection(tracer) as connection:
cursor = connection.cursor()
Expand All @@ -172,15 +186,15 @@ def test_simple_query_snapshot(tracer):
assert len(rows) == 1


@snapshot(include_tracer=True, ignores=["meta.error.stack"])
@snapshot(include_tracer=True, variants=SNAPSHOT_VARIANTS, ignores=["meta.error.stack"])
def test_simple_malformed_query_snapshot(tracer):
with get_connection(tracer) as connection:
cursor = connection.cursor()
with pytest.raises(mariadb.ProgrammingError):
cursor.execute("SELEC 1")


@snapshot(include_tracer=True)
@snapshot(include_tracer=True, variants=SNAPSHOT_VARIANTS)
def test_simple_query_fetchall_snapshot(tracer):
with override_config("mariadb", dict(trace_fetch_methods=True)):
with get_connection(tracer) as connection:
Expand All @@ -190,7 +204,7 @@ def test_simple_query_fetchall_snapshot(tracer):
assert len(rows) == 1


@snapshot(include_tracer=True)
@snapshot(include_tracer=True, variants=SNAPSHOT_VARIANTS)
def test_query_with_several_rows_snapshot(tracer):
with get_connection(tracer) as connection:
cursor = connection.cursor()
Expand All @@ -200,7 +214,7 @@ def test_query_with_several_rows_snapshot(tracer):
assert len(rows) == 3


@snapshot(include_tracer=True)
@snapshot(include_tracer=True, variants=SNAPSHOT_VARIANTS)
def test_query_with_several_rows_fetchall_snapshot(tracer):
with override_config("mariadb", dict(trace_fetch_methods=True)):
with get_connection(tracer) as connection:
Expand All @@ -211,7 +225,7 @@ def test_query_with_several_rows_fetchall_snapshot(tracer):
assert len(rows) == 3


@snapshot(include_tracer=True)
@snapshot(include_tracer=True, variants=SNAPSHOT_VARIANTS)
def test_query_many_fetchall_snapshot(tracer):
with override_config("mariadb", dict(trace_fetch_methods=True)):
with get_connection(tracer) as connection:
Expand All @@ -226,6 +240,7 @@ def test_query_many_fetchall_snapshot(tracer):
dummy_key VARCHAR(32) PRIMARY KEY,
dummy_value TEXT NOT NULL)"""
)
cursor.execute("DELETE FROM dummy")
tracer.enabled = True

stmt = "INSERT INTO dummy (dummy_key, dummy_value) VALUES (%s, %s)"
Expand All @@ -240,13 +255,13 @@ def test_query_many_fetchall_snapshot(tracer):
assert len(rows) == 2


@snapshot(include_tracer=True)
@snapshot(include_tracer=True, variants=SNAPSHOT_VARIANTS)
def test_commit_snapshot(tracer):
with get_connection(tracer) as connection:
connection.commit()


@snapshot(include_tracer=True)
@snapshot(include_tracer=True, variants=SNAPSHOT_VARIANTS)
def test_query_proc_snapshot(tracer):
with get_connection(tracer) as connection:
# create a procedure
Expand All @@ -267,7 +282,7 @@ def test_query_proc_snapshot(tracer):
cursor.callproc(proc, data)


@snapshot(include_tracer=True)
@snapshot(include_tracer=True, variants=SNAPSHOT_VARIANTS)
def test_analytics_with_rate_snapshot(tracer):
with override_config("mariadb", dict(analytics_enabled=True, analytics_sample_rate=0.5)):
with get_connection(tracer) as connection:
Expand All @@ -277,7 +292,7 @@ def test_analytics_with_rate_snapshot(tracer):
assert len(rows) == 1


@snapshot(include_tracer=True)
@snapshot(include_tracer=True, variants=SNAPSHOT_VARIANTS)
def test_analytics_without_rate_snapshot(tracer):
with override_config("mariadb", dict(analytics_enabled=True)):
with get_connection(tracer) as connection:
Expand Down
@@ -0,0 +1,30 @@
[[
{
"name": "mariadb.query",
"service": "mariadb",
"resource": "SELECT 1",
"trace_id": 0,
"span_id": 1,
"parent_id": 0,
"type": "sql",
"meta": {
"db.name": "test",
"db.user": "test",
"out.host": "127.0.0.1",
"runtime-id": "778c778962a54eeea3ae401d2417ef86"
},
"metrics": {
"_dd.agent_psr": 1.0,
"_dd.measured": 1,
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_dd1.sr.eausr": 0.5,
"_sampling_priority_v1": 1,
"db.rowcount": 1,
"out.port": 3306,
"sql.rows": 1,
"system.pid": 9677
},
"duration": 1412500,
"start": 1656521264659140100
}]]
Expand Up @@ -11,7 +11,7 @@
"db.name": "test",
"db.user": "test",
"out.host": "127.0.0.1",
"runtime-id": "afb83c6e2adf41f9a723786fdb1b223b"
"runtime-id": "93f76aae38d74161926ccd64013f5d01"
},
"metrics": {
"_dd.agent_psr": 1.0,
Expand All @@ -23,8 +23,8 @@
"db.rowcount": 0,
"out.port": 3306,
"sql.rows": 0,
"system.pid": 5857
"system.pid": 9600
},
"duration": 1238000,
"start": 1633039295271632000
"duration": 650000,
"start": 1656521180778211000
}]]
@@ -0,0 +1,30 @@
[[
{
"name": "mariadb.query",
"service": "mariadb",
"resource": "SELECT 1",
"trace_id": 0,
"span_id": 1,
"parent_id": 0,
"type": "sql",
"meta": {
"db.name": "test",
"db.user": "test",
"out.host": "127.0.0.1",
"runtime-id": "778c778962a54eeea3ae401d2417ef86"
},
"metrics": {
"_dd.agent_psr": 1.0,
"_dd.measured": 1,
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_dd1.sr.eausr": 1.0,
"_sampling_priority_v1": 1,
"db.rowcount": 1,
"out.port": 3306,
"sql.rows": 1,
"system.pid": 9677
},
"duration": 580200,
"start": 1656521264692636300
}]]
Expand Up @@ -11,7 +11,7 @@
"db.name": "test",
"db.user": "test",
"out.host": "127.0.0.1",
"runtime-id": "afb83c6e2adf41f9a723786fdb1b223b"
"runtime-id": "93f76aae38d74161926ccd64013f5d01"
},
"metrics": {
"_dd.agent_psr": 1.0,
Expand All @@ -23,8 +23,8 @@
"db.rowcount": 0,
"out.port": 3306,
"sql.rows": 0,
"system.pid": 5857
"system.pid": 9600
},
"duration": 976000,
"start": 1633039295305654000
"duration": 616000,
"start": 1656521180800547000
}]]
Expand Up @@ -10,16 +10,16 @@
"db.name": "test",
"db.user": "test",
"out.host": "127.0.0.1",
"runtime-id": "afb83c6e2adf41f9a723786fdb1b223b"
"runtime-id": "778c778962a54eeea3ae401d2417ef86"
},
"metrics": {
"_dd.agent_psr": 1.0,
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"out.port": 3306,
"system.pid": 5857
"system.pid": 9677
},
"duration": 784000,
"start": 1633039295184325000
"duration": 420500,
"start": 1656521264458364000
}]]
@@ -0,0 +1,25 @@
[[
{
"name": "mariadb.connection.commit",
"service": "mariadb",
"resource": "mariadb.connection.commit",
"trace_id": 0,
"span_id": 1,
"parent_id": 0,
"meta": {
"db.name": "test",
"db.user": "test",
"out.host": "127.0.0.1",
"runtime-id": "93f76aae38d74161926ccd64013f5d01"
},
"metrics": {
"_dd.agent_psr": 1.0,
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"out.port": 3306,
"system.pid": 9600
},
"duration": 395000,
"start": 1656521180729828000
}]]
@@ -0,0 +1,87 @@
[[
{
"name": "mariadb.query",
"service": "mariadb",
"resource": "INSERT INTO dummy (dummy_key, dummy_value) VALUES (%s, %s)",
"trace_id": 0,
"span_id": 1,
"parent_id": 0,
"type": "sql",
"meta": {
"db.name": "test",
"db.user": "test",
"out.host": "127.0.0.1",
"runtime-id": "778c778962a54eeea3ae401d2417ef86",
"sql.executemany": "true"
},
"metrics": {
"_dd.agent_psr": 1.0,
"_dd.measured": 1,
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"db.rowcount": 2,
"out.port": 3306,
"sql.rows": 2,
"system.pid": 9677
},
"duration": 1468400,
"start": 1656521264429166700
}],
[
{
"name": "mariadb.query",
"service": "mariadb",
"resource": "SELECT dummy_key, dummy_value FROM dummy ORDER BY dummy_key",
"trace_id": 1,
"span_id": 1,
"parent_id": 0,
"type": "sql",
"meta": {
"db.name": "test",
"db.user": "test",
"out.host": "127.0.0.1",
"runtime-id": "778c778962a54eeea3ae401d2417ef86"
},
"metrics": {
"_dd.agent_psr": 1.0,
"_dd.measured": 1,
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"db.rowcount": 2,
"out.port": 3306,
"sql.rows": 2,
"system.pid": 9677
},
"duration": 698300,
"start": 1656521264432090500
}],
[
{
"name": "mariadb.query.fetchall",
"service": "mariadb",
"resource": "SELECT dummy_key, dummy_value FROM dummy ORDER BY dummy_key",
"trace_id": 2,
"span_id": 1,
"parent_id": 0,
"type": "sql",
"meta": {
"db.name": "test",
"db.user": "test",
"out.host": "127.0.0.1",
"runtime-id": "778c778962a54eeea3ae401d2417ef86"
},
"metrics": {
"_dd.agent_psr": 1.0,
"_dd.top_level": 1,
"_dd.tracer_kr": 1.0,
"_sampling_priority_v1": 1,
"db.rowcount": 2,
"out.port": 3306,
"sql.rows": 2,
"system.pid": 9677
},
"duration": 94000,
"start": 1656521264433020400
}]]

0 comments on commit 22746a3

Please sign in to comment.