Documentation
¶
Index ¶
- type Allocation
- type AllocationQuery
- type AllocationResponse
- type AllocationSet
- type Asset
- type AssetBreakdown
- type AssetProperties
- type AssetQuery
- type AssetResponse
- type AssetSet
- type CloudCost
- type CloudCostProperties
- type CloudCostQuery
- type CloudCostResponse
- type CloudCostSet
- type CloudCostSummary
- type CostMetric
- type EfficiencyMetric
- type EfficiencyQuery
- type EfficiencyResponse
- type MCPRequest
- type MCPResponse
- type MCPServer
- func (s *MCPServer) ProcessMCPRequest(request *MCPRequest) (*MCPResponse, error)
- func (s *MCPServer) QueryAllocations(query *OpenCostQueryRequest) (*AllocationResponse, error)
- func (s *MCPServer) QueryAssets(query *OpenCostQueryRequest) (*AssetResponse, error)
- func (s *MCPServer) QueryCloudCosts(query *OpenCostQueryRequest) (*CloudCostResponse, error)
- func (s *MCPServer) QueryEfficiency(query *OpenCostQueryRequest) (*EfficiencyResponse, error)
- type NodeOverhead
- type OpenCostQueryRequest
- type QueryMetadata
- type QueryType
- type TimeWindow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Allocation ¶
type Allocation struct {
Name string `json:"name"` // Allocation key (namespace, cluster, etc.)
CPUCost float64 `json:"cpuCost"` // Cost of CPU usage
GPUCost float64 `json:"gpuCost"` // Cost of GPU usage
RAMCost float64 `json:"ramCost"` // Cost of memory usage
PVCost float64 `json:"pvCost"` // Cost of persistent volumes
NetworkCost float64 `json:"networkCost"` // Cost of network usage
ExternalCost float64 `json:"externalCost"` // External costs (cloud services, etc.)
TotalCost float64 `json:"totalCost"` // Sum of all costs above
CPUCoreHours float64 `json:"cpuCoreHours"` // Usage metrics: CPU core-hours
RAMByteHours float64 `json:"ramByteHours"` // Usage metrics: RAM byte-hours
GPUHours float64 `json:"gpuHours"` // Usage metrics: GPU-hours
PVByteHours float64 `json:"pvByteHours"` // Usage metrics: PV byte-hours
Start time.Time `json:"start"` // Start timestamp for this allocation
End time.Time `json:"end"` // End timestamp for this allocation
}
type AllocationQuery ¶
type AllocationQuery struct {
Step time.Duration `json:"step,omitempty"`
Accumulate bool `json:"accumulate,omitempty"`
Aggregate string `json:"aggregate,omitempty"`
IncludeIdle bool `json:"includeIdle,omitempty"`
IdleByNode bool `json:"idleByNode,omitempty"`
IncludeProportionalAssetResourceCosts bool `json:"includeProportionalAssetResourceCosts,omitempty"`
IncludeAggregatedMetadata bool `json:"includeAggregatedMetadata,omitempty"`
Filter string `json:"filter,omitempty"` // Filter expression for allocations (e.g., "cluster:production", "namespace:kube-system")
}
AllocationQuery contains the parameters for an allocation query.
type AllocationResponse ¶
type AllocationResponse struct {
// The allocation data, as a map of allocation sets.
Allocations map[string]*AllocationSet `json:"allocations"`
}
AllocationResponse represents the allocation data returned to the AI agent.
type AllocationSet ¶
type AllocationSet struct {
// The name of the allocation set.
Name string `json:"name"`
Properties map[string]string `json:"properties"`
Allocations []*Allocation `json:"allocations"`
}
AllocationSet represents a set of allocation data.
func (*AllocationSet) TotalCost ¶
func (as *AllocationSet) TotalCost() float64
TotalCost calculates the total cost of all allocations in the set.
type Asset ¶
type Asset struct {
Type string `json:"type"`
Properties AssetProperties `json:"properties"`
Labels map[string]string `json:"labels,omitempty"`
Start time.Time `json:"start"`
End time.Time `json:"end"`
Minutes float64 `json:"minutes"`
Adjustment float64 `json:"adjustment"`
TotalCost float64 `json:"totalCost"`
// Disk-specific fields
ByteHours float64 `json:"byteHours,omitempty"`
ByteHoursUsed *float64 `json:"byteHoursUsed,omitempty"`
ByteUsageMax *float64 `json:"byteUsageMax,omitempty"`
StorageClass string `json:"storageClass,omitempty"`
VolumeName string `json:"volumeName,omitempty"`
ClaimName string `json:"claimName,omitempty"`
ClaimNamespace string `json:"claimNamespace,omitempty"`
Local float64 `json:"local,omitempty"`
// Node-specific fields
NodeType string `json:"nodeType,omitempty"`
CPUCoreHours float64 `json:"cpuCoreHours,omitempty"`
RAMByteHours float64 `json:"ramByteHours,omitempty"`
GPUHours float64 `json:"gpuHours,omitempty"`
GPUCount float64 `json:"gpuCount,omitempty"`
CPUCost float64 `json:"cpuCost,omitempty"`
GPUCost float64 `json:"gpuCost,omitempty"`
RAMCost float64 `json:"ramCost,omitempty"`
Discount float64 `json:"discount,omitempty"`
Preemptible float64 `json:"preemptible,omitempty"`
// Breakdown fields (can be used for different types)
Breakdown *AssetBreakdown `json:"breakdown,omitempty"`
CPUBreakdown *AssetBreakdown `json:"cpuBreakdown,omitempty"`
RAMBreakdown *AssetBreakdown `json:"ramBreakdown,omitempty"`
// Overhead (Node-specific)
Overhead *NodeOverhead `json:"overhead,omitempty"`
// LoadBalancer-specific fields
Private bool `json:"private,omitempty"`
Ip string `json:"ip,omitempty"`
// Cloud-specific fields
Credit float64 `json:"credit,omitempty"`
}
Asset represents a single asset data point.
type AssetBreakdown ¶
type AssetProperties ¶
type AssetProperties struct {
Category string `json:"category,omitempty"`
Provider string `json:"provider,omitempty"`
Account string `json:"account,omitempty"`
Project string `json:"project,omitempty"`
Service string `json:"service,omitempty"`
Cluster string `json:"cluster,omitempty"`
Name string `json:"name,omitempty"`
ProviderID string `json:"providerID,omitempty"`
}
type AssetResponse ¶
type AssetResponse struct {
// The asset data, as a map of asset sets.
Assets map[string]*AssetSet `json:"assets"`
}
AssetResponse represents the asset data returned to the AI agent.
type AssetSet ¶
type AssetSet struct {
// The name of the asset set.
Name string `json:"name"`
// The asset data for the set.
Assets []*Asset `json:"assets"`
}
AssetSet represents a set of asset data.
type CloudCost ¶
type CloudCost struct {
Properties CloudCostProperties `json:"properties"`
Window TimeWindow `json:"window"`
ListCost CostMetric `json:"listCost"`
NetCost CostMetric `json:"netCost"`
AmortizedNetCost CostMetric `json:"amortizedNetCost"`
InvoicedCost CostMetric `json:"invoicedCost"`
AmortizedCost CostMetric `json:"amortizedCost"`
}
CloudCost represents a single cloud cost data point.
type CloudCostProperties ¶
type CloudCostProperties struct {
ProviderID string `json:"providerID,omitempty"`
Provider string `json:"provider,omitempty"`
AccountID string `json:"accountID,omitempty"`
AccountName string `json:"accountName,omitempty"`
InvoiceEntityID string `json:"invoiceEntityID,omitempty"`
InvoiceEntityName string `json:"invoiceEntityName,omitempty"`
RegionID string `json:"regionID,omitempty"`
AvailabilityZone string `json:"availabilityZone,omitempty"`
Service string `json:"service,omitempty"`
Category string `json:"category,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
}
CloudCostProperties defines the properties of a cloud cost item.
type CloudCostQuery ¶
type CloudCostQuery struct {
Aggregate string `json:"aggregate,omitempty"` // Comma-separated list of aggregation properties
Accumulate string `json:"accumulate,omitempty"` // e.g., "week", "day", "month"
Filter string `json:"filter,omitempty"` // Filter expression for cloud costs
Provider string `json:"provider,omitempty"` // Cloud provider filter (aws, gcp, azure, etc.)
Service string `json:"service,omitempty"` // Service filter (ec2, s3, compute, etc.)
Category string `json:"category,omitempty"` // Category filter (compute, storage, network, etc.)
Region string `json:"region,omitempty"` // Region filter
// Additional explicit fields for filtering
AccountID string `json:"accountID,omitempty"` // Alias of Account; maps to accountID
InvoiceEntityID string `json:"invoiceEntityID,omitempty"` // Invoice entity ID filter
ProviderID string `json:"providerID,omitempty"` // Cloud provider resource ID filter
Labels map[string]string `json:"labels,omitempty"` // Label filters (key->value)
}
CloudCostQuery contains the parameters for a cloud cost query.
type CloudCostResponse ¶
type CloudCostResponse struct {
// The cloud cost data, as a map of cloud cost sets.
CloudCosts map[string]*CloudCostSet `json:"cloudCosts"`
// Summary information
Summary *CloudCostSummary `json:"summary,omitempty"`
}
CloudCostResponse represents the cloud cost data returned to the AI agent.
type CloudCostSet ¶
type CloudCostSet struct {
// The name of the cloud cost set.
Name string `json:"name"`
// The cloud cost data for the set.
CloudCosts []*CloudCost `json:"cloudCosts"`
// Aggregation information
AggregationProperties []string `json:"aggregationProperties,omitempty"`
// Time window
Window *TimeWindow `json:"window,omitempty"`
}
CloudCostSet represents a set of cloud cost data.
type CloudCostSummary ¶
type CloudCostSummary struct {
TotalNetCost float64 `json:"totalNetCost"`
TotalAmortizedCost float64 `json:"totalAmortizedCost"`
TotalInvoicedCost float64 `json:"totalInvoicedCost"`
KubernetesPercent float64 `json:"kubernetesPercent"`
ProviderBreakdown map[string]float64 `json:"providerBreakdown,omitempty"`
ServiceBreakdown map[string]float64 `json:"serviceBreakdown,omitempty"`
RegionBreakdown map[string]float64 `json:"regionBreakdown,omitempty"`
}
CloudCostSummary provides summary information about cloud costs
type CostMetric ¶
type CostMetric struct {
Cost float64 `json:"cost"`
KubernetesPercent float64 `json:"kubernetesPercent"`
}
CostMetric represents a cost value with Kubernetes percentage
type EfficiencyMetric ¶ added in v1.119.0
type EfficiencyMetric struct {
Name string `json:"name"` // Pod/namespace/controller name based on aggregation
// Current state
CPUEfficiency float64 `json:"cpuEfficiency"` // Usage / Request ratio (0-1+)
MemoryEfficiency float64 `json:"memoryEfficiency"` // Usage / Request ratio (0-1+)
// Current requests and usage
CPUCoresRequested float64 `json:"cpuCoresRequested"`
CPUCoresUsed float64 `json:"cpuCoresUsed"`
RAMBytesRequested float64 `json:"ramBytesRequested"`
RAMBytesUsed float64 `json:"ramBytesUsed"`
// Recommendations (based on actual usage with buffer)
RecommendedCPURequest float64 `json:"recommendedCpuRequest"` // Recommended CPU cores
RecommendedRAMRequest float64 `json:"recommendedRamRequest"` // Recommended RAM bytes
// Resulting efficiency after applying recommendations
ResultingCPUEfficiency float64 `json:"resultingCpuEfficiency"`
ResultingMemoryEfficiency float64 `json:"resultingMemoryEfficiency"`
// Cost analysis
CurrentTotalCost float64 `json:"currentTotalCost"` // Current total cost
RecommendedCost float64 `json:"recommendedCost"` // Estimated cost with recommendations
CostSavings float64 `json:"costSavings"` // Potential savings
CostSavingsPercent float64 `json:"costSavingsPercent"` // Savings as percentage
// Buffer multiplier used for recommendations
EfficiencyBufferMultiplier float64 `json:"efficiencyBufferMultiplier"` // Buffer multiplier applied (e.g., 1.2 for 20% headroom)
// Time window
Start time.Time `json:"start"`
End time.Time `json:"end"`
}
EfficiencyMetric represents efficiency data for a single pod/workload.
type EfficiencyQuery ¶ added in v1.119.0
type EfficiencyQuery struct {
Aggregate string `json:"aggregate,omitempty"` // Aggregation properties (e.g., "pod", "namespace", "controller")
Filter string `json:"filter,omitempty"` // Filter expression for allocations (same as AllocationQuery)
EfficiencyBufferMultiplier *float64 `json:"efficiencyBufferMultiplier,omitempty"` // Buffer multiplier for recommendations (default: 1.2 for 20% headroom)
}
EfficiencyQuery contains the parameters for an efficiency query.
type EfficiencyResponse ¶ added in v1.119.0
type EfficiencyResponse struct {
Efficiencies []*EfficiencyMetric `json:"efficiencies"`
}
EfficiencyResponse represents the efficiency data returned to the AI agent.
type MCPRequest ¶
type MCPRequest struct {
SessionID string `json:"sessionId"`
Query *OpenCostQueryRequest `json:"query"`
}
MCPRequest represents a single turn in a conversation with the OpenCost MCP server.
type MCPResponse ¶
type MCPResponse struct {
Data interface{} `json:"data"`
QueryInfo QueryMetadata `json:"queryInfo"`
}
MCPResponse is the response from the OpenCost MCP server for a single turn.
type MCPServer ¶
type MCPServer struct {
// contains filtered or unexported fields
}
MCPServer holds the dependencies for the MCP API server.
func NewMCPServer ¶ added in v1.119.0
func NewMCPServer(costModel *costmodel.CostModel, provider models.Provider, cloudQuerier cloudcost.Querier) *MCPServer
NewMCPServer creates a new MCP Server.
func (*MCPServer) ProcessMCPRequest ¶ added in v1.119.0
func (s *MCPServer) ProcessMCPRequest(request *MCPRequest) (*MCPResponse, error)
func (*MCPServer) QueryAllocations ¶ added in v1.119.0
func (s *MCPServer) QueryAllocations(query *OpenCostQueryRequest) (*AllocationResponse, error)
func (*MCPServer) QueryAssets ¶ added in v1.119.0
func (s *MCPServer) QueryAssets(query *OpenCostQueryRequest) (*AssetResponse, error)
func (*MCPServer) QueryCloudCosts ¶ added in v1.119.0
func (s *MCPServer) QueryCloudCosts(query *OpenCostQueryRequest) (*CloudCostResponse, error)
QueryCloudCosts translates an MCP query into a CloudCost repository query and transforms the result.
func (*MCPServer) QueryEfficiency ¶ added in v1.119.0
func (s *MCPServer) QueryEfficiency(query *OpenCostQueryRequest) (*EfficiencyResponse, error)
QueryEfficiency queries allocation data and computes efficiency metrics with recommendations.
type NodeOverhead ¶
type NodeOverhead struct {
RamOverheadFraction float64 `json:"ramOverheadFraction"`
CpuOverheadFraction float64 `json:"cpuOverheadFraction"`
OverheadCostFraction float64 `json:"overheadCostFraction"`
}
NodeOverhead represents node overhead information
type OpenCostQueryRequest ¶
type OpenCostQueryRequest struct {
QueryType QueryType `json:"queryType" validate:"required,oneof=allocation asset cloudcost efficiency"`
Window string `json:"window" validate:"required"`
AllocationParams *AllocationQuery `json:"allocationParams,omitempty"`
AssetParams *AssetQuery `json:"assetParams,omitempty"`
CloudCostParams *CloudCostQuery `json:"cloudCostParams,omitempty"`
EfficiencyParams *EfficiencyQuery `json:"efficiencyParams,omitempty"`
}
OpenCostQueryRequest provides a unified interface for all OpenCost query types.
type QueryMetadata ¶
type QueryMetadata struct {
QueryID string `json:"queryId"`
Timestamp time.Time `json:"timestamp"`
ProcessingTime time.Duration `json:"processingTime"`
}
QueryMetadata contains metadata about the query execution.