Documentation
¶
Overview ¶
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 ¶
- type ActionExecutor
- type AddMemberRequest
- type AlertEvent
- type BudgetStatus
- type BudgetStatusSummary
- 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) 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 CreateBudgetRequest
- type CreateProjectRequest
- 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) 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) 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) SetProjectBudget(ctx context.Context, projectID string, budget *types.ProjectBudget) 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 ProjectFilter
- type ProjectListResponse
- type ProjectSummary
- type UpdateMemberRequest
- type UpdateProjectRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 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 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) 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 CreateBudgetRequest ¶
type CreateBudgetRequest 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"`
}
CreateBudgetRequest represents a request to create a project budget
func (*CreateBudgetRequest) Validate ¶
func (r *CreateBudgetRequest) Validate() error
Validate validates the create budget request
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
Budget *CreateBudgetRequest `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 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) 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) 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) 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) 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 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 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 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