Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // EventsCounter is the count of billing events EventsCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "billing_client", Name: "events_total", Help: "Number and type of billing events", }, []string{"status", "amount_type"}) // AmountsCounter is the total of the billing amounts AmountsCounter = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "billing_client", Name: "amounts_total", Help: "Number and type of billing amounts", }, []string{"status", "amount_type"}) )
Functions ¶
func MustRegisterMetrics ¶
func MustRegisterMetrics()
MustRegisterMetrics is a convenience function for registering all the metrics from this package
Types ¶
type AmountType ¶
type AmountType string
AmountType is a type-cast of the enum for the diferent amount types
const ( // ContainerSeconds is one of the billable metrics ContainerSeconds AmountType = "container-seconds" NodeSeconds AmountType = "node-seconds" WeaveNetSeconds AmountType = "weavenet-seconds" Samples AmountType = "samples" )
type Amounts ¶
type Amounts map[AmountType]int64
Amounts is a map of amount billable metrics to their values
type Client ¶
type Client struct { Config // contains filtered or unexported fields }
Client is a billing client for sending usage information to the billing system.
func (*Client) AddAmounts ¶
func (c *Client) AddAmounts(uniqueKey, internalInstanceID string, timestamp time.Time, amounts Amounts, metadata map[string]string) error
AddAmounts writes unit increments into the billing system. If the call does not complete (due to a crash, etc), then data may or may not have been written successfully.
Requests with the same `uniqueKey` can be retried indefinitely until they succeed, and the results will be deduped.
`uniqueKey` must be set, and not blank. If in doubt, generate a uuid and set that as the uniqueKey. Consider that hashing the raw input data may not be good enough since identical data may be sent from the client multiple times.
`internalInstanceID`, is *not* the external instance ID (e.g. "fluffy-bunny-47"), it is the numeric internal instance ID (e.g. "1234").
`timestamp` is used to determine which time bucket the usage occurred in, it is included so that the result is independent of how long processing takes. Note, in the event of buffering this timestamp may *not* agree with when the charge will be billed to the customer.
`amounts` is a map with all the various amounts we wish to charge the user for.
`metadata` is a general dumping ground for other metadata you may wish to include for auditability. In general, be careful about the size of data put here. Prefer including a lookup address over whole data. For example, include a report id or s3 address instead of the information in the report.
type Config ¶
Config is the config for a billing client
func (*Config) RegisterFlags ¶
RegisterFlags register the billing client flags with the main flag set
type Event ¶
type Event struct { UniqueKey string `json:"unique_key" msg:"unique_key"` InternalInstanceID string `json:"internal_instance_id" msg:"internal_instance_id"` OccurredAt time.Time `json:"occurred_at" msg:"occurred_at"` Amounts Amounts `json:"amounts" msg:"amounts"` Metadata map[string]string `json:"metadata" msg:"metadata"` }
Event is a record of some amount of billable usage for scope.