From 32cd56c90f736b16d025a8783155fbf6f3dcf63d Mon Sep 17 00:00:00 2001 From: Rakshith Bhyravabhotla Date: Fri, 5 Mar 2021 16:17:13 -0800 Subject: [PATCH] Perf tests for monitor exporter (#17067) * Perf tests for monitor * oops * updated * perf imporves * perf_mon --- .../tests/perfstress_tests/README.md | 50 +++++++++++++++++++ .../tests/perfstress_tests/__init__.py | 0 .../tests/perfstress_tests/trace_exporter.py | 47 +++++++++++++++++ 3 files changed, 97 insertions(+) create mode 100644 sdk/monitor/azure-monitor-opentelemetry-exporter/tests/perfstress_tests/README.md create mode 100644 sdk/monitor/azure-monitor-opentelemetry-exporter/tests/perfstress_tests/__init__.py create mode 100644 sdk/monitor/azure-monitor-opentelemetry-exporter/tests/perfstress_tests/trace_exporter.py diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/perfstress_tests/README.md b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/perfstress_tests/README.md new file mode 100644 index 000000000000..b35f9757c052 --- /dev/null +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/perfstress_tests/README.md @@ -0,0 +1,50 @@ +# Monitor Exporter Performance Tests + +In order to run the performance tests, the `azure-devtools` package must be installed. This is done as part of the `dev_requirements`. +Start by creating a new virtual environment for your perf tests. This will need to be a Python 3 environment, preferably >=3.7. + +### Setup for test resources + +These tests will run against a pre-configured Application Insights resource. The following environment variable will need to be set for the tests to access the live resources: +``` +APPLICATIONINSIGHTS_CONNECTION_STRING= +``` + +### Setup for perf test runs + +```cmd +(env) ~/azure-monitor-opentelemetry-exporter> pip install -r dev_requirements.txt +(env) ~/azure-monitor-opentelemetry-exporter> pip install -e . +``` + +## Test commands + +```cmd +(env) ~/azure-monitor-opentelemetry-exporter> cd tests +(env) ~/azure-monitor-opentelemetry-exporter/tests> perfstress MonitorExporterPerfTest --sync --num-spans=10 +``` + +### Common perf command line options +These options are available for all perf tests: +- `--duration=10` Number of seconds to run as many operations (the "run" function) as possible. Default is 10. +- `--iterations=1` Number of test iterations to run. Default is 1. +- `--parallel=1` Number of tests to run in parallel. Default is 1. +- `--warm-up=5` Number of seconds to spend warming up the connection before measuring begins. Default is 5. +- `--sync` Whether to run the tests in sync or async. Default is False (async). This must be set to True explicitly. +- `--no-cleanup` Whether to keep newly created resources after test run. Default is False (resources will be deleted). + +### MonitorExporter Test options +These options are available for all monitor exporter perf tests: +- `--num-spans` Number ofspans to be exported. Defaults to 10. + +### T2 Tests +The tests currently written for the T2 SDK: +- `MonitorExporterPerfTest` Collects sample traces and exports to application insights. + +## Example command + +**Note:** The `--sync` flag must be explicitly set for this package since there is no `async` support. + +```cmd +(env) ~/azure-monitor-opentelemetry-exporter/tests> perfstress MonitorExporterPerfTest --sync --num-spans=10 +``` diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/perfstress_tests/__init__.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/perfstress_tests/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/perfstress_tests/trace_exporter.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/perfstress_tests/trace_exporter.py new file mode 100644 index 000000000000..de90b25ee29d --- /dev/null +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/perfstress_tests/trace_exporter.py @@ -0,0 +1,47 @@ +#------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +#-------------------------------------------------------------------------- + +from azure_devtools.perfstress_tests import PerfStressTest + +from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter + +from opentelemetry import trace +from opentelemetry.sdk.trace import TracerProvider + +from azure.monitor.opentelemetry.exporter import AzureMonitorTraceExporter + +class MonitorExporterPerfTest(PerfStressTest): + def __init__(self, arguments): + super().__init__(arguments) + + # auth configuration + connection_string = self.get_from_env("APPLICATIONINSIGHTS_CONNECTION_STRING") + + # Create clients + self.exporter = AzureMonitorTraceExporter.from_connection_string(connection_string) + + trace.set_tracer_provider(TracerProvider()) + tracer = trace.get_tracer(__name__) + self.spans_list = [] + for _ in range(self.args.num_spans): + with tracer.start_as_current_span( + name="name" + ) as span: + self.spans_list.append(span) + + def run_sync(self): + """The synchronous perf test. + + Try to keep this minimal and focused. Using only a single client API. + Avoid putting any ancilliary logic (e.g. generating UUIDs), and put this in the setup/init instead + so that we're only measuring the client API call. + """ + self.exporter.export(self.spans_list) + + @staticmethod + def add_arguments(parser): + super(MonitorExporterPerfTest, MonitorExporterPerfTest).add_arguments(parser) + parser.add_argument('-n', '--num-spans', nargs='?', type=int, help='Number of spans to be exported. Defaults to 10', default=10)