cost

package
v1.1.15 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package cost provides cost tracking functionality for AWS services

Index

Constants

View Source
const (
	// DynamoDB Pricing (per request)
	DynamoDBReadRequestUnit  = 25    // $0.25 per million read request units (strongly consistent)
	DynamoDBWriteRequestUnit = 125   // $1.25 per million write request units
	DynamoDBStreamReadUnit   = 20    // $0.20 per million stream read request units
	DynamoDBStoragePerGB     = 25000 // $0.25 per GB-month (calculated per hour)

	// Lambda Pricing
	LambdaRequestCost       = 20   // $0.20 per million requests
	LambdaGBSecondCost      = 1667 // $0.0000166667 per GB-second
	LambdaDurationMinMS     = 1    // Minimum billable duration
	LambdaMemoryIncrementMB = 1    // Memory increments

	// S3 Pricing
	S3PutRequestCost    = 500   // $0.005 per 1,000 PUT requests
	S3GetRequestCost    = 40    // $0.0004 per 1,000 GET requests
	S3StorageStandardGB = 23000 // $0.023 per GB-month (calculated per hour)
	S3DataTransferPerGB = 90000 // $0.09 per GB data transfer out

	// CloudFront Pricing
	CloudFrontRequestCost    = 100   // $0.01 per 10,000 requests
	CloudFrontHTTPSCost      = 10    // $0.01 per 10,000 HTTPS requests
	CloudFrontDataTransferGB = 85000 // $0.085 per GB (first 10TB)

	// Micro to cents conversion
	MicroCentsToCents = 1000000
)

AWS Pricing Constants (in microcents for precision) Prices are per region - using us-east-1 as default

View Source
const (
	OperationTypeScan = "Scan"
)

DynamoDB operation type constants

Variables

View Source
var (
	ErrCircuitBreakerOpen      = errors.CircuitBreakerOpen()
	ErrCircuitBreakerReopened  = errors.CircuitBreakerReopened()
	ErrHourlyCostLimitExceeded = errors.HourlyCostLimitExceeded()
)

Legacy error variables for backwards compatibility These are now wrappers around the centralized error system

Functions

func BatchOperationExample

func BatchOperationExample(trackingDB *TrackingDB)

BatchOperationExample demonstrates enhanced batch operation tracking

func EnhancedCostAnalysis

func EnhancedCostAnalysis(tracker *EnhancedOperationTracker)

EnhancedCostAnalysis shows how to analyze tracked operations

func ExampleEnhancedUsage

func ExampleEnhancedUsage()

ExampleEnhancedUsage demonstrates how to use the enhanced cost tracking

func InitializeCostStorage

func InitializeCostStorage(cfg *appConfig.Config)

InitializeCostStorage initializes the global cost storage with configuration

func Middleware

func Middleware(logger *zap.Logger) func(HandlerFunc) HandlerFunc

Middleware wraps a handler with cost tracking

func RealTimeOptimization

func RealTimeOptimization(tracker *EnhancedOperationTracker, logger *zap.Logger)

RealTimeOptimization shows how enhanced tracking enables real-time optimization

func Track

func Track(ctx context.Context, fn func(*Tracker))

Track is a convenience function that tracks an operation cost if a tracker exists in the context It's safe to call even if no tracker is present

func TrackDataTransferContext

func TrackDataTransferContext(ctx context.Context, bytes int64)

TrackDataTransferContext tracks data transfer from context

func TrackDynamORMOperation

func TrackDynamORMOperation(ctx context.Context, operation string, fn func() error) error

TrackDynamORMOperation is a convenience function for tracking DynamORM operations

func TrackDynamoReadContext

func TrackDynamoReadContext(ctx context.Context, items int)

TrackDynamoReadContext tracks DynamoDB reads from context

func TrackDynamoWriteContext

func TrackDynamoWriteContext(ctx context.Context, items int)

TrackDynamoWriteContext tracks DynamoDB writes from context

func TrackRead

func TrackRead(_ context.Context, tracker *Tracker, _ string, items int64)

TrackRead tracks DynamoDB read operations (convenience function for storage layer)

func TrackS3GetContext

func TrackS3GetContext(ctx context.Context, count int)

TrackS3GetContext tracks S3 GET operations from context

func TrackS3PutContext

func TrackS3PutContext(ctx context.Context, count int)

TrackS3PutContext tracks S3 PUT operations from context

func TrackWrite

func TrackWrite(_ context.Context, tracker *Tracker, _ string, items int)

TrackWrite tracks DynamoDB write operations (convenience function for storage layer)

func TransactionExample

func TransactionExample(trackingDB *TrackingDB)

TransactionExample demonstrates transaction cost tracking

func WithDynamORMCostTracking

func WithDynamORMCostTracking(ctx context.Context, requestID, operationType string) context.Context

WithDynamORMCostTracking adds cost tracking to a context

func WithTracker

func WithTracker(ctx context.Context, tracker *Tracker) context.Context

WithTracker attaches a cost tracker to the context

Types

type AIServiceWithCostTracking

type AIServiceWithCostTracking struct {
	// contains filtered or unexported fields
}

AIServiceWithCostTracking wraps AIService with comprehensive cost tracking

func NewAIServiceWithCostTracking

func NewAIServiceWithCostTracking(aiService aiService, costTracker *Tracker, logger *zap.Logger) *AIServiceWithCostTracking

NewAIServiceWithCostTracking creates a cost-tracking wrapper for AI service

func (*AIServiceWithCostTracking) AnalyzeContentWithCostTracking

func (s *AIServiceWithCostTracking) AnalyzeContentWithCostTracking(ctx context.Context, content *ai.Content, userID string) (*ai.AIAnalysis, *models.SearchCostTracking, error)

AnalyzeContentWithCostTracking wraps AI content analysis with cost tracking

func (*AIServiceWithCostTracking) BulkEmbeddingGenerationWithCostTracking

func (s *AIServiceWithCostTracking) BulkEmbeddingGenerationWithCostTracking(ctx context.Context, texts []string, userID string) ([][]float32, *models.SearchCostTracking, error)

BulkEmbeddingGenerationWithCostTracking handles bulk embedding generation with cost optimization

func (*AIServiceWithCostTracking) GenerateEmbeddingWithCostTracking

func (s *AIServiceWithCostTracking) GenerateEmbeddingWithCostTracking(ctx context.Context, text string, userID string) ([]float32, *models.SearchCostTracking, error)

GenerateEmbeddingWithCostTracking wraps embedding generation with cost tracking

func (*AIServiceWithCostTracking) SemanticSearchWithCostTracking

func (s *AIServiceWithCostTracking) SemanticSearchWithCostTracking(ctx context.Context, query string, userID string, limit int, _ float64) ([]float32, []*models.SearchEmbedding, *models.SearchCostTracking, error)

SemanticSearchWithCostTracking performs semantic search with comprehensive cost tracking

type CircuitState

type CircuitState int

CircuitState represents the state of a circuit breaker

const (
	// StateClosed represents normal operation
	StateClosed CircuitState = iota
	// StateOpen represents circuit open - rejecting requests
	StateOpen
	// StateHalfOpen represents testing recovery
	StateHalfOpen
)

type ConsumedCapacity

type ConsumedCapacity struct {
	TableName              string                      // Table that consumed the capacity
	ReadCapacityUnits      float64                     // Read capacity units consumed
	WriteCapacityUnits     float64                     // Write capacity units consumed
	GlobalSecondaryIndexes map[string]ConsumedCapacity // GSI capacity consumption
	LocalSecondaryIndexes  map[string]ConsumedCapacity // LSI capacity consumption
}

ConsumedCapacity represents DynamoDB consumed capacity information

type Cost

type Cost struct {
	Service                    string    // "DynamoDB", "S3", "Lambda", etc.
	ReadCostMicroCents         int64     // Cost for read operations
	WriteCostMicroCents        int64     // Cost for write operations
	RequestCostMicroCents      int64     // Cost for requests
	StorageCostMicroCents      int64     // Cost for storage
	InvocationCostMicroCents   int64     // Cost for Lambda invocations
	DurationCostMicroCents     int64     // Cost for Lambda duration
	DataTransferCostMicroCents int64     // Cost for data transfer
	TotalMicroCents            int64     // Total cost in microcents
	Timestamp                  time.Time // When the cost was calculated
}

Cost represents the calculated cost of an operation

func CalculateDynamoDBCost

func CalculateDynamoDBCost(readUnits, writeUnits float64) Cost

CalculateDynamoDBCost calculates the cost of DynamoDB operations

func CalculateLambdaCost

func CalculateLambdaCost(duration time.Duration, memory int64) Cost

CalculateLambdaCost calculates the cost of Lambda invocations

func CalculateS3Cost

func CalculateS3Cost(requests int64, storage float64) Cost

CalculateS3Cost calculates the cost of S3 operations

func (*Cost) TotalDollars

func (c *Cost) TotalDollars() float64

TotalDollars returns the total cost in dollars

type CostCircuitBreaker

type CostCircuitBreaker struct {
	// contains filtered or unexported fields
}

CostCircuitBreaker implements cost-aware circuit breaking

func NewCostCircuitBreaker

func NewCostCircuitBreaker(config CostCircuitBreakerConfig) *CostCircuitBreaker

NewCostCircuitBreaker creates a new cost-aware circuit breaker

func (*CostCircuitBreaker) CheckCost

func (cb *CostCircuitBreaker) CheckCost(_ context.Context, estimatedCost float64) error

CheckCost validates if operation is within cost limits

func (*CostCircuitBreaker) RecordCost

func (cb *CostCircuitBreaker) RecordCost(cost float64)

RecordCost records actual operation cost

type CostCircuitBreakerConfig

type CostCircuitBreakerConfig struct {
	MaxCostPerHour    float64       // Maximum cost per hour in USD
	MaxCostPerRequest float64       // Maximum cost per request in USD
	WindowSize        time.Duration // Cost calculation window
	FailureThreshold  int           // Number of failures to open circuit
	RecoveryTimeout   time.Duration // Time before attempting recovery
}

CostCircuitBreakerConfig defines circuit breaker thresholds

type CostSample

type CostSample struct {
	// contains filtered or unexported fields
}

CostSample represents a single cost measurement

type CostWindow

type CostWindow struct {
	// contains filtered or unexported fields
}

CostWindow tracks costs within a time window

type DailyCostAggregate

type DailyCostAggregate struct {
	Date                string
	TotalCostMicrocents int64
	RequestCount        int64
	UniqueUsers         int64
	DynamoDBReads       int64
	DynamoDBWrites      int64
	LambdaInvocations   int64
	LambdaDurationMs    int64
	DataTransferBytes   int64
}

DailyCostAggregate represents aggregated costs for a single day.

type Driver

type Driver struct {
	Service           string  `json:"service"`
	Operation         string  `json:"operation"`
	CostMicroCents    int64   `json:"cost_microcents"`
	PercentageOfTotal float64 `json:"percentage_of_total"`
	OperationCount    int64   `json:"operation_count"`
	AverageCost       int64   `json:"average_cost"`
	Trend             string  `json:"trend"` // "INCREASING", "DECREASING", or "STABLE"
}

Driver represents a significant contributor to costs in the system

type DynamORMCostTracker

type DynamORMCostTracker struct {
	*Tracker // Embed existing cost tracker
	// contains filtered or unexported fields
}

DynamORMCostTracker wraps a DynamORM client with cost tracking capabilities

func NewDynamORMCostTracker

func NewDynamORMCostTracker(client core.DB, logger *zap.Logger) *DynamORMCostTracker

NewDynamORMCostTracker creates a new cost tracking wrapper for DynamORM

func NewDynamORMCostTrackerWithRequest

func NewDynamORMCostTrackerWithRequest(client core.DB, requestID, operationType string, logger *zap.Logger) *DynamORMCostTracker

NewDynamORMCostTrackerWithRequest creates a new cost tracking wrapper with request context

func WrapWithCostTracking

func WrapWithCostTracking(client core.DB, logger *zap.Logger) *DynamORMCostTracker

WrapWithCostTracking wraps a DynamORM client with cost tracking

func WrapWithCostTrackingAndRequest

func WrapWithCostTrackingAndRequest(client core.DB, requestID, operationType string, logger *zap.Logger) *DynamORMCostTracker

WrapWithCostTrackingAndRequest wraps a DynamORM client with cost tracking and request context

func (*DynamORMCostTracker) GetClient

func (ct *DynamORMCostTracker) GetClient() core.DB

GetClient returns the underlying DynamORM client

func (*DynamORMCostTracker) GetCostSummary

func (ct *DynamORMCostTracker) GetCostSummary() *OperationCost

GetCostSummary returns a summary of tracked costs

func (*DynamORMCostTracker) Reset

func (ct *DynamORMCostTracker) Reset()

Reset resets the cost tracking counters

func (*DynamORMCostTracker) TrackBatchWrite

func (ct *DynamORMCostTracker) TrackBatchWrite(ctx context.Context, tableName string, itemCount int, fn func() error) error

TrackBatchWrite wraps a DynamORM batch write operation with cost tracking

func (*DynamORMCostTracker) TrackComprehendRequest

func (ct *DynamORMCostTracker) TrackComprehendRequest(operation string, units int)

TrackComprehendRequest tracks AWS Comprehend API requests for cost tracking

func (*DynamORMCostTracker) TrackDelete

func (ct *DynamORMCostTracker) TrackDelete(ctx context.Context, tableName string, fn func() error) error

TrackDelete wraps a DynamORM delete operation with cost tracking

func (*DynamORMCostTracker) TrackOperation

func (ct *DynamORMCostTracker) TrackOperation(ctx context.Context, operation string, fn func() error) error

TrackOperation wraps a DynamORM operation with cost tracking

func (*DynamORMCostTracker) TrackPut

func (ct *DynamORMCostTracker) TrackPut(ctx context.Context, tableName string, fn func() error) error

TrackPut wraps a DynamORM put operation with cost tracking

func (*DynamORMCostTracker) TrackQuery

func (ct *DynamORMCostTracker) TrackQuery(ctx context.Context, tableName string, fn func() error) error

TrackQuery wraps a DynamORM query operation with cost tracking

func (*DynamORMCostTracker) TrackTransaction

func (ct *DynamORMCostTracker) TrackTransaction(ctx context.Context, operationCount int, fn func() error) error

TrackTransaction wraps a DynamORM transaction with cost tracking

func (*DynamORMCostTracker) TrackTranscribeRequest

func (ct *DynamORMCostTracker) TrackTranscribeRequest(jobName string, estimatedMinutes int)

TrackTranscribeRequest tracks AWS Transcribe API requests for cost tracking

func (*DynamORMCostTracker) TrackUpdate

func (ct *DynamORMCostTracker) TrackUpdate(ctx context.Context, tableName string, fn func() error) error

TrackUpdate wraps a DynamORM update operation with cost tracking

type DynamoDBTracker

type DynamoDBTracker struct {
	// contains filtered or unexported fields
}

DynamoDBTracker provides DynamoDB-specific cost calculations

func NewDynamoDBTracker

func NewDynamoDBTracker() *DynamoDBTracker

NewDynamoDBTracker creates a new DynamoDB cost tracker

func (*DynamoDBTracker) CalculateCost

func (dt *DynamoDBTracker) CalculateCost(operation DynamoOperation) Cost

CalculateCost calculates the cost of a DynamoDB operation

type DynamoOperation

type DynamoOperation struct {
	Type               string    // "Query", "Scan", "PutItem", "UpdateItem", "DeleteItem", "BatchWrite"
	TableName          string    // Name of the DynamoDB table
	ConsumedReadUnits  int64     // Read capacity units consumed
	ConsumedWriteUnits int64     // Write capacity units consumed
	ItemCount          int64     // Number of items affected
	IndexName          string    // GSI name if applicable
	OperationID        string    // Unique operation identifier
	UserID             string    // User associated with the operation
	Timestamp          time.Time // When the operation occurred
}

DynamoOperation represents a DynamoDB operation for cost tracking

type EnhancedOperationTracker

type EnhancedOperationTracker struct {
	// contains filtered or unexported fields
}

EnhancedOperationTracker provides detailed operation tracking with metadata

func NewEnhancedOperationTracker

func NewEnhancedOperationTracker(logger *zap.Logger) *EnhancedOperationTracker

NewEnhancedOperationTracker creates a new enhanced operation tracker

func (*EnhancedOperationTracker) ClearOperations

func (eot *EnhancedOperationTracker) ClearOperations()

ClearOperations clears all tracked operations

func (*EnhancedOperationTracker) GetAllOperations

func (eot *EnhancedOperationTracker) GetAllOperations() map[string]*OperationMetadata

GetAllOperations returns all tracked operations

func (*EnhancedOperationTracker) GetOperationMetadata

func (eot *EnhancedOperationTracker) GetOperationMetadata(operationID string) (*OperationMetadata, bool)

GetOperationMetadata retrieves metadata for an operation

func (*EnhancedOperationTracker) TrackOperation

func (eot *EnhancedOperationTracker) TrackOperation(operationID string, metadata *OperationMetadata)

TrackOperation records detailed operation metadata

type HandlerFunc

HandlerFunc is the type for Lambda API Gateway v2 handlers

func WrapHandler

func WrapHandler(handler HandlerFunc, logger *zap.Logger) HandlerFunc

WrapHandler wraps a handler function with cost tracking

type JobExecution

type JobExecution struct {
	// Job identification
	JobName     string
	Schedule    string
	CronPattern string
	Category    string
	Priority    string

	// Execution context
	Environment       string
	Region            string
	FunctionName      string
	RequestID         string
	ScheduledTime     time.Time
	NextScheduledTime time.Time

	// Execution timing
	StartTime time.Time
	EndTime   time.Time
	// contains filtered or unexported fields
}

JobExecution represents a tracked job execution

func NewJobExecution

func NewJobExecution(jobName, schedule string) *JobExecution

NewJobExecution creates a new job execution tracker

func (*JobExecution) AddTag

func (je *JobExecution) AddTag(key, value string)

AddTag adds a tag

func (*JobExecution) FinishWithCancellation

func (je *JobExecution) FinishWithCancellation(ctx context.Context, tracker *ScheduledJobCostTracker) error

FinishWithCancellation marks the job as cancelled and persists the cost record

func (*JobExecution) FinishWithError

func (je *JobExecution) FinishWithError(ctx context.Context, tracker *ScheduledJobCostTracker, errorMessage string) error

FinishWithError marks the job as failed and persists the cost record

func (*JobExecution) FinishWithSuccess

func (je *JobExecution) FinishWithSuccess(ctx context.Context, tracker *ScheduledJobCostTracker) error

FinishWithSuccess marks the job as successfully completed and persists the cost record

func (*JobExecution) FinishWithTimeout

func (je *JobExecution) FinishWithTimeout(ctx context.Context, tracker *ScheduledJobCostTracker) error

FinishWithTimeout marks the job as timed out and persists the cost record

func (*JobExecution) GetRecord

func (je *JobExecution) GetRecord() *models.ScheduledJobCostRecord

GetRecord returns the persisted cost record (if execution is finished)

func (*JobExecution) MarkError

func (je *JobExecution) MarkError(errorMessage string, retryCount, maxRetries int)

MarkError marks the job execution as failed with error details

func (*JobExecution) SetBatchSize

func (je *JobExecution) SetBatchSize(size int)

SetBatchSize sets the batch size used

func (*JobExecution) SetPerformanceMetric

func (je *JobExecution) SetPerformanceMetric(key string, value float64)

SetPerformanceMetric sets a performance metric

func (*JobExecution) SetProperty

func (je *JobExecution) SetProperty(key string, value interface{})

SetProperty sets a custom property

func (*JobExecution) TrackCascadingCosts

func (je *JobExecution) TrackCascadingCosts(triggeredJobs []string, costMicroCents int64, downstreamOps int64)

TrackCascadingCosts tracks costs of operations triggered by this job

func (*JobExecution) TrackCloudWatchLogs

func (je *JobExecution) TrackCloudWatchLogs(logEntries int64)

TrackCloudWatchLogs tracks CloudWatch logs written

func (*JobExecution) TrackDataTransfer

func (je *JobExecution) TrackDataTransfer(bytes int64)

TrackDataTransfer tracks data transfer volume

func (*JobExecution) TrackDynamoDBUsage

func (je *JobExecution) TrackDynamoDBUsage(readOps, writeOps int64, readCapacity, writeCapacity float64)

TrackDynamoDBUsage tracks DynamoDB operations and capacity

func (*JobExecution) TrackExternalAPIRequests

func (je *JobExecution) TrackExternalAPIRequests(requests int64)

TrackExternalAPIRequests tracks external API calls

func (*JobExecution) TrackItemsProcessed

func (je *JobExecution) TrackItemsProcessed(processed, skipped, errored int64)

TrackItemsProcessed tracks business logic metrics

func (*JobExecution) TrackLambdaUsage

func (je *JobExecution) TrackLambdaUsage(invocations, durationMs int64, memoryMB int)

TrackLambdaUsage tracks Lambda resource usage

func (*JobExecution) TrackS3Usage

func (je *JobExecution) TrackS3Usage(operations int64)

TrackS3Usage tracks S3 operations

func (*JobExecution) TrackSQSUsage

func (je *JobExecution) TrackSQSUsage(messages int64)

TrackSQSUsage tracks SQS message processing

func (*JobExecution) WithCategory

func (je *JobExecution) WithCategory(category string) *JobExecution

WithCategory sets the job category

func (*JobExecution) WithContext

func (je *JobExecution) WithContext(environment, region, functionName, requestID string) *JobExecution

WithContext sets the execution context

func (*JobExecution) WithPriority

func (je *JobExecution) WithPriority(priority string) *JobExecution

WithPriority sets the job priority

func (*JobExecution) WithScheduling

func (je *JobExecution) WithScheduling(cronPattern string, scheduledTime, nextScheduledTime time.Time) *JobExecution

WithScheduling sets scheduling information

type JobStepExecution

type JobStepExecution struct {
	StepName  string
	StartTime time.Time
	EndTime   time.Time
	Status    string
	Error     string
	// contains filtered or unexported fields
}

JobStepExecution represents a single step in a multi-step job

func (*JobStepExecution) SetStepMetric

func (step *JobStepExecution) SetStepMetric(key string, value float64)

SetStepMetric sets a step-specific metric

func (*JobStepExecution) SetStepProperty

func (step *JobStepExecution) SetStepProperty(key string, value interface{})

SetStepProperty sets a step-specific property

func (*JobStepExecution) TrackStepDynamoDBUsage

func (step *JobStepExecution) TrackStepDynamoDBUsage(operations int64)

TrackStepDynamoDBUsage tracks DynamoDB usage for the current step

func (*JobStepExecution) TrackStepItemsProcessed

func (step *JobStepExecution) TrackStepItemsProcessed(processed, errored int64)

TrackStepItemsProcessed tracks items processed for the current step

func (*JobStepExecution) TrackStepLambdaUsage

func (step *JobStepExecution) TrackStepLambdaUsage(durationMs int64)

TrackStepLambdaUsage tracks Lambda usage for the current step

type LambdaOperation

type LambdaOperation struct {
	FunctionName string        // Name of the Lambda function
	Duration     time.Duration // Actual execution duration
	MemoryMB     int64         // Memory allocated in MB
	MemoryUsedMB int64         // Memory actually used (if available)
	ColdStart    bool          // Whether this was a cold start
	RequestID    string        // Lambda request ID
	UserID       string        // User associated with the invocation
	Timestamp    time.Time     // When the invocation occurred
}

LambdaOperation represents a Lambda invocation for cost tracking

type LambdaTracker

type LambdaTracker struct {
	// contains filtered or unexported fields
}

LambdaTracker provides Lambda-specific cost calculations

func NewLambdaTracker

func NewLambdaTracker() *LambdaTracker

NewLambdaTracker creates a new Lambda cost tracker

func (*LambdaTracker) CalculateCost

func (lt *LambdaTracker) CalculateCost(operation LambdaOperation) Cost

CalculateCost calculates the cost of a Lambda invocation

type MetricData

type MetricData struct {
	Name       string             // Metric name
	Value      float64            // Metric value
	Unit       types.StandardUnit // CloudWatch unit
	Dimensions []types.Dimension  // CloudWatch dimensions
	Timestamp  time.Time          // Metric timestamp
}

MetricData represents a custom metric to be sent to CloudWatch

type MonthlyCostAggregate

type MonthlyCostAggregate struct {
	Year                    int
	Month                   int
	TotalCostMicrocents     int64
	ProjectedCostMicrocents int64
	RequestCount            int64
	UniqueUsers             int64
	DynamoDBReads           int64
	DynamoDBWrites          int64
	LambdaInvocations       int64
	LambdaDurationMs        int64
	DataTransferGB          float64
}

MonthlyCostAggregate represents aggregated costs for a month.

type MultiStepJobExecution

type MultiStepJobExecution struct {
	*JobExecution
	// contains filtered or unexported fields
}

MultiStepJobExecution tracks a job with multiple steps/subtasks

func NewMultiStepJobExecution

func NewMultiStepJobExecution(jobName, schedule string) *MultiStepJobExecution

NewMultiStepJobExecution creates a new multi-step job execution tracker

func (*MultiStepJobExecution) FinishStep

func (msje *MultiStepJobExecution) FinishStep(stepName, status string, err error)

FinishStep completes tracking for a step

func (*MultiStepJobExecution) GetCurrentStep

func (msje *MultiStepJobExecution) GetCurrentStep() *JobStepExecution

GetCurrentStep returns the currently executing step

func (*MultiStepJobExecution) GetStepSummary

func (msje *MultiStepJobExecution) GetStepSummary() map[string]*JobStepExecution

GetStepSummary returns a summary of all steps

func (*MultiStepJobExecution) StartStep

func (msje *MultiStepJobExecution) StartStep(stepName string) *JobStepExecution

StartStep starts tracking a new step

type OperationCost

type OperationCost struct {
	DynamoDBReads       int64     `json:"dynamodb_reads"`
	DynamoDBWrites      int64     `json:"dynamodb_writes"`
	DynamoDBStorage     int64     `json:"dynamodb_storage_bytes"`
	LambdaInvocations   int64     `json:"lambda_invocations"`
	LambdaDurationMs    int64     `json:"lambda_duration_ms"`
	LambdaMemoryMB      int64     `json:"lambda_memory_mb"`
	S3Gets              int64     `json:"s3_gets"`
	S3Puts              int64     `json:"s3_puts"`
	S3Storage           int64     `json:"s3_storage_bytes"`
	DataTransferBytes   int64     `json:"data_transfer_bytes"`
	TotalCostMicroCents int64     `json:"total_cost_microcents"`
	Timestamp           time.Time `json:"timestamp"`
	OperationType       string    `json:"operation_type"`
	RequestID           string    `json:"request_id"`
}

OperationCost represents the cost breakdown of a single operation

type OperationInfo

type OperationInfo struct {
	Type         string        // Operation type (e.g., "DynamoDB.Read", "S3.Put")
	ResourceName string        // Resource name (table name, bucket name, function name)
	Units        int64         // Capacity units (for DynamoDB)
	Bytes        int64         // Bytes transferred (for S3)
	Duration     time.Duration // Duration (for Lambda)
	MemoryMB     int64         // Memory allocation (for Lambda)
}

OperationInfo represents information about an operation to be tracked

type OperationMetadata

type OperationMetadata struct {
	OperationType     string            `json:"operation_type"`
	TableName         string            `json:"table_name"`
	IndexName         string            `json:"index_name,omitempty"`
	ItemCount         int               `json:"item_count"`
	FilterExpressions []string          `json:"filter_expressions,omitempty"`
	ProjectionFields  []string          `json:"projection_fields,omitempty"`
	ConsistentRead    bool              `json:"consistent_read"`
	BatchSize         int               `json:"batch_size,omitempty"`
	PaginationTokens  map[string]string `json:"pagination_tokens,omitempty"`
	Conditions        []QueryCondition  `json:"conditions,omitempty"`
}

OperationMetadata contains detailed information about a DynamoDB operation

type OptimizationSuggestion

type OptimizationSuggestion struct {
	Category         string `json:"category"`          // "DynamoDB", "S3", "Lambda", etc.
	Suggestion       string `json:"suggestion"`        // Human-readable suggestion
	EstimatedSavings int64  `json:"estimated_savings"` // Estimated savings in microcents
	Priority         string `json:"priority"`          // "High", "Medium", "Low"
	Effort           string `json:"effort"`            // "Low", "Medium", "High"
}

OptimizationSuggestion provides cost optimization recommendations

type QueryCondition

type QueryCondition struct {
	Field    string `json:"field"`
	Operator string `json:"operator"`
	Value    string `json:"value"` // Simplified for logging
}

QueryCondition represents a query condition for cost analysis

type S3API

type S3API interface {
	GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
	PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
	DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)
	HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error)
	ListObjectsV2(ctx context.Context, params *s3.ListObjectsV2Input, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)
}

S3API defines the subset of S3 operations we use

type S3CostWrapper

type S3CostWrapper struct {
	// contains filtered or unexported fields
}

S3CostWrapper wraps an S3 client to track costs

func NewS3Wrapper

func NewS3Wrapper(client S3API) *S3CostWrapper

NewS3Wrapper creates a new cost-tracking S3 wrapper

func (*S3CostWrapper) DeleteObject

func (w *S3CostWrapper) DeleteObject(ctx context.Context, params *s3.DeleteObjectInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectOutput, error)

DeleteObject tracks the cost of an S3 DeleteObject operation

func (*S3CostWrapper) GetObject

func (w *S3CostWrapper) GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)

GetObject tracks the cost of an S3 GetObject operation

func (*S3CostWrapper) HeadObject

func (w *S3CostWrapper) HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error)

HeadObject tracks the cost of an S3 HeadObject operation

func (*S3CostWrapper) ListObjectsV2

func (w *S3CostWrapper) ListObjectsV2(ctx context.Context, params *s3.ListObjectsV2Input, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)

ListObjectsV2 tracks the cost of an S3 ListObjectsV2 operation

func (*S3CostWrapper) PutObject

func (w *S3CostWrapper) PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)

PutObject tracks the cost of an S3 PutObject operation

type S3Operation

type S3Operation struct {
	Type             string    // "PutObject", "GetObject", "DeleteObject", "ListObjects"
	BucketName       string    // Name of the S3 bucket
	ObjectKey        string    // S3 object key
	RequestCount     int64     // Number of requests
	BytesTransferred int64     // Bytes uploaded/downloaded
	StorageClass     string    // Standard, IA, Glacier, etc.
	OperationID      string    // Unique operation identifier
	UserID           string    // User associated with the operation
	Timestamp        time.Time // When the operation occurred
}

S3Operation represents an S3 operation for cost tracking

type S3Tracker

type S3Tracker struct {
	// contains filtered or unexported fields
}

S3Tracker provides S3-specific cost calculations

func NewS3Tracker

func NewS3Tracker() *S3Tracker

NewS3Tracker creates a new S3 cost tracker

func (*S3Tracker) CalculateCost

func (st *S3Tracker) CalculateCost(operation S3Operation) Cost

CalculateCost calculates the cost of an S3 operation

type ScheduledJobCostRepository

type ScheduledJobCostRepository interface {
	Create(ctx context.Context, record *models.ScheduledJobCostRecord) error
	Update(ctx context.Context, record *models.ScheduledJobCostRecord) error
	GetByID(ctx context.Context, id string) (*models.ScheduledJobCostRecord, error)
	ListByJob(ctx context.Context, jobName, schedule string, startTime, endTime time.Time, limit int) ([]*models.ScheduledJobCostRecord, error)
	ListByStatus(ctx context.Context, status string, startTime, endTime time.Time, limit int) ([]*models.ScheduledJobCostRecord, error)
	ListByDateRange(ctx context.Context, startDate, endDate time.Time, limit int) ([]*models.ScheduledJobCostRecord, error)
	GetFailedJobs(ctx context.Context, startTime, endTime time.Time, limit int) ([]*models.ScheduledJobCostRecord, error)
	GetLongRunningJobs(ctx context.Context, thresholdMs int64, startTime, endTime time.Time, limit int) ([]*models.ScheduledJobCostRecord, error)
	GetHighCostJobs(ctx context.Context, thresholdDollars float64, startTime, endTime time.Time, limit int) ([]*models.ScheduledJobCostRecord, error)
	AggregateJobCosts(ctx context.Context, jobName, period string, windowStart, windowEnd time.Time) error
}

ScheduledJobCostRepository defines the interface for scheduled job cost persistence

type ScheduledJobCostTracker

type ScheduledJobCostTracker struct {
	// contains filtered or unexported fields
}

ScheduledJobCostTracker tracks costs for scheduled/cron jobs

func NewScheduledJobCostTracker

func NewScheduledJobCostTracker(repository ScheduledJobCostRepository, logger *zap.Logger) *ScheduledJobCostTracker

NewScheduledJobCostTracker creates a new scheduled job cost tracker

func (*ScheduledJobCostTracker) AggregateJobCosts

func (tracker *ScheduledJobCostTracker) AggregateJobCosts(ctx context.Context, jobName, period string, windowStart, windowEnd time.Time) error

AggregateJobCosts performs aggregation of scheduled job costs

func (*ScheduledJobCostTracker) GetFailedJobs

func (tracker *ScheduledJobCostTracker) GetFailedJobs(ctx context.Context, startTime, endTime time.Time, limit int) ([]*models.ScheduledJobCostRecord, error)

GetFailedJobs retrieves failed job executions

func (*ScheduledJobCostTracker) GetHighCostJobs

func (tracker *ScheduledJobCostTracker) GetHighCostJobs(ctx context.Context, thresholdDollars float64, startTime, endTime time.Time, limit int) ([]*models.ScheduledJobCostRecord, error)

GetHighCostJobs retrieves high-cost job executions

func (*ScheduledJobCostTracker) GetLongRunningJobs

func (tracker *ScheduledJobCostTracker) GetLongRunningJobs(ctx context.Context, thresholdMs int64, startTime, endTime time.Time, limit int) ([]*models.ScheduledJobCostRecord, error)

GetLongRunningJobs retrieves long-running job executions

func (*ScheduledJobCostTracker) TrackCleanupJob

func (tracker *ScheduledJobCostTracker) TrackCleanupJob(_ context.Context, cleanupType string, schedule string) (*JobExecution, error)

TrackCleanupJob tracks cleanup jobs (expired data, old logs, etc.)

func (*ScheduledJobCostTracker) TrackCostAggregationJob

func (tracker *ScheduledJobCostTracker) TrackCostAggregationJob(_ context.Context, period string, windowStart, windowEnd time.Time) (*JobExecution, error)

TrackCostAggregationJob tracks the cost aggregation job itself

func (*ScheduledJobCostTracker) TrackDeadLetterQueueProcessingJob

func (tracker *ScheduledJobCostTracker) TrackDeadLetterQueueProcessingJob(_ context.Context, queueName string) (*JobExecution, error)

TrackDeadLetterQueueProcessingJob tracks DLQ processing jobs

func (*ScheduledJobCostTracker) TrackIndexOptimizationJob

func (tracker *ScheduledJobCostTracker) TrackIndexOptimizationJob(_ context.Context, tableName string) (*JobExecution, error)

TrackIndexOptimizationJob tracks database index optimization jobs

func (*ScheduledJobCostTracker) TrackTrendCalculationJob

func (tracker *ScheduledJobCostTracker) TrackTrendCalculationJob(_ context.Context, trendType string, schedule string) (*JobExecution, error)

TrackTrendCalculationJob tracks trend calculation jobs

type ServiceMetric

type ServiceMetric struct {
	Name  string
	Value float64
	Unit  types.StandardUnit
}

ServiceMetric represents a metric specific to a service

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage handles persistence of cost data.

It is intentionally TableTheory-backed: Lesser does not use direct DynamoDB SDK calls.

func NewStorage

func NewStorage(db core.DB, tableName string, logger *zap.Logger) *Storage

NewStorage creates a new cost storage instance.

func (*Storage) SaveOperationCost

func (s *Storage) SaveOperationCost(ctx context.Context, cost *OperationCost) error

SaveOperationCost saves a single operation cost record.

type Summary

type Summary struct {
	TotalCostMicroCents      int64                    `json:"total_cost_microcents"`
	ServiceBreakdown         map[string]int64         `json:"service_breakdown"`
	OperationBreakdown       map[string]int64         `json:"operation_breakdown"`
	HourlyBreakdown          map[string]int64         `json:"hourly_breakdown"`
	TopDrivers               []Driver                 `json:"top_drivers"`
	CostTrends               []TrendPoint             `json:"cost_trends"`
	BudgetUtilization        float64                  `json:"budget_utilization"`
	ProjectedMonthlyCost     int64                    `json:"projected_monthly_cost"`
	RecommendedOptimizations []OptimizationSuggestion `json:"optimizations"`
}

Summary provides aggregated cost information across all services

type Thresholds

type Thresholds struct {
	DynamoDBReadWarning     float64 // dollars
	DynamoDBWriteWarning    float64 // dollars
	S3OperationWarning      float64 // dollars
	LambdaInvocationWarning float64 // dollars
	DailyBudgetLimit        float64 // dollars
}

Thresholds defines cost alert thresholds for various AWS services

type Tracker

type Tracker struct {
	// contains filtered or unexported fields
}

Tracker provides thread-safe cost tracking for operations

func FromContext

func FromContext(ctx context.Context) *Tracker

FromContext retrieves the cost tracker from the context Returns nil if no tracker is found

func New

func New() *Tracker

New creates a new cost tracker

func NewWithRequest

func NewWithRequest(requestID, operationType string) *Tracker

NewWithRequest creates a new cost tracker with request context

func (*Tracker) CalculateCost

func (t *Tracker) CalculateCost() *OperationCost

CalculateCost calculates the total cost of tracked operations

func (*Tracker) Clone

func (t *Tracker) Clone() *Tracker

Clone creates a copy of the tracker with current values

func (*Tracker) Merge

func (t *Tracker) Merge(other *Tracker)

Merge combines costs from another tracker

func (*Tracker) Reset

func (t *Tracker) Reset()

Reset resets all counters

func (*Tracker) TrackDataTransfer

func (t *Tracker) TrackDataTransfer(bytes int64)

TrackDataTransfer tracks data transfer out

func (*Tracker) TrackDynamoRead

func (t *Tracker) TrackDynamoRead(items int) error

TrackDynamoRead tracks DynamoDB read operations

func (*Tracker) TrackDynamoStorage

func (t *Tracker) TrackDynamoStorage(bytes int64)

TrackDynamoStorage tracks DynamoDB storage usage

func (*Tracker) TrackDynamoWrite

func (t *Tracker) TrackDynamoWrite(items int) error

TrackDynamoWrite tracks DynamoDB write operations

func (*Tracker) TrackLambdaInvocation

func (t *Tracker) TrackLambdaInvocation(durationMs int64, memoryMB int64)

TrackLambdaInvocation tracks Lambda invocation

func (*Tracker) TrackS3Get

func (t *Tracker) TrackS3Get(count int)

TrackS3Get tracks S3 GET operations

func (*Tracker) TrackS3Put

func (t *Tracker) TrackS3Put(count int)

TrackS3Put tracks S3 PUT operations

func (*Tracker) TrackS3Storage

func (t *Tracker) TrackS3Storage(bytes int64)

TrackS3Storage tracks S3 storage usage

type TrackingDB

type TrackingDB struct {
	core.DB
	// contains filtered or unexported fields
}

TrackingDB implements the core.DB interface with cost tracking

func NewTrackingDB

func NewTrackingDB(db core.DB, tracker *Tracker, logger *zap.Logger) *TrackingDB

NewTrackingDB creates a new cost tracking DB wrapper

func (*TrackingDB) GetTracker

func (ctdb *TrackingDB) GetTracker() *Tracker

GetTracker returns the cost tracker

func (*TrackingDB) Model

func (ctdb *TrackingDB) Model(model any) core.Query

Model wraps the Model method with enhanced cost tracking context

func (*TrackingDB) Transaction

func (ctdb *TrackingDB) Transaction(fn func(*core.Tx) error) error

Transaction wraps the Transaction method with enhanced operation estimation

type TrackingQuery

type TrackingQuery struct {
	// contains filtered or unexported fields
}

TrackingQuery wraps core.Query with enhanced cost tracking

func (*TrackingQuery) All

func (ctq *TrackingQuery) All(dest any) error

All wraps the All method with enhanced result counting

func (*TrackingQuery) AllPaginated

func (ctq *TrackingQuery) AllPaginated(dest any) (*core.PaginatedResult, error)

AllPaginated wraps the AllPaginated method with cost tracking

func (*TrackingQuery) BatchCreate

func (ctq *TrackingQuery) BatchCreate(items any) error

BatchCreate wraps the BatchCreate method with enhanced batch tracking

func (*TrackingQuery) BatchDelete

func (ctq *TrackingQuery) BatchDelete(keys []any) error

BatchDelete wraps the BatchDelete method with enhanced batch tracking

func (*TrackingQuery) BatchGet

func (ctq *TrackingQuery) BatchGet(keys []any, dest any) error

BatchGet wraps the BatchGet method with cost tracking

func (*TrackingQuery) BatchGetBuilder

func (ctq *TrackingQuery) BatchGetBuilder() core.BatchGetBuilder

BatchGetBuilder wraps the BatchGetBuilder for additional tracking

func (*TrackingQuery) BatchGetWithOptions

func (ctq *TrackingQuery) BatchGetWithOptions(keys []any, dest any, opts *core.BatchGetOptions) error

BatchGetWithOptions wraps the BatchGetWithOptions method with cost tracking

func (*TrackingQuery) BatchUpdateWithOptions

func (ctq *TrackingQuery) BatchUpdateWithOptions(items []any, fields []string, options ...any) error

BatchUpdateWithOptions wraps the BatchUpdateWithOptions method with cost tracking

func (*TrackingQuery) BatchWrite

func (ctq *TrackingQuery) BatchWrite(putItems []any, deleteKeys []any) error

BatchWrite wraps the BatchWrite method with enhanced batch tracking

func (*TrackingQuery) ConsistentRead

func (ctq *TrackingQuery) ConsistentRead() core.Query

ConsistentRead wraps the ConsistentRead method with read type tracking

func (*TrackingQuery) Count

func (ctq *TrackingQuery) Count() (int64, error)

Count wraps the Count method with cost tracking

func (*TrackingQuery) Create

func (ctq *TrackingQuery) Create() error

Create wraps the Create method with cost tracking

func (*TrackingQuery) CreateOrUpdate

func (ctq *TrackingQuery) CreateOrUpdate() error

CreateOrUpdate wraps the CreateOrUpdate method with cost tracking

func (*TrackingQuery) Cursor

func (ctq *TrackingQuery) Cursor(cursor string) core.Query

Cursor wraps the Cursor method

func (*TrackingQuery) Delete

func (ctq *TrackingQuery) Delete() error

Delete wraps the Delete method with cost tracking

func (*TrackingQuery) Filter

func (ctq *TrackingQuery) Filter(field string, op string, value any) core.Query

Filter wraps the Filter method with filter expression tracking

func (*TrackingQuery) FilterGroup

func (ctq *TrackingQuery) FilterGroup(fn func(core.Query)) core.Query

FilterGroup wraps the FilterGroup method

func (*TrackingQuery) First

func (ctq *TrackingQuery) First(dest any) error

First wraps the First method with enhanced tracking

func (*TrackingQuery) IfExists

func (ctq *TrackingQuery) IfExists() core.Query

IfExists wraps the IfExists method

func (*TrackingQuery) IfNotExists

func (ctq *TrackingQuery) IfNotExists() core.Query

IfNotExists wraps the IfNotExists method

func (*TrackingQuery) Index

func (ctq *TrackingQuery) Index(indexName string) core.Query

Index wraps the Index method with GSI tracking

func (*TrackingQuery) Limit

func (ctq *TrackingQuery) Limit(limit int) core.Query

Limit wraps the Limit method

func (*TrackingQuery) Offset

func (ctq *TrackingQuery) Offset(offset int) core.Query

Offset wraps the Offset method

func (*TrackingQuery) OrFilter

func (ctq *TrackingQuery) OrFilter(field string, op string, value any) core.Query

OrFilter wraps the OrFilter method

func (*TrackingQuery) OrFilterGroup

func (ctq *TrackingQuery) OrFilterGroup(fn func(core.Query)) core.Query

OrFilterGroup wraps the OrFilterGroup method

func (*TrackingQuery) OrderBy

func (ctq *TrackingQuery) OrderBy(field string, order string) core.Query

OrderBy wraps the OrderBy method

func (*TrackingQuery) ParallelScan

func (ctq *TrackingQuery) ParallelScan(segment int32, totalSegments int32) core.Query

ParallelScan wraps the ParallelScan method

func (*TrackingQuery) Scan

func (ctq *TrackingQuery) Scan(dest any) error

Scan wraps the Scan method with cost tracking

func (*TrackingQuery) ScanAllSegments

func (ctq *TrackingQuery) ScanAllSegments(dest any, totalSegments int32) error

ScanAllSegments wraps the ScanAllSegments method with cost tracking

func (*TrackingQuery) Select

func (ctq *TrackingQuery) Select(fields ...string) core.Query

Select wraps the Select method with projection tracking

func (*TrackingQuery) SetCursor

func (ctq *TrackingQuery) SetCursor(cursor string) error

SetCursor wraps the SetCursor method

func (*TrackingQuery) Update

func (ctq *TrackingQuery) Update(fields ...string) error

Update wraps the Update method with cost tracking

func (*TrackingQuery) UpdateBuilder

func (ctq *TrackingQuery) UpdateBuilder() core.UpdateBuilder

UpdateBuilder wraps the UpdateBuilder method

func (*TrackingQuery) Where

func (ctq *TrackingQuery) Where(field string, op string, value any) core.Query

Where wraps the Where method with condition tracking

func (*TrackingQuery) WithCondition

func (ctq *TrackingQuery) WithCondition(field, operator string, value any) core.Query

WithCondition wraps the WithCondition method

func (*TrackingQuery) WithConditionExpression

func (ctq *TrackingQuery) WithConditionExpression(expr string, values map[string]any) core.Query

WithConditionExpression wraps the WithConditionExpression method

func (*TrackingQuery) WithContext

func (ctq *TrackingQuery) WithContext(ctx context.Context) core.Query

WithContext wraps the WithContext method

func (*TrackingQuery) WithRetry

func (ctq *TrackingQuery) WithRetry(maxRetries int, initialDelay time.Duration) core.Query

WithRetry wraps the WithRetry method

type TrackingRepository

type TrackingRepository interface {
	// Store cost records
	StoreCost(ctx context.Context, cost *Cost) error
	StoreCostBatch(ctx context.Context, costs []*Cost) error

	// Retrieve cost information
	GetCostSummary(ctx context.Context, startTime, endTime time.Time) (*Summary, error)
	GetServiceCosts(ctx context.Context, service string, startTime, endTime time.Time) ([]*Cost, error)
	GetUserCosts(ctx context.Context, userID string, startTime, endTime time.Time) ([]*Cost, error)

	// Cost analysis
	GetTopDrivers(ctx context.Context, startTime, endTime time.Time, limit int) ([]Driver, error)
	GetCostTrends(ctx context.Context, startTime, endTime time.Time, granularity string) ([]TrendPoint, error)
	GetOptimizationSuggestions(ctx context.Context, lookbackDays int) ([]OptimizationSuggestion, error)
}

TrackingRepository interface for cost tracking storage

type TrackingService

type TrackingService struct {
	// contains filtered or unexported fields
}

TrackingService provides centralized cost tracking for all AWS operations

func NewCostTrackingService

func NewCostTrackingService(cloudWatch *cloudwatch.Client, logger *zap.Logger) *TrackingService

NewCostTrackingService creates a tracking service with default configuration

func NewCostTrackingServiceForLambda

func NewCostTrackingServiceForLambda(cloudWatch *cloudwatch.Client, logger *zap.Logger, functionName string) *TrackingService

NewCostTrackingServiceForLambda creates a tracking service optimized for Lambda environments

func NewCostTrackingServiceForRepository

func NewCostTrackingServiceForRepository(cloudWatch *cloudwatch.Client, logger *zap.Logger, repositoryName string) *TrackingService

NewCostTrackingServiceForRepository creates a tracking service optimized for repository operations

func NewTrackingService

func NewTrackingService(cloudWatch *cloudwatch.Client, logger *zap.Logger, config TrackingServiceConfig) *TrackingService

NewTrackingService creates a new centralized cost tracking service

func (*TrackingService) Close

func (ts *TrackingService) Close(ctx context.Context) error

Close gracefully shuts down the tracking service

func (*TrackingService) RecordMetrics

func (ts *TrackingService) RecordMetrics(ctx context.Context, metrics []MetricData) error

RecordMetrics records a batch of custom metrics to CloudWatch

func (*TrackingService) TrackDynamoOperation

func (ts *TrackingService) TrackDynamoOperation(ctx context.Context, operation DynamoOperation) error

TrackDynamoOperation tracks a DynamoDB operation with comprehensive cost calculation

func (*TrackingService) TrackLambdaInvocation

func (ts *TrackingService) TrackLambdaInvocation(ctx context.Context, operation LambdaOperation) error

TrackLambdaInvocation tracks a Lambda invocation with cost calculation

func (*TrackingService) TrackS3Operation

func (ts *TrackingService) TrackS3Operation(ctx context.Context, operation S3Operation) error

TrackS3Operation tracks an S3 operation with cost calculation

type TrackingServiceConfig

type TrackingServiceConfig struct {
	CloudWatchNamespace   string
	MetricsBatchSize      int
	MetricsFlushInterval  time.Duration
	EnableDetailedMetrics bool
	CostThresholds        Thresholds
}

TrackingServiceConfig contains configuration for the centralized cost tracking service

func DefaultTrackingServiceConfig

func DefaultTrackingServiceConfig() TrackingServiceConfig

DefaultTrackingServiceConfig returns sensible defaults for cost tracking

type TrendPoint

type TrendPoint struct {
	Timestamp      time.Time `json:"timestamp"`
	CostMicroCents int64     `json:"cost_microcents"`
	OperationCount int64     `json:"operation_count"`
}

TrendPoint represents a point in cost trends over time for analysis

type UnifiedCostTracker

type UnifiedCostTracker interface {
	// DynamoDB operations
	TrackDynamoRead(ctx context.Context, tableName string, units int64) error
	TrackDynamoWrite(ctx context.Context, tableName string, units int64) error
	TrackDynamoQuery(ctx context.Context, tableName string, units int64) error
	TrackDynamoScan(ctx context.Context, tableName string, units int64) error

	// S3 operations
	TrackS3Get(ctx context.Context, bucketName string, bytes int64) error
	TrackS3Put(ctx context.Context, bucketName string, bytes int64) error
	TrackS3Delete(ctx context.Context, bucketName string) error

	// Lambda operations
	TrackLambdaInvocation(ctx context.Context, functionName string, duration time.Duration, memoryMB int64) error

	// Metrics and reporting
	GetCurrentCostMicroCents() int64
	GetCostBreakdown() map[string]int64
	Reset()
}

UnifiedCostTracker provides a simplified interface for common cost tracking operations

type UnifiedTracker

type UnifiedTracker struct {
	// contains filtered or unexported fields
}

UnifiedTracker implements the UnifiedCostTracker interface using the centralized tracking service

func NewBatchTracker

func NewBatchTracker(cloudWatch *cloudwatch.Client, logger *zap.Logger, batchJobName, userID, requestID string) *UnifiedTracker

NewBatchTracker creates a cost tracker optimized for batch operations

func NewLambdaUnifiedTracker

func NewLambdaUnifiedTracker(cloudWatch *cloudwatch.Client, logger *zap.Logger, functionName, userID, requestID string) *UnifiedTracker

NewLambdaUnifiedTracker creates a cost tracker optimized for Lambda function operations

func NewRepositoryTracker

func NewRepositoryTracker(cloudWatch *cloudwatch.Client, logger *zap.Logger, repositoryName, userID, requestID string) *UnifiedTracker

NewRepositoryTracker creates a cost tracker optimized for repository operations

func NewRequestTracker

func NewRequestTracker(cloudWatch *cloudwatch.Client, logger *zap.Logger, endpoint, userID, requestID string) *UnifiedTracker

NewRequestTracker creates a cost tracker for a specific HTTP request

func NewUnifiedTracker

func NewUnifiedTracker(cloudWatch *cloudwatch.Client, logger *zap.Logger, userID, requestID string) *UnifiedTracker

NewUnifiedTracker creates a new unified cost tracker

func NewUnifiedTrackerWithService

func NewUnifiedTrackerWithService(service *TrackingService, logger *zap.Logger, userID, requestID string) *UnifiedTracker

NewUnifiedTrackerWithService creates a unified tracker using an existing tracking service

func (*UnifiedTracker) Close

func (ut *UnifiedTracker) Close(ctx context.Context) error

Close gracefully shuts down the unified tracker

func (*UnifiedTracker) GetCostBreakdown

func (ut *UnifiedTracker) GetCostBreakdown() map[string]int64

GetCostBreakdown returns cost breakdown by service

func (*UnifiedTracker) GetCostDollars

func (ut *UnifiedTracker) GetCostDollars() float64

GetCostDollars returns the total cost in dollars

func (*UnifiedTracker) GetCurrentCostMicroCents

func (ut *UnifiedTracker) GetCurrentCostMicroCents() int64

GetCurrentCostMicroCents returns the total accumulated cost in microcents

func (*UnifiedTracker) GetOperationCounts

func (ut *UnifiedTracker) GetOperationCounts() map[string]int64

GetOperationCounts returns the count of operations by type

func (*UnifiedTracker) Reset

func (ut *UnifiedTracker) Reset()

Reset clears all accumulated cost data

func (*UnifiedTracker) TrackDynamoOperationWithConsumedCapacity

func (ut *UnifiedTracker) TrackDynamoOperationWithConsumedCapacity(ctx context.Context, tableName, operationType string, consumedCapacity *ConsumedCapacity) error

TrackDynamoOperationWithConsumedCapacity tracks a DynamoDB operation using consumed capacity information

func (*UnifiedTracker) TrackDynamoQuery

func (ut *UnifiedTracker) TrackDynamoQuery(ctx context.Context, tableName string, units int64) error

TrackDynamoQuery tracks a DynamoDB query operation

func (*UnifiedTracker) TrackDynamoRead

func (ut *UnifiedTracker) TrackDynamoRead(ctx context.Context, tableName string, units int64) error

TrackDynamoRead tracks a DynamoDB read operation

func (*UnifiedTracker) TrackDynamoScan

func (ut *UnifiedTracker) TrackDynamoScan(ctx context.Context, tableName string, units int64) error

TrackDynamoScan tracks a DynamoDB scan operation

func (*UnifiedTracker) TrackDynamoWrite

func (ut *UnifiedTracker) TrackDynamoWrite(ctx context.Context, tableName string, units int64) error

TrackDynamoWrite tracks a DynamoDB write operation

func (*UnifiedTracker) TrackLambdaInvocation

func (ut *UnifiedTracker) TrackLambdaInvocation(ctx context.Context, functionName string, duration time.Duration, memoryMB int64) error

TrackLambdaInvocation tracks a Lambda function invocation

func (*UnifiedTracker) TrackMultipleOperations

func (ut *UnifiedTracker) TrackMultipleOperations(ctx context.Context, operations []OperationInfo) error

TrackMultipleOperations tracks multiple operations in a single call for efficiency

func (*UnifiedTracker) TrackS3Delete

func (ut *UnifiedTracker) TrackS3Delete(ctx context.Context, bucketName string) error

TrackS3Delete tracks an S3 delete operation

func (*UnifiedTracker) TrackS3Get

func (ut *UnifiedTracker) TrackS3Get(ctx context.Context, bucketName string, bytes int64) error

TrackS3Get tracks an S3 get operation

func (*UnifiedTracker) TrackS3Put

func (ut *UnifiedTracker) TrackS3Put(ctx context.Context, bucketName string, bytes int64) error

TrackS3Put tracks an S3 put operation

Jump to

Keyboard shortcuts

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