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

Add metrics instrumentation sqlalchemy #1645

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f08c3ad
Add metrics instrumentation sqlalchemy
shalevr Feb 6, 2023
28c8c2e
refactored the connection usage
shalevr Feb 6, 2023
cecafe1
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 6, 2023
ae56830
Add changelog entry and supports_metrics
shalevr Feb 6, 2023
eb5e1dc
Fix lint
shalevr Feb 6, 2023
b22f06a
Using semantic convention
shalevr Feb 7, 2023
85e81b0
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
srikanthccv Feb 13, 2023
454229a
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 13, 2023
2e59e58
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 13, 2023
281b933
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 13, 2023
d73eff3
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 13, 2023
a36873d
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 15, 2023
2af13ee
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 15, 2023
b5a9272
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 17, 2023
41a9b5a
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 17, 2023
176e8e6
Update test.yml
shalevr Feb 17, 2023
622f948
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
srikanthccv Feb 18, 2023
3104b4b
Fix Changelog
shalevr Feb 18, 2023
8c03ff9
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 18, 2023
35d1709
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 20, 2023
58532fc
Remove unused code
shalevr Feb 21, 2023
2ad2d06
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 22, 2023
dece77d
work with the metric basic test function from test_base.py
shalevr Feb 23, 2023
e9c6954
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 24, 2023
0a48b5a
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 25, 2023
244cde6
Merge branch 'main' into Metrics-instrumentation-sqlalchemy
shalevr Feb 25, 2023
71b234e
Fix merge issue
shalevr Feb 25, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'release/*'
pull_request:
env:
CORE_REPO_SHA: d0bb12b34b0c487198c935001636b6163485a50f
CORE_REPO_SHA: 2d1f0b9f5fce62549d1338882f37b91b95881c75
Copy link
Member Author

Choose a reason for hiding this comment

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


jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Optional, Sequence

import sqlalchemy
from sqlalchemy.pool import QueuePool

from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
from opentelemetry.sdk.metrics._internal.point import Metric
from opentelemetry.sdk.metrics.export import (
DataPointT,
HistogramDataPoint,
NumberDataPoint,
)
from opentelemetry.test.test_base import TestBase


Expand All @@ -38,93 +30,6 @@ def tearDown(self):
super().tearDown()
SQLAlchemyInstrumentor().uninstrument()

def get_sorted_metrics(self):
resource_metrics = (
self.memory_metrics_reader.get_metrics_data().resource_metrics
)

all_metrics = []
for metrics in resource_metrics:
for scope_metrics in metrics.scope_metrics:
all_metrics.extend(scope_metrics.metrics)

return self.sorted_metrics(all_metrics)

@staticmethod
def sorted_metrics(metrics):
"""
Sorts metrics by metric name.
"""
return sorted(
metrics,
key=lambda m: m.name,
)

def assert_metric_expected(
self,
metric: Metric,
expected_data_points: Sequence[DataPointT],
est_value_delta: Optional[float] = 0,
):
self.assertEqual(
len(expected_data_points), len(metric.data.data_points)
)
for expected_data_point in expected_data_points:
self.assert_data_point_expected(
expected_data_point, metric.data.data_points, est_value_delta
)

# pylint: disable=unidiomatic-typecheck
@staticmethod
def is_data_points_equal(
expected_data_point: DataPointT,
data_point: DataPointT,
est_value_delta: Optional[float] = 0,
):
if type(expected_data_point) != type(data_point) or not isinstance(
expected_data_point, (HistogramDataPoint, NumberDataPoint)
):
return False

values_diff = None
if isinstance(data_point, HistogramDataPoint):
values_diff = abs(expected_data_point.sum - data_point.sum)
elif isinstance(data_point, NumberDataPoint):
values_diff = abs(expected_data_point.value - data_point.value)

return (
values_diff <= est_value_delta
and expected_data_point.attributes == dict(data_point.attributes)
)

def assert_data_point_expected(
self,
expected_data_point: DataPointT,
data_points: Sequence[DataPointT],
est_value_delta: Optional[float] = 0,
):
is_data_point_exist = False
for data_point in data_points:
if self.is_data_points_equal(
expected_data_point, data_point, est_value_delta
):
is_data_point_exist = True
break

self.assertTrue(
is_data_point_exist,
msg=f"Data point {expected_data_point} does not exist",
)

@staticmethod
def create_number_data_point(value, attributes):
return NumberDataPoint(
value=value,
attributes=attributes,
start_time_unix_nano=0,
time_unix_nano=0,
)

def assert_pool_idle_used_expected(self, pool_name, idle, used):
metrics = self.get_sorted_metrics()
self.assertEqual(len(metrics), 1)
Expand Down