Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit c2d4629
Author: Timothy Pansino <[email protected]>
Date:   Wed May 10 15:59:13 2023 -0700

    Add required option for tox v4 (#795)

    * Add required option for tox v4

    * Update tox in GHA

    * Remove py27 no-cache-dir

commit a963649
Author: Hannah Stepanek <[email protected]>
Date:   Tue May 9 10:46:39 2023 -0700

    Run coverage around pytest (#813)

    * Run coverage around pytest

    * Trigger tests

    * Fixup

    * Add redis client_no_touch to ignore list

    * Temporarily remove kafka from coverage

    * Remove coverage for old libs

commit 3d82845
Author: Lalleh Rafeei <[email protected]>
Date:   Wed May 3 14:50:30 2023 -0700

    Omit some frameworks from coverage analysis (#810)

    * Omit some frameworks from coverage analysis

    * Remove commas

    * Change format of omit

    * Add relative_files option to coverage

    * Add absolute directory

    * Add envsitepackagedir

    * Add coveragerc file

    * Add codecov.yml

    * [Mega-Linter] Apply linters fixes

    * Revert coveragerc file settings

    * Add files in packages and more frameworks

    * Remove commented line

    ---------

    Co-authored-by: lrafeei <[email protected]>
    Co-authored-by: Hannah Stepanek <[email protected]>

commit fd0fa35
Author: Uma Annamalai <[email protected]>
Date:   Tue May 2 10:55:36 2023 -0700

    Add testing for genshi and mako. (#799)

    * Add testing for genshi and mako.

    * [Mega-Linter] Apply linters fixes

    ---------

    Co-authored-by: umaannamalai <[email protected]>
    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit be4fb3d
Author: Lalleh Rafeei <[email protected]>
Date:   Mon May 1 16:01:09 2023 -0700

    Add tests for Waitress (#797)

    * Change import format

    * Initial commit

    * Add more tests to adapter_waitress

    * Remove commented out code

    * [Mega-Linter] Apply linters fixes

    * Add assertions to all tests

    * Add more NR testing to waitress

    ---------

    Co-authored-by: lrafeei <[email protected]>
    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit 7103506
Author: Hannah Stepanek <[email protected]>
Date:   Mon May 1 14:12:31 2023 -0700

    Add tests for pyodbc (#796)

    * Add tests for pyodbc

    * Move imports into tests to get import coverage

    * Fixup: remove time import

    * Trigger tests

    ---------

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit 363122a
Author: Hannah Stepanek <[email protected]>
Date:   Mon May 1 13:34:35 2023 -0700

    Pin virtualenv, fix pip arg deprecation & disable kafka tests (#803)

    * Pin virtualenv

    * Fixup: use 20.21.1 instead

    * Replace install-options with config-settings

    See pypa/pip#11358.

    * Temporarily disable kafka tests
  • Loading branch information
TimPansino committed May 10, 2023
1 parent dc81a50 commit 5e1cc9d
Show file tree
Hide file tree
Showing 17 changed files with 588 additions and 266 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-python-matrix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ runs:
shell: bash
run: |
python3.10 -m pip install -U pip
python3.10 -m pip install -U wheel setuptools 'tox<4' virtualenv!=20.0.24
python3.10 -m pip install -U wheel setuptools tox 'virtualenv<20.22.0'
152 changes: 80 additions & 72 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- elasticsearchserver08
- gearman
- grpc
- kafka
#- kafka
- libcurl
- memcached
- mongodb
Expand Down Expand Up @@ -255,6 +255,14 @@ jobs:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-python-matrix

- name: Install odbc driver for postgresql
run: |
sudo apt-get update
sudo sudo apt-get install odbc-postgresql
sudo sed -i 's/Driver=psqlodbca.so/Driver=\/usr\/lib\/x86_64-linux-gnu\/odbc\/psqlodbca.so/g' /etc/odbcinst.ini
sudo sed -i 's/Driver=psqlodbcw.so/Driver=\/usr\/lib\/x86_64-linux-gnu\/odbc\/psqlodbcw.so/g' /etc/odbcinst.ini
sudo sed -i 's/Setup=libodbcpsqlS.so/Setup=\/usr\/lib\/x86_64-linux-gnu\/odbc\/libodbcpsqlS.so/g' /etc/odbcinst.ini
- name: Get Environments
id: get-envs
run: |
Expand Down Expand Up @@ -534,77 +542,77 @@ jobs:
path: ./**/.coverage.*
retention-days: 1

kafka:
env:
TOTAL_GROUPS: 4

strategy:
fail-fast: false
matrix:
group-number: [1, 2, 3, 4]

runs-on: ubuntu-20.04
timeout-minutes: 30

services:
zookeeper:
image: bitnami/zookeeper:3.7
env:
ALLOW_ANONYMOUS_LOGIN: yes

ports:
- 2181:2181

kafka:
image: bitnami/kafka:3.2
ports:
- 8080:8080
- 8081:8081
env:
ALLOW_PLAINTEXT_LISTENER: yes
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true
KAFKA_CFG_LISTENERS: L1://:8080,L2://:8081
KAFKA_CFG_ADVERTISED_LISTENERS: L1://127.0.0.1:8080,L2://kafka:8081,
KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: L1:PLAINTEXT,L2:PLAINTEXT
KAFKA_CFG_INTER_BROKER_LISTENER_NAME: L2

steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-python-matrix

# Special case packages
- name: Install librdkafka-dev
run: |
# Use lsb-release to find the codename of Ubuntu to use to install the correct library name
sudo apt-get update
sudo ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
sudo apt-get install -y wget gnupg2 software-properties-common
sudo wget -qO - https://packages.confluent.io/deb/7.2/archive.key | sudo apt-key add -
sudo add-apt-repository "deb https://packages.confluent.io/clients/deb $(lsb_release -cs) main"
sudo apt-get update
sudo apt-get install -y librdkafka-dev/$(lsb_release -c | cut -f 2)
- name: Get Environments
id: get-envs
run: |
echo "::set-output name=envs::$(tox -l | grep "^${{ github.job }}\-" | ./.github/workflows/get-envs.py)"
env:
GROUP_NUMBER: ${{ matrix.group-number }}

- name: Test
run: |
tox -vv -e ${{ steps.get-envs.outputs.envs }}
env:
TOX_PARALLEL_NO_SPINNER: 1
PY_COLORS: 0

- name: Upload Coverage Artifacts
uses: actions/upload-artifact@v3
with:
name: coverage-${{ github.job }}-${{ strategy.job-index }}
path: ./**/.coverage.*
retention-days: 1
#kafka:
# env:
# TOTAL_GROUPS: 4

# strategy:
# fail-fast: false
# matrix:
# group-number: [1, 2, 3, 4]

# runs-on: ubuntu-20.04
# timeout-minutes: 30

# services:
# zookeeper:
# image: bitnami/zookeeper:3.7
# env:
# ALLOW_ANONYMOUS_LOGIN: yes

# ports:
# - 2181:2181

# kafka:
# image: bitnami/kafka:3.2
# ports:
# - 8080:8080
# - 8081:8081
# env:
# ALLOW_PLAINTEXT_LISTENER: yes
# KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
# KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE: true
# KAFKA_CFG_LISTENERS: L1://:8080,L2://:8081
# KAFKA_CFG_ADVERTISED_LISTENERS: L1://127.0.0.1:8080,L2://kafka:8081,
# KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: L1:PLAINTEXT,L2:PLAINTEXT
# KAFKA_CFG_INTER_BROKER_LISTENER_NAME: L2

# steps:
# - uses: actions/checkout@v3
# - uses: ./.github/actions/setup-python-matrix

# # Special case packages
# - name: Install librdkafka-dev
# run: |
# # Use lsb-release to find the codename of Ubuntu to use to install the correct library name
# sudo apt-get update
# sudo ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
# sudo apt-get install -y wget gnupg2 software-properties-common
# sudo wget -qO - https://packages.confluent.io/deb/7.2/archive.key | sudo apt-key add -
# sudo add-apt-repository "deb https://packages.confluent.io/clients/deb $(lsb_release -cs) main"
# sudo apt-get update
# sudo apt-get install -y librdkafka-dev/$(lsb_release -c | cut -f 2)

# - name: Get Environments
# id: get-envs
# run: |
# echo "::set-output name=envs::$(tox -l | grep "^${{ github.job }}\-" | ./.github/workflows/get-envs.py)"
# env:
# GROUP_NUMBER: ${{ matrix.group-number }}

# - name: Test
# run: |
# tox -vv -e ${{ steps.get-envs.outputs.envs }}
# env:
# TOX_PARALLEL_NO_SPINNER: 1
# PY_COLORS: 0

# - name: Upload Coverage Artifacts
# uses: actions/upload-artifact@v3
# with:
# name: coverage-${{ github.job }}-${{ strategy.job-index }}
# path: ./**/.coverage.*
# retention-days: 1

mongodb:
env:
Expand Down
21 changes: 21 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ignore:
- "newrelic/packages/**/*"
- "newrelic/packages/*"
- "newrelic/hooks/adapter_meinheld.py"
- "newrelic/hooks/adapter_flup.py"
- "newrelic/hooks/component_piston.py"
- "newrelic/hooks/datastore_pyelasticsearch.py"
- "newrelic/hooks/external_pywapi.py"
- "newrelic/hooks/external_dropbox.py"
- "newrelic/hooks/external_facepy.py"
- "newrelic/hooks/external_xmlrpclib.py"
- "newrelic/hooks/framework_pylons.py"
- "newrelic/hooks/framework_web2py.py"
- "newrelic/hooks/middleware_weberror.py"
- "newrelic/hooks/framework_webpy.py"
- "newrelic/hooks/database_oursql.py"
- "newrelic/hooks/database_psycopg2ct.py"
- "newrelic/hooks/datastore_umemcache.py"
# Temporarily disable kafka
- "newrelic/hooks/messagebroker_kafkapython.py"
- "newrelic/hooks/messagebroker_confluentkafka.py"
17 changes: 8 additions & 9 deletions newrelic/hooks/adapter_waitress.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import newrelic.api.wsgi_application
import newrelic.api.in_function
from newrelic.api.in_function import wrap_in_function
from newrelic.api.wsgi_application import WSGIApplicationWrapper
from newrelic.common.package_version_utils import get_package_version

def instrument_waitress_server(module):

def wrap_wsgi_application_entry_point(server, application,
*args, **kwargs):
application = newrelic.api.wsgi_application.WSGIApplicationWrapper(
application)
def instrument_waitress_server(module):
def wrap_wsgi_application_entry_point(server, application, *args, **kwargs):
dispatcher_details = ("Waitress", get_package_version("waitress"))
application = WSGIApplicationWrapper(application, dispatcher=dispatcher_details)
args = [server, application] + list(args)
return (args, kwargs)

newrelic.api.in_function.wrap_in_function(module,
'WSGIServer.__init__', wrap_wsgi_application_entry_point)
wrap_in_function(module, "WSGIServer.__init__", wrap_wsgi_application_entry_point)
54 changes: 54 additions & 0 deletions tests/adapter_waitress/_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from threading import Thread
from time import sleep

from testing_support.sample_applications import (
raise_exception_application,
raise_exception_finalize,
raise_exception_response,
simple_app_raw,
)
from testing_support.util import get_open_port


def sample_application(environ, start_response):
path_info = environ.get("PATH_INFO")

if path_info.startswith("/raise-exception-application"):
return raise_exception_application(environ, start_response)
elif path_info.startswith("/raise-exception-response"):
return raise_exception_response(environ, start_response)
elif path_info.startswith("/raise-exception-finalize"):
return raise_exception_finalize(environ, start_response)

return simple_app_raw(environ, start_response)


def setup_application():
port = get_open_port()

def run_wsgi():
from waitress import serve

serve(sample_application, host="127.0.0.1", port=port)

wsgi_thread = Thread(target=run_wsgi)
wsgi_thread.daemon = True
wsgi_thread.start()

sleep(1)

return port
40 changes: 40 additions & 0 deletions tests/adapter_waitress/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2010 New Relic, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest
import webtest
from testing_support.fixtures import ( # noqa: F401; pylint: disable=W0611
collector_agent_registration_fixture,
collector_available_fixture,
)

_default_settings = {
"transaction_tracer.explain_threshold": 0.0,
"transaction_tracer.transaction_threshold": 0.0,
"transaction_tracer.stack_trace_threshold": 0.0,
"debug.log_data_collector_payloads": True,
"debug.record_transaction_failure": True,
}

collector_agent_registration = collector_agent_registration_fixture(
app_name="Python Agent Test (Waitress)", default_settings=_default_settings
)


@pytest.fixture(autouse=True, scope="session")
def target_application():
import _application

port = _application.setup_application()
return webtest.TestApp("http://localhost:%d" % port)
Loading

0 comments on commit 5e1cc9d

Please sign in to comment.