From 852437c8341f503f96e791934c316544fae5b664 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Thu, 25 Jun 2020 15:56:09 -0700 Subject: [PATCH 01/32] WIP --- .../examples/metrics/auto_collector.py | 11 +- .../sdk/auto_collection/__init__.py | 3 +- .../sdk/auto_collection/dependency_metrics.py | 79 +++++++++----- .../auto_collection/live_metrics/__init__.py | 8 +- .../auto_collection/metrics_span_processor.py | 35 +----- .../sdk/auto_collection/request_metrics.py | 101 +++++++++++++----- .../auto_collection/test_auto_collection.py | 12 +-- .../test_dependency_metrics.py | 68 +++++++----- .../test_metrics_span_processor.py | 101 +----------------- .../auto_collection/test_request_metrics.py | 84 ++++++++++++--- azure_monitor/tests/test_base_exporter.py | 2 +- 11 files changed, 248 insertions(+), 256 deletions(-) diff --git a/azure_monitor/examples/metrics/auto_collector.py b/azure_monitor/examples/metrics/auto_collector.py index fd7617c..95c060c 100644 --- a/azure_monitor/examples/metrics/auto_collector.py +++ b/azure_monitor/examples/metrics/auto_collector.py @@ -5,16 +5,11 @@ from opentelemetry.sdk.trace import TracerProvider from azure_monitor import AzureMonitorMetricsExporter -from azure_monitor.sdk.auto_collection import ( - AutoCollection, - AzureMetricsSpanProcessor, -) +from azure_monitor.sdk.auto_collection import AutoCollection # Add Span Processor to get metrics about traces trace.set_tracer_provider(TracerProvider()) tracer = trace.get_tracer_provider().get_tracer(__name__) -span_processor = AzureMetricsSpanProcessor() -trace.get_tracer_provider().add_span_processor(span_processor) metrics.set_meter_provider(MeterProvider()) meter = metrics.get_meter(__name__) @@ -25,9 +20,7 @@ testing_label_set = {"environment": "testing"} # Automatically collect standard metrics -auto_collection = AutoCollection( - meter=meter, labels=testing_label_set, span_processor=span_processor -) +auto_collection = AutoCollection(meter=meter, labels=testing_label_set) metrics.get_meter_provider().start_pipeline(meter, exporter, 2) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py index 59e0705..e38a511 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py @@ -40,10 +40,9 @@ def __init__( self, meter: Meter, labels: Dict[str, str], - span_processor: AzureMetricsSpanProcessor, ): col_type = AutoCollectionType.STANDARD_METRICS self._performance_metrics = PerformanceMetrics(meter, labels, col_type) self._request_metrics = RequestMetrics( - meter, labels, span_processor, col_type + meter, labels, col_type ) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py index b6dea9e..286d030 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py @@ -1,16 +1,54 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. +import logging +import threading import time from typing import Dict +import requests +from opentelemetry import context from opentelemetry.metrics import Meter, Observer from opentelemetry.sdk.metrics import UpDownSumObserver -from azure_monitor.sdk.auto_collection.metrics_span_processor import ( - AzureMetricsSpanProcessor, -) +_dependency_lock = threading.Lock() +logger = logging.getLogger(__name__) dependency_map = dict() +ORIGINAL_REQUEST = requests.Session.request + + +def dependency_patch(*args, **kwargs) -> None: + start_time = time.time() + + try: + result = ORIGINAL_REQUEST(*args, **kwargs) + except Exception as exc: + exception = exc + result = getattr(exc, "response", None) + end_time = time.time() + + # Only collect request metric if sent from non-exporter thread + if context.get_value("suppress_instrumentation") is None: + # We don't want multiple threads updating this at once + with _dependency_lock: + try: + # Update duration + duration = dependency_map.get("duration", 0) + dependency_map["duration"] = duration + (end_time - start_time) + # Update count + count = dependency_map.get("count", 0) + dependency_map["count"] = count + 1 + # Update failed count + if ( + result is not None + and result.status_code >= 200 + and result.status_code < 300 + ) or exception is not None: + failed_count = dependency_map.get("failed_count", 0) + dependency_map["failed_count"] = failed_count + 1 + except Exception as exc: + logger.warning("Error handling failed request metrics.") + return result class DependencyMetrics: @@ -20,19 +58,14 @@ class DependencyMetrics: Args: meter: OpenTelemetry Meter labels: Dictionary of labels - span_processor: Azure Metrics Span Processor collection_type: Standard or Live Metrics """ - def __init__( - self, - meter: Meter, - labels: Dict[str, str], - span_processor: AzureMetricsSpanProcessor, - ): + def __init__(self, meter: Meter, labels: Dict[str, str]): self._meter = meter self._labels = labels - self._span_processor = span_processor + # Patch requests + requests.Session.request = dependency_patch meter.register_observer( callback=self._track_dependency_duration, @@ -66,7 +99,7 @@ def _track_dependency_rate(self, observer: Observer) -> None: using the requests library within an elapsed time and dividing that value over the elapsed time. """ - current_count = self._span_processor.dependency_count + current_count = dependency_map.get("count", 0) current_time = time.time() last_count = dependency_map.get("last_count", 0) last_time = dependency_map.get("last_time") @@ -96,23 +129,17 @@ def _track_dependency_duration(self, observer: Observer) -> None: and dividing over the amount of outgoing requests over an elapsed time. """ last_average_duration = dependency_map.get("last_average_duration", 0) - interval_duration = ( - self._span_processor.dependency_duration - - dependency_map.get("last_duration", 0) - ) - interval_count = ( - self._span_processor.dependency_count - - dependency_map.get("last_count", 0) + interval_duration = dependency_map.get( + "duration", 0 + ) - dependency_map.get("last_duration", 0) + interval_count = dependency_map.get("count", 0) - dependency_map.get( + "last_count", 0 ) try: result = interval_duration / interval_count - dependency_map[ - "last_count" - ] = self._span_processor.dependency_count + dependency_map["last_count"] = dependency_map.get("count", 0) dependency_map["last_average_duration"] = result - dependency_map[ - "last_duration" - ] = self._span_processor.dependency_duration + dependency_map["last_duration"] = dependency_map.get("duration", 0) observer.observe(int(result), self._labels) except ZeroDivisionError: # If interval_count is 0, exporter call made too close to previous @@ -126,7 +153,7 @@ def _track_failure_rate(self, observer: Observer) -> None: using the requests library within an elapsed time and dividing that value over the elapsed time. """ - current_failed_count = self._span_processor.failed_dependency_count + current_failed_count = dependency_map.get("failed_count", 0) current_time = time.time() last_failed_count = dependency_map.get("last_failed_count", 0) last_time = dependency_map.get("last_time") diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/__init__.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/__init__.py index 0bd1428..9e41b00 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/__init__.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/__init__.py @@ -41,12 +41,8 @@ def __init__( ): col_type = AutoCollectionType.LIVE_METRICS self._performance_metrics = PerformanceMetrics(meter, labels, col_type) - self._dependency_metrics = DependencyMetrics( - meter, labels, span_processor - ) - self._request_metrics = RequestMetrics( - meter, labels, span_processor, col_type - ) + self._dependency_metrics = DependencyMetrics(meter, labels) + self._request_metrics = RequestMetrics(meter, labels, col_type) self._manager = LiveMetricsManager( meter, instrumentation_key, span_processor ) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/metrics_span_processor.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/metrics_span_processor.py index 660809e..990497d 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/metrics_span_processor.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/metrics_span_processor.py @@ -4,7 +4,6 @@ import logging from opentelemetry.sdk.trace import Span, SpanProcessor -from opentelemetry.trace import SpanKind from azure_monitor.export.trace import convert_span_to_envelope @@ -13,49 +12,21 @@ class AzureMetricsSpanProcessor(SpanProcessor): """AzureMetricsSpanProcessor is an implementation of `SpanProcessor` used - to generate Azure specific metrics, including dependencies/requests rate, average duration - and failed dependencies/requests. + to generate documents for Live Metrics. """ def __init__(self): self.is_collecting_documents = False self.documents = collections.deque() - self.request_count = 0 - self.dependency_count = 0 - self.failed_request_count = 0 - self.failed_dependency_count = 0 - self.request_duration = 0 - self.dependency_duration = 0 def on_start(self, span: Span) -> None: pass def on_end(self, span: Span) -> None: try: - if span.kind == SpanKind.SERVER: - self.request_count = self.request_count + 1 - duration = ( - span.end_time - span.start_time - ) / 1000000 # Convert to milliseconds - self.request_duration = self.request_duration + duration + if self.is_collecting_documents: if not span.status.is_ok: - self.failed_request_count = self.failed_request_count + 1 - if self.is_collecting_documents: - self.documents.append(convert_span_to_envelope(span)) - - elif span.kind == SpanKind.CLIENT: - self.dependency_count = self.dependency_count + 1 - duration = ( - span.end_time - span.start_time - ) / 1000000 # Convert to milliseconds - self.dependency_duration = self.dependency_duration + duration - if not span.status.is_ok: - self.failed_dependency_count = ( - self.failed_dependency_count + 1 - ) - if self.is_collecting_documents: - self.documents.append(convert_span_to_envelope(span)) - + self.documents.append(convert_span_to_envelope(span)) # pylint: disable=broad-except except Exception: logger.exception("Exception while processing Span.") diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py index c78294d..45da6af 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py @@ -1,19 +1,74 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. import logging +import threading import time +from http.server import HTTPServer from typing import Dict from opentelemetry.metrics import Meter, Observer from opentelemetry.sdk.metrics import UpDownSumObserver -from azure_monitor.sdk.auto_collection.metrics_span_processor import ( - AzureMetricsSpanProcessor, -) from azure_monitor.sdk.auto_collection.utils import AutoCollectionType +_requests_lock = threading.Lock() logger = logging.getLogger(__name__) requests_map = dict() +ORIGINAL_CONSTRUCTOR = HTTPServer.__init__ + + +def request_patch(func): + def wrapper(self=None): + start_time = time.time() + func(self) + end_time = time.time() + + with _requests_lock: + # Update Count + count = requests_map.get("count", 0) + requests_map["count"] = count + 1 + # Update duration + duration = requests_map.get("duration", 0) + requests_map["duration"] = duration + (end_time - start_time) + + return wrapper + + +def send_response_patch(func): + def wrapper(self, code, message=None): + func(self, code, message) + if code >= 200 and code < 300: + with _requests_lock: + # Update Count + failed_count = requests_map.get("failed_count", 0) + requests_map["failed_count"] = failed_count + 1 + + return wrapper + + +def server_patch(*args, **kwargs): + if len(args) >= 3: + handler = args[2] + if handler: + # Patch the handler methods if they exist + if "do_DELETE" in dir(handler): + handler.do_DELETE = request_patch(handler.do_DELETE) + if "do_GET" in dir(handler): + handler.do_GET = request_patch(handler.do_GET) + if "do_HEAD" in dir(handler): + handler.do_HEAD = request_patch(handler.do_HEAD) + if "do_OPTIONS" in dir(handler): + handler.do_OPTIONS = request_patch(handler.do_OPTIONS) + if "do_POST" in dir(handler): + handler.do_POST = request_patch(handler.do_POST) + if "do_PUT" in dir(handler): + handler.do_PUT = request_patch(handler.do_PUT) + if "send_response" in dir(handler): + handler.send_response = send_response_patch( + handler.send_response + ) + result = ORIGINAL_CONSTRUCTOR(*args, **kwargs) + return result class RequestMetrics: @@ -24,7 +79,6 @@ class RequestMetrics: Args: meter: OpenTelemetry Meter labels: Dictionary of labels - span_processor: Azure Metrics Span Processor collection_type: Standard or Live Metrics """ @@ -32,12 +86,12 @@ def __init__( self, meter: Meter, labels: Dict[str, str], - span_processor: AzureMetricsSpanProcessor, collection_type: AutoCollectionType, ): self._meter = meter self._labels = labels - self._span_processor = span_processor + # Patch the HTTPServer handler to track request information + HTTPServer.__init__ = server_patch if collection_type == AutoCollectionType.LIVE_METRICS: meter.register_observer( @@ -72,20 +126,17 @@ def _track_request_duration(self, observer: Observer) -> None: and dividing over the amount of incoming requests over an elapsed time. """ last_average_duration = requests_map.get("last_average_duration", 0) - interval_duration = ( - self._span_processor.request_duration - - requests_map.get("last_duration", 0) + interval_duration = requests_map.get("duration", 0) - requests_map.get( + "last_duration", 0 ) - interval_count = self._span_processor.request_count - requests_map.get( + interval_count = requests_map.get("count", 0) - requests_map.get( "last_count", 0 ) try: result = interval_duration / interval_count - requests_map["last_count"] = self._span_processor.request_count + requests_map["last_count"] = requests_map.get("count", 0) requests_map["last_average_duration"] = result - requests_map[ - "last_duration" - ] = self._span_processor.request_duration + requests_map["last_duration"] = requests_map.get("duration", 0) observer.observe(int(result), self._labels) except ZeroDivisionError: # If interval_count is 0, exporter call made too close to previous @@ -107,15 +158,14 @@ def _track_request_rate(self, observer: Observer) -> None: # last_rate_time is None the first time this function is called if last_time is not None: interval_time = current_time - requests_map.get("last_time", 0) - interval_count = ( - self._span_processor.request_count - - requests_map.get("last_count", 0) - ) + interval_count = requests_map.get( + "count", 0 + ) - requests_map.get("last_count", 0) result = interval_count / interval_time else: result = 0.0 requests_map["last_time"] = current_time - requests_map["last_count"] = self._span_processor.request_count + requests_map["last_count"] = requests_map.get("count", 0) requests_map["last_rate"] = result observer.observe(result, self._labels) except ZeroDivisionError: @@ -138,17 +188,16 @@ def _track_request_failed_rate(self, observer: Observer) -> None: # last_rate_time is None the first time this function is called if last_time is not None: interval_time = current_time - requests_map.get("last_time", 0) - interval_count = ( - self._span_processor.failed_request_count - - requests_map.get("last_failed_count", 0) - ) + interval_count = requests_map.get( + "failed_count", 0 + ) - requests_map.get("last_failed_count", 0) result = interval_count / interval_time else: result = 0.0 requests_map["last_time"] = current_time - requests_map[ - "last_failed_count" - ] = self._span_processor.failed_request_count + requests_map["last_failed_count"] = requests_map.get( + "failed_count", 0 + ) requests_map["last_rate"] = result observer.observe(result, self._labels) except ZeroDivisionError: diff --git a/azure_monitor/tests/auto_collection/test_auto_collection.py b/azure_monitor/tests/auto_collection/test_auto_collection.py index 40c2f8d..6c85d12 100644 --- a/azure_monitor/tests/auto_collection/test_auto_collection.py +++ b/azure_monitor/tests/auto_collection/test_auto_collection.py @@ -7,10 +7,7 @@ from opentelemetry import metrics from opentelemetry.sdk.metrics import MeterProvider -from azure_monitor.sdk.auto_collection import ( - AutoCollection, - AzureMetricsSpanProcessor, -) +from azure_monitor.sdk.auto_collection import AutoCollection # pylint: disable=protected-access @@ -20,7 +17,6 @@ def setUpClass(cls): metrics.set_meter_provider(MeterProvider()) cls._meter = metrics.get_meter(__name__) cls._test_labels = tuple({"environment": "staging"}.items()) - cls._span_processor = AzureMetricsSpanProcessor() @classmethod def tearDownClass(cls): @@ -35,11 +31,7 @@ def tearDownClass(cls): def test_constructor(self, mock_requests, mock_performance): """Test the constructor.""" - AutoCollection( - meter=self._meter, - labels=self._test_labels, - span_processor=self._span_processor, - ) + AutoCollection(meter=self._meter, labels=self._test_labels) self.assertEqual(mock_performance.called, True) self.assertEqual(mock_requests.called, True) self.assertEqual(mock_performance.call_args[0][0], self._meter) diff --git a/azure_monitor/tests/auto_collection/test_dependency_metrics.py b/azure_monitor/tests/auto_collection/test_dependency_metrics.py index 7ea3413..64a65e7 100644 --- a/azure_monitor/tests/auto_collection/test_dependency_metrics.py +++ b/azure_monitor/tests/auto_collection/test_dependency_metrics.py @@ -2,16 +2,17 @@ # Licensed under the MIT License. import unittest +from http.server import HTTPServer from unittest import mock +import requests from opentelemetry import metrics from opentelemetry.sdk.metrics import MeterProvider, Observer from azure_monitor.sdk.auto_collection import dependency_metrics -from azure_monitor.sdk.auto_collection.metrics_span_processor import ( - AzureMetricsSpanProcessor, -) +ORIGINAL_FUNCTION = requests.Session.request +ORIGINAL_CONS = HTTPServer.__init__ # pylint: disable=protected-access class TestDependencyMetrics(unittest.TestCase): @@ -20,21 +21,22 @@ def setUpClass(cls): metrics.set_meter_provider(MeterProvider()) cls._meter = metrics.get_meter(__name__) cls._test_labels = {"environment": "staging"} - cls._span_processor = AzureMetricsSpanProcessor() @classmethod def tearDown(cls): + requests.Session.request = ORIGINAL_FUNCTION + dependency_metrics.ORIGINAL_CONSTRUCTOR = ORIGINAL_CONS metrics._METER_PROVIDER = None def setUp(self): dependency_metrics.dependency_map.clear() + requests.Session.request = ORIGINAL_FUNCTION + dependency_metrics.ORIGINAL_CONSTRUCTOR = ORIGINAL_CONS def test_constructor(self): mock_meter = mock.Mock() metrics_collector = dependency_metrics.DependencyMetrics( - meter=mock_meter, - labels=self._test_labels, - span_processor=self._span_processor, + meter=mock_meter, labels=self._test_labels ) self.assertEqual(metrics_collector._meter, mock_meter) self.assertEqual(metrics_collector._labels, self._test_labels) @@ -67,9 +69,7 @@ def test_constructor(self): def test_track_dependency_rate(self, time_mock): time_mock.time.return_value = 100 metrics_collector = dependency_metrics.DependencyMetrics( - meter=self._meter, - labels=self._test_labels, - span_processor=self._span_processor, + meter=self._meter, labels=self._test_labels ) obs = Observer( callback=metrics_collector._track_dependency_rate, @@ -80,7 +80,7 @@ def test_track_dependency_rate(self, time_mock): meter=self._meter, ) dependency_metrics.dependency_map["last_time"] = 98.0 - self._span_processor.dependency_count = 4 + dependency_metrics.dependency_map["count"] = 4 metrics_collector._track_dependency_rate(obs) self.assertEqual( obs.aggregators[tuple(self._test_labels.items())].current, 2 @@ -90,9 +90,7 @@ def test_track_dependency_rate(self, time_mock): def test_track_dependency_rate_time_none(self, time_mock): time_mock.time.return_value = 100 metrics_collector = dependency_metrics.DependencyMetrics( - meter=self._meter, - labels=self._test_labels, - span_processor=self._span_processor, + meter=self._meter, labels=self._test_labels ) dependency_metrics.dependency_map["last_time"] = None obs = Observer( @@ -112,9 +110,7 @@ def test_track_dependency_rate_time_none(self, time_mock): def test_track_dependency_rate_error(self, time_mock): time_mock.time.return_value = 100 metrics_collector = dependency_metrics.DependencyMetrics( - meter=self._meter, - labels=self._test_labels, - span_processor=self._span_processor, + meter=self._meter, labels=self._test_labels ) dependency_metrics.dependency_map["last_time"] = 100 dependency_metrics.dependency_map["last_result"] = 5.0 @@ -135,9 +131,7 @@ def test_track_dependency_rate_error(self, time_mock): def test_track_failed_dependency_rate(self, time_mock): time_mock.time.return_value = 100 metrics_collector = dependency_metrics.DependencyMetrics( - meter=self._meter, - labels=self._test_labels, - span_processor=self._span_processor, + meter=self._meter, labels=self._test_labels ) obs = Observer( callback=metrics_collector._track_failure_rate, @@ -148,7 +142,7 @@ def test_track_failed_dependency_rate(self, time_mock): meter=self._meter, ) dependency_metrics.dependency_map["last_time"] = 98 - self._span_processor.failed_dependency_count = 4 + dependency_metrics.dependency_map["failed_count"] = 4 metrics_collector._track_failure_rate(obs) self.assertEqual( obs.aggregators[tuple(self._test_labels.items())].current, 2.0 @@ -160,7 +154,6 @@ def test_track_failed_dependency_rate_time_none(self, time_mock): metrics_collector = dependency_metrics.DependencyMetrics( meter=self._meter, labels=self._test_labels, - span_processor=self._span_processor, ) dependency_metrics.dependency_map["last_time"] = None obs = Observer( @@ -182,7 +175,6 @@ def test_track_failed_dependency_rate_error(self, time_mock): metrics_collector = dependency_metrics.DependencyMetrics( meter=self._meter, labels=self._test_labels, - span_processor=self._span_processor, ) dependency_metrics.dependency_map["last_time"] = 100 dependency_metrics.dependency_map["last_result"] = 5.0 @@ -203,10 +195,9 @@ def test_track_dependency_duration(self): metrics_collector = dependency_metrics.DependencyMetrics( meter=self._meter, labels=self._test_labels, - span_processor=self._span_processor, ) - self._span_processor.dependency_duration = 100 - self._span_processor.dependency_count = 10 + dependency_metrics.dependency_map["duration"] = 100 + dependency_metrics.dependency_map["count"] = 10 dependency_metrics.dependency_map["last_count"] = 5 obs = Observer( callback=metrics_collector._track_dependency_duration, @@ -225,10 +216,9 @@ def test_track_dependency_duration_error(self): metrics_collector = dependency_metrics.DependencyMetrics( meter=self._meter, labels=self._test_labels, - span_processor=self._span_processor, ) - self._span_processor.dependency_duration = 100 - self._span_processor.dependency_count = 10 + dependency_metrics.dependency_map["duration"] = 100 + dependency_metrics.dependency_map["count"] = 10 dependency_metrics.dependency_map["last_count"] = 10 obs = Observer( callback=metrics_collector._track_dependency_duration, @@ -242,3 +232,23 @@ def test_track_dependency_duration_error(self): self.assertEqual( obs.aggregators[tuple(self._test_labels.items())].current, 0 ) + + @mock.patch( + "azure_monitor.sdk.auto_collection.dependency_metrics.ORIGINAL_REQUEST" + ) + def test_dependency_patch(self, request_mock): + session = requests.Session() + dependency_metrics.dependency_patch(session) + self.assertEqual(dependency_metrics.dependency_map["count"], 1) + request_mock.assert_called_with(session) + + @mock.patch( + "azure_monitor.sdk.auto_collection.dependency_metrics.ORIGINAL_REQUEST" + ) + @mock.patch("azure_monitor.sdk.auto_collection.dependency_metrics.context") + def test_dependency_patch_suppress(self, context_mock, request_mock): + context_mock.get_value.return_value = {} + session = requests.Session() + dependency_metrics.dependency_patch(session) + self.assertEqual(dependency_metrics.dependency_map.get("count"), None) + request_mock.assert_called_with(session) diff --git a/azure_monitor/tests/auto_collection/test_metrics_span_processor.py b/azure_monitor/tests/auto_collection/test_metrics_span_processor.py index 216ca34..cf5fb6a 100644 --- a/azure_monitor/tests/auto_collection/test_metrics_span_processor.py +++ b/azure_monitor/tests/auto_collection/test_metrics_span_processor.py @@ -13,106 +13,7 @@ # pylint: disable=protected-access -class TestAutoCollection(unittest.TestCase): - def test_constructor(self): - """Test the constructor.""" - span_processor = AzureMetricsSpanProcessor() - self.assertEqual(span_processor.dependency_count, 0) - self.assertEqual(span_processor.dependency_duration, 0) - self.assertEqual(span_processor.failed_dependency_count, 0) - self.assertEqual(span_processor.request_count, 0) - self.assertEqual(span_processor.request_duration, 0) - self.assertEqual(span_processor.failed_request_count, 0) - - def test_ok_dependency(self): - """Test the functionality when Client Span is ended.""" - span_processor = AzureMetricsSpanProcessor() - test_span = Span( - name="test", - kind=SpanKind.CLIENT, - context=SpanContext( - trace_id=36873507687745823477771305566750195431, - span_id=12030755672171557338, - is_remote=False, - ), - ) - test_span._start_time = 5000000 - test_span._end_time = 15000000 - span_processor.on_end(test_span) - self.assertEqual(span_processor.request_count, 0) - self.assertEqual(span_processor.request_duration, 0) - self.assertEqual(span_processor.failed_request_count, 0) - self.assertEqual(span_processor.dependency_count, 1) - self.assertEqual(span_processor.dependency_duration, 10) - self.assertEqual(span_processor.failed_dependency_count, 0) - - def test_failed_dependency(self): - """Test the functionality when Client Span is ended.""" - span_processor = AzureMetricsSpanProcessor() - test_span = Span( - name="test", - kind=SpanKind.CLIENT, - context=SpanContext( - trace_id=36873507687745823477771305566750195431, - span_id=12030755672171557338, - is_remote=False, - ), - ) - test_span.set_status(Status(StatusCanonicalCode.INTERNAL, "test")) - test_span._start_time = 5000000 - test_span._end_time = 15000000 - span_processor.on_end(test_span) - self.assertEqual(span_processor.request_count, 0) - self.assertEqual(span_processor.request_duration, 0) - self.assertEqual(span_processor.failed_request_count, 0) - self.assertEqual(span_processor.dependency_count, 1) - self.assertEqual(span_processor.dependency_duration, 10) - self.assertEqual(span_processor.failed_dependency_count, 1) - - def test_ok_request(self): - """Test the functionality when Server Span is ended.""" - span_processor = AzureMetricsSpanProcessor() - test_span = Span( - name="test", - kind=SpanKind.SERVER, - context=SpanContext( - trace_id=36873507687745823477771305566750195431, - span_id=12030755672171557338, - is_remote=False, - ), - ) - test_span._start_time = 5000000 - test_span._end_time = 15000000 - span_processor.on_end(test_span) - self.assertEqual(span_processor.dependency_count, 0) - self.assertEqual(span_processor.dependency_duration, 0) - self.assertEqual(span_processor.failed_dependency_count, 0) - self.assertEqual(span_processor.request_count, 1) - self.assertEqual(span_processor.request_duration, 10) - self.assertEqual(span_processor.failed_request_count, 0) - - def test_failed_request(self): - """Test the functionality when Server Span is ended.""" - span_processor = AzureMetricsSpanProcessor() - test_span = Span( - name="test", - kind=SpanKind.SERVER, - context=SpanContext( - trace_id=36873507687745823477771305566750195431, - span_id=12030755672171557338, - is_remote=False, - ), - ) - test_span.set_status(Status(StatusCanonicalCode.INTERNAL, "test")) - test_span._start_time = 5000000 - test_span._end_time = 15000000 - span_processor.on_end(test_span) - self.assertEqual(span_processor.dependency_count, 0) - self.assertEqual(span_processor.dependency_duration, 0) - self.assertEqual(span_processor.failed_dependency_count, 0) - self.assertEqual(span_processor.request_count, 1) - self.assertEqual(span_processor.request_duration, 10) - self.assertEqual(span_processor.failed_request_count, 1) +class TestMetricsSpanProcessor(unittest.TestCase): def test_document_collection(self): """Test the document collection.""" diff --git a/azure_monitor/tests/auto_collection/test_request_metrics.py b/azure_monitor/tests/auto_collection/test_request_metrics.py index a367834..e89d23e 100644 --- a/azure_monitor/tests/auto_collection/test_request_metrics.py +++ b/azure_monitor/tests/auto_collection/test_request_metrics.py @@ -2,17 +2,16 @@ # Licensed under the MIT License. import unittest +from http.server import HTTPServer from unittest import mock from opentelemetry import metrics from opentelemetry.sdk.metrics import MeterProvider, Observer from azure_monitor.sdk.auto_collection import request_metrics -from azure_monitor.sdk.auto_collection.metrics_span_processor import ( - AzureMetricsSpanProcessor, -) from azure_monitor.sdk.auto_collection.utils import AutoCollectionType +ORIGINAL_CONS = HTTPServer.__init__ # pylint: disable=protected-access class TestRequestMetrics(unittest.TestCase): @@ -21,7 +20,6 @@ def setUpClass(cls): metrics.set_meter_provider(MeterProvider()) cls._meter = metrics.get_meter(__name__) cls._test_labels = {"environment": "staging"} - cls._span_processor = AzureMetricsSpanProcessor() @classmethod def tearDown(cls): @@ -29,13 +27,13 @@ def tearDown(cls): def setUp(self): request_metrics.requests_map.clear() + request_metrics.ORIGINAL_CONSTRUCTOR = ORIGINAL_CONS def test_constructor(self): mock_meter = mock.Mock() request_metrics_collector = request_metrics.RequestMetrics( meter=mock_meter, labels=self._test_labels, - span_processor=self._span_processor, collection_type=AutoCollectionType.STANDARD_METRICS, ) self.assertEqual(request_metrics_collector._meter, mock_meter) @@ -62,11 +60,10 @@ def test_track_request_duration(self): request_metrics_collector = request_metrics.RequestMetrics( meter=self._meter, labels=self._test_labels, - span_processor=self._span_processor, collection_type=AutoCollectionType.STANDARD_METRICS, ) - self._span_processor.request_duration = 100 - self._span_processor.request_count = 10 + request_metrics.requests_map["duration"] = 100 + request_metrics.requests_map["count"] = 10 request_metrics.requests_map["last_count"] = 5 obs = Observer( callback=request_metrics_collector._track_request_duration, @@ -85,11 +82,10 @@ def test_track_request_duration_error(self): request_metrics_collector = request_metrics.RequestMetrics( meter=self._meter, labels=self._test_labels, - span_processor=self._span_processor, collection_type=AutoCollectionType.STANDARD_METRICS, ) - self._span_processor.request_duration = 100 - self._span_processor.request_count = 10 + request_metrics.requests_map["duration"] = 100 + request_metrics.requests_map["count"] = 10 request_metrics.requests_map["last_count"] = 10 obs = Observer( callback=request_metrics_collector._track_request_duration, @@ -109,12 +105,11 @@ def test_track_request_rate(self, time_mock): request_metrics_collector = request_metrics.RequestMetrics( meter=self._meter, labels=self._test_labels, - span_processor=self._span_processor, collection_type=AutoCollectionType.STANDARD_METRICS, ) time_mock.time.return_value = 100 request_metrics.requests_map["last_time"] = 98 - self._span_processor.request_count = 4 + request_metrics.requests_map["count"] = 4 obs = Observer( callback=request_metrics_collector._track_request_rate, name="\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Requests/Sec", @@ -134,7 +129,6 @@ def test_track_request_rate_time_none(self, time_mock): request_metrics_collector = request_metrics.RequestMetrics( meter=self._meter, labels=self._test_labels, - span_processor=self._span_processor, collection_type=AutoCollectionType.STANDARD_METRICS, ) request_metrics.requests_map["last_time"] = None @@ -156,7 +150,6 @@ def test_track_request_rate_error(self, time_mock): request_metrics_collector = request_metrics.RequestMetrics( meter=self._meter, labels=self._test_labels, - span_processor=self._span_processor, collection_type=AutoCollectionType.STANDARD_METRICS, ) time_mock.time.return_value = 100 @@ -174,3 +167,64 @@ def test_track_request_rate_error(self, time_mock): self.assertEqual( obs.aggregators[tuple(self._test_labels.items())].current, 5.0 ) + + def test_request_patch(self): + map = request_metrics.requests_map # pylint: disable=redefined-builtin + func = mock.Mock() + new_func = request_metrics.request_patch(func) + new_func() + + self.assertEqual(map["count"], 1) + self.assertIsNotNone(map["duration"]) + self.assertEqual(len(func.call_args_list), 1) + + def test_server_patch(self): + request_metrics.ORIGINAL_CONSTRUCTOR = lambda x, y, z: None + with mock.patch( + "azure_monitor.sdk.auto_collection.request_metrics.request_patch" + ) as request_mock: + handler = mock.Mock() + handler.do_DELETE.return_value = None + handler.do_GET.return_value = None + handler.do_HEAD.return_value = None + handler.do_OPTIONS.return_value = None + handler.do_POST.return_value = None + handler.do_PUT.return_value = None + result = request_metrics.server_patch(None, None, handler) + handler.do_DELETE() + handler.do_GET() + handler.do_HEAD() + handler.do_OPTIONS() + handler.do_POST() + handler.do_PUT() + + self.assertEqual(result, None) + self.assertEqual(len(request_mock.call_args_list), 6) + + def test_server_patch_no_methods(self): + request_metrics.ORIGINAL_CONSTRUCTOR = lambda x, y, z: None + with mock.patch( + "azure_monitor.sdk.auto_collection.request_metrics.request_patch" + ) as request_mock: + handler = mock.Mock() + result = request_metrics.server_patch(None, None, handler) + handler.do_DELETE() + handler.do_GET() + handler.do_HEAD() + handler.do_OPTIONS() + handler.do_POST() + handler.do_PUT() + + self.assertEqual(result, None) + self.assertEqual(len(request_mock.call_args_list), 0) + + def test_server_patch_no_args(self): + request_metrics.ORIGINAL_CONSTRUCTOR = lambda x, y: None + req = request_metrics.server_patch(None, None) + + self.assertEqual(req, None) + + def test_server_patch_no_handler(self): + request_metrics.ORIGINAL_CONSTRUCTOR = lambda x, y, z: None + req = request_metrics.server_patch(None, None, None) + self.assertEqual(req, None) diff --git a/azure_monitor/tests/test_base_exporter.py b/azure_monitor/tests/test_base_exporter.py index d197d47..b939d7a 100644 --- a/azure_monitor/tests/test_base_exporter.py +++ b/azure_monitor/tests/test_base_exporter.py @@ -80,7 +80,7 @@ def test_constructor(self): "4321abcd-5678-4efa-8abc-1234567890ab", ) self.assertEqual( - base.options.proxies, {"https": "https://test-proxy.com"}, + base.options.proxies, {"https": "https://test-proxy.com"} ) self.assertEqual(base.options.storage_maintenance_period, 2) self.assertEqual(base.options.storage_max_size, 3) From 6eb612624b4f1c14b20b92cd46d3bab5ed9178a4 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Thu, 25 Jun 2020 16:26:03 -0700 Subject: [PATCH 02/32] Lint --- .../azure_monitor/sdk/auto_collection/__init__.py | 10 ++-------- .../sdk/auto_collection/dependency_metrics.py | 3 +-- .../auto_collection/test_dependency_metrics.py | 13 +++++-------- .../auto_collection/test_metrics_span_processor.py | 1 - .../tests/auto_collection/test_request_metrics.py | 1 + 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py index e38a511..c0f4355 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py @@ -36,13 +36,7 @@ class AutoCollection: labels: Dictionary of labels """ - def __init__( - self, - meter: Meter, - labels: Dict[str, str], - ): + def __init__(self, meter: Meter, labels: Dict[str, str]): col_type = AutoCollectionType.STANDARD_METRICS self._performance_metrics = PerformanceMetrics(meter, labels, col_type) - self._request_metrics = RequestMetrics( - meter, labels, col_type - ) + self._request_metrics = RequestMetrics(meter, labels, col_type) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py index 286d030..1c71c9f 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py @@ -10,7 +10,6 @@ from opentelemetry.metrics import Meter, Observer from opentelemetry.sdk.metrics import UpDownSumObserver - _dependency_lock = threading.Lock() logger = logging.getLogger(__name__) dependency_map = dict() @@ -46,7 +45,7 @@ def dependency_patch(*args, **kwargs) -> None: ) or exception is not None: failed_count = dependency_map.get("failed_count", 0) dependency_map["failed_count"] = failed_count + 1 - except Exception as exc: + except Exception: logger.warning("Error handling failed request metrics.") return result diff --git a/azure_monitor/tests/auto_collection/test_dependency_metrics.py b/azure_monitor/tests/auto_collection/test_dependency_metrics.py index 64a65e7..5b1f5f1 100644 --- a/azure_monitor/tests/auto_collection/test_dependency_metrics.py +++ b/azure_monitor/tests/auto_collection/test_dependency_metrics.py @@ -14,6 +14,7 @@ ORIGINAL_FUNCTION = requests.Session.request ORIGINAL_CONS = HTTPServer.__init__ + # pylint: disable=protected-access class TestDependencyMetrics(unittest.TestCase): @classmethod @@ -152,8 +153,7 @@ def test_track_failed_dependency_rate(self, time_mock): def test_track_failed_dependency_rate_time_none(self, time_mock): time_mock.time.return_value = 100 metrics_collector = dependency_metrics.DependencyMetrics( - meter=self._meter, - labels=self._test_labels, + meter=self._meter, labels=self._test_labels ) dependency_metrics.dependency_map["last_time"] = None obs = Observer( @@ -173,8 +173,7 @@ def test_track_failed_dependency_rate_time_none(self, time_mock): def test_track_failed_dependency_rate_error(self, time_mock): time_mock.time.return_value = 100 metrics_collector = dependency_metrics.DependencyMetrics( - meter=self._meter, - labels=self._test_labels, + meter=self._meter, labels=self._test_labels ) dependency_metrics.dependency_map["last_time"] = 100 dependency_metrics.dependency_map["last_result"] = 5.0 @@ -193,8 +192,7 @@ def test_track_failed_dependency_rate_error(self, time_mock): def test_track_dependency_duration(self): metrics_collector = dependency_metrics.DependencyMetrics( - meter=self._meter, - labels=self._test_labels, + meter=self._meter, labels=self._test_labels ) dependency_metrics.dependency_map["duration"] = 100 dependency_metrics.dependency_map["count"] = 10 @@ -214,8 +212,7 @@ def test_track_dependency_duration(self): def test_track_dependency_duration_error(self): metrics_collector = dependency_metrics.DependencyMetrics( - meter=self._meter, - labels=self._test_labels, + meter=self._meter, labels=self._test_labels ) dependency_metrics.dependency_map["duration"] = 100 dependency_metrics.dependency_map["count"] = 10 diff --git a/azure_monitor/tests/auto_collection/test_metrics_span_processor.py b/azure_monitor/tests/auto_collection/test_metrics_span_processor.py index cf5fb6a..7c880be 100644 --- a/azure_monitor/tests/auto_collection/test_metrics_span_processor.py +++ b/azure_monitor/tests/auto_collection/test_metrics_span_processor.py @@ -14,7 +14,6 @@ # pylint: disable=protected-access class TestMetricsSpanProcessor(unittest.TestCase): - def test_document_collection(self): """Test the document collection.""" span_processor = AzureMetricsSpanProcessor() diff --git a/azure_monitor/tests/auto_collection/test_request_metrics.py b/azure_monitor/tests/auto_collection/test_request_metrics.py index e89d23e..ec76bee 100644 --- a/azure_monitor/tests/auto_collection/test_request_metrics.py +++ b/azure_monitor/tests/auto_collection/test_request_metrics.py @@ -13,6 +13,7 @@ ORIGINAL_CONS = HTTPServer.__init__ + # pylint: disable=protected-access class TestRequestMetrics(unittest.TestCase): @classmethod From 329c5d5977b2cdda6a0691341c72516702d58fb8 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Thu, 25 Jun 2020 16:38:46 -0700 Subject: [PATCH 03/32] Lint --- .../src/azure_monitor/sdk/auto_collection/dependency_metrics.py | 2 +- .../src/azure_monitor/sdk/auto_collection/request_metrics.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py index 1c71c9f..bb73c4e 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py @@ -45,7 +45,7 @@ def dependency_patch(*args, **kwargs) -> None: ) or exception is not None: failed_count = dependency_map.get("failed_count", 0) dependency_map["failed_count"] = failed_count + 1 - except Exception: + except Exception: # pylint: disable=broad-except logger.warning("Error handling failed request metrics.") return result diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py index 45da6af..05dbcc7 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py @@ -37,7 +37,7 @@ def wrapper(self=None): def send_response_patch(func): def wrapper(self, code, message=None): func(self, code, message) - if code >= 200 and code < 300: + if code >= 200 < 300: with _requests_lock: # Update Count failed_count = requests_map.get("failed_count", 0) From 981b5513385e77035702cb2896c368203e955bce Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Thu, 25 Jun 2020 16:42:14 -0700 Subject: [PATCH 04/32] broad-except --- .../src/azure_monitor/sdk/auto_collection/dependency_metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py index bb73c4e..a2a8336 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py @@ -21,7 +21,7 @@ def dependency_patch(*args, **kwargs) -> None: try: result = ORIGINAL_REQUEST(*args, **kwargs) - except Exception as exc: + except Exception as exc: # pylint: disable=broad-except exception = exc result = getattr(exc, "response", None) end_time = time.time() From 275bc8468bca0e5733d0670ff45640909204c39c Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Thu, 25 Jun 2020 16:45:42 -0700 Subject: [PATCH 05/32] Format --- .../src/azure_monitor/sdk/auto_collection/dependency_metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py index a2a8336..927f612 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py @@ -21,7 +21,7 @@ def dependency_patch(*args, **kwargs) -> None: try: result = ORIGINAL_REQUEST(*args, **kwargs) - except Exception as exc: # pylint: disable=broad-except + except Exception as exc: # pylint: disable=broad-except exception = exc result = getattr(exc, "response", None) end_time = time.time() From dd69ab43dc84c1e438b87ff6f9c06675bbb66b35 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 29 Jun 2020 13:14:02 -0700 Subject: [PATCH 06/32] update --- azure_monitor/CHANGELOG.md | 5 +++++ azure_monitor/src/azure_monitor/version.py | 2 +- docs/conf.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/azure_monitor/CHANGELOG.md b/azure_monitor/CHANGELOG.md index efd4f8a..8d3bebe 100644 --- a/azure_monitor/CHANGELOG.md +++ b/azure_monitor/CHANGELOG.md @@ -2,6 +2,11 @@ ## Unreleased +## 0.4b.0 +Released 2020-06-29 + +- Added live metrics + ([#96](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/96)) - Remove dependency metrics from auto-collection ([#92](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/92)) - Change default local storage directory diff --git a/azure_monitor/src/azure_monitor/version.py b/azure_monitor/src/azure_monitor/version.py index 7942442..139f7a5 100644 --- a/azure_monitor/src/azure_monitor/version.py +++ b/azure_monitor/src/azure_monitor/version.py @@ -1,3 +1,3 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -__version__ = "0.4.dev0" +__version__ = "0.5.dev0" diff --git a/docs/conf.py b/docs/conf.py index b503d5f..c72e032 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,7 +28,7 @@ author = "Microsoft" # The full version, including alpha/beta/rc tags -release = "0.2b.0" +release = "0.4b.0" # -- General configuration --------------------------------------------------- From 07d262156ab62b228752084e1ee8136c0e4beed5 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Mon, 29 Jun 2020 16:27:46 -0700 Subject: [PATCH 07/32] Addressing comments --- .../sdk/auto_collection/__init__.py | 6 +----- .../sdk/auto_collection/dependency_metrics.py | 7 +++---- .../sdk/auto_collection/performance_metrics.py | 2 +- .../sdk/auto_collection/request_metrics.py | 2 +- .../azure_monitor/sdk/auto_collection/utils.py | 2 +- .../auto_collection/test_performance_metrics.py | 16 ++++++++-------- .../auto_collection/test_request_metrics.py | 12 ++++++------ 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py index c0f4355..3753983 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/__init__.py @@ -5,9 +5,6 @@ from opentelemetry.metrics import Meter -from azure_monitor.sdk.auto_collection.dependency_metrics import ( - DependencyMetrics, -) from azure_monitor.sdk.auto_collection.metrics_span_processor import ( AzureMetricsSpanProcessor, ) @@ -21,7 +18,6 @@ "AutoCollection", "AutoCollectionType", "AzureMetricsSpanProcessor", - "DependencyMetrics", "RequestMetrics", "PerformanceMetrics", ] @@ -37,6 +33,6 @@ class AutoCollection: """ def __init__(self, meter: Meter, labels: Dict[str, str]): - col_type = AutoCollectionType.STANDARD_METRICS + col_type = AutoCollectionType.PERF_COUNTER self._performance_metrics = PerformanceMetrics(meter, labels, col_type) self._request_metrics = RequestMetrics(meter, labels, col_type) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py index 927f612..5244ba5 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py @@ -40,13 +40,13 @@ def dependency_patch(*args, **kwargs) -> None: # Update failed count if ( result is not None - and result.status_code >= 200 - and result.status_code < 300 + and result.status_code < 200 + and result.status_code >= 300 ) or exception is not None: failed_count = dependency_map.get("failed_count", 0) dependency_map["failed_count"] = failed_count + 1 except Exception: # pylint: disable=broad-except - logger.warning("Error handling failed request metrics.") + logger.warning("Error handling failed dependency metrics.") return result @@ -57,7 +57,6 @@ class DependencyMetrics: Args: meter: OpenTelemetry Meter labels: Dictionary of labels - collection_type: Standard or Live Metrics """ def __init__(self, meter: Meter, labels: Dict[str, str]): diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/performance_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/performance_metrics.py index 7c5f458..47b2743 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/performance_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/performance_metrics.py @@ -43,7 +43,7 @@ def __init__( observer_type=UpDownSumObserver, ) - if collection_type == AutoCollectionType.STANDARD_METRICS: + if collection_type == AutoCollectionType.PERF_COUNTER: self._meter.register_observer( callback=self._track_memory, name="\\Memory\\Available Bytes", diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py index 05dbcc7..6b93f4b 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py @@ -37,7 +37,7 @@ def wrapper(self=None): def send_response_patch(func): def wrapper(self, code, message=None): func(self, code, message) - if code >= 200 < 300: + if code < 200 >= 300: with _requests_lock: # Update Count failed_count = requests_map.get("failed_count", 0) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/utils.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/utils.py index acbc811..8883b11 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/utils.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/utils.py @@ -7,5 +7,5 @@ class AutoCollectionType(Enum): """Automatic collection of metrics type """ - STANDARD_METRICS = 0 + PERF_COUNTER = 0 LIVE_METRICS = 1 diff --git a/azure_monitor/tests/auto_collection/test_performance_metrics.py b/azure_monitor/tests/auto_collection/test_performance_metrics.py index 0474a22..e7b5f18 100644 --- a/azure_monitor/tests/auto_collection/test_performance_metrics.py +++ b/azure_monitor/tests/auto_collection/test_performance_metrics.py @@ -31,12 +31,12 @@ def setUpClass(cls): def tearDownClass(cls): metrics._METER_PROVIDER = None - def test_constructor_standard_metrics(self): + def test_constructor_PERF_COUNTER(self): mock_meter = mock.Mock() performance_metrics_collector = PerformanceMetrics( meter=mock_meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) self.assertEqual(performance_metrics_collector._meter, mock_meter) self.assertEqual( @@ -105,7 +105,7 @@ def test_track_cpu(self): performance_metrics_collector = PerformanceMetrics( meter=self._meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) with mock.patch("psutil.cpu_times_percent") as processor_mock: cpu = collections.namedtuple("cpu", "idle") @@ -129,7 +129,7 @@ def test_track_memory(self, psutil_mock): performance_metrics_collector = PerformanceMetrics( meter=self._meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) memory = collections.namedtuple("memory", "available") vmem = memory(available=100) @@ -178,7 +178,7 @@ def test_track_process_cpu(self, psutil_mock): performance_metrics_collector = PerformanceMetrics( meter=self._meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) process_mock.cpu_percent.return_value = 44.4 psutil_mock.cpu_count.return_value = 2 @@ -203,7 +203,7 @@ def test_track_process_cpu_exception(self, logger_mock): performance_metrics_collector = PerformanceMetrics( meter=self._meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) psutil_mock.cpu_count.return_value = None obs = Observer( @@ -224,7 +224,7 @@ def test_track_process_memory(self): performance_metrics_collector = PerformanceMetrics( meter=self._meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) memory = collections.namedtuple("memory", "rss") pmem = memory(rss=100) @@ -251,7 +251,7 @@ def test_track_process_memory_exception(self, logger_mock): performance_metrics_collector = PerformanceMetrics( meter=self._meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) obs = Observer( callback=performance_metrics_collector._track_process_memory, diff --git a/azure_monitor/tests/auto_collection/test_request_metrics.py b/azure_monitor/tests/auto_collection/test_request_metrics.py index ec76bee..015c63d 100644 --- a/azure_monitor/tests/auto_collection/test_request_metrics.py +++ b/azure_monitor/tests/auto_collection/test_request_metrics.py @@ -35,7 +35,7 @@ def test_constructor(self): request_metrics_collector = request_metrics.RequestMetrics( meter=mock_meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) self.assertEqual(request_metrics_collector._meter, mock_meter) self.assertEqual(request_metrics_collector._labels, self._test_labels) @@ -61,7 +61,7 @@ def test_track_request_duration(self): request_metrics_collector = request_metrics.RequestMetrics( meter=self._meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) request_metrics.requests_map["duration"] = 100 request_metrics.requests_map["count"] = 10 @@ -83,7 +83,7 @@ def test_track_request_duration_error(self): request_metrics_collector = request_metrics.RequestMetrics( meter=self._meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) request_metrics.requests_map["duration"] = 100 request_metrics.requests_map["count"] = 10 @@ -106,7 +106,7 @@ def test_track_request_rate(self, time_mock): request_metrics_collector = request_metrics.RequestMetrics( meter=self._meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) time_mock.time.return_value = 100 request_metrics.requests_map["last_time"] = 98 @@ -130,7 +130,7 @@ def test_track_request_rate_time_none(self, time_mock): request_metrics_collector = request_metrics.RequestMetrics( meter=self._meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) request_metrics.requests_map["last_time"] = None obs = Observer( @@ -151,7 +151,7 @@ def test_track_request_rate_error(self, time_mock): request_metrics_collector = request_metrics.RequestMetrics( meter=self._meter, labels=self._test_labels, - collection_type=AutoCollectionType.STANDARD_METRICS, + collection_type=AutoCollectionType.PERF_COUNTER, ) time_mock.time.return_value = 100 request_metrics.requests_map["last_rate"] = 5.0 From f2b35451937f667763d6fa398410d230c5d187e5 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Mon, 29 Jun 2020 16:41:01 -0700 Subject: [PATCH 08/32] Fixing name --- azure_monitor/tests/auto_collection/test_performance_metrics.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure_monitor/tests/auto_collection/test_performance_metrics.py b/azure_monitor/tests/auto_collection/test_performance_metrics.py index e7b5f18..060e928 100644 --- a/azure_monitor/tests/auto_collection/test_performance_metrics.py +++ b/azure_monitor/tests/auto_collection/test_performance_metrics.py @@ -31,7 +31,7 @@ def setUpClass(cls): def tearDownClass(cls): metrics._METER_PROVIDER = None - def test_constructor_PERF_COUNTER(self): + def test_constructor_perf_counters(self): mock_meter = mock.Mock() performance_metrics_collector = PerformanceMetrics( meter=mock_meter, From ec258d1e77fad409dc93b6ea569ee8538d0ba1e8 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Tue, 30 Jun 2020 15:19:23 -0700 Subject: [PATCH 09/32] Fix issue with metric names and types --- .../sdk/auto_collection/dependency_metrics.py | 18 +++++++-------- .../sdk/auto_collection/request_metrics.py | 22 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py index 5244ba5..2f3a29b 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py @@ -70,7 +70,7 @@ def __init__(self, meter: Meter, labels: Dict[str, str]): name="\\ApplicationInsights\\Dependency Call Duration", description="Average Outgoing Requests duration", unit="milliseconds", - value_type=int, + value_type=float, observer_type=UpDownSumObserver, ) meter.register_observer( @@ -101,7 +101,7 @@ def _track_dependency_rate(self, observer: Observer) -> None: current_time = time.time() last_count = dependency_map.get("last_count", 0) last_time = dependency_map.get("last_time") - last_result = dependency_map.get("last_result", 0) + last_result = dependency_map.get("last_result", 0.0) try: # last_time is None the very first time this function is called @@ -126,10 +126,10 @@ def _track_dependency_duration(self, observer: Observer) -> None: Calculated by getting the time it takes to make an outgoing request and dividing over the amount of outgoing requests over an elapsed time. """ - last_average_duration = dependency_map.get("last_average_duration", 0) + last_average_duration = dependency_map.get("last_average_duration", 0.0) interval_duration = dependency_map.get( - "duration", 0 - ) - dependency_map.get("last_duration", 0) + "duration", 0.0 + ) - dependency_map.get("last_duration", 0.0) interval_count = dependency_map.get("count", 0) - dependency_map.get( "last_count", 0 ) @@ -137,12 +137,12 @@ def _track_dependency_duration(self, observer: Observer) -> None: result = interval_duration / interval_count dependency_map["last_count"] = dependency_map.get("count", 0) dependency_map["last_average_duration"] = result - dependency_map["last_duration"] = dependency_map.get("duration", 0) - observer.observe(int(result), self._labels) + dependency_map["last_duration"] = dependency_map.get("duration", 0.0) + observer.observe(result, self._labels) except ZeroDivisionError: # If interval_count is 0, exporter call made too close to previous # Return the previous result if this is the case - observer.observe(int(last_average_duration), self._labels) + observer.observe(last_average_duration, self._labels) def _track_failure_rate(self, observer: Observer) -> None: """ Track Failed Dependency rate @@ -155,7 +155,7 @@ def _track_failure_rate(self, observer: Observer) -> None: current_time = time.time() last_failed_count = dependency_map.get("last_failed_count", 0) last_time = dependency_map.get("last_time") - last_result = dependency_map.get("last_result", 0) + last_result = dependency_map.get("last_result", 0.0) try: # last_time is None the very first time this function is called diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py index 6b93f4b..52e9cef 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py @@ -104,15 +104,15 @@ def __init__( ) meter.register_observer( callback=self._track_request_duration, - name="\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Request Execution Time", + name="\\ApplicationInsights\\Request Duration", description="Incoming Requests Average Execution Time", unit="milliseconds", - value_type=int, + value_type=float, observer_type=UpDownSumObserver, ) meter.register_observer( callback=self._track_request_rate, - name="\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Requests/Sec", + name="\\ApplicationInsights\\Requests/Sec", description="Incoming Requests Rate", unit="rps", value_type=float, @@ -125,9 +125,9 @@ def _track_request_duration(self, observer: Observer) -> None: Calculated by getting the time it takes to make an incoming request and dividing over the amount of incoming requests over an elapsed time. """ - last_average_duration = requests_map.get("last_average_duration", 0) - interval_duration = requests_map.get("duration", 0) - requests_map.get( - "last_duration", 0 + last_average_duration = requests_map.get("last_average_duration", 0.0) + interval_duration = requests_map.get("duration", 0.0) - requests_map.get( + "last_duration", 0.0 ) interval_count = requests_map.get("count", 0) - requests_map.get( "last_count", 0 @@ -136,12 +136,12 @@ def _track_request_duration(self, observer: Observer) -> None: result = interval_duration / interval_count requests_map["last_count"] = requests_map.get("count", 0) requests_map["last_average_duration"] = result - requests_map["last_duration"] = requests_map.get("duration", 0) - observer.observe(int(result), self._labels) + requests_map["last_duration"] = requests_map.get("duration", 0.0) + observer.observe(result, self._labels) except ZeroDivisionError: # If interval_count is 0, exporter call made too close to previous # Return the previous result if this is the case - observer.observe(int(last_average_duration), self._labels) + observer.observe(last_average_duration, self._labels) def _track_request_rate(self, observer: Observer) -> None: """ Track Request execution rate @@ -151,7 +151,7 @@ def _track_request_rate(self, observer: Observer) -> None: over the elapsed time. """ current_time = time.time() - last_rate = requests_map.get("last_rate", 0) + last_rate = requests_map.get("last_rate", 0.0) last_time = requests_map.get("last_time") try: @@ -181,7 +181,7 @@ def _track_request_failed_rate(self, observer: Observer) -> None: over the elapsed time. """ current_time = time.time() - last_rate = requests_map.get("last_rate", 0) + last_rate = requests_map.get("last_rate", 0.0) last_time = requests_map.get("last_time") try: From 3957865639142abe8a51831e23c191a81c6e7acf Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Tue, 30 Jun 2020 15:24:45 -0700 Subject: [PATCH 10/32] Format --- .../sdk/auto_collection/dependency_metrics.py | 8 ++++++-- .../azure_monitor/sdk/auto_collection/request_metrics.py | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py index 2f3a29b..6229351 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/dependency_metrics.py @@ -126,7 +126,9 @@ def _track_dependency_duration(self, observer: Observer) -> None: Calculated by getting the time it takes to make an outgoing request and dividing over the amount of outgoing requests over an elapsed time. """ - last_average_duration = dependency_map.get("last_average_duration", 0.0) + last_average_duration = dependency_map.get( + "last_average_duration", 0.0 + ) interval_duration = dependency_map.get( "duration", 0.0 ) - dependency_map.get("last_duration", 0.0) @@ -137,7 +139,9 @@ def _track_dependency_duration(self, observer: Observer) -> None: result = interval_duration / interval_count dependency_map["last_count"] = dependency_map.get("count", 0) dependency_map["last_average_duration"] = result - dependency_map["last_duration"] = dependency_map.get("duration", 0.0) + dependency_map["last_duration"] = dependency_map.get( + "duration", 0.0 + ) observer.observe(result, self._labels) except ZeroDivisionError: # If interval_count is 0, exporter call made too close to previous diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py index 52e9cef..2cbfab4 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/request_metrics.py @@ -126,9 +126,9 @@ def _track_request_duration(self, observer: Observer) -> None: and dividing over the amount of incoming requests over an elapsed time. """ last_average_duration = requests_map.get("last_average_duration", 0.0) - interval_duration = requests_map.get("duration", 0.0) - requests_map.get( - "last_duration", 0.0 - ) + interval_duration = requests_map.get( + "duration", 0.0 + ) - requests_map.get("last_duration", 0.0) interval_count = requests_map.get("count", 0) - requests_map.get( "last_count", 0 ) From c22b392549f0c9c37bf814e3f2a9743ad9f5e6f6 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Tue, 30 Jun 2020 15:42:02 -0700 Subject: [PATCH 11/32] Updating tests --- .../tests/auto_collection/test_dependency_metrics.py | 6 +++--- .../tests/auto_collection/test_request_metrics.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/azure_monitor/tests/auto_collection/test_dependency_metrics.py b/azure_monitor/tests/auto_collection/test_dependency_metrics.py index 5b1f5f1..308d71e 100644 --- a/azure_monitor/tests/auto_collection/test_dependency_metrics.py +++ b/azure_monitor/tests/auto_collection/test_dependency_metrics.py @@ -49,7 +49,7 @@ def test_constructor(self): name="\\ApplicationInsights\\Dependency Call Duration", description="Average Outgoing Requests duration", unit="milliseconds", - value_type=int, + value_type=float, ) create_metric_calls[1].assert_called_with( callback=metrics_collector._track_failure_rate, @@ -202,7 +202,7 @@ def test_track_dependency_duration(self): name="test", description="test", unit="test", - value_type=int, + value_type=float, meter=self._meter, ) metrics_collector._track_dependency_duration(obs) @@ -222,7 +222,7 @@ def test_track_dependency_duration_error(self): name="test", description="test", unit="test", - value_type=int, + value_type=float, meter=self._meter, ) metrics_collector._track_dependency_duration(obs) diff --git a/azure_monitor/tests/auto_collection/test_request_metrics.py b/azure_monitor/tests/auto_collection/test_request_metrics.py index 015c63d..2e29b4c 100644 --- a/azure_monitor/tests/auto_collection/test_request_metrics.py +++ b/azure_monitor/tests/auto_collection/test_request_metrics.py @@ -43,15 +43,15 @@ def test_constructor(self): create_metric_calls = mock_meter.register_observer.call_args_list create_metric_calls[0].assert_called_with( callback=request_metrics_collector._track_request_duration, - name="\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Request Execution Time", + name="\\ApplicationInsights\\Request Duration", description="Incoming Requests Average Execution Time", unit="milliseconds", - value_type=int, + value_type=float, ) create_metric_calls[1].assert_called_with( callback=request_metrics_collector._track_request_rate, - name="\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Requests/Sec", + name="\\ApplicationInsights\\Requests/Sec", description="Incoming Requests Rate", unit="rps", value_type=float, @@ -71,7 +71,7 @@ def test_track_request_duration(self): name="\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Request Execution Time", description="Incoming Requests Average Execution Time", unit="milliseconds", - value_type=int, + value_type=float, meter=self._meter, ) request_metrics_collector._track_request_duration(obs) @@ -93,7 +93,7 @@ def test_track_request_duration_error(self): name="\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Request Execution Time", description="Incoming Requests Average Execution Time", unit="milliseconds", - value_type=int, + value_type=float, meter=self._meter, ) request_metrics_collector._track_request_duration(obs) From 925ee64b16213f1a5fe1cc78a9587f3096b9d2e8 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Mon, 6 Jul 2020 16:26:49 -0700 Subject: [PATCH 12/32] Updating logger exceptions in auto_collection --- .../sdk/auto_collection/live_metrics/exporter.py | 2 +- .../sdk/auto_collection/metrics_span_processor.py | 2 +- .../azure_monitor/sdk/auto_collection/performance_metrics.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/exporter.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/exporter.py index 4c9e859..b200b05 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/exporter.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/exporter.py @@ -61,7 +61,7 @@ def export( return MetricsExportResult.SUCCESS except Exception: # pylint: disable=broad-except - logger.exception("Exception occurred while exporting the data.") + logger.warning("Exception occurred while exporting the data.") return MetricsExportResult.FAILURE diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/metrics_span_processor.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/metrics_span_processor.py index 990497d..0ef5908 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/metrics_span_processor.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/metrics_span_processor.py @@ -29,7 +29,7 @@ def on_end(self, span: Span) -> None: self.documents.append(convert_span_to_envelope(span)) # pylint: disable=broad-except except Exception: - logger.exception("Exception while processing Span.") + logger.warning("Exception while processing Span.") def shutdown(self) -> None: pass diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/performance_metrics.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/performance_metrics.py index 47b2743..417e068 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/performance_metrics.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/performance_metrics.py @@ -110,7 +110,7 @@ def _track_process_cpu(self, observer: Observer) -> None: cpu_count = psutil.cpu_count(logical=True) observer.observe(PROCESS.cpu_percent() / cpu_count, self._labels) except Exception: # pylint: disable=broad-except - logger.exception("Error handling get process cpu usage.") + logger.warning("Error handling get process cpu usage.") def _track_process_memory(self, observer: Observer) -> None: """ Track Memory @@ -121,7 +121,7 @@ def _track_process_memory(self, observer: Observer) -> None: try: observer.observe(PROCESS.memory_info().rss, self._labels) except Exception: # pylint: disable=broad-except - logger.exception("Error handling get process private bytes.") + logger.warning("Error handling get process private bytes.") def _track_commited_memory(self, observer: Observer) -> None: """ Track Commited Memory From 0f0807032236ead1075a9f88b9c1202e23f98e08 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Mon, 6 Jul 2020 16:33:16 -0700 Subject: [PATCH 13/32] Updating tests --- .../tests/auto_collection/test_performance_metrics.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure_monitor/tests/auto_collection/test_performance_metrics.py b/azure_monitor/tests/auto_collection/test_performance_metrics.py index 060e928..c0af696 100644 --- a/azure_monitor/tests/auto_collection/test_performance_metrics.py +++ b/azure_monitor/tests/auto_collection/test_performance_metrics.py @@ -215,7 +215,7 @@ def test_track_process_cpu_exception(self, logger_mock): meter=self._meter, ) performance_metrics_collector._track_process_cpu(obs) - self.assertEqual(logger_mock.exception.called, True) + self.assertEqual(logger_mock.warning.called, True) def test_track_process_memory(self): with mock.patch( @@ -262,4 +262,4 @@ def test_track_process_memory_exception(self, logger_mock): meter=self._meter, ) performance_metrics_collector._track_process_memory(obs) - self.assertEqual(logger_mock.exception.called, True) + self.assertEqual(logger_mock.warning.called, True) From e8508b1593cc58b856ed34c50179ff1ede4bcf36 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 10 Aug 2020 11:56:30 -0700 Subject: [PATCH 14/32] test --- azure_monitor/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure_monitor/CHANGELOG.md b/azure_monitor/CHANGELOG.md index 8d3bebe..e368be8 100644 --- a/azure_monitor/CHANGELOG.md +++ b/azure_monitor/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## Unreleased - +a ## 0.4b.0 Released 2020-06-29 From d822c0dd9b7def0db487fa02ca37f3af05ddf795 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 10 Aug 2020 11:58:00 -0700 Subject: [PATCH 15/32] Update setup.cfg --- azure_monitor/setup.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure_monitor/setup.cfg b/azure_monitor/setup.cfg index b0f48bb..a4e89f0 100644 --- a/azure_monitor/setup.cfg +++ b/azure_monitor/setup.cfg @@ -28,8 +28,8 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.10b0 - opentelemetry-sdk == 0.10b0 + opentelemetry-api == 0.11b0 + opentelemetry-sdk == 0.11b0 psutil >= 5.6.3 requests ~= 2.0 From e326f1848c4ccae3c000ec241f17e989ccfb52bc Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 10 Aug 2020 13:01:45 -0700 Subject: [PATCH 16/32] fix formatting --- azure_monitor/src/azure_monitor/storage.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azure_monitor/src/azure_monitor/storage.py b/azure_monitor/src/azure_monitor/storage.py index 714aed7..958643c 100644 --- a/azure_monitor/src/azure_monitor/storage.py +++ b/azure_monitor/src/azure_monitor/storage.py @@ -200,10 +200,10 @@ def _check_storage_size(self): if size >= self.max_size: logger.warning( "Persistent storage max capacity has been " - "reached. Currently at %fKB. Telemetry will be " + "reached. Currently at {}KB. Telemetry will be " "lost. Please consider increasing the value of " - "'storage_max_size' in exporter config.", - format(size / 1024), + "'storage_max_size' in exporter config." + .format(size/1024) ) return False return True From 00c950da6046174f6f922643b24396dcb631eca4 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 10 Aug 2020 13:05:06 -0700 Subject: [PATCH 17/32] black --- azure_monitor/src/azure_monitor/storage.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/azure_monitor/src/azure_monitor/storage.py b/azure_monitor/src/azure_monitor/storage.py index 958643c..67c91a1 100644 --- a/azure_monitor/src/azure_monitor/storage.py +++ b/azure_monitor/src/azure_monitor/storage.py @@ -202,8 +202,9 @@ def _check_storage_size(self): "Persistent storage max capacity has been " "reached. Currently at {}KB. Telemetry will be " "lost. Please consider increasing the value of " - "'storage_max_size' in exporter config." - .format(size/1024) + "'storage_max_size' in exporter config.".format( + size / 1024 + ) ) return False return True From 160215c37a26bc9b46609c95e7f4c0dbfcccd6f6 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 10 Aug 2020 13:19:20 -0700 Subject: [PATCH 18/32] lint --- azure_monitor/src/azure_monitor/storage.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/azure_monitor/src/azure_monitor/storage.py b/azure_monitor/src/azure_monitor/storage.py index 67c91a1..4a22bf5 100644 --- a/azure_monitor/src/azure_monitor/storage.py +++ b/azure_monitor/src/azure_monitor/storage.py @@ -198,12 +198,13 @@ def _check_storage_size(self): ) continue if size >= self.max_size: + # pylint: disable=logging-format-interpolation logger.warning( "Persistent storage max capacity has been " "reached. Currently at {}KB. Telemetry will be " "lost. Please consider increasing the value of " "'storage_max_size' in exporter config.".format( - size / 1024 + str(size / 1024) ) ) return False From f24b2510d1428347403d946685ee04952c836afc Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 10 Aug 2020 14:02:57 -0700 Subject: [PATCH 19/32] Update CHANGELOG.md --- azure_monitor/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure_monitor/CHANGELOG.md b/azure_monitor/CHANGELOG.md index e368be8..8d3bebe 100644 --- a/azure_monitor/CHANGELOG.md +++ b/azure_monitor/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## Unreleased -a + ## 0.4b.0 Released 2020-06-29 From 56a601ee0db4ea7951e64816390fd526c7624a60 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 24 Aug 2020 15:03:42 -0700 Subject: [PATCH 20/32] note --- azure_monitor/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azure_monitor/README.md b/azure_monitor/README.md index 98b692d..b417715 100644 --- a/azure_monitor/README.md +++ b/azure_monitor/README.md @@ -1,7 +1,9 @@ -# OpenTelemetry Azure Monitor SDKs and Exporters +# OpenTelemetry Azure Monitor SDKs and Exporters (Private preview) [![PyPI version](https://badge.fury.io/py/opentelemetry-azure-monitor.svg)](https://badge.fury.io/py/opentelemetry-azure-monitor) +The OpenTelemetry Azure Monitor SDK and exporter are in private preview. They are not recommended for a production environment. + ## Installation ```sh From 083e642dde4ea1b1d1ffc24e612a5a541d9ea842 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 24 Aug 2020 15:13:35 -0700 Subject: [PATCH 21/32] lint --- azure_monitor/src/azure_monitor/options.py | 1 + azure_monitor/src/azure_monitor/utils.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/azure_monitor/src/azure_monitor/options.py b/azure_monitor/src/azure_monitor/options.py index 36e2630..0764ef7 100644 --- a/azure_monitor/src/azure_monitor/options.py +++ b/azure_monitor/src/azure_monitor/options.py @@ -135,6 +135,7 @@ def parse_connection_string(connection_string) -> typing.Dict: # Convert keys to lower-case due to case type-insensitive checking result = {key.lower(): value for key, value in result.items()} except Exception: + # pylint: disable=raise-missing-from raise ValueError("Invalid connection string") # Validate authorization auth = result.get("authorization") diff --git a/azure_monitor/src/azure_monitor/utils.py b/azure_monitor/src/azure_monitor/utils.py index c2f4998..ec3a742 100644 --- a/azure_monitor/src/azure_monitor/utils.py +++ b/azure_monitor/src/azure_monitor/utils.py @@ -58,7 +58,7 @@ class PeriodicTask(threading.Thread): """ def __init__(self, interval, function, args=None, kwargs=None): - super(PeriodicTask, self).__init__() + super(PeriodicTask).__init__() self.interval = interval self.function = function self.args = args or [] From 2bef867b52eadfb9da24455c295eea133d96274c Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 24 Aug 2020 15:17:47 -0700 Subject: [PATCH 22/32] lint --- azure_monitor/src/azure_monitor/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure_monitor/src/azure_monitor/utils.py b/azure_monitor/src/azure_monitor/utils.py index ec3a742..b8da222 100644 --- a/azure_monitor/src/azure_monitor/utils.py +++ b/azure_monitor/src/azure_monitor/utils.py @@ -58,7 +58,7 @@ class PeriodicTask(threading.Thread): """ def __init__(self, interval, function, args=None, kwargs=None): - super(PeriodicTask).__init__() + super().__init__() self.interval = interval self.function = function self.args = args or [] From 2f4bb2a517dcf1992621683973fa5e77443a59c6 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 24 Aug 2020 16:30:53 -0700 Subject: [PATCH 23/32] change epoch --- azure_monitor/CHANGELOG.md | 3 +++ azure_monitor/examples/metrics/observer.py | 2 +- .../sdk/auto_collection/live_metrics/sender.py | 3 +-- .../sdk/auto_collection/live_metrics/utils.py | 14 ++++++++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/azure_monitor/CHANGELOG.md b/azure_monitor/CHANGELOG.md index 8d3bebe..711e594 100644 --- a/azure_monitor/CHANGELOG.md +++ b/azure_monitor/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- Change epoch for live metrics + ([#115](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/115)) + ## 0.4b.0 Released 2020-06-29 diff --git a/azure_monitor/examples/metrics/observer.py b/azure_monitor/examples/metrics/observer.py index 52f21ac..66b1c64 100644 --- a/azure_monitor/examples/metrics/observer.py +++ b/azure_monitor/examples/metrics/observer.py @@ -48,4 +48,4 @@ def get_ram_usage_callback(observer): label_keys=(), ) -input("Metrics will be printed soon. Press a key to finish...\n") +input("Press any key to exit...") diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/sender.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/sender.py index 27f39e3..9872efb 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/sender.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/sender.py @@ -3,7 +3,6 @@ # import json import logging -import time import requests @@ -42,7 +41,7 @@ def _send_request(self, data: str, request_type: str) -> requests.Response: "Expect": "100-continue", "Content-Type": "application/json; charset=utf-8", utils.LIVE_METRICS_TRANSMISSION_TIME_HEADER: str( - round(time.time()) * 1000 + utils.get_time_since_epoch() ), }, ) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py index cfba984..b099604 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py @@ -1,7 +1,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. # -import time +import datetime import uuid from azure_monitor.protocol import LiveMetricEnvelope @@ -22,7 +22,17 @@ def create_metric_envelope(instrumentation_key: str): machine_name=azure_monitor_context.get("ai.device.id"), metrics=None, stream_id=STREAM_ID, - timestamp="/Date({0})/".format(str(int(time.time()) * 1000)), + timestamp="/Date({0})/".format(str(get_time_since_epoch())), version=azure_monitor_context.get("ai.internal.sdkVersion"), ) return envelope + + +def get_time_since_epoch(): + now = datetime.datetime.now() + # epoch is defined as 12:00:00 midnight on January 1, 0001 for Microsoft + epoch = datetime.datetime(1,1,1) + delta = (now - epoch).total_seconds() + # return the number of 100-nanosecond intervals + delta = round(delta * 10000000) + return delta From 7f6a5c626065a6338711f520d92744157fb71dd6 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 24 Aug 2020 16:35:11 -0700 Subject: [PATCH 24/32] lint --- .../azure_monitor/sdk/auto_collection/live_metrics/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py index b099604..3023319 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py @@ -31,8 +31,8 @@ def create_metric_envelope(instrumentation_key: str): def get_time_since_epoch(): now = datetime.datetime.now() # epoch is defined as 12:00:00 midnight on January 1, 0001 for Microsoft - epoch = datetime.datetime(1,1,1) + epoch = datetime.datetime(1, 1, 1) delta = (now - epoch).total_seconds() - # return the number of 100-nanosecond intervals + # return the number of 100-nanosecond intervals delta = round(delta * 10000000) return delta From dd212d03e08381db9513e27c6ab401d07d006f02 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 24 Aug 2020 18:40:54 -0700 Subject: [PATCH 25/32] revert time --- .../azure_monitor/sdk/auto_collection/live_metrics/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py index 3023319..5893497 100644 --- a/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py +++ b/azure_monitor/src/azure_monitor/sdk/auto_collection/live_metrics/utils.py @@ -2,6 +2,7 @@ # Licensed under the MIT License. # import datetime +import time import uuid from azure_monitor.protocol import LiveMetricEnvelope @@ -22,7 +23,7 @@ def create_metric_envelope(instrumentation_key: str): machine_name=azure_monitor_context.get("ai.device.id"), metrics=None, stream_id=STREAM_ID, - timestamp="/Date({0})/".format(str(get_time_since_epoch())), + timestamp="/Date({0})/".format(str(int(time.time()) * 1000)), version=azure_monitor_context.get("ai.internal.sdkVersion"), ) return envelope From e79d95a8d42755656989e7199ce8b7b41f71e9d3 Mon Sep 17 00:00:00 2001 From: Hector Hernandez Guzman Date: Fri, 4 Sep 2020 18:38:12 -0700 Subject: [PATCH 26/32] Changing ikey in tests --- .../tests/auto_collection/live_metrics/test_exporter.py | 4 ++-- .../tests/auto_collection/live_metrics/test_manager.py | 2 +- .../tests/auto_collection/live_metrics/test_sender.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/azure_monitor/tests/auto_collection/live_metrics/test_exporter.py b/azure_monitor/tests/auto_collection/live_metrics/test_exporter.py index c480a0d..c376e71 100644 --- a/azure_monitor/tests/auto_collection/live_metrics/test_exporter.py +++ b/azure_monitor/tests/auto_collection/live_metrics/test_exporter.py @@ -44,7 +44,7 @@ def func(*_args, **_kwargs): class TestLiveMetricsExporter(unittest.TestCase): @classmethod def setUpClass(cls): - cls._instrumentation_key = "99c42f65-1656-4c41-afde-bd86b709a4a7" + cls._instrumentation_key = "12345678-1234-5678-abcd-12345678abcd" metrics.set_meter_provider(MeterProvider()) cls._meter = metrics.get_meter(__name__) cls._test_metric = cls._meter.create_metric( @@ -140,7 +140,7 @@ def test_live_metric_envelope_observer(self): self.assertIsInstance(envelope, LiveMetricEnvelope) self.assertEqual( envelope.instrumentation_key, - "99c42f65-1656-4c41-afde-bd86b709a4a7", + "12345678-1234-5678-abcd-12345678abcd", ) self.assertEqual(envelope.documents, []) self.assertEqual(envelope.metrics[0].name, "testname") diff --git a/azure_monitor/tests/auto_collection/live_metrics/test_manager.py b/azure_monitor/tests/auto_collection/live_metrics/test_manager.py index 7b9dc1d..90fcc92 100644 --- a/azure_monitor/tests/auto_collection/live_metrics/test_manager.py +++ b/azure_monitor/tests/auto_collection/live_metrics/test_manager.py @@ -32,7 +32,7 @@ def setUpClass(cls): ) testing_labels = {"environment": "testing"} cls._test_metric.add(5, testing_labels) - cls._instrumentation_key = "99c42f65-1656-4c41-afde-bd86b709a4a7" + cls._instrumentation_key = "12345678-1234-5678-abcd-12345678abcd" cls._manager = None cls._ping = None cls._post = None diff --git a/azure_monitor/tests/auto_collection/live_metrics/test_sender.py b/azure_monitor/tests/auto_collection/live_metrics/test_sender.py index dadf95c..b29859d 100644 --- a/azure_monitor/tests/auto_collection/live_metrics/test_sender.py +++ b/azure_monitor/tests/auto_collection/live_metrics/test_sender.py @@ -14,7 +14,7 @@ class TestLiveMetricsSender(unittest.TestCase): @classmethod def setUpClass(cls): - cls._instrumentation_key = "99c42f65-1656-4c41-afde-bd86b709a4a7" + cls._instrumentation_key = "12345678-1234-5678-abcd-12345678abcd" def test_constructor(self): """Test the constructor.""" From 77272cab50fb83e63c127adb103193bd2d42ae6a Mon Sep 17 00:00:00 2001 From: Leighton Date: Thu, 17 Sep 2020 23:16:40 -0400 Subject: [PATCH 27/32] update --- azure_monitor/examples/metrics/simple.py | 1 - azure_monitor/examples/traces/client.py | 4 ++-- azure_monitor/examples/traces/request.py | 28 ------------------------ azure_monitor/examples/traces/server.py | 4 ++-- azure_monitor/setup.cfg | 4 ++-- 5 files changed, 6 insertions(+), 35 deletions(-) delete mode 100644 azure_monitor/examples/traces/request.py diff --git a/azure_monitor/examples/metrics/simple.py b/azure_monitor/examples/metrics/simple.py index 34c7fd1..363047c 100644 --- a/azure_monitor/examples/metrics/simple.py +++ b/azure_monitor/examples/metrics/simple.py @@ -18,7 +18,6 @@ unit="1", value_type=int, metric_type=Counter, - label_keys=("environment",), ) testing_labels = {"environment": "testing"} diff --git a/azure_monitor/examples/traces/client.py b/azure_monitor/examples/traces/client.py index 027f8dc..ad322a7 100644 --- a/azure_monitor/examples/traces/client.py +++ b/azure_monitor/examples/traces/client.py @@ -5,7 +5,7 @@ # pylint: disable=no-name-in-module import requests from opentelemetry import trace -from opentelemetry.ext.requests import RequestsInstrumentor +from opentelemetry.instrumentation.requests import RequestsInstrumentor from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchExportSpanProcessor @@ -21,6 +21,6 @@ ) trace.get_tracer_provider().add_span_processor(span_processor) -response = requests.get(url="http://127.0.0.1:8080/") +response = requests.get(url="http://example.com/") input("Press any key to exit...") diff --git a/azure_monitor/examples/traces/request.py b/azure_monitor/examples/traces/request.py deleted file mode 100644 index b9942a0..0000000 --- a/azure_monitor/examples/traces/request.py +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. -# pylint: disable=import-error -# pylint: disable=no-member -# pylint: disable=no-name-in-module -import requests -from opentelemetry import trace -from opentelemetry.ext.requests import RequestsInstrumentor -from opentelemetry.sdk.trace import TracerProvider -from opentelemetry.sdk.trace.export import SimpleExportSpanProcessor - -from azure_monitor import AzureMonitorSpanExporter - -trace.set_tracer_provider(TracerProvider()) - -RequestsInstrumentor().instrument() -span_processor = SimpleExportSpanProcessor( - AzureMonitorSpanExporter( - connection_string="InstrumentationKey=" - ) -) -trace.get_tracer_provider().add_span_processor(span_processor) -tracer = trace.get_tracer(__name__) - -with tracer.start_as_current_span("parent"): - response = requests.get("https://azure.microsoft.com/", timeout=5) - -input("Press any key to exit...") diff --git a/azure_monitor/examples/traces/server.py b/azure_monitor/examples/traces/server.py index 51039c8..be08550 100644 --- a/azure_monitor/examples/traces/server.py +++ b/azure_monitor/examples/traces/server.py @@ -5,8 +5,8 @@ # pylint: disable=no-name-in-module import requests from opentelemetry import trace -from opentelemetry.ext.flask import FlaskInstrumentor -from opentelemetry.ext.requests import RequestsInstrumentor +from opentelemetry.instrumentation.flask import FlaskInstrumentor +from opentelemetry.instrumentation.requests import RequestsInstrumentor from opentelemetry.sdk.trace import TracerProvider from opentelemetry.sdk.trace.export import BatchExportSpanProcessor diff --git a/azure_monitor/setup.cfg b/azure_monitor/setup.cfg index a4e89f0..442f56d 100644 --- a/azure_monitor/setup.cfg +++ b/azure_monitor/setup.cfg @@ -28,8 +28,8 @@ package_dir= =src packages=find_namespace: install_requires = - opentelemetry-api == 0.11b0 - opentelemetry-sdk == 0.11b0 + opentelemetry-api == 0.13b0 + opentelemetry-sdk == 0.13b0 psutil >= 5.6.3 requests ~= 2.0 From a8c50ca1828fe3b148e3417f94c236d6da402522 Mon Sep 17 00:00:00 2001 From: Leighton Date: Thu, 17 Sep 2020 23:28:23 -0400 Subject: [PATCH 28/32] fix tests --- azure_monitor/setup.cfg | 3 +-- .../tests/auto_collection/test_dependency_metrics.py | 8 -------- .../tests/auto_collection/test_performance_metrics.py | 7 ------- .../tests/auto_collection/test_request_metrics.py | 5 ----- 4 files changed, 1 insertion(+), 22 deletions(-) diff --git a/azure_monitor/setup.cfg b/azure_monitor/setup.cfg index 442f56d..9e5d68c 100644 --- a/azure_monitor/setup.cfg +++ b/azure_monitor/setup.cfg @@ -16,14 +16,13 @@ classifiers = License :: OSI Approved :: MIT License Programming Language :: Python Programming Language :: Python :: 3 - Programming Language :: Python :: 3.4 Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 [options] -python_requires = >=3.4 +python_requires = >=3.5 package_dir= =src packages=find_namespace: diff --git a/azure_monitor/tests/auto_collection/test_dependency_metrics.py b/azure_monitor/tests/auto_collection/test_dependency_metrics.py index 308d71e..702d990 100644 --- a/azure_monitor/tests/auto_collection/test_dependency_metrics.py +++ b/azure_monitor/tests/auto_collection/test_dependency_metrics.py @@ -78,7 +78,6 @@ def test_track_dependency_rate(self, time_mock): description="Outgoing Requests per second", unit="rps", value_type=float, - meter=self._meter, ) dependency_metrics.dependency_map["last_time"] = 98.0 dependency_metrics.dependency_map["count"] = 4 @@ -100,7 +99,6 @@ def test_track_dependency_rate_time_none(self, time_mock): description="Outgoing Requests per second", unit="rps", value_type=float, - meter=self._meter, ) metrics_collector._track_dependency_rate(obs) self.assertEqual( @@ -121,7 +119,6 @@ def test_track_dependency_rate_error(self, time_mock): description="Outgoing Requests per second", unit="rps", value_type=float, - meter=self._meter, ) metrics_collector._track_dependency_rate(obs) self.assertEqual( @@ -140,7 +137,6 @@ def test_track_failed_dependency_rate(self, time_mock): description="test", unit="test", value_type=float, - meter=self._meter, ) dependency_metrics.dependency_map["last_time"] = 98 dependency_metrics.dependency_map["failed_count"] = 4 @@ -162,7 +158,6 @@ def test_track_failed_dependency_rate_time_none(self, time_mock): description="test", unit="test", value_type=float, - meter=self._meter, ) metrics_collector._track_failure_rate(obs) self.assertEqual( @@ -183,7 +178,6 @@ def test_track_failed_dependency_rate_error(self, time_mock): description="test", unit="test", value_type=float, - meter=self._meter, ) metrics_collector._track_failure_rate(obs) self.assertEqual( @@ -203,7 +197,6 @@ def test_track_dependency_duration(self): description="test", unit="test", value_type=float, - meter=self._meter, ) metrics_collector._track_dependency_duration(obs) self.assertEqual( @@ -223,7 +216,6 @@ def test_track_dependency_duration_error(self): description="test", unit="test", value_type=float, - meter=self._meter, ) metrics_collector._track_dependency_duration(obs) self.assertEqual( diff --git a/azure_monitor/tests/auto_collection/test_performance_metrics.py b/azure_monitor/tests/auto_collection/test_performance_metrics.py index c0af696..ef5b6d4 100644 --- a/azure_monitor/tests/auto_collection/test_performance_metrics.py +++ b/azure_monitor/tests/auto_collection/test_performance_metrics.py @@ -117,7 +117,6 @@ def test_track_cpu(self): description="Processor time as a percentage", unit="percentage", value_type=float, - meter=self._meter, ) performance_metrics_collector._track_cpu(obs) self.assertEqual( @@ -140,7 +139,6 @@ def test_track_memory(self, psutil_mock): description="Amount of available memory in bytes", unit="byte", value_type=int, - meter=self._meter, ) performance_metrics_collector._track_memory(obs) self.assertEqual( @@ -163,7 +161,6 @@ def test_track_commited_memory(self, psutil_mock): description="Amount of available memory in bytes", unit="byte", value_type=int, - meter=self._meter, ) performance_metrics_collector._track_commited_memory(obs) self.assertEqual( @@ -188,7 +185,6 @@ def test_track_process_cpu(self, psutil_mock): description="Process CPU usage as a percentage", unit="percentage", value_type=float, - meter=self._meter, ) performance_metrics_collector._track_process_cpu(obs) self.assertEqual( @@ -212,7 +208,6 @@ def test_track_process_cpu_exception(self, logger_mock): description="Process CPU usage as a percentage", unit="percentage", value_type=float, - meter=self._meter, ) performance_metrics_collector._track_process_cpu(obs) self.assertEqual(logger_mock.warning.called, True) @@ -235,7 +230,6 @@ def test_track_process_memory(self): description="Amount of memory process has used in bytes", unit="byte", value_type=int, - meter=self._meter, ) performance_metrics_collector._track_process_memory(obs) self.assertEqual( @@ -259,7 +253,6 @@ def test_track_process_memory_exception(self, logger_mock): description="Amount of memory process has used in bytes", unit="byte", value_type=int, - meter=self._meter, ) performance_metrics_collector._track_process_memory(obs) self.assertEqual(logger_mock.warning.called, True) diff --git a/azure_monitor/tests/auto_collection/test_request_metrics.py b/azure_monitor/tests/auto_collection/test_request_metrics.py index 2e29b4c..2ec6a85 100644 --- a/azure_monitor/tests/auto_collection/test_request_metrics.py +++ b/azure_monitor/tests/auto_collection/test_request_metrics.py @@ -72,7 +72,6 @@ def test_track_request_duration(self): description="Incoming Requests Average Execution Time", unit="milliseconds", value_type=float, - meter=self._meter, ) request_metrics_collector._track_request_duration(obs) self.assertEqual( @@ -94,7 +93,6 @@ def test_track_request_duration_error(self): description="Incoming Requests Average Execution Time", unit="milliseconds", value_type=float, - meter=self._meter, ) request_metrics_collector._track_request_duration(obs) self.assertEqual( @@ -117,7 +115,6 @@ def test_track_request_rate(self, time_mock): description="Incoming Requests Average Execution Rate", unit="rps", value_type=float, - meter=self._meter, ) request_metrics_collector._track_request_rate(obs) self.assertEqual( @@ -139,7 +136,6 @@ def test_track_request_rate_time_none(self, time_mock): description="Incoming Requests Average Execution Rate", unit="rps", value_type=float, - meter=self._meter, ) request_metrics_collector._track_request_rate(obs) self.assertEqual( @@ -162,7 +158,6 @@ def test_track_request_rate_error(self, time_mock): description="Incoming Requests Average Execution Rate", unit="rps", value_type=float, - meter=self._meter, ) request_metrics_collector._track_request_rate(obs) self.assertEqual( From 0196d6e536dcb77752ac63b4bd8b65d46fbf81df Mon Sep 17 00:00:00 2001 From: Leighton Date: Thu, 17 Sep 2020 23:33:18 -0400 Subject: [PATCH 29/32] remove 3.4 --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index 9966fa7..553dd55 100644 --- a/tox.ini +++ b/tox.ini @@ -2,8 +2,8 @@ skipsdist = True skip_missing_interpreters = True envlist = - py3{4,5,6,7,8}-test-{azure_monitor} - py3{4,5,6,7,8}-coverage + py3{5,6,7,8}-test-{azure_monitor} + py3{5,6,7,8}-coverage lint docs From f1c34c5789572f3aa2fd349c4d57388b8e435167 Mon Sep 17 00:00:00 2001 From: Leighton Date: Thu, 17 Sep 2020 23:37:48 -0400 Subject: [PATCH 30/32] Update .travis.yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2cfc918..c48fd48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ dist: xenial language: python python: - - '3.4' - '3.5' - '3.6' - '3.7' From 978a9df28f915342440e311b6603209e67d4d465 Mon Sep 17 00:00:00 2001 From: Leighton Date: Thu, 24 Sep 2020 15:05:24 -0400 Subject: [PATCH 31/32] Update conf.py --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index c72e032..d688cbc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,7 +28,7 @@ author = "Microsoft" # The full version, including alpha/beta/rc tags -release = "0.4b.0" +release = "0.5b.0" # -- General configuration --------------------------------------------------- From 52b2eb65a0eab27bdb79f96e11620a2e003f1da5 Mon Sep 17 00:00:00 2001 From: Leighton Date: Thu, 24 Sep 2020 15:28:37 -0400 Subject: [PATCH 32/32] Update CHANGELOG.md --- azure_monitor/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/azure_monitor/CHANGELOG.md b/azure_monitor/CHANGELOG.md index 79f696f..e9a25f2 100644 --- a/azure_monitor/CHANGELOG.md +++ b/azure_monitor/CHANGELOG.md @@ -7,6 +7,8 @@ Released 2020-09-24 - Change epoch for live metrics ([#115](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/115)) +- Dropping support for Python 3.4 + ([#117](https://github.com/microsoft/opentelemetry-azure-monitor-python/pull/117)) ## 0.4b.0 Released 2020-06-29