finops

package
v0.0.0-...-b85db87 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultRates = ResourceRates{
	CPUCoreHour:          0.032,
	RAMGBHour:            0.005,
	HeuristicPremium:     1.5,
	ExternalAPICost:      0.0001,
	AITokenCost:          0.0005,
	DropletStandardBasic: 0.00893,
	LoadBalancerStandard: 0.02232,
}

DefaultRates for DigitalOcean / K8s managed nodes

View Source
var Stats = &GlobalStats{}

Functions

This section is empty.

Types

type Estimator

type Estimator interface {
	Estimate(unit UnitCost) error
	GetProviderBurnRate(providerID string, lastNDays int) (float64, error)
}

Estimator interface for different storage/processing backends

type GlobalStats

type GlobalStats struct {
	TotalScrapes   int
	TotalDuration  time.Duration
	ExpensiveTasks []string
	// contains filtered or unexported fields
}

GlobalStats tracks real-time performance metrics

func (*GlobalStats) GetSummary

func (s *GlobalStats) GetSummary() map[string]any

GetSummary returns a summary of the statistics.

func (*GlobalStats) Record

func (s *GlobalStats) Record(cantorID string, duration time.Duration)

Record updates the statistics with the given cantor ID and task duration.

type GovernanceEngine

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

GovernanceEngine is responsible for enforcing FinOps guardrails. It monitors burn rates and dynamically blocks operations that exceed budgets.

func NewGovernanceEngine

func NewGovernanceEngine(estimator *TimescaleEstimator, dailyLimitUSD float64) *GovernanceEngine

NewGovernanceEngine creates a new FinOps guardrail system.

func (*GovernanceEngine) GetBlockedList

func (g *GovernanceEngine) GetBlockedList() []string

GetBlockedList returns the list of currently throttled ProviderIDs.

func (*GovernanceEngine) IsAllowed

func (g *GovernanceEngine) IsAllowed(providerID string) bool

IsAllowed checks if a provider is permitted to execute an operation. This is an O(1) in-memory check, critical for high-throughput systems.

func (*GovernanceEngine) StartMonitor

func (g *GovernanceEngine) StartMonitor(ctx context.Context, interval time.Duration)

StartMonitor begins a background routine that periodically evaluates burn rates.

type OptimizationTip

type OptimizationTip struct {
	Title       string
	Description string
	Potential   float64 // Estimated monthly savings
}

OptimizationTip provides actionable advice

func GenerateTips

func GenerateTips(dropletCount, lbCount int) []OptimizationTip

GenerateTips analyzes the current state and suggests savings

type ResourceRates

type ResourceRates struct {
	CPUCoreHour      float64
	RAMGBHour        float64
	HeuristicPremium float64
	ExternalAPICost  float64
	AITokenCost      float64 // Cost per AI request (estimated)
	// Legacy fields for compatibility
	DropletStandardBasic float64
	LoadBalancerStandard float64
}

ResourceRates defines hourly costs for resources.

func (ResourceRates) CalculateTaskCost

func (r ResourceRates) CalculateTaskCost(st ScraperType, duration time.Duration, cpuCores float64, memGB float64) float64

CalculateTaskCost computes the real-time cost of an operation based on resource consumption

func (ResourceRates) Summary

func (r ResourceRates) Summary(droplets, lbs int) string

Summary calculates the estimated monthly cost (Legacy compatibility)

type ScrapeMetric

type ScrapeMetric struct {
	CantorID     string
	Duration     time.Duration
	BytesFetched int
}

ScrapeMetric tracks the efficiency of data collection (Legacy compatibility)

type ScraperType

type ScraperType string

ScraperType defines the complexity of the operation

const (
	ScraperStatic    ScraperType = "static"
	ScraperHeuristic ScraperType = "heuristic"
	ScraperDiscovery ScraperType = "discovery" // e.g., Geocoding/URL Analysis
	ScraperLLM       ScraperType = "llm"       // AI-powered operations (Gemini)
)

type TimescaleEstimator

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

TimescaleEstimator implements the Estimator interface using a TimescaleDB backend.

func NewTimescaleEstimator

func NewTimescaleEstimator(db *pgxpool.Pool, rates ResourceRates) *TimescaleEstimator

NewTimescaleEstimator creates a new estimator with a DB pool and rates configuration.

func (*TimescaleEstimator) Estimate

func (e *TimescaleEstimator) Estimate(unit UnitCost) error

Estimate calculates the cost for a unit and persists it to TimescaleDB. This is our core Unit Economics function, now aligned with FOCUS 1.0.

func (*TimescaleEstimator) GetProviderBurnRate

func (e *TimescaleEstimator) GetProviderBurnRate(providerID string, lastNDays int) (float64, error)

GetProviderBurnRate returns the average hourly cost for a provider in the last N days. This allows for "Waste Detection" (e.g. a provider that is expensive but returns no data).

func (*TimescaleEstimator) LogScrape

func (e *TimescaleEstimator) LogScrape(providerID string, st ScraperType, duration time.Duration)

LogScrape is a helper to record a scrape and estimate its cost immediately.

type UnitCost

type UnitCost struct {
	Time            time.Time
	ProviderID      string
	ScraperType     ScraperType
	Duration        time.Duration
	EstimatedCost   float64 // In USD
	TraceID         string
	ServiceCategory string // FOCUS: ServiceCategory (e.g., AI, Compute)
	ResourceName    string // FOCUS: ResourceName
}

UnitCost represents the calculated cost for a single operation, aligned with FOCUS 1.0

Jump to

Keyboard shortcuts

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