Skip to content

Commit

Permalink
Merge branch 'main' into nov_20_ba_pathing_mock
Browse files Browse the repository at this point in the history
  • Loading branch information
JerrySentry authored Nov 22, 2024
2 parents 9351e4e + 70ec67f commit 04f796a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
40 changes: 40 additions & 0 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
import logging
import os

from gunicorn.glogging import Logger
from prometheus_client import multiprocess


def child_exit(server, worker):
if worker and worker.pid and "PROMETHEUS_MULTIPROC_DIR" in os.environ:
multiprocess.mark_process_dead(worker.pid)


class CustomGunicornLogger(Logger):
"""
A custom class for logging gunicorn startup logs, these are for the logging that takes
place before the Django app starts and takes over with its own defined logging formats.
This class ensures the gunicorn minimum log level to be INFO instead of the default ERROR.
"""

def setup(self, cfg):
super().setup(cfg)
custom_format = "[%(levelname)s] [%(process)d] [%(asctime)s] %(message)s "
date_format = "%Y-%m-%d %H:%M:%S %z"
formatter = logging.Formatter(fmt=custom_format, datefmt=date_format)

# Update handlers with the custom formatter
for handler in self.error_log.handlers:
handler.setFormatter(formatter)
for handler in self.access_log.handlers:
handler.setFormatter(formatter)


logconfig_dict = {
"loggers": {
"gunicorn.error": {
"level": "INFO",
"handlers": ["console"],
"propagate": False,
},
"gunicorn.access": {
"level": "INFO",
"handlers": ["console"],
"propagate": False,
},
}
}

logger_class = CustomGunicornLogger
8 changes: 4 additions & 4 deletions upload/tests/views/test_upload_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_deactivated_repo(db):
)
client = APIClient()
client.credentials(HTTP_AUTHORIZATION="token " + repository.upload_token)
response = client.post(url, {"commit_sha": "abc123"}, format="json")
response = client.post(url, {"commitid": "abc123"}, format="json")
assert response.status_code == 400
assert "This repository is deactivated" in str(response.json())

Expand All @@ -91,7 +91,7 @@ def test_upload_coverage_with_errors(db):

# Invalid flag format
response = client.post(
url, {"commit_sha": "abc123", "flags": "not-a-list"}, format="json"
url, {"commitid": "abc123", "flags": "not-a-list"}, format="json"
)
assert response.status_code == 400
assert "flags" in response.json()
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_upload_coverage_post(db, mocker):
"ci_service": "ci_service",
"ci_url": "ci_url",
"code": "code",
"commit_sha": commit.commitid,
"commitid": commit.commitid,
"flags": ["flag1", "flag2"],
"job_code": "job_code",
"version": "version",
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_upload_coverage_post_shelter(db, mocker):
"ci_service": "ci_service",
"ci_url": "ci_url",
"code": "code",
"commit_sha": commit.commitid,
"commitid": commit.commitid,
"flags": ["flag1", "flag2"],
"job_code": "job_code",
"storage_path": "shelter/test/path.txt",
Expand Down
12 changes: 6 additions & 6 deletions upload/views/upload_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ def post(self, request: HttpRequest, *args, **kwargs) -> Response:

# Create commit
create_commit_data = dict(
commitid=request.data.get("commit_sha"),
parent_commit_id=request.data.get("parent_sha"),
pullid=request.data.get("pull_request_number"),
branch=request.data.get("branch"),
commitid=request.data.get("commitid"),
parent_commit_id=request.data.get("parent_commit_id"),
pullid=request.data.get("pullid"),
)
commit_serializer = CommitSerializer(data=create_commit_data)
if not commit_serializer.is_valid():
Expand Down Expand Up @@ -107,10 +107,10 @@ def post(self, request: HttpRequest, *args, **kwargs) -> Response:

# Do upload
upload_data = dict(
ci_url=request.data.get("build_url"),
env=request.data.get("env_vars"),
flags=request.data.get("flags"),
ci_service=request.data.get("ci_service"),
ci_url=request.data.get("ci_url"),
env=request.data.get("env"),
flags=request.data.get("flags"),
job_code=request.data.get("job_code"),
name=request.data.get("name"),
version=request.data.get("version"),
Expand Down

0 comments on commit 04f796a

Please sign in to comment.