Skip to content

Commit

Permalink
Fix celery and urllib tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl committed Feb 12, 2024
1 parent 8fd2105 commit f19bc45
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,44 @@ def test_basic_metric(self):

def test_metric_uninstrument(self):
CeleryInstrumentor().instrument()
metrics = self.get_metrics()
self.assertEqual(len(metrics), 1)

self.get_metrics()
self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics[0]
.data.data_points[0]
.bucket_counts[1]
),
1,
)

self.get_metrics()
self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics[0]
.data.data_points[0]
.bucket_counts[1]
),
2,
)

CeleryInstrumentor().uninstrument()

self.assertIsNone(self.memory_metrics_reader.get_metrics_data())
self.get_metrics()
self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics[0]
.data.data_points[0]
.bucket_counts[1]
),
2,
)
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,147 @@ def test_basic_metric_request_not_empty(self):
)
def test_metric_uninstrument(self):
with request.urlopen(self.URL):
metrics = self.get_sorted_metrics()
self.assertEqual(len(metrics), 3)

self.assertEqual(metrics[0].data.data_points[0].sum, 1)
self.assertEqual(metrics[1].data.data_points[0].sum, 0)
self.assertEqual(metrics[2].data.data_points[0].sum, 6)
self.assertEqual(
len(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics
)
),
3,
)

self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics[0]
.data.data_points[0]
.bucket_counts[1]
),
1,
)
self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics[1]
.data.data_points[0]
.bucket_counts[0]
),
1,
)
self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics[2]
.data.data_points[0]
.bucket_counts[2]
),
1,
)

with request.urlopen(self.URL):

self.assertEqual(
len(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics
)
),
3,
)

self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics[0]
.data.data_points[0]
.bucket_counts[1]
),
2,
)
self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics[1]
.data.data_points[0]
.bucket_counts[0]
),
2,
)
self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics[2]
.data.data_points[0]
.bucket_counts[2]
),
2,
)

URLLibInstrumentor().uninstrument()

with request.urlopen(self.URL):

self.assertEqual(
len(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics
)
),
3,
)

URLLibInstrumentor().uninstrument()
with request.urlopen(self.URL):
self.assertIsNone(
self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics[0]
.data.data_points[0]
.bucket_counts[1]
),
2,
)
self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
)
.resource_metrics[0]
.scope_metrics[0]
.metrics[1]
.data.data_points[0]
.bucket_counts[0]
),
2,
)
self.assertEqual(
(
self.memory_metrics_reader.get_metrics_data()
.resource_metrics[0]
.scope_metrics[0]
.metrics[2]
.data.data_points[0]
.bucket_counts[2]
),
2,
)

0 comments on commit f19bc45

Please sign in to comment.