Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve logging/tracing and track performance counters #427

Merged
merged 2 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions flux_local/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import contextvars
from contextlib import contextmanager
import logging
from time import perf_counter
from typing import Generator


_LOGGER = logging.getLogger(__name__)

# No public API
Expand All @@ -18,9 +20,12 @@
def trace_context(name: str) -> Generator[None, None, None]:
stack = trace.get([])
token = trace.set(stack + [name])
_LOGGER.debug("[Trace] > %s", name)
label = " > ".join(stack + [name])
t1 = perf_counter()
_LOGGER.debug("[Trace] > %s", label)
try:
yield
finally:
t2 = perf_counter()
trace.reset(token)
_LOGGER.debug("[Trace] < %s", name)
_LOGGER.debug("[Trace] < %s (%0.2fs)", label, (t2 - t1))
7 changes: 4 additions & 3 deletions flux_local/git_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ async def kustomization_traversal(selector: PathSelector) -> list[Kustomization]
while not path_queue.empty():
(path, visit_ks) = path_queue.get()
_LOGGER.debug("Visiting path (%s) %s", selector.path, path)
with trace_context(f"Traversing Kustomization '{str(path)}'"):
label = visit_ks.namespaced_name if visit_ks else str(path)
with trace_context(f"Kustomization '{label}'"):
cmd: kustomize.Kustomize
if visit_ks is None:
cmd = kustomize.grep(
Expand Down Expand Up @@ -458,7 +459,7 @@ async def build_kustomization(
):
return ([], [], [])

with trace_context(f"Build Kustomization '{kustomization.namespaced_name}'"):
with trace_context(f"Build '{kustomization.namespaced_name}'"):
cmd = kustomize.flux_build(kustomization, root / kustomization.path)
skips = []
if kustomization_selector.skip_crds:
Expand Down Expand Up @@ -541,7 +542,7 @@ async def build_manifest(
if not selector.cluster.enabled:
return Manifest(clusters=[])

with trace_context(f"Traversing Cluster '{str(selector.path.path)}'"):
with trace_context(f"Cluster '{str(selector.path.path)}'"):
results = await kustomization_traversal(selector.path)
clusters = [
Cluster(
Expand Down
Loading