Skip to content

Commit

Permalink
Report actor versions in night log email
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Oct 29, 2024
1 parent 9b113d9 commit cad068c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 26 deletions.
50 changes: 44 additions & 6 deletions src/lvmapi/data/night_log_email_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,21 @@
margin: 5px 0px 15px 0px;
}

ul {
list-style-position: outside;
}

li {
white-space: pre-line;
}

li + li {
margin-top: 10px;
}

pre.version-tab {
tab-size: 4;
}
</style>
</head>

Expand Down Expand Up @@ -75,25 +87,26 @@ <h1 class="header-text">
</div>
<hr />
{% if weather %}
<lu>
<ul>
{% for comment in weather %}
<li>{{ comment.comment }}</li>
{% endfor %}
</lu>
</ul>
{% else %}
<div>No comments.</div>
{% endif %}


<div class="section">
Issues / bugs
</div>
<hr />
{% if issues %}
<lu>
<ul>
{% for comment in issues %}
<li>{{ comment.comment }}</li>
{% endfor %}
</lu>
</ul>
{% else %}
<div>No comments.</div>
{% endif %}
Expand All @@ -103,15 +116,40 @@ <h1 class="header-text">
</div>
<hr />
{% if other %}
<lu>
<ul>
{% for comment in other %}
<li>{{ comment.comment }}</li>
{% endfor %}
</lu>
</ul>
{% else %}
<div>No comments.</div>
{% endif %}

<div class="section">
Software versions
</div>
<hr />
{% if software_versions %}
<table style="border: 0; padding: 5px">
{% for actor, version in software_versions.items() %}
<tr>
<td>
<code style="font-size: 10pt">
{{ actor }}
</code>
</td>
<td>
<code style="margin-left: 20px; font-size: 10pt">
{{ version or "N/A" }}
</code>
</td>
</tr>
{% endfor %}
</table>
{% else %}
<div>No data.</div>
{% endif %}

<div class="section">
Exposures
</div>
Expand Down
23 changes: 3 additions & 20 deletions src/lvmapi/routers/actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@

from __future__ import annotations

import asyncio

from typing import Annotated

from fastapi import APIRouter, Query, Request
from pydantic import BaseModel

from lvmapi import config
from lvmapi.tasks import restart_kubernetes_deployment_task
from lvmapi.tools.rabbitmq import CluClient, ping_actors
from lvmapi.tools.logs import get_actor_versions
from lvmapi.tools.rabbitmq import ping_actors


class HealthResponse(BaseModel):
Expand Down Expand Up @@ -108,21 +107,5 @@ async def get_actor_versions_route(
) -> dict[str, str | None]:
"""Returns the version of an actor."""

actors: list[str] = config["actors"]["list"]
if actor is not None:
actors = [actor]

async with CluClient() as client:
version_cmds = await asyncio.gather(
*[client.send_command(actor, "version") for actor in actors]
)

versions: dict[str, str | None] = {}
for iactor, version_cmd in enumerate(version_cmds):
try:
version: str | None = version_cmd.replies.get("version")
except Exception:
version = None
versions[actors[iactor]] = version

return versions
return (await get_actor_versions(actor=actor))
36 changes: 36 additions & 0 deletions src/lvmapi/tools/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from __future__ import annotations

import asyncio
import io
import json
import pathlib
Expand All @@ -29,6 +30,7 @@
from sdsstools import get_sjd, run_in_executor

from lvmapi import config
from lvmapi.tools.rabbitmq import CluClient
from lvmapi.tools.slack import post_message


Expand Down Expand Up @@ -245,6 +247,29 @@ async def get_exposure_table_ascii(
return exposure_io.read()


async def get_actor_versions(actor: str | None = None):
"""Returns a list of actor versions."""

actors: list[str] = config["actors"]["list"]
if actor is not None:
actors = [actor]

async with CluClient() as client:
version_cmds = await asyncio.gather(
*[client.send_command(actor, "version") for actor in actors]
)

versions: dict[str, str | None] = {}
for iactor, version_cmd in enumerate(version_cmds):
try:
version: str | None = version_cmd.replies.get("version")
except Exception:
version = None
versions[actors[iactor]] = version

return versions


NIGHT_LOG_CATEGORIES = set(["observers", "weather", "issues", "other"])


Expand Down Expand Up @@ -501,6 +526,10 @@ async def get_plaintext_night_log(sjd: int | None = None):
-----
{other}
Versions
--------
{versions}
Exposure data
-------------
{exposure_data}
Expand Down Expand Up @@ -532,13 +561,17 @@ async def get_plaintext_night_log(sjd: int | None = None):
compact_lamps=True,
)

versions = await get_actor_versions()
versions_l = [f"{actor}: {version or '?'}" for actor, version in versions.items()]

return nigh_log.format(
date=date,
sjd=sjd,
observers=observers,
weather="\n".join(weather) or "No comments",
issues="\n".join(issues) or "No comments",
other="\n".join(other) or "No comments",
versions="\n".join(versions_l),
exposure_data=exposure_table or "No exposures found",
)

Expand Down Expand Up @@ -589,6 +622,8 @@ async def email_night_log(
date = Time(sjd - 1, format="mjd").datetime.strftime("%A, %B %-d, %Y")
lvmweb_url = config["night_logs.lvmweb_url"] + str(sjd)

versions = await get_actor_versions()

html_message = html_template.render(
sjd=sjd,
lvmweb_url=lvmweb_url,
Expand All @@ -598,6 +633,7 @@ async def email_night_log(
issues=data["comments"]["issues"],
other=data["comments"]["other"],
exposure_table=exposure_table,
software_versions=versions,
)

recipients = config["night_logs.email_recipients"]
Expand Down

0 comments on commit cad068c

Please sign in to comment.