Skip to content

Commit

Permalink
Merge pull request #376 from camptocamp/fix
Browse files Browse the repository at this point in the history
Better watch doc
  • Loading branch information
sbrunner authored Jun 17, 2024
2 parents 54a67c0 + 34ce666 commit 9253428
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 34 deletions.
Binary file modified acceptance_tests/logs-log-command.mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified acceptance_tests/logs-log-json.mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified acceptance_tests/logs-log-multiline.mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 15 additions & 15 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,41 @@ services:
target: runner
environment:
&app-env # https://docs.pylonsproject.org/projects/pyramid/en/1.6-branch/narr/environment.html
PYRAMID_DEBUG_ALL: TRUE
PYRAMID_RELOAD_ALL: TRUE
PYRAMID_DEBUG_ALL: 'TRUE'
PYRAMID_RELOAD_ALL: 'TRUE'
PYRAMID_DEFAULT_LOCALE_NAME: en
LOG_LEVEL: DEBUG
C2CWSGIUTILS_LOG_LEVEL: INFO
SQL_LOG_LEVEL: INFO
GUNICORN_LOG_LEVEL: INFO
OTHER_LOG_LEVEL: INFO
C2C_AUTH_GITHUB_REPOSITORY: camptocamp/github-app-geo-project
C2C_AUTH_GITHUB_SECRET: 1234567890123456789
C2C_AUTH_GITHUB_CLIENT_ID: 1234
C2C_AUTH_GITHUB_CLIENT_SECRET: 1234
C2C_PROMETHEUS_PORT: 9110
C2C_AUTH_GITHUB_SECRET: '1234567890123456789'
C2C_AUTH_GITHUB_CLIENT_ID: '1234'
C2C_AUTH_GITHUB_CLIENT_SECRET: '1234'
C2C_PROMETHEUS_PORT: '9110'
TEST_USER: test
TEST_APPLICATION: test
SQLALCHEMY_URL: postgresql://postgresql:postgresql@db/tests
SQLALCHEMY_POOL_RECYCLE: 3600
SQLALCHEMY_POOL_SIZE: 10
SQLALCHEMY_MAX_OVERFLOW: 20
SQLALCHEMY_POOL_RECYCLE: '3600'
SQLALCHEMY_POOL_SIZE: '10'
SQLALCHEMY_MAX_OVERFLOW: '20'
SQLALCHEMY_SLAVE_URL: postgresql://postgresql:postgresql@db/tests
SQLALCHEMY_SLAVE_POOL_RECYCLE: 3600
SQLALCHEMY_SLAVE_POOL_SIZE: 10
SQLALCHEMY_SLAVE_MAX_OVERFLOW: 20
SQLALCHEMY_SLAVE_POOL_RECYCLE: '3600'
SQLALCHEMY_SLAVE_POOL_SIZE: '10'
SQLALCHEMY_SLAVE_MAX_OVERFLOW: '20'
GHCI_TEST_GITHUB_APP_ID: ${GHCI_TEST_GITHUB_APP_ID}
GHCI_TEST_GITHUB_APP_PRIVATE_KEY: ${GHCI_TEST_GITHUB_APP_PRIVATE_KEY}
GHCI_TEST_GITHUB_APP_URL: https://github.com/apps/test
GHCI_SESSION_SECRET: 1234
GHCI_SESSION_SALT: 1234
GHCI_SESSION_SECRET: '1234'
GHCI_SESSION_SALT: '1234'
GHCI_CONFIGURATION: /etc/ghci/config.yaml
VISIBLE_ENTRY_POINT: /
PGHOST: db
PGUSER: postgresql
PGPASSWORD: postgresql
PGDATABASE: tests
PGPORT: 5432
PGPORT: '5432'
volumes:
- ./docker/test-app/config.yaml:/etc/ghci/config.yaml:ro
- ./github_app_geo_project:/app/github_app_geo_project:ro
Expand Down
6 changes: 2 additions & 4 deletions github_app_geo_project/module/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,6 @@ def get_alternate_versions(security: c2cciutils.security.Security, branch: str)
alternate_index = security.alternate_tag_index
version_index = security.version_index

if alternate_index < 0:
return []

if version_index < 0:
_LOGGER.warning("No Version column in the SECURITY.md")
return []
Expand All @@ -776,7 +773,8 @@ def get_alternate_versions(security: c2cciutils.security.Security, branch: str)
result = []
for row in security.data:
if row[version_index] == branch:
result = [v.strip() for v in row[alternate_index].split(",") if v.strip()]
if alternate_index >= 0:
result = [v.strip() for v in row[alternate_index].split(",") if v.strip()]
last = True
elif last:
last = False
Expand Down
40 changes: 25 additions & 15 deletions github_app_geo_project/scripts/process_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import asyncio
import contextvars
import datetime
import io
import logging
import os
import socket
Expand All @@ -21,7 +22,7 @@
import prometheus_client
import sentry_sdk
import sqlalchemy.orm
from prometheus_client import Gauge
from prometheus_client import Gauge, Info

from github_app_geo_project import configuration, models, module, project_configuration, utils
from github_app_geo_project.module import modules
Expand All @@ -31,6 +32,7 @@
_LOGGER = logging.getLogger(__name__)

_NB_JOBS = Gauge("ghci_jobs_number", "Number of jobs", ["status"])
_JOBS = Info("ghci_jobs", "Running jobs", [])


class _JobInfo(NamedTuple):
Expand Down Expand Up @@ -779,7 +781,7 @@ async def __call__(self, *args: Any, **kwds: Any) -> Any:
await asyncio.sleep(empty_thread_sleep if empty else 0)


class _UpdateCounter:
class _WatchDog:
def __init__(
self,
Session: sqlalchemy.orm.sessionmaker[ # pylint: disable=invalid-name,unsubscriptable-object
Expand All @@ -790,25 +792,34 @@ def __init__(

async def __call__(self, *args: Any, **kwds: Any) -> Any:
while True:
_LOGGER.debug("Watch dog: alive")
with self.Session() as session:
for status in models.JobStatus:
_NB_JOBS.labels(status.name).set(
session.query(models.Queue).filter(models.Queue.status == status).count()
)
await asyncio.sleep(0)
await asyncio.sleep(10)


async def _watch_dog() -> None:
while True:
_LOGGER.debug("Watch dog: alive")
with open("/var/ghci/watch_dog", "w", encoding="utf-8") as file_:
file_.write(datetime.datetime.now().isoformat())
info = {}
text = []
for id_, job in _RUNNING_JOBS.items():
file_.write(
f"{id_}: {job.module} {job.event_name} {job.repository} [{job.priority}] (Worker max priority {job.worker_max_priority})\n"
text.append(
f"{id_}: {job.module} {job.event_name} {job.repository} [{job.priority}] (Worker max priority {job.worker_max_priority})"
)
await asyncio.sleep(60)
info[f"job-id-{id_}"] = (
f"{job.module} {job.event_name} {job.repository} [{job.priority}] (Worker max priority {job.worker_max_priority})"
)
for task in asyncio.all_tasks():
txt = io.StringIO()
task.print_stack(file=txt)
text.append("-" * 30)
text.append(txt.getvalue())
info[f"task-{id(task)}"] = txt.getvalue()
_JOBS.info(info)
with open("/var/ghci/watch_dog", "w", encoding="utf-8") as file_:
file_.write(datetime.datetime.now().isoformat())
file_.write("\n".join(text))
file_.write("\n")
await asyncio.sleep(10)


async def _async_main() -> None:
Expand Down Expand Up @@ -842,8 +853,7 @@ async def _async_main() -> None:

threads_call = []
if not args.exit_when_empty:
threads_call.append(_UpdateCounter(Session)())
threads_call.append(_watch_dog())
threads_call.append(_WatchDog(Session)())

for priority in priority_groups:
threads_call.append(_Run(config, Session, args.exit_when_empty, priority)())
Expand Down

0 comments on commit 9253428

Please sign in to comment.