Documentation
¶
Overview ¶
Package recorder implements a reference plugin that records all gRPC requests and optionally returns mock cost responses.
Index ¶
- Constants
- type Config
- type Mocker
- func (m *Mocker) CreateActualCostResponse() *pbc.GetActualCostResponse
- func (m *Mocker) CreateEstimateCostResponse() *pbc.EstimateCostResponse
- func (m *Mocker) CreateProjectedCostResponse() *pbc.GetProjectedCostResponse
- func (m *Mocker) CreateRecommendationsResponse() *pbc.GetRecommendationsResponse
- func (m *Mocker) GenerateActualCost() float64
- func (m *Mocker) GenerateProjectedCost() float64
- func (m *Mocker) GenerateRecommendations() []*pbc.Recommendation
- type RecordedRequest
- type Recorder
- type RecorderPlugin
- func (p *RecorderPlugin) EstimateCost(_ context.Context, req *pbc.EstimateCostRequest) (*pbc.EstimateCostResponse, error)
- func (p *RecorderPlugin) GetActualCost(_ context.Context, req *pbc.GetActualCostRequest) (*pbc.GetActualCostResponse, error)
- func (p *RecorderPlugin) GetPluginInfo(_ context.Context, req *pbc.GetPluginInfoRequest) (*pbc.GetPluginInfoResponse, error)
- func (p *RecorderPlugin) GetPricingSpec(_ context.Context, req *pbc.GetPricingSpecRequest) (*pbc.GetPricingSpecResponse, error)
- func (p *RecorderPlugin) GetProjectedCost(_ context.Context, req *pbc.GetProjectedCostRequest) (*pbc.GetProjectedCostResponse, error)
- func (p *RecorderPlugin) GetRecommendations(_ context.Context, req *pbc.GetRecommendationsRequest) (*pbc.GetRecommendationsResponse, error)
- func (p *RecorderPlugin) Name() string
- func (p *RecorderPlugin) Shutdown()
- func (p *RecorderPlugin) Supports(_ context.Context, req *pbc.SupportsRequest) (*pbc.SupportsResponse, error)
- type RequestMetadata
Constants ¶
const ( EnvOutputDir = "FINFOCUS_RECORDER_OUTPUT_DIR" EnvMockResponse = "FINFOCUS_RECORDER_MOCK_RESPONSE" )
Environment variable names for configuration.
const ( DefaultOutputDir = "./recorded_data" DefaultMockResponse = false )
Default configuration values.
const ( // MinProjectedCost is the minimum projected cost: $0.01 per month. MinProjectedCost = 0.01 // MaxProjectedCost is the maximum projected cost: $1000 per month. MaxProjectedCost = 1000.0 // MinActualCost is the minimum actual cost: $0.001 per day. MinActualCost = 0.001 // MaxActualCost is the maximum actual cost: $100 per day. MaxActualCost = 100.0 // HoursPerMonth is the standard hours per month for cost conversions. HoursPerMonth = 730.0 )
Cost range constants for mock generation.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// OutputDir is the directory where recorded JSON files are written.
// Default: "./recorded_data"
OutputDir string
// MockResponse enables randomized mock cost responses.
// When false (default), the plugin returns zero/empty costs.
MockResponse bool
}
Config holds runtime configuration for the recorder plugin. Configuration is loaded from environment variables with sensible defaults.
func LoadConfig ¶
func LoadConfig() *Config
LoadConfig creates a Config from environment variables. Missing variables use default values.
type Mocker ¶
type Mocker struct {
// contains filtered or unexported fields
}
Mocker generates randomized but valid cost responses for testing.
func (*Mocker) CreateActualCostResponse ¶
func (m *Mocker) CreateActualCostResponse() *pbc.GetActualCostResponse
CreateActualCostResponse creates a mock GetActualCostResponse.
func (*Mocker) CreateEstimateCostResponse ¶
func (m *Mocker) CreateEstimateCostResponse() *pbc.EstimateCostResponse
CreateEstimateCostResponse creates a mock EstimateCostResponse.
func (*Mocker) CreateProjectedCostResponse ¶
func (m *Mocker) CreateProjectedCostResponse() *pbc.GetProjectedCostResponse
CreateProjectedCostResponse creates a mock GetProjectedCostResponse.
func (*Mocker) CreateRecommendationsResponse ¶ added in v0.2.4
func (m *Mocker) CreateRecommendationsResponse() *pbc.GetRecommendationsResponse
CreateRecommendationsResponse creates a mock GetRecommendationsResponse.
func (*Mocker) GenerateActualCost ¶
GenerateActualCost generates a randomized daily cost. Uses log-scale distribution for realistic cost spread.
func (*Mocker) GenerateProjectedCost ¶
GenerateProjectedCost generates a randomized monthly cost. Uses log-scale distribution for realistic cost spread.
func (*Mocker) GenerateRecommendations ¶ added in v0.2.4
func (m *Mocker) GenerateRecommendations() []*pbc.Recommendation
GenerateRecommendations generates a randomized list of recommendations.
type RecordedRequest ¶
type RecordedRequest struct {
Timestamp string `json:"timestamp"`
Method string `json:"method"`
RequestID string `json:"requestId"`
Request json.RawMessage `json:"request"`
Metadata RequestMetadata `json:"metadata"`
}
RecordedRequest represents a captured gRPC request.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder handles serialization of gRPC requests to JSON files. It is thread-safe and handles I/O errors gracefully.
func NewRecorder ¶
NewRecorder creates a new Recorder instance. It creates the output directory if it doesn't exist.
type RecorderPlugin ¶
type RecorderPlugin struct {
*pluginsdk.BasePlugin
// contains filtered or unexported fields
}
RecorderPlugin implements the CostSourceService interface. It records all incoming gRPC requests to JSON files and optionally returns mock cost responses for testing purposes.
This plugin serves as a reference implementation demonstrating pluginsdk v0.4.6 patterns including:
- BasePlugin embedding for common functionality
- Request validation using SDK helpers
- Graceful shutdown handling
- Thread-safe operation
func NewRecorderPlugin ¶
func NewRecorderPlugin(cfg *Config, logger zerolog.Logger) *RecorderPlugin
NewRecorderPlugin creates a new recorder plugin instance. The plugin is configured via the provided Config and will:
- Record all requests to JSON files in Config.OutputDir
- Return mock responses if Config.MockResponse is true
- Return zero/empty costs if Config.MockResponse is false
func (*RecorderPlugin) EstimateCost ¶
func (p *RecorderPlugin) EstimateCost( _ context.Context, req *pbc.EstimateCostRequest, ) (*pbc.EstimateCostResponse, error)
EstimateCost returns a cost estimate for a resource. When mock responses are enabled, it generates randomized cost data; otherwise it returns a zero-cost response.
func (*RecorderPlugin) GetActualCost ¶
func (p *RecorderPlugin) GetActualCost( _ context.Context, req *pbc.GetActualCostRequest, ) (*pbc.GetActualCostResponse, error)
GetActualCost handles actual cost requests. It validates the request, records it to disk, and returns either:
- Mock cost data (if MockResponse is enabled)
- Empty results (if MockResponse is disabled)
func (*RecorderPlugin) GetPluginInfo ¶ added in v0.2.4
func (p *RecorderPlugin) GetPluginInfo( _ context.Context, req *pbc.GetPluginInfoRequest, ) (*pbc.GetPluginInfoResponse, error)
GetPluginInfo returns information about the plugin.
func (*RecorderPlugin) GetPricingSpec ¶
func (p *RecorderPlugin) GetPricingSpec( _ context.Context, req *pbc.GetPricingSpecRequest, ) (*pbc.GetPricingSpecResponse, error)
GetPricingSpec returns the pricing specification for a resource. The recorder plugin returns an empty response since it does not provide real pricing data.
func (*RecorderPlugin) GetProjectedCost ¶
func (p *RecorderPlugin) GetProjectedCost( _ context.Context, req *pbc.GetProjectedCostRequest, ) (*pbc.GetProjectedCostResponse, error)
GetProjectedCost handles projected cost requests. It validates the request, records it to disk, and returns either:
- Mock cost data (if MockResponse is enabled)
- Zero cost with explanatory note (if MockResponse is disabled)
func (*RecorderPlugin) GetRecommendations ¶ added in v0.2.4
func (p *RecorderPlugin) GetRecommendations( _ context.Context, req *pbc.GetRecommendationsRequest, ) (*pbc.GetRecommendationsResponse, error)
GetRecommendations handles recommendations requests.
func (*RecorderPlugin) Name ¶
func (p *RecorderPlugin) Name() string
Name returns the plugin identifier. This method satisfies the pluginsdk.Plugin interface.
func (*RecorderPlugin) Shutdown ¶
func (p *RecorderPlugin) Shutdown()
Shutdown performs graceful shutdown of the plugin. It flushes any pending writes and releases resources.
func (*RecorderPlugin) Supports ¶ added in v0.3.0
func (p *RecorderPlugin) Supports( _ context.Context, req *pbc.SupportsRequest, ) (*pbc.SupportsResponse, error)
Supports overrides BasePlugin's default to always return false. The recorder is a synthetic/demo plugin and should not be auto-selected for real cost processing by the engine's resource matching logic. The request is still recorded to disk for debugging purposes.
type RequestMetadata ¶
type RequestMetadata struct {
ReceivedAt string `json:"receivedAt"`
ProcessingTimeMs int64 `json:"processingTimeMs"`
}
RequestMetadata contains optional metadata about the request.