{"modulePath":"github.com/cloudzero/cloudzero-agent","version":"v1.3.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package utils\n\nPackage utils provides utility functions and types for CloudZero Agent operational support.\n\nPackage utils provides utility functions and types for CloudZero Agent operational support. This package implements reusable utility components that support CloudZero Agent operations across multiple architectural layers, providing consistent patterns for common tasks including time management, data processing, and operational utilities.\n\nThe utilities maintain clean interfaces and testable implementations, enabling their use across Primary Adapters, Application Core, and Secondary Adapters while providing consistent behavior and operational reliability.\n\nKey capabilities:\n\n  - Time management: Clock abstraction with UTC standardization for consistent timestamps\n  - Data processing: Chunk processing utilities for batching and streaming operations\n  - Format utilities: Standardized formatting for storage and transmission\n  - Testing support: Mock implementations and test utilities for reliable testing\n\nIntegration patterns:\n\n  - Domain services: Time providers for business logic operations\n  - Storage operations: Timestamp formatting for database persistence\n  - Data processing: Chunking utilities for efficient batch operations\n  - Testing infrastructure: Mock utilities for deterministic testing\n\nThe package follows dependency injection patterns, providing interfaces that enable testing and operational flexibility while maintaining consistent behavior across CloudZero Agent components.\n\n## Functions\n\n```go\nfunc Chunk[T any](list []T, n int) [][]T\n```\nChunk divides a slice into smaller sub-slices of specified size for efficient batch processing. This generic utility function enables CloudZero Agent to process large datasets in manageable chunks, optimizing memory usage and enabling controlled processing rates.\n\nBatch processing applications:\n\n  - Metric data processing: Split large metric batches for efficient storage operations\n  - API requests: Batch CloudZero platform uploads to respect rate limits\n  - Database operations: Process large record sets in manageable transactions\n  - Memory management: Control memory usage during large data processing\n\nParameters:\n\n  - list: Source slice of any type T to be divided into chunks\n  - n: Maximum size of each chunk (must be positive)\n\nBehavior characteristics:\n\n  - Zero/negative chunk size: Returns original slice wrapped in single chunk\n  - Uneven division: Final chunk contains remaining elements (may be smaller than n)\n  - Empty input: Returns empty slice of chunks\n  - Preserves element order: Maintains original ordering within and across chunks\n\nPerformance considerations:\n\n  - Uses slice operations for efficient memory allocation\n  - Minimizes memory copying through slice references\n  - Scales linearly with input size\n  - Suitable for processing large datasets without memory exhaustion\n\nReturns a slice of slices, where each inner slice contains at most n elements from the original input, enabling controlled batch processing operations.\n\n```go\nfunc FormatForStorage(t time.Time) string\n```\nFormatForStorage converts time values to standardized string format for database storage and transmission. This function provides consistent time formatting across all CloudZero Agent storage operations, ensuring reliable time representation and parsing for operational data persistence.\n\nFormat specification:\n\n  - Pattern: \"2006-01-02 15:04:05.999999999 -0700 MST\"\n  - Precision: Nanosecond-level accuracy for high-precision time requirements\n  - Timezone: Includes timezone information for accurate time reconstruction\n  - Compatibility: Parseable format for database systems and CloudZero platform\n\nUsage contexts:\n\n  - Database persistence: Timestamp formatting for storage operations\n  - API transmission: Standardized time format for CloudZero platform communication\n  - Audit logging: Consistent time representation for operational records\n  - Metric attribution: Time formatting for temporal data analysis\n\nThe format preserves full time precision and timezone information while providing human-readable representation suitable for both machine processing and debugging.\n\nReturns the formatted time string suitable for storage and transmission.\n\n## Types\n\n```go\ntype Clock struct{}\n```\nClock provides production time operations for CloudZero Agent components. This struct implements the TimeProvider interface with real system clock integration, providing UTC-standardized timestamps for consistent time handling across all agent operations.\n\nDesign characteristics:\n\n  - UTC normalization: All timestamps converted to UTC for consistent storage and processing\n  - Production reliability: Uses system clock for accurate time representation\n  - Interface compliance: Implements types.TimeProvider for dependency injection\n  - Zero configuration: No setup required, ready for immediate use\n\nUsage patterns:\n\n  - Domain services: Inject Clock for business logic time requirements\n  - Storage operations: Generate timestamps for database records\n  - Metric processing: Timestamp metric data for temporal analysis\n  - Audit logging: Record operation times for compliance and debugging\n\nThe Clock provides a simple abstraction over system time that enables testing through interface substitution while providing reliable time operations in production.\n\n```go\nfunc (c *Clock) GetCurrentTime() time.Time\n```\nGetCurrentTime returns the current system time normalized to UTC timezone. This method implements the TimeProvider interface requirement, providing consistent time representation across all CloudZero Agent operations regardless of system timezone.\n\nUTC normalization ensures:\n\n  - Consistent timestamps across different deployment environments\n  - Reliable time comparisons and calculations\n  - Standard format for storage and transmission\n  - Compatibility with CloudZero platform expectations\n\nThis method is called frequently throughout CloudZero Agent operations for:\n\n  - Database record timestamps\n  - Metric data time attribution\n  - Audit log entries\n  - Business logic time calculations\n\nReturns the current system time converted to UTC timezone.\n\n","path":"github.com/cloudzero/cloudzero-agent/app/utils","name":"utils","synopsis":"Package utils provides utility functions and types for CloudZero Agent operational support.","isRedistributable":true}
