mirror of
https://github.com/imjasonh/git-k8s
synced 2026-07-16 20:45:03 +00:00
Add pkg/workspace.Manager that provides Acquire/Release semantics for Git repos. When GIT_CACHE_DIR is set and a GitRepository has spec.cache.enabled, controllers use on-disk bare clones with incremental fetch; otherwise they fall back to the existing in-memory clone behavior. Key changes: - New pkg/workspace package with Manager, Workspace, GC, Deepen, and context-based injection (WithManager/GetManager) - GitRepository API gains spec.cache (CacheConfig) and status.cache (CacheStatus) with deepcopy and CRD schema updates - Push, sync, and resolver reconcilers now use workspace.Acquire/Release instead of inline memory.NewStorage + git.CloneContext - Shallow clone by default; sync/resolver deepen as needed for merge-base - New Prometheus metrics: workspace_acquire_duration_seconds, workspace_cache_hit_total, workspace_cache_miss_total - Deployment manifests include commented-out PVC configuration - Comprehensive unit tests for workspace package (21 tests) - E2E tests for cache-free and cache-enabled push flows https://claude.ai/code/session_01NULGxaCLPMT1yDVEAsffc5
53 lines
2 KiB
Go
53 lines
2 KiB
Go
package metrics
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
var (
|
|
// ReconcileCount tracks the total number of reconciliations by controller and result.
|
|
ReconcileCount = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: "gitkube",
|
|
Name: "reconcile_count_total",
|
|
Help: "Total number of reconciliations.",
|
|
}, []string{"controller", "result"})
|
|
|
|
// ReconcileLatency tracks reconciliation duration by controller.
|
|
ReconcileLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
|
Namespace: "gitkube",
|
|
Name: "reconcile_duration_seconds",
|
|
Help: "Duration of reconciliations in seconds.",
|
|
Buckets: prometheus.ExponentialBuckets(0.01, 3, 10), // 10ms to ~3min
|
|
}, []string{"controller"})
|
|
|
|
// GitOperationDuration tracks the duration of Git operations.
|
|
GitOperationDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
|
Namespace: "gitkube",
|
|
Name: "git_operation_duration_seconds",
|
|
Help: "Duration of Git operations (clone, push, ls-remote).",
|
|
Buckets: prometheus.ExponentialBuckets(0.1, 3, 8), // 100ms to ~3.6min
|
|
}, []string{"operation"})
|
|
|
|
// WorkspaceAcquireDuration tracks how long it takes to acquire a workspace.
|
|
WorkspaceAcquireDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
|
Namespace: "gitkube",
|
|
Name: "workspace_acquire_duration_seconds",
|
|
Help: "Duration of workspace acquire operations.",
|
|
Buckets: prometheus.ExponentialBuckets(0.1, 3, 8),
|
|
}, []string{"mode"})
|
|
|
|
// WorkspaceCacheHit tracks cache hits in workspace acquisition.
|
|
WorkspaceCacheHit = promauto.NewCounter(prometheus.CounterOpts{
|
|
Namespace: "gitkube",
|
|
Name: "workspace_cache_hit_total",
|
|
Help: "Total number of workspace cache hits.",
|
|
})
|
|
|
|
// WorkspaceCacheMiss tracks cache misses in workspace acquisition.
|
|
WorkspaceCacheMiss = promauto.NewCounter(prometheus.CounterOpts{
|
|
Namespace: "gitkube",
|
|
Name: "workspace_cache_miss_total",
|
|
Help: "Total number of workspace cache misses.",
|
|
})
|
|
)
|