repo

package
v1.2.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package repo provides concrete repository implementations for CloudZero Agent resource metadata storage. This package implements the Secondary Adapter layer in the hexagonal architecture, providing persistent storage for Kubernetes resource metadata essential for cost allocation and billing operations.

The repository implementations bridge the gap between domain services and database storage, handling the persistence of resource metadata collected during webhook admission processing and enabling cost allocation analysis across the CloudZero platform.

Key responsibilities:

  • Resource metadata persistence: Store Kubernetes resource cost allocation information
  • CRUD operations: Complete Create, Read, Update, Delete operations for resource data
  • Query support: Flexible querying capabilities for resource discovery and analysis
  • Transaction management: Atomic operations for data consistency during complex workflows
  • Error handling: Comprehensive error translation and operational monitoring

Architecture:

  • resourceRepoImpl: Concrete implementation of ResourceStore interface
  • In-memory repositories: SQLite-based storage for testing and lightweight deployments
  • Metrics integration: Prometheus monitoring for storage operation tracking
  • Database abstraction: GORM-based implementation supporting multiple database backends

The repository layer is essential for CloudZero Agent cost allocation functionality, persisting resource metadata that enables billing attribution and cost optimization analysis across Kubernetes deployments.

Integration points:

  • Webhook handlers: Store resource metadata during admission processing
  • Cost allocation services: Query resource data for billing calculations
  • Monitoring systems: Track resource metadata volume and storage health
  • Configuration management: Support dynamic policy updates and resource classification

Index

Constants

This section is empty.

Variables

View Source
var (

	// StorageWriteFailures tracks repository operation failures across all resource types and operations.
	// This Prometheus counter vector enables operational monitoring of storage layer health
	// and provides detailed failure analysis for troubleshooting and capacity planning.
	//
	// Labels provide comprehensive failure analysis:
	//   - "resource_type": Kubernetes resource type ID for failure categorization
	//   - "namespace": Resource namespace for scope-based analysis
	//   - "resource_name": Specific resource name for detailed troubleshooting
	//   - "action": Operation type (create, update, delete) for failure pattern analysis
	//
	// Operational use cases:
	//   - Alerting: Trigger alerts when failure rates exceed acceptable thresholds
	//   - Troubleshooting: Identify specific resources or operations causing storage issues
	//   - Capacity planning: Monitor storage load and failure patterns over time
	//   - Cost allocation impact: Track storage failures that may affect billing accuracy
	//
	// Example queries:
	//   - Total failure rate: rate(storage_write_failure_total[5m])
	//   - Failures by namespace: sum by (namespace) (storage_write_failure_total)
	//   - Create operation failures: storage_write_failure_total{action="create"}
	StorageWriteFailures = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "storage_write_failure_total",
			Help: "Total number of storage write failures.",
		},
		[]string{"resource_type", "namespace", "resource_name", "action"},
	)
)

Functions

func NewInMemoryResourceRepository

func NewInMemoryResourceRepository(clock types.TimeProvider) (types.ResourceStore, error)

NewInMemoryResourceRepository creates a new in-memory resource repository.

func NewResourceRepository

func NewResourceRepository(clock types.TimeProvider, db *gorm.DB) (types.ResourceStore, error)

NewResourceRepository creates a new resource repository with the given clock and database connection.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL