Skip to content

Commit

Permalink
Merge branch 'main' into develop-k2-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
AnupamJuniwal committed Dec 13, 2023
2 parents a7e4870 + 030cfc9 commit 140bb54
Show file tree
Hide file tree
Showing 76 changed files with 1,682 additions and 980 deletions.
10 changes: 4 additions & 6 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ FROM ghcr.io/newrelic/newrelic-python-agent-ci:${IMAGE_TAG}
# Setup non-root user
USER root
ARG UID=1000
ARG GID=$UID
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

# Move pyenv installation
ENV PYENV_ROOT="${HOME}/.pyenv"
ENV PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:${PATH}"
RUN mv /root/.pyenv /home/vscode/.pyenv && \
chown -R vscode:vscode /home/vscode/.pyenv
# Fix pyenv installation
RUN echo 'eval "$(pyenv init -)"' >>${HOME}/.bashrc && \
chown -R vscode:vscode ${PYENV_ROOT}

# Set user
USER ${UID}:${GID}
54 changes: 7 additions & 47 deletions .github/actions/update-rpm-config/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ inputs:
description: "Language agent to configure (eg. python)"
required: true
default: "python"
target-system:
description: "Target System: prod|staging|all"
required: true
default: "all"
agent-version:
description: "3-4 digit agent version number (eg. 1.2.3) with optional leading v (ignored)"
required: true
Expand All @@ -19,9 +15,6 @@ inputs:
production-api-key:
description: "API key for New Relic Production"
required: false
staging-api-key:
description: "API key for New Relic Staging"
required: false

runs:
using: "composite"
Expand All @@ -42,64 +35,31 @@ runs:
run: |
echo "CONTENT_TYPE='Content-Type: application/json'" >> $GITHUB_ENV
- name: Update Staging system configuration page
- name: Update system configuration page
shell: bash
if: ${{ inputs.dry-run == 'false' && (inputs.target-system == 'staging' || inputs.target-system == 'all') }}
run: |
curl -X POST 'https://staging-api.newrelic.com/v2/system_configuration.json' \
-H "X-Api-Key:${{ inputs.staging-api-key }}" -i \
-H ${{ env.CONTENT_TYPE }} \
-d ${{ env.PAYLOAD }}
- name: Update Production system configuration page
shell: bash
if: ${{ inputs.dry-run == 'false' && (inputs.target-system == 'prod' || inputs.target-system == 'all') }}
if: ${{ inputs.dry-run == 'false' }}
run: |
curl -X POST 'https://api.newrelic.com/v2/system_configuration.json' \
-H "X-Api-Key:${{ inputs.production-api-key }}" -i \
-H ${{ env.CONTENT_TYPE }} \
-d ${{ env.PAYLOAD }}
- name: Verify Staging system configuration update
shell: bash
if: ${{ inputs.dry-run == 'false' && (inputs.target-system == 'staging' || inputs.target-system == 'all') }}
run: |
STAGING_VERSION=$(curl -X GET 'https://staging-api.newrelic.com/v2/system_configuration.json' \
-H "X-Api-Key:${{ inputs.staging-api-key }}" \
-H "${{ env.CONTENT_TYPE }}" | jq ".system_configurations | from_entries | .${{inputs.agent-language}}_agent_version")
if [ "${{ env.AGENT_VERSION }}" != "$STAGING_VERSION" ]; then
echo "Staging version mismatch: $STAGING_VERSION"
exit 1
fi
- name: Verify Production system configuration update
- name: Verify system configuration update
shell: bash
if: ${{ inputs.dry-run == 'false' && (inputs.target-system == 'prod' || inputs.target-system == 'all') }}
if: ${{ inputs.dry-run == 'false' }}
run: |
PROD_VERSION=$(curl -X GET 'https://api.newrelic.com/v2/system_configuration.json' \
-H "X-Api-Key:${{ inputs.production-api-key }}" \
-H "${{ env.CONTENT_TYPE }}" | jq ".system_configurations | from_entries | .${{inputs.agent-language}}_agent_version")
if [ "${{ env.AGENT_VERSION }}" != "$PROD_VERSION" ]; then
echo "Production version mismatch: $PROD_VERSION"
echo "Version mismatch: $PROD_VERSION"
exit 1
fi
- name: (dry-run) Update Staging system configuration page
shell: bash
if: ${{ inputs.dry-run != 'false' && (inputs.target-system == 'staging' || inputs.target-system == 'all') }}
run: |
cat << EOF
curl -X POST 'https://staging-api.newrelic.com/v2/system_configuration.json' \
-H "X-Api-Key:**REDACTED**" -i \
-H ${{ env.CONTENT_TYPE }} \
-d ${{ env.PAYLOAD }}
EOF
- name: (dry-run) Update Production system configuration page
- name: (dry-run) Update system configuration page
shell: bash
if: ${{ inputs.dry-run != 'false' && (inputs.target-system == 'prod' || inputs.target-system == 'all') }}
if: ${{ inputs.dry-run != 'false' }}
run: |
cat << EOF
curl -X POST 'https://api.newrelic.com/v2/system_configuration.json' \
Expand Down
6 changes: 3 additions & 3 deletions .github/containers/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ ENV HOME /root
WORKDIR "${HOME}"

# Install pyenv
ENV PYENV_ROOT="${HOME}/.pyenv"
ENV PYENV_ROOT="/usr/local/pyenv"
RUN curl https://pyenv.run/ | /bin/bash
ENV PATH="$PYENV_ROOT/bin:$PYENV_ROOT/shims:${PATH}"
RUN echo 'eval "$(pyenv init -)"' >>$HOME/.bashrc && \
ENV PATH="${PYENV_ROOT}/bin:${PYENV_ROOT}/shims:${PATH}"
RUN echo 'eval "$(pyenv init -)"' >>${HOME}/.bashrc && \
pyenv update

# Install Python
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deploy-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ jobs:
target-system: "all"
agent-version: "${{ github.ref_name }}"
dry-run: "false"
production-api-key: ${{ secrets.NEW_RELIC_API_KEY_PRODUCTION }}"
staging-api-key: ${{ secrets.NEW_RELIC_API_KEY_STAGING }}"
production-api-key: ${{ secrets.NEW_RELIC_API_KEY_PRODUCTION }}
staging-api-key: ${{ secrets.NEW_RELIC_API_KEY_STAGING }}
58 changes: 0 additions & 58 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
- python
- elasticsearchserver07
- elasticsearchserver08
- gearman
- grpc
- kafka
- memcached
Expand Down Expand Up @@ -967,63 +966,6 @@ jobs:
path: ./**/.coverage.*
retention-days: 1

gearman:
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:
gearman:
image: artefactual/gearmand
ports:
- 8080:4730
# Set health checks to wait until gearman has started
options: >-
--health-cmd "(echo status ; sleep 0.1) | nc 127.0.0.1 4730 -w 1"
--health-interval 10s
--health-timeout 5s
--health-retries 5
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

firestore:
env:
TOTAL_GROUPS: 1
Expand Down
70 changes: 39 additions & 31 deletions newrelic/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@

from __future__ import print_function

import sys
import logging
import sys

_builtin_plugins = [
'debug_console',
'generate_config',
'license_key',
'local_config',
'network_config',
'record_deploy',
'run_program',
'run_python',
'server_config',
'validate_config'
"debug_console",
"generate_config",
"license_key",
"local_config",
"network_config",
"record_deploy",
"run_program",
"run_python",
"server_config",
"validate_config",
]

_commands = {}


def command(name, options='', description='', hidden=False,
log_intercept=True, deprecated=False):
def command(name, options="", description="", hidden=False, log_intercept=True, deprecated=False):
def wrapper(callback):
callback.name = name
callback.options = options
Expand All @@ -44,22 +43,23 @@ def wrapper(callback):
callback.deprecated = deprecated
_commands[name] = callback
return callback

return wrapper


def usage(name):
details = _commands[name]
if details.deprecated:
print("[WARNING] This command is deprecated and will be removed")
print('Usage: newrelic-admin %s %s' % (name, details.options))
print("Usage: newrelic-admin %s %s" % (name, details.options))


@command('help', '[command]', hidden=True)
@command("help", "[command]", hidden=True)
def help(args):
if not args:
print('Usage: newrelic-admin command [options]')
print("Usage: newrelic-admin command [options]")
print()
print("Type 'newrelic-admin help <command>'", end='')
print("Type 'newrelic-admin help <command>'", end="")
print("for help on a specific command.")
print()
print("Available commands are:")
Expand All @@ -68,24 +68,24 @@ def help(args):
for name in commands:
details = _commands[name]
if not details.hidden:
print(' ', name)
print(" ", name)

else:
name = args[0]

if name not in _commands:
print("Unknown command '%s'." % name, end=' ')
print("Unknown command '%s'." % name, end=" ")
print("Type 'newrelic-admin help' for usage.")

else:
details = _commands[name]

print('Usage: newrelic-admin %s %s' % (name, details.options))
print("Usage: newrelic-admin %s %s" % (name, details.options))
if details.description:
print()
description = details.description
if details.deprecated:
description = '[DEPRECATED] ' + description
description = "[DEPRECATED] " + description
print(description)


Expand All @@ -99,37 +99,45 @@ def emit(self, record):
if len(logging.root.handlers) != 0:
return

if record.name.startswith('newrelic.packages'):
if record.name.startswith("newrelic.packages"):
return

if record.levelno < logging.WARNING:
return

return logging.StreamHandler.emit(self, record)

_stdout_logger = logging.getLogger('newrelic')
_stdout_logger = logging.getLogger("newrelic")
_stdout_handler = FilteredStreamHandler(sys.stdout)
_stdout_format = '%(levelname)s - %(message)s\n'
_stdout_format = "%(levelname)s - %(message)s\n"
_stdout_formatter = logging.Formatter(_stdout_format)
_stdout_handler.setFormatter(_stdout_formatter)
_stdout_logger.addHandler(_stdout_handler)


def load_internal_plugins():
for name in _builtin_plugins:
module_name = '%s.%s' % (__name__, name)
module_name = "%s.%s" % (__name__, name)
__import__(module_name)


def load_external_plugins():
try:
import pkg_resources
# Preferred after Python 3.10
if sys.version_info >= (3, 10):
from importlib.metadata import entry_points
# Introduced in Python 3.8
elif sys.version_info >= (3, 8) and sys.version_info <= (3, 9):
from importlib_metadata import entry_points
# Removed in Python 3.12
else:
from pkg_resources import iter_entry_points as entry_points
except ImportError:
return

group = 'newrelic.admin'
group = "newrelic.admin"

for entrypoint in pkg_resources.iter_entry_points(group=group):
for entrypoint in entry_points(group=group):
__import__(entrypoint.module_name)


Expand All @@ -138,12 +146,12 @@ def main():
if len(sys.argv) > 1:
command = sys.argv[1]
else:
command = 'help'
command = "help"

callback = _commands[command]

except Exception:
print("Unknown command '%s'." % command, end='')
print("Unknown command '%s'." % command, end="")
print("Type 'newrelic-admin help' for usage.")
sys.exit(1)

Expand All @@ -156,5 +164,5 @@ def main():
load_internal_plugins()
load_external_plugins()

if __name__ == '__main__':
if __name__ == "__main__":
main()
Loading

0 comments on commit 140bb54

Please sign in to comment.