Documentation
¶
Overview ¶
Package utils provides utility functions and types for CloudZero Agent operational support.
Package 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.
The 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.
Key capabilities:
- Time management: Clock abstraction with UTC standardization for consistent timestamps
- Data processing: Chunk processing utilities for batching and streaming operations
- Format utilities: Standardized formatting for storage and transmission
- Testing support: Mock implementations and test utilities for reliable testing
Integration patterns:
- Domain services: Time providers for business logic operations
- Storage operations: Timestamp formatting for database persistence
- Data processing: Chunking utilities for efficient batch operations
- Testing infrastructure: Mock utilities for deterministic testing
The package follows dependency injection patterns, providing interfaces that enable testing and operational flexibility while maintaining consistent behavior across CloudZero Agent components.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chunk ¶
Chunk 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.
Batch processing applications:
- Metric data processing: Split large metric batches for efficient storage operations
- API requests: Batch CloudZero platform uploads to respect rate limits
- Database operations: Process large record sets in manageable transactions
- Memory management: Control memory usage during large data processing
Parameters:
- list: Source slice of any type T to be divided into chunks
- n: Maximum size of each chunk (must be positive)
Behavior characteristics:
- Zero/negative chunk size: Returns original slice wrapped in single chunk
- Uneven division: Final chunk contains remaining elements (may be smaller than n)
- Empty input: Returns empty slice of chunks
- Preserves element order: Maintains original ordering within and across chunks
Performance considerations:
- Uses slice operations for efficient memory allocation
- Minimizes memory copying through slice references
- Scales linearly with input size
- Suitable for processing large datasets without memory exhaustion
Returns a slice of slices, where each inner slice contains at most n elements from the original input, enabling controlled batch processing operations.
func FormatForStorage ¶
FormatForStorage 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.
Format specification:
- Pattern: "2006-01-02 15:04:05.999999999 -0700 MST"
- Precision: Nanosecond-level accuracy for high-precision time requirements
- Timezone: Includes timezone information for accurate time reconstruction
- Compatibility: Parseable format for database systems and CloudZero platform
Usage contexts:
- Database persistence: Timestamp formatting for storage operations
- API transmission: Standardized time format for CloudZero platform communication
- Audit logging: Consistent time representation for operational records
- Metric attribution: Time formatting for temporal data analysis
The format preserves full time precision and timezone information while providing human-readable representation suitable for both machine processing and debugging.
Returns the formatted time string suitable for storage and transmission.
Types ¶
type Clock ¶
type Clock struct{}
Clock 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.
Design characteristics:
- UTC normalization: All timestamps converted to UTC for consistent storage and processing
- Production reliability: Uses system clock for accurate time representation
- Interface compliance: Implements types.TimeProvider for dependency injection
- Zero configuration: No setup required, ready for immediate use
Usage patterns:
- Domain services: Inject Clock for business logic time requirements
- Storage operations: Generate timestamps for database records
- Metric processing: Timestamp metric data for temporal analysis
- Audit logging: Record operation times for compliance and debugging
The Clock provides a simple abstraction over system time that enables testing through interface substitution while providing reliable time operations in production.
func (*Clock) GetCurrentTime ¶
GetCurrentTime 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.
UTC normalization ensures:
- Consistent timestamps across different deployment environments
- Reliable time comparisons and calculations
- Standard format for storage and transmission
- Compatibility with CloudZero platform expectations
This method is called frequently throughout CloudZero Agent operations for:
- Database record timestamps
- Metric data time attribution
- Audit log entries
- Business logic time calculations
Returns the current system time converted to UTC timezone.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package k8s contains helpers for working with the Kubernetes Client.
|
Package k8s contains helpers for working with the Kubernetes Client. |
|
Package lock provides an interface for file-based locking.
|
Package lock provides an interface for file-based locking. |
|
Package parallel provides utilities for running tasks in parallel.
|
Package parallel provides utilities for running tasks in parallel. |
|
Package scout provides cloud environment detection and metadata retrieval capabilities for cloud environments.
|
Package scout provides cloud environment detection and metadata retrieval capabilities for cloud environments. |
|
auto
Package auto provides auto-detection capabilities for the CloudZero Scout.
|
Package auto provides auto-detection capabilities for the CloudZero Scout. |
|
aws
Package aws provides AWS cloud environment detection and metadata retrieval capabilities using the EC2 instance metadata service (IMDS) v2 with fallback to v1.
|
Package aws provides AWS cloud environment detection and metadata retrieval capabilities using the EC2 instance metadata service (IMDS) v2 with fallback to v1. |
|
azure
Package azure provides Azure cloud environment detection and metadata retrieval capabilities using the Azure Instance Metadata Service (IMDS).
|
Package azure provides Azure cloud environment detection and metadata retrieval capabilities using the Azure Instance Metadata Service (IMDS). |
|
google
Package google provides functionality for detecting and gathering environment information from Google Cloud metadat services.
|
Package google provides functionality for detecting and gathering environment information from Google Cloud metadat services. |
|
types
Package types defines core types and interfaces for cloud environment detection and metadata retrieval.
|
Package types defines core types and interfaces for cloud environment detection and metadata retrieval. |
|
types/mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
|
Package telemetry contains code for posting telemetry data to the CloudZero API.
|
Package telemetry contains code for posting telemetry data to the CloudZero API. |