Skip to content

Commit

Permalink
chore: fix telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
uptickmetachu committed Sep 10, 2024
1 parent cafe3c2 commit c86ceae
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 30 deletions.
58 changes: 31 additions & 27 deletions gitops_server/workers/deployer/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,33 +115,37 @@ async def from_push_event(cls, push_event):
)

async def deploy(self):
with tracer.start_as_current_span("deploy"):
added_apps, updated_apps, removed_apps = self.calculate_app_deltas()
if not (added_apps | updated_apps | removed_apps):
logger.info("No deltas; aborting.")
return
logger.info(
f"Running deployment for these deltas: A{list(added_apps)}, U{list(updated_apps)},"
f" R{list(removed_apps)}"
)
await post_init_summary(
source=self.current_app_definitions.name,
username=self.author_name,
added_apps=added_apps,
updated_apps=updated_apps,
removed_apps=removed_apps,
commit_message=self.commit_message,
)
update_results = await asyncio.gather(
*[
self.update_app_deployment(self.current_app_definitions.apps[app_name])
for app_name in (added_apps | updated_apps)
]
)
uninstall_results = await asyncio.gather(
*[self.uninstall_app(self.previous_app_definitions.apps[app_name]) for app_name in removed_apps]
)
await post_result_summary(self.current_app_definitions.name, update_results + uninstall_results)
added_apps, updated_apps, removed_apps = self.calculate_app_deltas()
current_span = trace.get_current_span()
if current_span:
current_span.set_attribute("gitops.added_apps", len(added_apps))
current_span.set_attribute("gitops.updated_aps", len(updated_apps))
current_span.set_attribute("gitops.removed_app", len(removed_apps))
if not (added_apps | updated_apps | removed_apps):
logger.info("No deltas; aborting.")
return
logger.info(
f"Running deployment for these deltas: A{list(added_apps)}, U{list(updated_apps)},"
f" R{list(removed_apps)}"
)
await post_init_summary(
source=self.current_app_definitions.name,
username=self.author_name,
added_apps=added_apps,
updated_apps=updated_apps,
removed_apps=removed_apps,
commit_message=self.commit_message,
)
update_results = await asyncio.gather(
*[
self.update_app_deployment(self.current_app_definitions.apps[app_name])
for app_name in (added_apps | updated_apps)
]
)
uninstall_results = await asyncio.gather(
*[self.uninstall_app(self.previous_app_definitions.apps[app_name]) for app_name in removed_apps]
)
await post_result_summary(self.current_app_definitions.name, update_results + uninstall_results)

async def uninstall_app(self, app: App) -> UpdateAppResult:
with tracer.start_as_current_span("uninstall_app", attributes={"app": app.name}):
Expand Down
15 changes: 13 additions & 2 deletions gitops_server/workers/deployer/worker.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import asyncio
import logging

from opentelemetry import trace

from .deploy import Deployer

logger = logging.getLogger("gitops_worker")

tracer = trace.get_tracer(__name__)


class DeployQueueWorker:
"""Simple synchronous background work queue.
Expand Down Expand Up @@ -52,5 +56,12 @@ async def process_work(self):
ref = work.get("ref")
logger.info(f'Have a push to "{ref}".')
if ref == "refs/heads/master":
deployer = await Deployer.from_push_event(work)
await deployer.deploy()
with tracer.start_as_current_span("gitops_process_webhook") as current_span:
deployer = await Deployer.from_push_event(work)
current_span.set_attribute("gitops.ref", ref)
current_span.set_attribute("gitops.after", work.get("after"))
current_span.set_attribute("gitops.before", work.get("before"))
current_span.set_attribute("gitops.author_email", deployer.author_email)
current_span.set_attribute("gitops.author_name", deployer.author_name)
current_span.set_attribute("gitops.commit_message", deployer.commit_message)
await deployer.deploy()
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c86ceae

Please sign in to comment.