Skip to content

Commit

Permalink
Merge pull request #377 from camptocamp/fix
Browse files Browse the repository at this point in the history
Separate Prometeus and file watch
  • Loading branch information
sbrunner authored Jun 18, 2024
2 parents 9253428 + 6f656b8 commit fc1244c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 16 deletions.
11 changes: 10 additions & 1 deletion github_app_geo_project/module/audit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ async def _snyk_fix(
"<br>\n".join(
[
*fixable_vulnerabilities_summary.values(),
f"{os.path.basename(os.getcwd())}:{branch}",
f"Project: {os.path.basename(os.getcwd())}:{branch}",
f"See logs: {logs_url}",
]
)
Expand Down Expand Up @@ -443,6 +443,15 @@ async def _npm_audit_fix(
)
if message is not None:
result.append(message)
if not success:
await module_utils.run_timeout(
["poetry", "--version"],
os.environ.copy(),
10,
"Poetry version",
"Error while getting the Poetry version",
"Timeout while getting the Poetry version",
)
_LOGGER.debug("Fixing version in %s", package_lock_file_name)
# Remove the add '~' in the version in the package.json
with open(os.path.join(directory, "package.json"), encoding="utf-8") as package_file:
Expand Down
11 changes: 3 additions & 8 deletions github_app_geo_project/module/workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,14 @@ def get_actions(self, context: module.GetActionContext) -> list[module.Action[di
async def process(
self, context: module.ProcessContext[None, dict[str, Any], dict[str, Any]]
) -> module.ProcessOutput[dict[str, Any], dict[str, Any]]:
full_repo = f"{context.github_project.owner}/{context.github_project.repository}"
repo_data = context.transversal_status.setdefault(
context.github_project.owner + "/" + context.github_project.repository, {}
)

module_utils.manage_updated(
context.transversal_status,
f"{context.github_project.owner}/{context.github_project.repository}",
days_old=30,
)
module_utils.manage_updated(context.transversal_status, full_repo, days_old=30)

repo = context.github_project.github.get_repo(
context.github_project.owner + "/" + context.github_project.repository
)
repo = context.github_project.github.get_repo(full_repo)

stabilization_branches = [repo.default_branch]
security_file = None
Expand Down
33 changes: 27 additions & 6 deletions github_app_geo_project/scripts/process_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import socket
import subprocess # nosec
import sys
import time
import urllib.parse
from typing import Any, NamedTuple, cast

Expand Down Expand Up @@ -760,6 +761,9 @@ def __init__(
self.max_priority = max_priority

async def __call__(self, *args: Any, **kwds: Any) -> Any:
current_task = asyncio.current_task()
if current_task is not None:
current_task.set_name(f"Run ({self.max_priority})")
empty_thread_sleep = int(os.environ.get("GHCI_EMPTY_THREAD_SLEEP", 10))

while True:
Expand All @@ -781,7 +785,7 @@ async def __call__(self, *args: Any, **kwds: Any) -> Any:
await asyncio.sleep(empty_thread_sleep if empty else 0)


class _WatchDog:
class _PrometheusWatch:
def __init__(
self,
Session: sqlalchemy.orm.sessionmaker[ # pylint: disable=invalid-name,unsubscriptable-object
Expand All @@ -791,14 +795,18 @@ def __init__(
self.Session = Session # pylint: disable=invalid-name

async def __call__(self, *args: Any, **kwds: Any) -> Any:
current_task = asyncio.current_task()
if current_task is not None:
current_task.set_name("PrometheusWatch")
await asyncio.to_thread(self._watch)

def _watch(self) -> None:
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)
info = {}
text = []
for id_, job in _RUNNING_JOBS.items():
Expand All @@ -815,11 +823,23 @@ async def __call__(self, *args: Any, **kwds: Any) -> Any:
text.append(txt.getvalue())
info[f"task-{id(task)}"] = txt.getvalue()
_JOBS.info(info)
with open("/var/ghci/job_info", "w", encoding="utf-8") as file_:
file_.write("\n".join(text))
file_.write("\n")
time.sleep(10)


class _WatchDog:
async def __call__(self, *args: Any, **kwds: Any) -> Any:
current_task = asyncio.current_task()
if current_task is not None:
current_task.set_name("WatchDog")
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())
file_.write("\n".join(text))
file_.write("\n")
await asyncio.sleep(10)
await asyncio.sleep(60)


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

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

for priority in priority_groups:
threads_call.append(_Run(config, Session, args.exit_when_empty, priority)())
Expand Down
1 change: 0 additions & 1 deletion github_app_geo_project/views/webhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def webhook(request: pyramid.request.Request) -> dict[str, None]:
.where(models.Queue.check_run_id == data["check_run"]["id"])
.values(
{
"priority": module.PRIORITY_HIGH,
"status": models.JobStatus.NEW,
"started_at": None,
"finished_at": None,
Expand Down

0 comments on commit fc1244c

Please sign in to comment.