Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main into mlops #912

Merged
merged 35 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
db07523
Exclude command line functionality from test coverage (#855)
lrafeei Jun 27, 2023
c2fd5e3
FIX: resilient environment settings (#825)
aaeabdo Jun 27, 2023
9883c2b
Replace drop_transaction logic by using transaction context manager (…
lrafeei Jun 28, 2023
998b035
Upgrade to Pypy38 for TypedDict (#861)
lrafeei Jun 30, 2023
66c2e19
Add profile_trace testing (#858)
umaannamalai Jun 30, 2023
e663c36
Add Transaction API Tests (#857)
lrafeei Jun 30, 2023
3bdb013
Add tests for jinja2. (#842)
umaannamalai Jun 30, 2023
6644846
Add tests for newrelic/config.py (#860)
hmstepanek Jun 30, 2023
ee92363
Fix starlette testing matrix for updated behavior. (#869)
TimPansino Jul 14, 2023
53fc51a
Correct Serverless Distributed Tracing Logic (#870)
TimPansino Jul 14, 2023
2f580af
Fix Kafka CI (#863)
TimPansino Jul 14, 2023
a7080e9
Change image tag to latest (#871)
hmstepanek Jul 17, 2023
56ea815
Add full version for pypy3.8 to tox (#872)
lrafeei Jul 18, 2023
a248688
Instrument RedisCluster (#809)
hmstepanek Jul 27, 2023
08eec5e
Ignore Django instrumentation from older versions (#859)
lrafeei Jul 28, 2023
4b3768b
Modify postgresql tests to include WITH query (#885)
lrafeei Aug 2, 2023
17f8937
Develop redis addons (#888)
lrafeei Aug 10, 2023
8ebe9a3
Add google firestore instrumentation (#893)
umaannamalai Aug 10, 2023
238b64d
Base Devcontainer on CI Image (#873)
TimPansino Aug 10, 2023
dc87bd3
Add support for redis v5. (#895)
umaannamalai Aug 15, 2023
7d76243
Use importlib.metadata first to avoid deprecation warnings (#878)
renanivo Aug 16, 2023
f1a673e
Fix Normalization Rules (#894)
TimPansino Aug 16, 2023
6a6228f
Fix database instance metric bug (#905)
hmstepanek Aug 18, 2023
62abb45
Add check for both path and file (#907)
hmstepanek Aug 21, 2023
399c81f
Update structlog instrumentation. (#865)
umaannamalai Aug 23, 2023
94d74f8
Merge main into MLops dev branch
lrafeei Aug 25, 2023
7b7abe0
Merge branch 'develop-scikitlearn' into merge-main-into-mlops
lrafeei Aug 26, 2023
3988ecc
GraphQL Async Instrumentation Support (#908)
umaannamalai Aug 28, 2023
0baf8d5
Develop swap redis asyncio commits (#913)
lrafeei Aug 28, 2023
faaccd0
Increase days until stale. (#909)
umaannamalai Aug 28, 2023
b1be563
Pin anyio version to below 4.0.0 (#916)
lrafeei Sep 1, 2023
dbe3856
Merge branch 'develop-scikitlearn' into merge-main-into-mlops
lrafeei Sep 12, 2023
e371b02
Add redis.asyncio.Connection instrumentation (#919)
lrafeei Sep 12, 2023
6814571
Merge branch 'main' into merge-main-into-mlops
lrafeei Sep 12, 2023
0180c65
Merge branch 'develop-scikitlearn' into merge-main-into-mlops
TimPansino Sep 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
ARG IMAGE=ghcr.io/newrelic-experimental/pyenv-devcontainer:latest

# To target other architectures, change the --platform directive in the Dockerfile.
FROM --platform=linux/amd64 ${IMAGE}
ARG IMAGE_TAG=latest
FROM ghcr.io/newrelic/newrelic-python-agent-ci:${IMAGE_TAG}

# Setup non-root user
USER root
ARG UID=1000
ARG GID=$UID
ENV HOME /home/vscode
RUN mkdir -p ${HOME} && \
groupadd --gid ${GID} vscode && \
useradd --uid ${UID} --gid ${GID} --home ${HOME} vscode && \
chown -R ${UID}:${GID} /home/vscode
USER ${UID}:${GID}
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// To target other architectures, change the --platform directive in the Dockerfile.
"dockerfile": "Dockerfile",
"args": {
"IMAGE": "ghcr.io/newrelic-experimental/pyenv-devcontainer:latest"
"IMAGE_TAG": "latest"
}
},
"remoteUser": "vscode",
Expand Down
13 changes: 11 additions & 2 deletions .github/containers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
build-essential \
curl \
expat \
fish \
fontconfig \
freetds-common \
freetds-dev \
gcc \
Expand All @@ -46,13 +48,16 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
python2-dev \
python3-dev \
python3-pip \
sudo \
tzdata \
unixodbc-dev \
unzip \
vim \
wget \
zip \
zlib1g \
zlib1g-dev && \
zlib1g-dev \
zsh && \
rm -rf /var/lib/apt/lists/*

# Build librdkafka from source
Expand Down Expand Up @@ -93,6 +98,10 @@ RUN echo 'eval "$(pyenv init -)"' >>$HOME/.bashrc && \
# Install Python
ARG PYTHON_VERSIONS="3.10 3.9 3.8 3.7 3.11 2.7 pypy2.7-7.3.12 pypy3.8-7.3.11"
COPY --chown=1000:1000 --chmod=+x ./install-python.sh /tmp/install-python.sh
COPY ./requirements.txt /requirements.txt
RUN /tmp/install-python.sh && \
rm /tmp/install-python.sh

# Install dependencies for main python installation
COPY ./requirements.txt /tmp/requirements.txt
RUN pyenv exec pip install --upgrade -r /tmp/requirements.txt && \
rm /tmp/requirements.txt
4 changes: 2 additions & 2 deletions .github/containers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ REPO_ROOT:=$(realpath $(MAKEFILE_DIR)../../)
.PHONY: default
default: test

# Perform a shortened build for testing
.PHONY: build
build:
@# Perform a shortened build for testing
@docker build $(MAKEFILE_DIR) \
-t ghcr.io/newrelic/newrelic-python-agent-ci:local \
--build-arg='PYTHON_VERSIONS=3.10 2.7'

# Ensure python versions are usable
.PHONY: test
test: build
@# Ensure python versions are usable
@docker run --rm ghcr.io/newrelic/python-agent-ci:local /bin/bash -c '\
python3.10 --version && \
python2.7 --version && \
Expand Down
8 changes: 6 additions & 2 deletions .github/containers/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
bandit
black
flake8
isort
pip
setuptools
wheel
tox
virtualenv<20.22.0
tox
wheel
2 changes: 1 addition & 1 deletion .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
#
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 60
daysUntilStale: 365
# Number of days of inactivity before a stale issue is closed
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
daysUntilClose: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-ci-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ jobs:
with:
push: ${{ github.event_name != 'pull_request' }}
context: .github/containers
platforms: linux/amd64
platforms: ${{ (github.ref == 'refs/head/main') && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
165 changes: 165 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
- postgres
- rabbitmq
- redis
- rediscluster
- solr

steps:
Expand Down Expand Up @@ -384,6 +385,105 @@ jobs:
path: ./**/.coverage.*
retention-days: 1

rediscluster:
env:
TOTAL_GROUPS: 1

strategy:
fail-fast: false
matrix:
group-number: [1]

runs-on: ubuntu-20.04
container:
image: ghcr.io/newrelic/newrelic-python-agent-ci:latest
options: >-
--add-host=host.docker.internal:host-gateway
timeout-minutes: 30

services:
redis1:
image: hmstepanek/redis-cluster-node:1.0.0
ports:
- 6379:6379
- 16379:16379
options: >-
--add-host=host.docker.internal:host-gateway

redis2:
image: hmstepanek/redis-cluster-node:1.0.0
ports:
- 6380:6379
- 16380:16379
options: >-
--add-host=host.docker.internal:host-gateway

redis3:
image: hmstepanek/redis-cluster-node:1.0.0
ports:
- 6381:6379
- 16381:16379
options: >-
--add-host=host.docker.internal:host-gateway

redis4:
image: hmstepanek/redis-cluster-node:1.0.0
ports:
- 6382:6379
- 16382:16379
options: >-
--add-host=host.docker.internal:host-gateway

redis5:
image: hmstepanek/redis-cluster-node:1.0.0
ports:
- 6383:6379
- 16383:16379
options: >-
--add-host=host.docker.internal:host-gateway

redis6:
image: hmstepanek/redis-cluster-node:1.0.0
ports:
- 6384:6379
- 16384:16379
options: >-
--add-host=host.docker.internal:host-gateway

cluster-setup:
image: hmstepanek/redis-cluster:1.0.0
options: >-
--add-host=host.docker.internal:host-gateway

steps:
- uses: actions/checkout@v3

- name: Fetch git tags
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git fetch --tags origin

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

- name: Test
run: |
tox -vv -e ${{ steps.get-envs.outputs.envs }} -p auto
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

redis:
env:
TOTAL_GROUPS: 2
Expand Down Expand Up @@ -924,3 +1024,68 @@ jobs:
name: coverage-${{ github.job }}-${{ strategy.job-index }}
path: ./**/.coverage.*
retention-days: 1

firestore:
env:
TOTAL_GROUPS: 1

strategy:
fail-fast: false
matrix:
group-number: [1]

runs-on: ubuntu-20.04
container:
image: ghcr.io/newrelic/newrelic-python-agent-ci:latest
options: >-
--add-host=host.docker.internal:host-gateway
timeout-minutes: 30

services:
firestore:
# Image set here MUST be repeated down below in options. See comment below.
image: gcr.io/google.com/cloudsdktool/google-cloud-cli:437.0.1-emulators
ports:
- 8080:8080
# Set health checks to wait 5 seconds in lieu of an actual healthcheck
options: >-
--health-cmd "echo success"
--health-interval 10s
--health-timeout 5s
--health-retries 5
--health-start-period 5s
gcr.io/google.com/cloudsdktool/google-cloud-cli:437.0.1-emulators /bin/bash -c "gcloud emulators firestore start --host-port=0.0.0.0:8080" ||
# This is a very hacky solution. GitHub Actions doesn't provide APIs for setting commands on services, but allows adding arbitrary options.
# --entrypoint won't work as it only accepts an executable and not the [] syntax.
# Instead, we specify the image again the command afterwards like a call to docker create. The result is a few environment variables
# and the original command being appended to our hijacked docker create command. We can avoid any issues by adding || to prevent that
# from every being executed as bash commands.

steps:
- uses: actions/checkout@v3

- name: Fetch git tags
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git fetch --tags origin

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

- name: Test
run: |
tox -vv -e ${{ steps.get-envs.outputs.envs }} -p auto
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
26 changes: 8 additions & 18 deletions newrelic/api/database_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import logging

from newrelic.api.time_trace import TimeTrace, current_trace
from newrelic.common.async_wrapper import async_wrapper
from newrelic.common.async_wrapper import async_wrapper as get_async_wrapper
from newrelic.common.object_wrapper import FunctionWrapper, wrap_object
from newrelic.core.database_node import DatabaseNode
from newrelic.core.stack_trace import current_stack
Expand Down Expand Up @@ -44,11 +44,6 @@ def register_database_client(
dbapi2_module._nr_explain_query = explain_query
dbapi2_module._nr_explain_stmts = explain_stmts
dbapi2_module._nr_instance_info = instance_info
dbapi2_module._nr_datastore_instance_feature_flag = False


def enable_datastore_instance_feature(dbapi2_module):
dbapi2_module._nr_datastore_instance_feature_flag = True


class DatabaseTrace(TimeTrace):
Expand Down Expand Up @@ -153,12 +148,7 @@ def finalize_data(self, transaction, exc=None, value=None, tb=None):

if instance_enabled or db_name_enabled:

if (
self.dbapi2_module
and self.connect_params
and self.dbapi2_module._nr_datastore_instance_feature_flag
and self.dbapi2_module._nr_instance_info is not None
):
if self.dbapi2_module and self.connect_params and self.dbapi2_module._nr_instance_info is not None:

instance_info = self.dbapi2_module._nr_instance_info(*self.connect_params)

Expand Down Expand Up @@ -244,9 +234,9 @@ def create_node(self):
)


def DatabaseTraceWrapper(wrapped, sql, dbapi2_module=None):
def DatabaseTraceWrapper(wrapped, sql, dbapi2_module=None, async_wrapper=None):
def _nr_database_trace_wrapper_(wrapped, instance, args, kwargs):
wrapper = async_wrapper(wrapped)
wrapper = async_wrapper if async_wrapper is not None else get_async_wrapper(wrapped)
if not wrapper:
parent = current_trace()
if not parent:
Expand All @@ -273,9 +263,9 @@ def _nr_database_trace_wrapper_(wrapped, instance, args, kwargs):
return FunctionWrapper(wrapped, _nr_database_trace_wrapper_)


def database_trace(sql, dbapi2_module=None):
return functools.partial(DatabaseTraceWrapper, sql=sql, dbapi2_module=dbapi2_module)
def database_trace(sql, dbapi2_module=None, async_wrapper=None):
return functools.partial(DatabaseTraceWrapper, sql=sql, dbapi2_module=dbapi2_module, async_wrapper=async_wrapper)


def wrap_database_trace(module, object_path, sql, dbapi2_module=None):
wrap_object(module, object_path, DatabaseTraceWrapper, (sql, dbapi2_module))
def wrap_database_trace(module, object_path, sql, dbapi2_module=None, async_wrapper=None):
wrap_object(module, object_path, DatabaseTraceWrapper, (sql, dbapi2_module, async_wrapper))
Loading