Documentation
¶
Overview ¶
Package aws provides AWS Marketplace Metering API integration for Zerfoo. It uses an interface-based client so no AWS SDK dependency is required at compile time.
Index ¶
Constants ¶
const ( DimensionInferenceRequests = "inference-requests" DimensionTokensProcessed = "tokens-processed" DimensionGPUHours = "gpu-hours" )
Dimension names for AWS Marketplace metering.
Variables ¶
This section is empty.
Functions ¶
func ValidateDimension ¶
ValidateDimension returns an error if name is not a known metering dimension.
Types ¶
type HTTPMeteringClient ¶
type HTTPMeteringClient struct {
// Endpoint is the AWS Marketplace Metering Service endpoint URL.
Endpoint string
// ProductCode is the AWS Marketplace product code.
ProductCode string
// HTTPClient is the underlying HTTP client. Defaults to http.DefaultClient.
HTTPClient *http.Client
}
HTTPMeteringClient is a lightweight MeteringClient that calls the Marketplace Metering endpoint directly over HTTP. Replace with an SDK-based client in production by implementing the MeteringClient interface with the AWS SDK.
func NewHTTPMeteringClient ¶
func NewHTTPMeteringClient(endpoint, productCode string) *HTTPMeteringClient
NewHTTPMeteringClient creates a new HTTPMeteringClient with sensible defaults.
func (*HTTPMeteringClient) BatchMeterUsage ¶
func (c *HTTPMeteringClient) BatchMeterUsage(ctx context.Context, payload MeteringPayload) (*MeteringResult, error)
BatchMeterUsage implements MeteringClient.
type Meter ¶
type Meter struct {
// contains filtered or unexported fields
}
Meter aggregates usage and reports it via a MeteringClient.
func NewMeter ¶
func NewMeter(client MeteringClient, productCode, customerIdentifier string) *Meter
NewMeter creates a Meter backed by the given MeteringClient.
func (*Meter) RecordGPUHours ¶
RecordGPUHours reports GPU hours consumed (in fractional seconds stored as hundredths of an hour, rounded to integer) to Marketplace.
func (*Meter) RecordInferenceRequests ¶
RecordInferenceRequests reports a count of inference requests to Marketplace.
type MeteringClient ¶
type MeteringClient interface {
// BatchMeterUsage sends usage records to the AWS Marketplace Metering Service.
BatchMeterUsage(ctx context.Context, payload MeteringPayload) (*MeteringResult, error)
}
MeteringClient defines the interface for AWS Marketplace metering operations. Implementing this interface without the AWS SDK allows injecting mocks in tests.
type MeteringPayload ¶
type MeteringPayload struct {
// ProductCode identifies the product in AWS Marketplace.
ProductCode string `json:"productCode"`
// UsageRecords contains one or more usage records to report.
UsageRecords []UsageRecord `json:"usageRecords"`
}
MeteringPayload is the request body sent to the Marketplace Metering API.
type MeteringResult ¶
type MeteringResult struct {
Results []struct {
UsageRecord UsageRecord `json:"usageRecord"`
Status string `json:"status"` // "Success", "CustomerNotSubscribed", "DuplicateRecord"
} `json:"results"`
UnprocessedRecords []UsageRecord `json:"unprocessedRecords"`
}
MeteringResult holds the response from a BatchMeterUsage call.
type UsageRecord ¶
type UsageRecord struct {
// Timestamp is the time the usage occurred (must be within the past hour).
Timestamp time.Time `json:"timestamp"`
// CustomerIdentifier is the AWS Marketplace customer identifier.
CustomerIdentifier string `json:"customerIdentifier"`
// Dimension is one of the defined metering dimensions.
Dimension string `json:"dimension"`
// Quantity is the amount of usage for the given dimension.
Quantity int64 `json:"quantity"`
}
UsageRecord represents a single metering record sent to AWS Marketplace.