feat(observability): metrics + OTel spans for git/sops hot path (#63)#81
Merged
Conversation
… path (#63) cloneAndReadFile is on every reconcile but emitted no metrics or spans, so git-fetch and decrypt latency were invisible during incidents. Add an internal/metrics package registering custom collectors with the controller-runtime registry (exposed on the existing /metrics endpoint): - provider_kubeconfig_git_fetch_duration_seconds{repo,branch,operation,result} - provider_kubeconfig_git_cache_total{repo,branch,operation} - provider_kubeconfig_sops_decrypt_duration_seconds{format,result} - provider_kubeconfig_reconcile_errors_total{stage} (git|decrypt|secret|downstream) EnsureCloned now returns an Operation (clone|pull|revision) so the cache counter can distinguish a fresh clone from a cache-hit pull, without the git package taking an observability dependency. FormatFromPath is exported for the decrypt-format metric label. Add OpenTelemetry spans around EnsureCloned, ReadFile and SOPSDecrypt via a new internal/tracing package. Tracing is off by default and activates only when a standard OTLP endpoint is configured (OTEL_EXPORTER_OTLP_*), so behavior is unchanged out of the box; failures to init only log. Also enrich the wrapped errors on this path to carry repo URL and file path, and document metrics + tracing in the README. Closes #63 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #63.
cloneAndReadFileruns on every reconcile but emitted no metrics or spans — git-fetch and decrypt latency were the blind spot during incidents.Metrics
New
internal/metricspackage registers custom collectors with the controller-runtime registry, so they're exposed on the manager's existing/metricsendpoint (no new server):provider_kubeconfig_git_fetch_duration_secondsrepo, branch, operation, resultprovider_kubeconfig_git_cache_totalrepo, branch, operationprovider_kubeconfig_sops_decrypt_duration_secondsformat, resultprovider_kubeconfig_reconcile_errors_totalstage(git|decrypt|secret|downstream)EnsureClonednow returns anOperation(clone\|pull\|revision) so the cache counter distinguishes a fresh clone from a cache-hit pull — without thegitpackage taking an observability dependency (keeps it reusable).FormatFromPathis exported for the decrypt-format label.Tracing
New
internal/tracingpackage adds OTel spans aroundEnsureCloned,ReadFile, andSOPSDecrypt. Off by default — activates only when a standard OTLP endpoint is set (OTEL_EXPORTER_OTLP_ENDPOINT), so out-of-the-box behavior is unchanged and a bad endpoint only logs (never fatal).Also
testutil), tracing disabled-by-default, andEnsureClonedoperation assertion.go build/test -race/vetandgolangci-lint(pinned v2.11.4) all clean. New direct deps (prometheus/client_golang,otel,otel/sdk,otel/trace,otlptracegrpc) were already present transitively — just promoted bygo mod tidy.🤖 Generated with Claude Code