From 71376a573087a53eb39f3136a171193c7e9541c4 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Fri, 20 Jan 2023 15:03:32 -0800 Subject: [PATCH 01/11] fix tox --- .github/workflows/test.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 251892f1..749aa797 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,12 +14,13 @@ jobs: py38: 3.8 py39: 3.9 py310: "3.10" + py311: "3.11" RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false # ensures the entire test matrix is run, even if one permutation fails matrix: - python-version: [ py37, py38, py39, py310 ] + python-version: [ py37, py38, py39, py310, py311 ] package: ["distro"] os: [ ubuntu-20.04, windows-2019 ] steps: @@ -40,6 +41,11 @@ jobs: .tox ~/.cache/pip key: v3-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'test-requirements.txt') }} + - name: Windows does not let git check out files with long names + if: ${{ matrix.os == 'windows-2019'}} + run: git config --system core.longpaths true + - name: run tox + run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} misc: strategy: fail-fast: false From 559376ec5e50623ba35e6e0550aa056cbdabc9d7 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Fri, 20 Jan 2023 15:43:58 -0800 Subject: [PATCH 02/11] PYTHON --- .github/workflows/test.yml | 6 +++--- tox.ini | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 749aa797..87c2fac8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,8 +42,8 @@ jobs: ~/.cache/pip key: v3-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'test-requirements.txt') }} - name: Windows does not let git check out files with long names - if: ${{ matrix.os == 'windows-2019'}} - run: git config --system core.longpaths true + if: ${{ matrix.os == 'windows-2019'}} + run: git config --system core.longpaths true - name: run tox run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} misc: @@ -59,7 +59,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: 3.11 architecture: 'x64' - name: Install tox run: pip install -U tox diff --git a/tox.ini b/tox.ini index 8e2f8937..91eae117 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ skipsdist = True skip_missing_interpreters = True envlist = - py3{6,7,8,9,10,11}-distro + py3{7,8,9,10,11}-distro lint [testenv] @@ -16,7 +16,7 @@ commands = pytest {posargs} [testenv:lint] -basepython: python3.9 +basepython: python3.11 recreate = True deps = -r lint-requirements.txt From 197380afe9804865294aa0547d7460d9ae3c8d81 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Fri, 20 Jan 2023 15:51:37 -0800 Subject: [PATCH 03/11] Update test.yml --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 87c2fac8..315556d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,7 @@ jobs: python-version: ${{ env[matrix.python-version] }} architecture: 'x64' - name: Install tox - run: pip install -U tox-factor + run: pip install tox==3.27.1 -U tox-factor - name: Cache tox environment # Preserves .tox directory between runs for faster installs uses: actions/cache@v2 From 52ab06318ddd6321d983e0a51a0c027a173609f9 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Fri, 20 Jan 2023 15:55:37 -0800 Subject: [PATCH 04/11] Update tox.ini --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 91eae117..5ac05bb2 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ deps = -r test-requirements.txt commands_pre = - python -m pip install -e {toxinidir}/azure-monitor-opentelemetry-distro + python -m pip install {toxinidir}/azure-monitor-opentelemetry-distro . commands = pytest {posargs} From f0dd355ea61f86ce13729ff9d3543e20eb59e319 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 23 Jan 2023 10:24:27 -0800 Subject: [PATCH 05/11] Update test_constants.py --- .../tests/test_constants.py | 298 +++++++++--------- 1 file changed, 149 insertions(+), 149 deletions(-) diff --git a/azure-monitor-opentelemetry-distro/tests/test_constants.py b/azure-monitor-opentelemetry-distro/tests/test_constants.py index d887435e..e4315411 100644 --- a/azure-monitor-opentelemetry-distro/tests/test_constants.py +++ b/azure-monitor-opentelemetry-distro/tests/test_constants.py @@ -1,149 +1,149 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License in the project root for -# license information. -# -------------------------------------------------------------------------- - -from importlib import reload -from os import environ -from unittest import TestCase -from unittest.mock import patch - -from azure.monitor.opentelemetry.distro import _constants - -TEST_VALUE = "TEST_VALUE" -TEST_IKEY = "1234abcd-ab12-34cd-ab12-a23456abcdef" -TEST_CONN_STR = f"InstrumentationKey={TEST_IKEY};IngestionEndpoint=https://centralus-2.in.applicationinsights.azure.com/;LiveEndpoint=https://centralus.livediagnostics.monitor.azure.com/" - - -def clear_env_var(env_var): - if env_var in environ: - del environ[env_var] - - -class TestConstants(TestCase): - @patch.dict( - "os.environ", - {"ApplicationInsightsAgent_EXTENSION_VERSION": TEST_VALUE}, - ) - def test_extension_version(self): - reload(_constants) - self.assertEqual(_constants._EXTENSION_VERSION, TEST_VALUE) - - def test_extension_version_default(self): - clear_env_var("ApplicationInsightsAgent_EXTENSION_VERSION") - reload(_constants) - self.assertEqual(_constants._EXTENSION_VERSION, "disabled") - - @patch.dict( - "os.environ", {"APPLICATIONINSIGHTS_CONNECTION_STRING": TEST_CONN_STR} - ) - def test_ikey(self): - reload(_constants) - self.assertEqual(_constants._CUSTOMER_IKEY, TEST_IKEY) - - def test_ikey_defaults(self): - clear_env_var("APPLICATIONINSIGHTS_CONNECTION_STRING") - reload(_constants) - self.assertEqual(_constants._CUSTOMER_IKEY, "unknown") - - # TODO: Enabled when duplciate logging issue is solved - # @patch.dict( - # "os.environ", - # {"AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS": "True"}, - # ) - # def test_exporter_diagnostics_enabled(self): - # reload(_constants) - # self.assertTrue(_constants._EXPORTER_DIAGNOSTICS_ENABLED) - - # def test_exporter_diagnostics_disabled(self): - # clear_env_var("AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS") - # reload(_constants) - # self.assertFalse(_constants._EXPORTER_DIAGNOSTICS_ENABLED) - - # @patch.dict( - # "os.environ", - # {"AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS": "foobar"}, - # ) - # def test_exporter_diagnostics_other(self): - # reload(_constants) - # self.assertFalse(_constants._EXPORTER_DIAGNOSTICS_ENABLED) - - @patch.dict("os.environ", {"WEBSITE_SITE_NAME": TEST_VALUE}) - def test_diagnostics_enabled(self): - reload(_constants) - self.assertTrue(_constants._IS_DIAGNOSTICS_ENABLED) - - def test_diagnostics_disabled(self): - clear_env_var("WEBSITE_SITE_NAME") - reload(_constants) - self.assertFalse(_constants._IS_DIAGNOSTICS_ENABLED) - - @patch( - "azure.monitor.opentelemetry.distro._constants.platform.system", - return_value="Linux", - ) - def test_log_path_linux(self, mock_system): - self.assertEqual( - _constants._get_log_path(), "/var/log/applicationinsights" - ) - - @patch( - "azure.monitor.opentelemetry.distro._constants.platform.system", - return_value="Linux", - ) - def test_status_log_path_linux(self, mock_system): - self.assertEqual( - _constants._get_log_path(status_log_path=True), - "/var/log/applicationinsights", - ) - - @patch( - "azure.monitor.opentelemetry.distro._constants.platform.system", - return_value="Windows", - ) - @patch("pathlib.Path.home", return_value="\\HOME\\DIR") - def test_log_path_windows(self, mock_system, mock_home): - self.assertEqual( - _constants._get_log_path(), - "\\HOME\\DIR\\LogFiles\\ApplicationInsights", - ) - - @patch( - "azure.monitor.opentelemetry.distro._constants.platform.system", - return_value="Windows", - ) - @patch("pathlib.Path.home", return_value="\\HOME\\DIR") - def test_status_log_path_windows(self, mock_system, mock_home): - self.assertEqual( - _constants._get_log_path(status_log_path=True), - "\\HOME\\DIR\\LogFiles\\ApplicationInsights\\status", - ) - - @patch( - "azure.monitor.opentelemetry.distro._constants.platform.system", - return_value="Window", - ) - def test_log_path_other(self, mock_platform): - self.assertIsNone(_constants._get_log_path()) - - @patch( - "azure.monitor.opentelemetry.distro._constants.platform.system", - return_value="linux", - ) - def test_status_log_path_other(self, mock_platform): - self.assertIsNone(_constants._get_log_path(status_log_path=True)) - - @patch.dict("os.environ", {"key": "value"}) - def test_env_var_or_default(self): - self.assertEqual(_constants._env_var_or_default("key"), "value") - - @patch.dict("os.environ", {}) - def test_env_var_or_default_empty(self): - self.assertEqual(_constants._env_var_or_default("key"), "") - - @patch.dict("os.environ", {}) - def test_env_var_or_default_empty_with_defaults(self): - self.assertEqual( - _constants._env_var_or_default("key", default_val="value"), "value" - ) +# # ------------------------------------------------------------------------- +# # Copyright (c) Microsoft Corporation. All rights reserved. +# # Licensed under the MIT License. See License in the project root for +# # license information. +# # -------------------------------------------------------------------------- + +# from importlib import reload +# from os import environ +# from unittest import TestCase +# from unittest.mock import patch + +# from azure.monitor.opentelemetry.distro import _constants + +# TEST_VALUE = "TEST_VALUE" +# TEST_IKEY = "1234abcd-ab12-34cd-ab12-a23456abcdef" +# TEST_CONN_STR = f"InstrumentationKey={TEST_IKEY};IngestionEndpoint=https://centralus-2.in.applicationinsights.azure.com/;LiveEndpoint=https://centralus.livediagnostics.monitor.azure.com/" + + +# def clear_env_var(env_var): +# if env_var in environ: +# del environ[env_var] + + +# class TestConstants(TestCase): +# @patch.dict( +# "os.environ", +# {"ApplicationInsightsAgent_EXTENSION_VERSION": TEST_VALUE}, +# ) +# def test_extension_version(self): +# reload(_constants) +# self.assertEqual(_constants._EXTENSION_VERSION, TEST_VALUE) + +# def test_extension_version_default(self): +# clear_env_var("ApplicationInsightsAgent_EXTENSION_VERSION") +# reload(_constants) +# self.assertEqual(_constants._EXTENSION_VERSION, "disabled") + +# @patch.dict( +# "os.environ", {"APPLICATIONINSIGHTS_CONNECTION_STRING": TEST_CONN_STR} +# ) +# def test_ikey(self): +# reload(_constants) +# self.assertEqual(_constants._CUSTOMER_IKEY, TEST_IKEY) + +# def test_ikey_defaults(self): +# clear_env_var("APPLICATIONINSIGHTS_CONNECTION_STRING") +# reload(_constants) +# self.assertEqual(_constants._CUSTOMER_IKEY, "unknown") + +# # TODO: Enabled when duplciate logging issue is solved +# # @patch.dict( +# # "os.environ", +# # {"AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS": "True"}, +# # ) +# # def test_exporter_diagnostics_enabled(self): +# # reload(_constants) +# # self.assertTrue(_constants._EXPORTER_DIAGNOSTICS_ENABLED) + +# # def test_exporter_diagnostics_disabled(self): +# # clear_env_var("AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS") +# # reload(_constants) +# # self.assertFalse(_constants._EXPORTER_DIAGNOSTICS_ENABLED) + +# # @patch.dict( +# # "os.environ", +# # {"AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS": "foobar"}, +# # ) +# # def test_exporter_diagnostics_other(self): +# # reload(_constants) +# # self.assertFalse(_constants._EXPORTER_DIAGNOSTICS_ENABLED) + +# @patch.dict("os.environ", {"WEBSITE_SITE_NAME": TEST_VALUE}) +# def test_diagnostics_enabled(self): +# reload(_constants) +# self.assertTrue(_constants._IS_DIAGNOSTICS_ENABLED) + +# def test_diagnostics_disabled(self): +# clear_env_var("WEBSITE_SITE_NAME") +# reload(_constants) +# self.assertFalse(_constants._IS_DIAGNOSTICS_ENABLED) + +# @patch( +# "azure.monitor.opentelemetry.distro._constants.platform.system", +# return_value="Linux", +# ) +# def test_log_path_linux(self, mock_system): +# self.assertEqual( +# _constants._get_log_path(), "/var/log/applicationinsights" +# ) + +# @patch( +# "azure.monitor.opentelemetry.distro._constants.platform.system", +# return_value="Linux", +# ) +# def test_status_log_path_linux(self, mock_system): +# self.assertEqual( +# _constants._get_log_path(status_log_path=True), +# "/var/log/applicationinsights", +# ) + +# @patch( +# "azure.monitor.opentelemetry.distro._constants.platform.system", +# return_value="Windows", +# ) +# @patch("pathlib.Path.home", return_value="\\HOME\\DIR") +# def test_log_path_windows(self, mock_system, mock_home): +# self.assertEqual( +# _constants._get_log_path(), +# "\\HOME\\DIR\\LogFiles\\ApplicationInsights", +# ) + +# @patch( +# "azure.monitor.opentelemetry.distro._constants.platform.system", +# return_value="Windows", +# ) +# @patch("pathlib.Path.home", return_value="\\HOME\\DIR") +# def test_status_log_path_windows(self, mock_system, mock_home): +# self.assertEqual( +# _constants._get_log_path(status_log_path=True), +# "\\HOME\\DIR\\LogFiles\\ApplicationInsights\\status", +# ) + +# @patch( +# "azure.monitor.opentelemetry.distro._constants.platform.system", +# return_value="Window", +# ) +# def test_log_path_other(self, mock_platform): +# self.assertIsNone(_constants._get_log_path()) + +# @patch( +# "azure.monitor.opentelemetry.distro._constants.platform.system", +# return_value="linux", +# ) +# def test_status_log_path_other(self, mock_platform): +# self.assertIsNone(_constants._get_log_path(status_log_path=True)) + +# @patch.dict("os.environ", {"key": "value"}) +# def test_env_var_or_default(self): +# self.assertEqual(_constants._env_var_or_default("key"), "value") + +# @patch.dict("os.environ", {}) +# def test_env_var_or_default_empty(self): +# self.assertEqual(_constants._env_var_or_default("key"), "") + +# @patch.dict("os.environ", {}) +# def test_env_var_or_default_empty_with_defaults(self): +# self.assertEqual( +# _constants._env_var_or_default("key", default_val="value"), "value" +# ) From b4cc1cf7a711526157068455c0008788b5f1c697 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 23 Jan 2023 10:26:22 -0800 Subject: [PATCH 06/11] tox --- .../tests/test_constants.py | 298 +++++++++--------- tox.ini | 2 +- 2 files changed, 150 insertions(+), 150 deletions(-) diff --git a/azure-monitor-opentelemetry-distro/tests/test_constants.py b/azure-monitor-opentelemetry-distro/tests/test_constants.py index e4315411..d887435e 100644 --- a/azure-monitor-opentelemetry-distro/tests/test_constants.py +++ b/azure-monitor-opentelemetry-distro/tests/test_constants.py @@ -1,149 +1,149 @@ -# # ------------------------------------------------------------------------- -# # Copyright (c) Microsoft Corporation. All rights reserved. -# # Licensed under the MIT License. See License in the project root for -# # license information. -# # -------------------------------------------------------------------------- - -# from importlib import reload -# from os import environ -# from unittest import TestCase -# from unittest.mock import patch - -# from azure.monitor.opentelemetry.distro import _constants - -# TEST_VALUE = "TEST_VALUE" -# TEST_IKEY = "1234abcd-ab12-34cd-ab12-a23456abcdef" -# TEST_CONN_STR = f"InstrumentationKey={TEST_IKEY};IngestionEndpoint=https://centralus-2.in.applicationinsights.azure.com/;LiveEndpoint=https://centralus.livediagnostics.monitor.azure.com/" - - -# def clear_env_var(env_var): -# if env_var in environ: -# del environ[env_var] - - -# class TestConstants(TestCase): -# @patch.dict( -# "os.environ", -# {"ApplicationInsightsAgent_EXTENSION_VERSION": TEST_VALUE}, -# ) -# def test_extension_version(self): -# reload(_constants) -# self.assertEqual(_constants._EXTENSION_VERSION, TEST_VALUE) - -# def test_extension_version_default(self): -# clear_env_var("ApplicationInsightsAgent_EXTENSION_VERSION") -# reload(_constants) -# self.assertEqual(_constants._EXTENSION_VERSION, "disabled") - -# @patch.dict( -# "os.environ", {"APPLICATIONINSIGHTS_CONNECTION_STRING": TEST_CONN_STR} -# ) -# def test_ikey(self): -# reload(_constants) -# self.assertEqual(_constants._CUSTOMER_IKEY, TEST_IKEY) - -# def test_ikey_defaults(self): -# clear_env_var("APPLICATIONINSIGHTS_CONNECTION_STRING") -# reload(_constants) -# self.assertEqual(_constants._CUSTOMER_IKEY, "unknown") - -# # TODO: Enabled when duplciate logging issue is solved -# # @patch.dict( -# # "os.environ", -# # {"AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS": "True"}, -# # ) -# # def test_exporter_diagnostics_enabled(self): -# # reload(_constants) -# # self.assertTrue(_constants._EXPORTER_DIAGNOSTICS_ENABLED) - -# # def test_exporter_diagnostics_disabled(self): -# # clear_env_var("AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS") -# # reload(_constants) -# # self.assertFalse(_constants._EXPORTER_DIAGNOSTICS_ENABLED) - -# # @patch.dict( -# # "os.environ", -# # {"AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS": "foobar"}, -# # ) -# # def test_exporter_diagnostics_other(self): -# # reload(_constants) -# # self.assertFalse(_constants._EXPORTER_DIAGNOSTICS_ENABLED) - -# @patch.dict("os.environ", {"WEBSITE_SITE_NAME": TEST_VALUE}) -# def test_diagnostics_enabled(self): -# reload(_constants) -# self.assertTrue(_constants._IS_DIAGNOSTICS_ENABLED) - -# def test_diagnostics_disabled(self): -# clear_env_var("WEBSITE_SITE_NAME") -# reload(_constants) -# self.assertFalse(_constants._IS_DIAGNOSTICS_ENABLED) - -# @patch( -# "azure.monitor.opentelemetry.distro._constants.platform.system", -# return_value="Linux", -# ) -# def test_log_path_linux(self, mock_system): -# self.assertEqual( -# _constants._get_log_path(), "/var/log/applicationinsights" -# ) - -# @patch( -# "azure.monitor.opentelemetry.distro._constants.platform.system", -# return_value="Linux", -# ) -# def test_status_log_path_linux(self, mock_system): -# self.assertEqual( -# _constants._get_log_path(status_log_path=True), -# "/var/log/applicationinsights", -# ) - -# @patch( -# "azure.monitor.opentelemetry.distro._constants.platform.system", -# return_value="Windows", -# ) -# @patch("pathlib.Path.home", return_value="\\HOME\\DIR") -# def test_log_path_windows(self, mock_system, mock_home): -# self.assertEqual( -# _constants._get_log_path(), -# "\\HOME\\DIR\\LogFiles\\ApplicationInsights", -# ) - -# @patch( -# "azure.monitor.opentelemetry.distro._constants.platform.system", -# return_value="Windows", -# ) -# @patch("pathlib.Path.home", return_value="\\HOME\\DIR") -# def test_status_log_path_windows(self, mock_system, mock_home): -# self.assertEqual( -# _constants._get_log_path(status_log_path=True), -# "\\HOME\\DIR\\LogFiles\\ApplicationInsights\\status", -# ) - -# @patch( -# "azure.monitor.opentelemetry.distro._constants.platform.system", -# return_value="Window", -# ) -# def test_log_path_other(self, mock_platform): -# self.assertIsNone(_constants._get_log_path()) - -# @patch( -# "azure.monitor.opentelemetry.distro._constants.platform.system", -# return_value="linux", -# ) -# def test_status_log_path_other(self, mock_platform): -# self.assertIsNone(_constants._get_log_path(status_log_path=True)) - -# @patch.dict("os.environ", {"key": "value"}) -# def test_env_var_or_default(self): -# self.assertEqual(_constants._env_var_or_default("key"), "value") - -# @patch.dict("os.environ", {}) -# def test_env_var_or_default_empty(self): -# self.assertEqual(_constants._env_var_or_default("key"), "") - -# @patch.dict("os.environ", {}) -# def test_env_var_or_default_empty_with_defaults(self): -# self.assertEqual( -# _constants._env_var_or_default("key", default_val="value"), "value" -# ) +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License in the project root for +# license information. +# -------------------------------------------------------------------------- + +from importlib import reload +from os import environ +from unittest import TestCase +from unittest.mock import patch + +from azure.monitor.opentelemetry.distro import _constants + +TEST_VALUE = "TEST_VALUE" +TEST_IKEY = "1234abcd-ab12-34cd-ab12-a23456abcdef" +TEST_CONN_STR = f"InstrumentationKey={TEST_IKEY};IngestionEndpoint=https://centralus-2.in.applicationinsights.azure.com/;LiveEndpoint=https://centralus.livediagnostics.monitor.azure.com/" + + +def clear_env_var(env_var): + if env_var in environ: + del environ[env_var] + + +class TestConstants(TestCase): + @patch.dict( + "os.environ", + {"ApplicationInsightsAgent_EXTENSION_VERSION": TEST_VALUE}, + ) + def test_extension_version(self): + reload(_constants) + self.assertEqual(_constants._EXTENSION_VERSION, TEST_VALUE) + + def test_extension_version_default(self): + clear_env_var("ApplicationInsightsAgent_EXTENSION_VERSION") + reload(_constants) + self.assertEqual(_constants._EXTENSION_VERSION, "disabled") + + @patch.dict( + "os.environ", {"APPLICATIONINSIGHTS_CONNECTION_STRING": TEST_CONN_STR} + ) + def test_ikey(self): + reload(_constants) + self.assertEqual(_constants._CUSTOMER_IKEY, TEST_IKEY) + + def test_ikey_defaults(self): + clear_env_var("APPLICATIONINSIGHTS_CONNECTION_STRING") + reload(_constants) + self.assertEqual(_constants._CUSTOMER_IKEY, "unknown") + + # TODO: Enabled when duplciate logging issue is solved + # @patch.dict( + # "os.environ", + # {"AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS": "True"}, + # ) + # def test_exporter_diagnostics_enabled(self): + # reload(_constants) + # self.assertTrue(_constants._EXPORTER_DIAGNOSTICS_ENABLED) + + # def test_exporter_diagnostics_disabled(self): + # clear_env_var("AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS") + # reload(_constants) + # self.assertFalse(_constants._EXPORTER_DIAGNOSTICS_ENABLED) + + # @patch.dict( + # "os.environ", + # {"AZURE_MONITOR_OPENTELEMETRY_DISTRO_ENABLE_EXPORTER_DIAGNOSTICS": "foobar"}, + # ) + # def test_exporter_diagnostics_other(self): + # reload(_constants) + # self.assertFalse(_constants._EXPORTER_DIAGNOSTICS_ENABLED) + + @patch.dict("os.environ", {"WEBSITE_SITE_NAME": TEST_VALUE}) + def test_diagnostics_enabled(self): + reload(_constants) + self.assertTrue(_constants._IS_DIAGNOSTICS_ENABLED) + + def test_diagnostics_disabled(self): + clear_env_var("WEBSITE_SITE_NAME") + reload(_constants) + self.assertFalse(_constants._IS_DIAGNOSTICS_ENABLED) + + @patch( + "azure.monitor.opentelemetry.distro._constants.platform.system", + return_value="Linux", + ) + def test_log_path_linux(self, mock_system): + self.assertEqual( + _constants._get_log_path(), "/var/log/applicationinsights" + ) + + @patch( + "azure.monitor.opentelemetry.distro._constants.platform.system", + return_value="Linux", + ) + def test_status_log_path_linux(self, mock_system): + self.assertEqual( + _constants._get_log_path(status_log_path=True), + "/var/log/applicationinsights", + ) + + @patch( + "azure.monitor.opentelemetry.distro._constants.platform.system", + return_value="Windows", + ) + @patch("pathlib.Path.home", return_value="\\HOME\\DIR") + def test_log_path_windows(self, mock_system, mock_home): + self.assertEqual( + _constants._get_log_path(), + "\\HOME\\DIR\\LogFiles\\ApplicationInsights", + ) + + @patch( + "azure.monitor.opentelemetry.distro._constants.platform.system", + return_value="Windows", + ) + @patch("pathlib.Path.home", return_value="\\HOME\\DIR") + def test_status_log_path_windows(self, mock_system, mock_home): + self.assertEqual( + _constants._get_log_path(status_log_path=True), + "\\HOME\\DIR\\LogFiles\\ApplicationInsights\\status", + ) + + @patch( + "azure.monitor.opentelemetry.distro._constants.platform.system", + return_value="Window", + ) + def test_log_path_other(self, mock_platform): + self.assertIsNone(_constants._get_log_path()) + + @patch( + "azure.monitor.opentelemetry.distro._constants.platform.system", + return_value="linux", + ) + def test_status_log_path_other(self, mock_platform): + self.assertIsNone(_constants._get_log_path(status_log_path=True)) + + @patch.dict("os.environ", {"key": "value"}) + def test_env_var_or_default(self): + self.assertEqual(_constants._env_var_or_default("key"), "value") + + @patch.dict("os.environ", {}) + def test_env_var_or_default_empty(self): + self.assertEqual(_constants._env_var_or_default("key"), "") + + @patch.dict("os.environ", {}) + def test_env_var_or_default_empty_with_defaults(self): + self.assertEqual( + _constants._env_var_or_default("key", default_val="value"), "value" + ) diff --git a/tox.ini b/tox.ini index 5ac05bb2..0af0bd12 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ deps = -r test-requirements.txt commands_pre = - python -m pip install {toxinidir}/azure-monitor-opentelemetry-distro . + python -m pip install {toxinidir}/azure-monitor-opentelemetry-distro commands = pytest {posargs} From b7283554f6591674aec79e11415ac12ac59e56cf Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 23 Jan 2023 10:33:44 -0800 Subject: [PATCH 07/11] Update _version.py --- .../azure/monitor/opentelemetry/distro/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_version.py b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_version.py index 24ef9d09..48f54e3b 100644 --- a/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_version.py +++ b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_version.py @@ -4,4 +4,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "1.0.0b8" +VERSION = "1.0.0b8.dev0" From 603684c3eae9c6b71f56f4d2d235662a873dab6d Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 23 Jan 2023 10:35:59 -0800 Subject: [PATCH 08/11] Update tox.ini --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 0af0bd12..5ac05bb2 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ deps = -r test-requirements.txt commands_pre = - python -m pip install {toxinidir}/azure-monitor-opentelemetry-distro + python -m pip install {toxinidir}/azure-monitor-opentelemetry-distro . commands = pytest {posargs} From 43ac724e1c18fa0c627fe84d9e551547a7814777 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 23 Jan 2023 10:39:58 -0800 Subject: [PATCH 09/11] Update tox.ini --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 5ac05bb2..91eae117 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ deps = -r test-requirements.txt commands_pre = - python -m pip install {toxinidir}/azure-monitor-opentelemetry-distro . + python -m pip install -e {toxinidir}/azure-monitor-opentelemetry-distro commands = pytest {posargs} From ac2b82b07b399c3ae268f08137b735603c67210f Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 23 Jan 2023 10:49:17 -0800 Subject: [PATCH 10/11] tox --- test-requirements.txt | 1 + tox.ini | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/test-requirements.txt b/test-requirements.txt index 9d908300..a6c7e573 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,5 @@ pytest psycopg2 flask +django requests \ No newline at end of file diff --git a/tox.ini b/tox.ini index 91eae117..0aad9c15 100644 --- a/tox.ini +++ b/tox.ini @@ -9,11 +9,15 @@ envlist = deps = -r test-requirements.txt +changedir = + distro: azure-monitor-opentelemetry-distro/tests + commands_pre = - python -m pip install -e {toxinidir}/azure-monitor-opentelemetry-distro + py3{7,8,9,10,11}: python -m pip install -U pip setuptools wheel + distro: pip install {toxinidir}/azure-monitor-opentelemetry-distro commands = - pytest {posargs} + distro: pytest {posargs} [testenv:lint] basepython: python3.11 From ccdb194f598a7eff166b6293498d83fb639c9c07 Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Mon, 23 Jan 2023 10:55:11 -0800 Subject: [PATCH 11/11] Update _version.py --- .../azure/monitor/opentelemetry/distro/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_version.py b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_version.py index 48f54e3b..24ef9d09 100644 --- a/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_version.py +++ b/azure-monitor-opentelemetry-distro/azure/monitor/opentelemetry/distro/_version.py @@ -4,4 +4,4 @@ # license information. # -------------------------------------------------------------------------- -VERSION = "1.0.0b8.dev0" +VERSION = "1.0.0b8"