Documentation
¶
Overview ¶
Package project provides budget and allocation management for v0.5.10+
This file implements the multi-budget system enabling:
- 1 budget → N projects (single grant funding multiple projects)
- N budgets → 1 project (multi-source funding)
Package project provides project and budget management functionality for Prism.
This package implements project-based resource organization, budget tracking, and cost controls that enable researchers to organize instances, storage, and costs around research projects with proper financial oversight.
Index ¶
- Variables
- type ActionExecutor
- type AddMemberRequest
- type AlertEvent
- type AllocationSummary
- type BudgetManager
- func (bm *BudgetManager) ActivateBackupFunding(ctx context.Context, projectID string, primaryAllocationID string, ...) error
- func (bm *BudgetManager) CheckAllocationStatus(ctx context.Context, allocationID string) (exhausted bool, remaining float64, err error)
- func (bm *BudgetManager) Close() error
- func (bm *BudgetManager) CreateAllocation(ctx context.Context, req *CreateAllocationRequest) (*types.ProjectBudgetAllocation, error)
- func (bm *BudgetManager) CreateBudget(ctx context.Context, req *CreateBudgetRequest) (*types.Budget, error)
- func (bm *BudgetManager) DeleteAllocation(ctx context.Context, allocationID string) error
- func (bm *BudgetManager) DeleteBudget(ctx context.Context, budgetID string) error
- func (bm *BudgetManager) GenerateBudgetRollupReport(ctx context.Context) (*BudgetRollupReport, error)
- func (bm *BudgetManager) GetAllocation(ctx context.Context, allocationID string) (*types.ProjectBudgetAllocation, error)
- func (bm *BudgetManager) GetBudget(ctx context.Context, budgetID string) (*types.Budget, error)
- func (bm *BudgetManager) GetBudgetAllocations(ctx context.Context, budgetID string) ([]*types.ProjectBudgetAllocation, error)
- func (bm *BudgetManager) GetBudgetByName(ctx context.Context, name string) (*types.Budget, error)
- func (bm *BudgetManager) GetBudgetReallocationHistory(ctx context.Context, budgetID string) ([]*ReallocationRecord, error)
- func (bm *BudgetManager) GetBudgetSummary(ctx context.Context, budgetID string) (*types.BudgetSummary, error)
- func (bm *BudgetManager) GetBudgetSummaryReport(ctx context.Context, budgetID string) (*BudgetSummaryReport, error)
- func (bm *BudgetManager) GetProjectAllocations(ctx context.Context, projectID string) ([]*types.ProjectBudgetAllocation, error)
- func (bm *BudgetManager) GetProjectCostRollup(ctx context.Context, projectIDs []string) ([]ProjectCostSummary, error)
- func (bm *BudgetManager) GetProjectFundingSummary(ctx context.Context, projectID string) (*types.ProjectFundingSummary, error)
- func (bm *BudgetManager) GetReallocationHistory(ctx context.Context, allocationID string) ([]*ReallocationRecord, error)
- func (bm *BudgetManager) ListBudgets(ctx context.Context) ([]*types.Budget, error)
- func (bm *BudgetManager) ReallocateFunds(ctx context.Context, req *ReallocateFundsRequest) (*ReallocationRecord, error)
- func (bm *BudgetManager) RecordSpending(ctx context.Context, allocationID string, amount float64) (*SpendingResult, error)
- func (bm *BudgetManager) UpdateAllocation(ctx context.Context, allocationID string, req *UpdateAllocationRequest) (*types.ProjectBudgetAllocation, error)
- func (bm *BudgetManager) UpdateBudget(ctx context.Context, budgetID string, req *UpdateBudgetRequest) (*types.Budget, error)
- type BudgetRollupReport
- type BudgetStatus
- type BudgetStatusSummary
- type BudgetSummaryReport
- type BudgetTracker
- func (bt *BudgetTracker) CheckBudgetStatus(projectID string) (*BudgetStatus, error)
- func (bt *BudgetTracker) Close() error
- func (bt *BudgetTracker) GetAllProjectIDs() []string
- func (bt *BudgetTracker) GetBudgetStatus(projectID string) (map[string]interface{}, error)
- func (bt *BudgetTracker) GetCostBreakdown(projectID string, startDate, endDate time.Time) (*types.ProjectCostBreakdown, error)
- func (bt *BudgetTracker) GetCostTrends(projectID string, period string) (map[string]interface{}, error)
- func (bt *BudgetTracker) GetCurrentMonthlyRate(projectID string) float64
- func (bt *BudgetTracker) GetProjectCostHistory(projectID string, days int) ([]float64, error)
- func (bt *BudgetTracker) GetResourceUsage(projectID string, period time.Duration) (*types.ProjectResourceUsage, error)
- func (bt *BudgetTracker) InitializeProject(projectID string, budget *types.ProjectBudget) error
- func (bt *BudgetTracker) RemoveProject(projectID string) error
- func (bt *BudgetTracker) SetActionExecutor(executor ActionExecutor)
- func (bt *BudgetTracker) UpdateProjectCosts(projectID string, instances []types.Instance, ...) error
- func (bt *BudgetTracker) UpdateProjectSpending(projectID string, instanceCosts []types.InstanceCost, ...) error
- type CostCalculator
- func (c *CostCalculator) CalculateInstanceCosts(instances []types.Instance) ([]types.InstanceCost, float64)
- func (c *CostCalculator) CalculateStorageCosts(storageVolumes []types.StorageVolume) ([]types.StorageCost, float64)
- func (c *CostCalculator) EstimateHibernationSavings(instanceType string, hibernatedHours float64) float64
- func (c *CostCalculator) EstimateMonthlyCost(instanceType string, storageGB int) float64
- func (c *CostCalculator) GetInstanceHourlyRate(instanceType string) float64
- func (c *CostCalculator) GetStorageMonthlyRate(storageType string) float64
- type CostDataPoint
- type CreateAllocationRequest
- type CreateBudgetRequest
- type CreateProjectBudgetRequest
- type CreateProjectRequest
- type ForecastDataPoint
- type Manager
- func (m *Manager) AddProjectMember(ctx context.Context, projectID string, member *types.ProjectMember) error
- func (m *Manager) AllowLaunches(ctx context.Context, projectID string) error
- func (m *Manager) CheckBudgetStatus(ctx context.Context, projectID string) (*BudgetStatus, error)
- func (m *Manager) ClearDefaultAllocation(ctx context.Context, projectID string) error
- func (m *Manager) Close() error
- func (m *Manager) CreateProject(ctx context.Context, req *CreateProjectRequest) (*types.Project, error)
- func (m *Manager) DeleteProject(ctx context.Context, projectID string) error
- func (m *Manager) DisableProjectBudget(ctx context.Context, projectID string) error
- func (m *Manager) GetProject(ctx context.Context, projectID string) (*types.Project, error)
- func (m *Manager) GetProjectByName(ctx context.Context, name string) (*types.Project, error)
- func (m *Manager) GetProjectCostBreakdown(ctx context.Context, projectID string, startDate, endDate time.Time) (*types.ProjectCostBreakdown, error)
- func (m *Manager) GetProjectForecast(ctx context.Context, projectID string, req *ProjectForecastRequest) (*ProjectForecastResponse, error)
- func (m *Manager) GetProjectResourceUsage(ctx context.Context, projectID string, period time.Duration) (*types.ProjectResourceUsage, error)
- func (m *Manager) IsLaunchPrevented(ctx context.Context, projectID string) (bool, error)
- func (m *Manager) ListProjects(ctx context.Context, filter *ProjectFilter) ([]*types.Project, error)
- func (m *Manager) PreventLaunches(ctx context.Context, projectID string) error
- func (m *Manager) RemoveProjectMember(ctx context.Context, projectID, userID string) error
- func (m *Manager) SetDefaultAllocation(ctx context.Context, projectID string, allocationID string) error
- func (m *Manager) SetProjectBudget(ctx context.Context, projectID string, budget *types.ProjectBudget) error
- func (m *Manager) TransferProject(ctx context.Context, projectID string, req *TransferProjectRequest) (*types.Project, error)
- func (m *Manager) UpdateProject(ctx context.Context, projectID string, req *UpdateProjectRequest) (*types.Project, error)
- func (m *Manager) UpdateProjectBudget(ctx context.Context, projectID string, budget *types.ProjectBudget) error
- func (m *Manager) UpdateProjectMember(ctx context.Context, projectID, userID string, role types.ProjectRole) error
- type ProjectBudgetData
- type ProjectCostSummary
- type ProjectFilter
- type ProjectForecastRequest
- type ProjectForecastResponse
- type ProjectListResponse
- type ProjectSummary
- type ReallocateFundsRequest
- type ReallocationRecord
- type SpendingResult
- type TransferProjectRequest
- type UpdateAllocationRequest
- type UpdateBudgetRequest
- type UpdateMemberRequest
- type UpdateProjectRequest
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDuplicateProjectName is returned when attempting to create a project with a name that already exists ErrDuplicateProjectName = errors.New("project name already exists") )
Error constants
Functions ¶
This section is empty.
Types ¶
type ActionExecutor ¶
type ActionExecutor interface {
// ExecuteHibernateAll hibernates all instances for a project
ExecuteHibernateAll(projectID string) error
// ExecuteStopAll stops all instances for a project
ExecuteStopAll(projectID string) error
// ExecutePreventLaunch sets a flag to prevent new launches for a project
ExecutePreventLaunch(projectID string) error
}
ActionExecutor defines the interface for executing budget auto actions
type AddMemberRequest ¶
type AddMemberRequest struct {
// UserID is the user identifier
UserID string `json:"user_id"`
// Role is the project role for the member
Role types.ProjectRole `json:"role"`
// AddedBy is who is adding the member
AddedBy string `json:"added_by"`
}
AddMemberRequest represents a request to add a member to a project
func (*AddMemberRequest) Validate ¶
func (r *AddMemberRequest) Validate() error
Validate validates the add member request
type AlertEvent ¶
type AlertEvent struct {
Timestamp time.Time `json:"timestamp"`
AlertType types.BudgetAlertType `json:"alert_type"`
Threshold float64 `json:"threshold"`
SpentAmount float64 `json:"spent_amount"`
Message string `json:"message"`
Resolved bool `json:"resolved"`
}
AlertEvent represents a budget alert event
type AllocationSummary ¶ added in v0.5.10
type AllocationSummary struct {
// AllocationID is the allocation identifier
AllocationID string `json:"allocation_id"`
// BudgetID is the parent budget identifier
BudgetID string `json:"budget_id"`
// BudgetName is the parent budget name
BudgetName string `json:"budget_name"`
// AllocatedAmount is how much was allocated
AllocatedAmount float64 `json:"allocated_amount"`
// SpentAmount is how much has been spent
SpentAmount float64 `json:"spent_amount"`
// RemainingAmount is the remaining allocation
RemainingAmount float64 `json:"remaining_amount"`
// Utilization is the percentage of allocation spent (0.0-1.0)
Utilization float64 `json:"utilization"`
// HasBackup indicates if backup funding is configured
HasBackup bool `json:"has_backup"`
}
AllocationSummary provides allocation-level information (v0.5.10+ Issue #100)
type BudgetManager ¶ added in v0.5.10
type BudgetManager struct {
// contains filtered or unexported fields
}
BudgetManager handles budget pools and project allocations
func NewBudgetManager ¶ added in v0.5.10
func NewBudgetManager() (*BudgetManager, error)
NewBudgetManager creates a new budget manager
func (*BudgetManager) ActivateBackupFunding ¶ added in v0.5.10
func (bm *BudgetManager) ActivateBackupFunding(ctx context.Context, projectID string, primaryAllocationID string, backupAllocationID string) error
ActivateBackupFunding switches a project to its backup funding allocation This is called when the primary allocation is exhausted and backup exists
func (*BudgetManager) CheckAllocationStatus ¶ added in v0.5.10
func (bm *BudgetManager) CheckAllocationStatus(ctx context.Context, allocationID string) (exhausted bool, remaining float64, err error)
CheckAllocationStatus checks if an allocation is exhausted or nearing exhaustion
func (*BudgetManager) Close ¶ added in v0.5.10
func (bm *BudgetManager) Close() error
Close cleanly shuts down the budget manager
func (*BudgetManager) CreateAllocation ¶ added in v0.5.10
func (bm *BudgetManager) CreateAllocation(ctx context.Context, req *CreateAllocationRequest) (*types.ProjectBudgetAllocation, error)
CreateAllocation creates a new project budget allocation
func (*BudgetManager) CreateBudget ¶ added in v0.5.10
func (bm *BudgetManager) CreateBudget(ctx context.Context, req *CreateBudgetRequest) (*types.Budget, error)
CreateBudget creates a new budget pool
func (*BudgetManager) DeleteAllocation ¶ added in v0.5.10
func (bm *BudgetManager) DeleteAllocation(ctx context.Context, allocationID string) error
DeleteAllocation removes an allocation
func (*BudgetManager) DeleteBudget ¶ added in v0.5.10
func (bm *BudgetManager) DeleteBudget(ctx context.Context, budgetID string) error
DeleteBudget removes a budget and all associated allocations
func (*BudgetManager) GenerateBudgetRollupReport ¶ added in v0.5.10
func (bm *BudgetManager) GenerateBudgetRollupReport(ctx context.Context) (*BudgetRollupReport, error)
GenerateBudgetRollupReport generates a comprehensive rollup report across all budgets (v0.5.10+ Issue #100)
func (*BudgetManager) GetAllocation ¶ added in v0.5.10
func (bm *BudgetManager) GetAllocation(ctx context.Context, allocationID string) (*types.ProjectBudgetAllocation, error)
GetAllocation retrieves an allocation by ID
func (*BudgetManager) GetBudgetAllocations ¶ added in v0.5.10
func (bm *BudgetManager) GetBudgetAllocations(ctx context.Context, budgetID string) ([]*types.ProjectBudgetAllocation, error)
GetBudgetAllocations retrieves all allocations for a budget
func (*BudgetManager) GetBudgetByName ¶ added in v0.5.10
GetBudgetByName retrieves a budget by name
func (*BudgetManager) GetBudgetReallocationHistory ¶ added in v0.5.10
func (bm *BudgetManager) GetBudgetReallocationHistory(ctx context.Context, budgetID string) ([]*ReallocationRecord, error)
GetBudgetReallocationHistory retrieves all reallocations for a budget (v0.5.10+ Issue #99)
func (*BudgetManager) GetBudgetSummary ¶ added in v0.5.10
func (bm *BudgetManager) GetBudgetSummary(ctx context.Context, budgetID string) (*types.BudgetSummary, error)
GetBudgetSummary generates a summary view of a budget
func (*BudgetManager) GetBudgetSummaryReport ¶ added in v0.5.10
func (bm *BudgetManager) GetBudgetSummaryReport(ctx context.Context, budgetID string) (*BudgetSummaryReport, error)
GetBudgetSummaryReport generates a detailed summary for a specific budget (v0.5.10+ Issue #100)
func (*BudgetManager) GetProjectAllocations ¶ added in v0.5.10
func (bm *BudgetManager) GetProjectAllocations(ctx context.Context, projectID string) ([]*types.ProjectBudgetAllocation, error)
GetProjectAllocations retrieves all allocations for a project
func (*BudgetManager) GetProjectCostRollup ¶ added in v0.5.10
func (bm *BudgetManager) GetProjectCostRollup(ctx context.Context, projectIDs []string) ([]ProjectCostSummary, error)
GetProjectCostRollup generates cost rollup for specific projects (v0.5.10+ Issue #100)
func (*BudgetManager) GetProjectFundingSummary ¶ added in v0.5.10
func (bm *BudgetManager) GetProjectFundingSummary(ctx context.Context, projectID string) (*types.ProjectFundingSummary, error)
GetProjectFundingSummary generates a summary view of all funding for a project
func (*BudgetManager) GetReallocationHistory ¶ added in v0.5.10
func (bm *BudgetManager) GetReallocationHistory(ctx context.Context, allocationID string) ([]*ReallocationRecord, error)
GetReallocationHistory retrieves reallocation history for a specific allocation (v0.5.10+ Issue #99)
func (*BudgetManager) ListBudgets ¶ added in v0.5.10
ListBudgets retrieves all budgets
func (*BudgetManager) ReallocateFunds ¶ added in v0.5.10
func (bm *BudgetManager) ReallocateFunds(ctx context.Context, req *ReallocateFundsRequest) (*ReallocationRecord, error)
ReallocateFunds moves funds between allocations atomically (v0.5.10+ Issue #99)
func (*BudgetManager) RecordSpending ¶ added in v0.5.10
func (bm *BudgetManager) RecordSpending(ctx context.Context, allocationID string, amount float64) (*SpendingResult, error)
RecordSpending records spending against an allocation with backup funding support (v0.5.10+) Returns SpendingResult indicating if backup was activated
func (*BudgetManager) UpdateAllocation ¶ added in v0.5.10
func (bm *BudgetManager) UpdateAllocation(ctx context.Context, allocationID string, req *UpdateAllocationRequest) (*types.ProjectBudgetAllocation, error)
UpdateAllocation updates an existing allocation
func (*BudgetManager) UpdateBudget ¶ added in v0.5.10
func (bm *BudgetManager) UpdateBudget(ctx context.Context, budgetID string, req *UpdateBudgetRequest) (*types.Budget, error)
UpdateBudget updates an existing budget
type BudgetRollupReport ¶ added in v0.5.10
type BudgetRollupReport struct {
// ReportID is a unique identifier for this report
ReportID string `json:"report_id"`
// GeneratedAt is when this report was generated
GeneratedAt time.Time `json:"generated_at"`
// BudgetSummaries provides per-budget rollup information
BudgetSummaries []BudgetSummaryReport `json:"budget_summaries"`
// TotalBudgets is the total number of budgets in the report
TotalBudgets int `json:"total_budgets"`
// TotalAllocated is the sum of all budget allocations
TotalAllocated float64 `json:"total_allocated"`
// TotalSpent is the sum of all spending across all budgets
TotalSpent float64 `json:"total_spent"`
// TotalRemaining is the total remaining across all budgets
TotalRemaining float64 `json:"total_remaining"`
// OverallUtilization is the percentage of total budget utilized (0.0-1.0)
OverallUtilization float64 `json:"overall_utilization"`
// ProjectCount is the total number of projects funded
ProjectCount int `json:"project_count"`
}
BudgetRollupReport provides aggregated cost and budget information (v0.5.10+ Issue #100)
type BudgetStatus ¶
type BudgetStatus struct {
// ProjectID is the project identifier
ProjectID string `json:"project_id"`
// BudgetEnabled indicates if budget tracking is enabled
BudgetEnabled bool `json:"budget_enabled"`
// TotalBudget is the total project budget
TotalBudget float64 `json:"total_budget"`
// SpentAmount is the current amount spent
SpentAmount float64 `json:"spent_amount"`
// RemainingBudget is the remaining budget
RemainingBudget float64 `json:"remaining_budget"`
// SpentPercentage is the percentage of budget spent (0.0-1.0)
SpentPercentage float64 `json:"spent_percentage"`
// ProjectedMonthlySpend is the projected monthly spending based on current usage
ProjectedMonthlySpend float64 `json:"projected_monthly_spend"`
// DaysUntilBudgetExhausted estimates when budget will be exhausted at current rate
DaysUntilBudgetExhausted *int `json:"days_until_exhausted,omitempty"`
// ActiveAlerts are currently active budget alerts
ActiveAlerts []string `json:"active_alerts"`
// TriggeredActions are actions that have been triggered
TriggeredActions []string `json:"triggered_actions"`
// LastUpdated is when this status was calculated
LastUpdated time.Time `json:"last_updated"`
}
BudgetStatus represents the current budget status of a project
type BudgetStatusSummary ¶
type BudgetStatusSummary struct {
// TotalBudget is the total project budget
TotalBudget float64 `json:"total_budget"`
// SpentAmount is the current amount spent
SpentAmount float64 `json:"spent_amount"`
// SpentPercentage is the percentage of budget spent (0.0-1.0)
SpentPercentage float64 `json:"spent_percentage"`
// AlertCount is the number of active alerts
AlertCount int `json:"alert_count"`
}
BudgetStatusSummary provides a condensed view of budget status
type BudgetSummaryReport ¶ added in v0.5.10
type BudgetSummaryReport struct {
// BudgetID is the budget identifier
BudgetID string `json:"budget_id"`
// BudgetName is the budget name
BudgetName string `json:"budget_name"`
// Period is the budget period
Period string `json:"period"`
// TotalAmount is the total budget amount
TotalAmount float64 `json:"total_amount"`
// AllocatedAmount is how much has been allocated to projects
AllocatedAmount float64 `json:"allocated_amount"`
// SpentAmount is how much has been spent
SpentAmount float64 `json:"spent_amount"`
// RemainingAmount is the remaining unspent budget
RemainingAmount float64 `json:"remaining_amount"`
// Utilization is the percentage of budget utilized (0.0-1.0)
Utilization float64 `json:"utilization"`
// ProjectCount is the number of projects funded by this budget
ProjectCount int `json:"project_count"`
// AllocationCount is the number of allocations from this budget
AllocationCount int `json:"allocation_count"`
// Projects provides per-project information
Projects []ProjectCostSummary `json:"projects"`
}
BudgetSummaryReport provides detailed budget information (v0.5.10+ Issue #100)
type BudgetTracker ¶
type BudgetTracker struct {
// contains filtered or unexported fields
}
BudgetTracker handles budget tracking and cost analysis for projects
func NewBudgetTracker ¶
func NewBudgetTracker() (*BudgetTracker, error)
NewBudgetTracker creates a new budget tracker
func (*BudgetTracker) CheckBudgetStatus ¶
func (bt *BudgetTracker) CheckBudgetStatus(projectID string) (*BudgetStatus, error)
CheckBudgetStatus checks the current budget status and returns detailed information
func (*BudgetTracker) Close ¶
func (bt *BudgetTracker) Close() error
Close cleanly shuts down the budget tracker
func (*BudgetTracker) GetAllProjectIDs ¶
func (bt *BudgetTracker) GetAllProjectIDs() []string
GetCostTrends returns cost trends for a project over a specified period GetAllProjectIDs returns all project IDs being tracked
func (*BudgetTracker) GetBudgetStatus ¶
func (bt *BudgetTracker) GetBudgetStatus(projectID string) (map[string]interface{}, error)
GetBudgetStatus returns the current budget status for a project
func (*BudgetTracker) GetCostBreakdown ¶
func (bt *BudgetTracker) GetCostBreakdown(projectID string, startDate, endDate time.Time) (*types.ProjectCostBreakdown, error)
GetCostBreakdown retrieves detailed cost analysis for a project
func (*BudgetTracker) GetCostTrends ¶
func (bt *BudgetTracker) GetCostTrends(projectID string, period string) (map[string]interface{}, error)
func (*BudgetTracker) GetCurrentMonthlyRate ¶ added in v0.6.0
func (bt *BudgetTracker) GetCurrentMonthlyRate(projectID string) float64
GetCurrentMonthlyRate calculates the current monthly spending rate for a project This is a simplified implementation for Issue #326
func (*BudgetTracker) GetProjectCostHistory ¶
func (bt *BudgetTracker) GetProjectCostHistory(projectID string, days int) ([]float64, error)
GetProjectCostHistory returns cost history for a project
func (*BudgetTracker) GetResourceUsage ¶
func (bt *BudgetTracker) GetResourceUsage(projectID string, period time.Duration) (*types.ProjectResourceUsage, error)
GetResourceUsage retrieves resource utilization metrics for a project
func (*BudgetTracker) InitializeProject ¶
func (bt *BudgetTracker) InitializeProject(projectID string, budget *types.ProjectBudget) error
InitializeProject initializes budget tracking for a new project
func (*BudgetTracker) RemoveProject ¶
func (bt *BudgetTracker) RemoveProject(projectID string) error
RemoveProject removes budget tracking for a project
func (*BudgetTracker) SetActionExecutor ¶
func (bt *BudgetTracker) SetActionExecutor(executor ActionExecutor)
SetActionExecutor sets the action executor for budget auto actions
func (*BudgetTracker) UpdateProjectCosts ¶
func (bt *BudgetTracker) UpdateProjectCosts(projectID string, instances []types.Instance, storageVolumes []types.StorageVolume) error
UpdateProjectCosts updates cost tracking for a project
func (*BudgetTracker) UpdateProjectSpending ¶
func (bt *BudgetTracker) UpdateProjectSpending(projectID string, instanceCosts []types.InstanceCost, storageCosts []types.StorageCost) error
UpdateProjectSpending updates project spending with instance and storage costs
type CostCalculator ¶
type CostCalculator struct {
}
CostCalculator calculates AWS costs for instances and storage
func (*CostCalculator) CalculateInstanceCosts ¶
func (c *CostCalculator) CalculateInstanceCosts(instances []types.Instance) ([]types.InstanceCost, float64)
CalculateInstanceCosts calculates costs for a list of instances
func (*CostCalculator) CalculateStorageCosts ¶
func (c *CostCalculator) CalculateStorageCosts(storageVolumes []types.StorageVolume) ([]types.StorageCost, float64)
CalculateStorageCosts calculates costs for all storage volumes
func (*CostCalculator) EstimateHibernationSavings ¶
func (c *CostCalculator) EstimateHibernationSavings(instanceType string, hibernatedHours float64) float64
EstimateHibernationSavings estimates the cost savings from hibernating vs running
func (*CostCalculator) EstimateMonthlyCost ¶
func (c *CostCalculator) EstimateMonthlyCost(instanceType string, storageGB int) float64
EstimateMonthlyCost estimates the monthly cost for running an instance continuously
func (*CostCalculator) GetInstanceHourlyRate ¶
func (c *CostCalculator) GetInstanceHourlyRate(instanceType string) float64
GetInstanceHourlyRate returns the hourly rate for an instance type
func (*CostCalculator) GetStorageMonthlyRate ¶
func (c *CostCalculator) GetStorageMonthlyRate(storageType string) float64
GetStorageMonthlyRate returns the monthly rate per GB for a storage type
type CostDataPoint ¶
type CostDataPoint struct {
Timestamp time.Time `json:"timestamp"`
TotalCost float64 `json:"total_cost"`
InstanceCosts []types.InstanceCost `json:"instance_costs"`
StorageCosts []types.StorageCost `json:"storage_costs"`
DailyCost float64 `json:"daily_cost"`
}
CostDataPoint represents a point-in-time cost measurement
type CreateAllocationRequest ¶ added in v0.5.10
type CreateAllocationRequest struct {
// BudgetID is the parent budget pool
BudgetID string `json:"budget_id"`
// ProjectID is the project receiving the allocation
ProjectID string `json:"project_id"`
// AllocatedAmount is how much of the budget to allocate to this project
AllocatedAmount float64 `json:"allocated_amount"`
// AlertThreshold is an optional project-specific alert threshold (overrides budget default)
AlertThreshold *float64 `json:"alert_threshold,omitempty"`
// BackupAllocationID is an optional backup funding source for exhaustion (#234)
BackupAllocationID *string `json:"backup_allocation_id,omitempty"`
// Notes provide context for this allocation
Notes string `json:"notes,omitempty"`
// AllocatedBy is the user who created the allocation
AllocatedBy string `json:"allocated_by"`
}
CreateAllocationRequest represents a request to allocate budget to a project
func (*CreateAllocationRequest) Validate ¶ added in v0.5.10
func (r *CreateAllocationRequest) Validate() error
Validate validates the create allocation request
type CreateBudgetRequest ¶
type CreateBudgetRequest struct {
// Name is the budget name (e.g., "NSF Grant CISE-2024-12345")
Name string `json:"name"`
// Description provides budget details
Description string `json:"description"`
// TotalAmount is the total budget pool in USD
TotalAmount float64 `json:"total_amount"`
// Period defines the budget period
Period types.BudgetPeriod `json:"period"`
// StartDate is when the budget period began
StartDate time.Time `json:"start_date"`
// EndDate is when the budget period ends (optional for ongoing budgets)
EndDate *time.Time `json:"end_date,omitempty"`
// AlertThreshold is the global alert percentage (0.0-1.0)
AlertThreshold float64 `json:"alert_threshold"`
// CreatedBy is the user who created the budget
CreatedBy string `json:"created_by"`
// Tags for budget organization
Tags map[string]string `json:"tags,omitempty"`
}
CreateBudgetRequest represents a request to create a budget pool (v0.5.10+)
func (*CreateBudgetRequest) Validate ¶
func (r *CreateBudgetRequest) Validate() error
Validate validates the create budget request
type CreateProjectBudgetRequest ¶ added in v0.5.10
type CreateProjectBudgetRequest struct {
// TotalBudget is the total project budget in USD
TotalBudget float64 `json:"total_budget"`
// MonthlyLimit is the optional monthly spending limit in USD
MonthlyLimit *float64 `json:"monthly_limit,omitempty"`
// DailyLimit is the optional daily spending limit in USD
DailyLimit *float64 `json:"daily_limit,omitempty"`
// AlertThresholds define when to send budget alerts
AlertThresholds []types.BudgetAlert `json:"alert_thresholds,omitempty"`
// AutoActions define automatic actions when thresholds are reached
AutoActions []types.BudgetAutoAction `json:"auto_actions,omitempty"`
// BudgetPeriod defines the budget period
BudgetPeriod types.BudgetPeriod `json:"budget_period"`
// EndDate is when the budget period ends (optional)
EndDate *time.Time `json:"end_date,omitempty"`
}
CreateProjectBudgetRequest represents a request to create a project budget (DEPRECATED in v0.5.10) Use CreateBudgetRequest + CreateAllocationRequest instead
func (*CreateProjectBudgetRequest) Validate ¶ added in v0.5.10
func (r *CreateProjectBudgetRequest) Validate() error
Validate validates the create project budget request (DEPRECATED in v0.5.10)
type CreateProjectRequest ¶
type CreateProjectRequest struct {
// Name is the project name (required)
Name string `json:"name"`
// Description provides project details
Description string `json:"description"`
// Owner is the project owner/principal investigator
Owner string `json:"owner"`
// Tags for project organization
Tags map[string]string `json:"tags,omitempty"`
// Budget contains optional budget configuration (DEPRECATED in v0.5.10)
// Use Budget/Allocation system instead
Budget *CreateProjectBudgetRequest `json:"budget,omitempty"`
}
CreateProjectRequest represents a request to create a new project
func (*CreateProjectRequest) Validate ¶
func (r *CreateProjectRequest) Validate() error
Validate validates the create project request
type ForecastDataPoint ¶ added in v0.6.0
type ForecastDataPoint struct {
// Month is the month for this data point (YYYY-MM format)
Month string `json:"month"`
// ProjectedCost is the projected spending for this month
ProjectedCost float64 `json:"projected_cost"`
// CumulativeCost is the cumulative cost to date
CumulativeCost float64 `json:"cumulative_cost"`
// ActualCost is the actual cost (for historical data only)
ActualCost *float64 `json:"actual_cost,omitempty"`
}
ForecastDataPoint represents a single month's forecast
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles project lifecycle, budget tracking, and cost controls
func (*Manager) AddProjectMember ¶
func (m *Manager) AddProjectMember(ctx context.Context, projectID string, member *types.ProjectMember) error
AddProjectMember adds a member to a project
func (*Manager) AllowLaunches ¶
AllowLaunches allows new instance launches for a project (clears launch prevention)
func (*Manager) CheckBudgetStatus ¶
CheckBudgetStatus checks the current budget status and triggers alerts if needed
func (*Manager) ClearDefaultAllocation ¶ added in v0.5.10
ClearDefaultAllocation clears the default funding allocation for a project (v0.5.10+)
func (*Manager) CreateProject ¶
func (m *Manager) CreateProject(ctx context.Context, req *CreateProjectRequest) (*types.Project, error)
CreateProject creates a new research project
func (*Manager) DeleteProject ¶
DeleteProject removes a project and all associated data
func (*Manager) DisableProjectBudget ¶
DisableProjectBudget disables budget tracking for a project
func (*Manager) GetProject ¶
GetProject retrieves a project by ID
func (*Manager) GetProjectByName ¶
GetProjectByName retrieves a project by name
func (*Manager) GetProjectCostBreakdown ¶
func (m *Manager) GetProjectCostBreakdown(ctx context.Context, projectID string, startDate, endDate time.Time) (*types.ProjectCostBreakdown, error)
GetProjectCostBreakdown retrieves detailed cost analysis for a project
func (*Manager) GetProjectForecast ¶ added in v0.6.0
func (m *Manager) GetProjectForecast(ctx context.Context, projectID string, req *ProjectForecastRequest) (*ProjectForecastResponse, error)
GetProjectForecast generates cost forecast data for a project
func (*Manager) GetProjectResourceUsage ¶
func (m *Manager) GetProjectResourceUsage(ctx context.Context, projectID string, period time.Duration) (*types.ProjectResourceUsage, error)
GetProjectResourceUsage retrieves resource utilization metrics for a project
func (*Manager) IsLaunchPrevented ¶
IsLaunchPrevented checks if launches are prevented for a project
func (*Manager) ListProjects ¶
func (m *Manager) ListProjects(ctx context.Context, filter *ProjectFilter) ([]*types.Project, error)
ListProjects retrieves projects with optional filtering
func (*Manager) PreventLaunches ¶
PreventLaunches prevents new instance launches for a project
func (*Manager) RemoveProjectMember ¶
RemoveProjectMember removes a member from a project
func (*Manager) SetDefaultAllocation ¶ added in v0.5.10
func (m *Manager) SetDefaultAllocation(ctx context.Context, projectID string, allocationID string) error
SetDefaultAllocation sets the default funding allocation for a project (v0.5.10+)
func (*Manager) SetProjectBudget ¶
func (m *Manager) SetProjectBudget(ctx context.Context, projectID string, budget *types.ProjectBudget) error
SetProjectBudget sets or enables budget tracking for a project
func (*Manager) TransferProject ¶ added in v0.6.0
func (m *Manager) TransferProject(ctx context.Context, projectID string, req *TransferProjectRequest) (*types.Project, error)
TransferProject transfers project ownership to a new owner
func (*Manager) UpdateProject ¶
func (m *Manager) UpdateProject(ctx context.Context, projectID string, req *UpdateProjectRequest) (*types.Project, error)
UpdateProject updates an existing project
func (*Manager) UpdateProjectBudget ¶
func (m *Manager) UpdateProjectBudget(ctx context.Context, projectID string, budget *types.ProjectBudget) error
UpdateProjectBudget updates an existing project budget
func (*Manager) UpdateProjectMember ¶
func (m *Manager) UpdateProjectMember(ctx context.Context, projectID, userID string, role types.ProjectRole) error
UpdateProjectMember updates a member's role in a project
type ProjectBudgetData ¶
type ProjectBudgetData struct {
ProjectID string `json:"project_id"`
Budget *types.ProjectBudget `json:"budget"`
CostHistory []CostDataPoint `json:"cost_history"`
AlertHistory []AlertEvent `json:"alert_history"`
LastUpdated time.Time `json:"last_updated"`
}
ProjectBudgetData stores budget tracking data for a project
type ProjectCostSummary ¶ added in v0.5.10
type ProjectCostSummary struct {
// ProjectID is the project identifier
ProjectID string `json:"project_id"`
// ProjectName is the project name
ProjectName string `json:"project_name"`
// FundingSources lists all funding allocations for this project
FundingSources []AllocationSummary `json:"funding_sources"`
// TotalAllocated is the total allocated to this project across all sources
TotalAllocated float64 `json:"total_allocated"`
// TotalSpent is the total spent by this project
TotalSpent float64 `json:"total_spent"`
// TotalRemaining is the remaining budget for this project
TotalRemaining float64 `json:"total_remaining"`
// Utilization is the percentage of allocated budget spent (0.0-1.0)
Utilization float64 `json:"utilization"`
}
ProjectCostSummary provides project-level cost information (v0.5.10+ Issue #100)
type ProjectFilter ¶
type ProjectFilter struct {
// Owner filters by project owner
Owner string `json:"owner,omitempty"`
// Status filters by project status
Status *types.ProjectStatus `json:"status,omitempty"`
// Tags filters by project tags (all specified tags must match)
Tags map[string]string `json:"tags,omitempty"`
// CreatedAfter filters projects created after this date
CreatedAfter *time.Time `json:"created_after,omitempty"`
// CreatedBefore filters projects created before this date
CreatedBefore *time.Time `json:"created_before,omitempty"`
// HasBudget filters projects with/without budgets
HasBudget *bool `json:"has_budget,omitempty"`
}
ProjectFilter defines filtering options for listing projects
type ProjectForecastRequest ¶ added in v0.6.0
type ProjectForecastRequest struct {
// Months is the number of months to forecast (default: 6)
Months int `json:"months,omitempty"`
// IncludeHistorical includes historical spending data in response
IncludeHistorical bool `json:"include_historical,omitempty"`
}
ProjectForecastRequest represents a request for cost forecast data
type ProjectForecastResponse ¶ added in v0.6.0
type ProjectForecastResponse struct {
// ProjectID is the project identifier
ProjectID string `json:"project_id"`
// GeneratedAt is when this forecast was generated
GeneratedAt time.Time `json:"generated_at"`
// CurrentMonthlyRate is the current monthly spending rate
CurrentMonthlyRate float64 `json:"current_monthly_rate"`
// ForecastData contains month-by-month projections
ForecastData []ForecastDataPoint `json:"forecast_data"`
// HistoricalData contains past spending (if requested)
HistoricalData []ForecastDataPoint `json:"historical_data,omitempty"`
// ProjectedExhaustion estimates when budget will be exhausted (if applicable)
ProjectedExhaustion *time.Time `json:"projected_exhaustion,omitempty"`
// Confidence indicates forecast confidence level (0.0-1.0)
Confidence float64 `json:"confidence"`
}
ProjectForecastResponse provides cost forecast information
type ProjectListResponse ¶
type ProjectListResponse struct {
// Projects are the matching projects
Projects []ProjectSummary `json:"projects"`
// TotalCount is the total number of projects (before pagination)
TotalCount int `json:"total_count"`
// FilteredCount is the number of projects matching the filter
FilteredCount int `json:"filtered_count"`
}
ProjectListResponse represents the response for listing projects
type ProjectSummary ¶
type ProjectSummary struct {
// ID is the project identifier
ID string `json:"id"`
// Name is the project name
Name string `json:"name"`
// Owner is the project owner
Owner string `json:"owner"`
// Status is the project status
Status types.ProjectStatus `json:"status"`
// MemberCount is the number of project members
MemberCount int `json:"member_count"`
// ActiveInstances is the number of currently active instances
ActiveInstances int `json:"active_instances"`
// TotalCost is the total project cost to date
TotalCost float64 `json:"total_cost"`
// BudgetStatus provides budget information if budget is enabled
BudgetStatus *BudgetStatusSummary `json:"budget_status,omitempty"`
// CreatedAt is when the project was created
CreatedAt time.Time `json:"created_at"`
// LastActivity is when the project had its last activity
LastActivity time.Time `json:"last_activity"`
}
ProjectSummary provides a condensed view of project information
type ReallocateFundsRequest ¶ added in v0.5.10
type ReallocateFundsRequest struct {
// SourceAllocationID is where funds are moved from
SourceAllocationID string `json:"source_allocation_id"`
// DestinationAllocationID is where funds are moved to
DestinationAllocationID string `json:"destination_allocation_id"`
// Amount is how much to reallocate (USD)
Amount float64 `json:"amount"`
// Reason explains why the reallocation is being made (required for audit)
Reason string `json:"reason"`
// PerformedBy is the user making the reallocation
PerformedBy string `json:"performed_by"`
}
ReallocateFundsRequest represents a request to reallocate funds between allocations (v0.5.10+ Issue #99)
func (*ReallocateFundsRequest) Validate ¶ added in v0.5.10
func (r *ReallocateFundsRequest) Validate() error
Validate validates the reallocate funds request
type ReallocationRecord ¶ added in v0.5.10
type ReallocationRecord struct {
// ID is the unique reallocation identifier
ID string `json:"id"`
// SourceAllocationID is where funds were moved from
SourceAllocationID string `json:"source_allocation_id"`
// DestinationAllocationID is where funds were moved to
DestinationAllocationID string `json:"destination_allocation_id"`
// SourceBudgetID is the source budget (for cross-budget tracking)
SourceBudgetID string `json:"source_budget_id"`
// DestinationBudgetID is the destination budget (for cross-budget tracking)
DestinationBudgetID string `json:"destination_budget_id"`
// Amount is how much was reallocated (USD)
Amount float64 `json:"amount"`
// Reason explains why the reallocation was made
Reason string `json:"reason"`
// PerformedBy is the user who made the reallocation
PerformedBy string `json:"performed_by"`
// Timestamp is when the reallocation occurred
Timestamp time.Time `json:"timestamp"`
}
ReallocationRecord tracks a funds reallocation for audit purposes (v0.5.10+ Issue #99)
type SpendingResult ¶ added in v0.5.10
type SpendingResult struct {
AllocationID string
AllocationExhausted bool
BackupActivated bool
BackupAllocationID string
WarningMessage string
}
SpendingResult contains information about spending and potential backup activation
type TransferProjectRequest ¶ added in v0.6.0
type TransferProjectRequest struct {
// NewOwnerID is the user ID of the new project owner
NewOwnerID string `json:"new_owner_id"`
// TransferredBy is the user making the transfer (must be current owner)
TransferredBy string `json:"transferred_by"`
// Reason provides context for the transfer (optional)
Reason string `json:"reason,omitempty"`
}
TransferProjectRequest represents a request to transfer project ownership
func (*TransferProjectRequest) Validate ¶ added in v0.6.0
func (r *TransferProjectRequest) Validate() error
Validate validates the transfer project request
type UpdateAllocationRequest ¶ added in v0.5.10
type UpdateAllocationRequest struct {
// AllocatedAmount is the new allocated amount (optional)
AllocatedAmount *float64 `json:"allocated_amount,omitempty"`
// AlertThreshold is the new alert threshold (optional)
AlertThreshold *float64 `json:"alert_threshold,omitempty"`
// BackupAllocationID is the new backup allocation (optional)
BackupAllocationID *string `json:"backup_allocation_id,omitempty"`
// Notes are the new notes (optional)
Notes *string `json:"notes,omitempty"`
}
UpdateAllocationRequest represents a request to update an allocation
type UpdateBudgetRequest ¶ added in v0.5.10
type UpdateBudgetRequest struct {
// Name is the new budget name (optional)
Name *string `json:"name,omitempty"`
// Description is the new budget description (optional)
Description *string `json:"description,omitempty"`
// TotalAmount is the new total amount (optional)
TotalAmount *float64 `json:"total_amount,omitempty"`
// AlertThreshold is the new alert threshold (optional)
AlertThreshold *float64 `json:"alert_threshold,omitempty"`
// EndDate is the new end date (optional)
EndDate *time.Time `json:"end_date,omitempty"`
// Tags are the new budget tags (optional)
Tags map[string]string `json:"tags,omitempty"`
}
UpdateBudgetRequest represents a request to update a budget
type UpdateMemberRequest ¶
type UpdateMemberRequest struct {
// Role is the new role for the member
Role types.ProjectRole `json:"role"`
}
UpdateMemberRequest represents a request to update a project member
func (*UpdateMemberRequest) Validate ¶
func (r *UpdateMemberRequest) Validate() error
Validate validates the update member request
type UpdateProjectRequest ¶
type UpdateProjectRequest struct {
// Name is the new project name (optional)
Name *string `json:"name,omitempty"`
// Description is the new project description (optional)
Description *string `json:"description,omitempty"`
// Tags are the new project tags (optional)
Tags map[string]string `json:"tags,omitempty"`
// Status is the new project status (optional)
Status *types.ProjectStatus `json:"status,omitempty"`
}
UpdateProjectRequest represents a request to update a project