Documentation ¶
Index ¶
- Constants
- func WithBillableEvents(query string, filter eventio.EventFilter, args ...interface{}) (string, []interface{}, error)
- type BillableEventRows
- type CachedBillableEventRows
- type Config
- type EventStore
- func (e *EventStore) Consolidate(filter eventio.EventFilter) error
- func (e *EventStore) ConsolidateAll() error
- func (e *EventStore) ConsolidateFullMonths(startAt string, endAt string) error
- func (s *EventStore) ForecastBillableEventRows(ctx context.Context, events []eventio.UsageEvent, filter eventio.EventFilter) (eventio.BillableEventRows, error)
- func (s *EventStore) ForecastBillableEvents(input []eventio.UsageEvent, filter eventio.EventFilter) ([]eventio.BillableEvent, error)
- func (s *EventStore) GetBillableEventRows(ctx context.Context, filter eventio.EventFilter) (eventio.BillableEventRows, error)
- func (s *EventStore) GetBillableEvents(filter eventio.EventFilter) ([]eventio.BillableEvent, error)
- func (e *EventStore) GetConsolidatedBillableEventRows(ctx context.Context, filter eventio.EventFilter) (eventio.BillableEventRows, error)
- func (e *EventStore) GetConsolidatedBillableEvents(filter eventio.EventFilter) ([]eventio.BillableEvent, error)
- func (s *EventStore) GetCurrencyRates(filter eventio.TimeRangeFilter) ([]eventio.CurrencyRate, error)
- func (s *EventStore) GetEvents(filter eventio.RawEventFilter) ([]eventio.RawEvent, error)
- func (s *EventStore) GetPricingPlans(filter eventio.TimeRangeFilter) ([]eventio.PricingPlan, error)
- func (s *EventStore) GetTotalCost() ([]eventio.TotalCost, error)
- func (s *EventStore) GetUsageEventRows(filter eventio.EventFilter) (eventio.UsageEventRows, error)
- func (s *EventStore) GetUsageEvents(filter eventio.EventFilter) ([]eventio.UsageEvent, error)
- func (s *EventStore) GetVATRates(filter eventio.TimeRangeFilter) ([]eventio.VATRate, error)
- func (s *EventStore) Init() error
- func (e *EventStore) IsRangeConsolidated(filter eventio.EventFilter) (bool, error)
- func (s *EventStore) Refresh() error
- func (s *EventStore) StoreEvents(events []eventio.RawEvent) error
- type UsageEventRows
Constants ¶
const ( AppUsageTableName = "app_usage_events" ServiceUsageTableName = "service_usage_events" ComputePlanGUID = "f4d4b95a-f55e-4593-8d54-3364c25798c4" ComputeServiceGUID = "4f6f0a18-cdd4-4e51-8b6b-dc39b696e61b" TaskPlanGUID = "ebfa9453-ef66-450c-8c37-d53dfd931038" StagingPlanGUID = "9d071c77-7a68-4346-9981-e8dafac95b6f" DefaultInitTimeout = 25 * time.Minute DefaultRefreshTimeout = 25 * time.Minute DefaultStoreTimeout = 45 * time.Second DefaultQueryTimeout = 45 * time.Second )
const ( DummyOrgGUID = "00000001-0000-0000-0000-000000000000" DummyOrgName = "my-org" DummySpaceGUID = "00000001-0001-0000-0000-000000000000" DummySpaceName = "my-space" )
const (
DefaultConsolidationStartDate = "2017-07-01"
)
Variables ¶
This section is empty.
Functions ¶
func WithBillableEvents ¶ added in v0.43.0
func WithBillableEvents(query string, filter eventio.EventFilter, args ...interface{}) (string, []interface{}, error)
WithBillableEvents wraps a given query with a subquery called billable_events, containing the result of applying the given pricing formula to the events for the given filter.
Other included tables are:
- components_with_price: Components and formulas selected for this filter
- filtered range: time range of the filter
Types ¶
type BillableEventRows ¶
type BillableEventRows struct {
// contains filtered or unexported fields
}
func (*BillableEventRows) Close ¶
func (ber *BillableEventRows) Close() error
Close ends the query connection. You must call this. So stick it in a defer.
func (*BillableEventRows) Err ¶
func (ber *BillableEventRows) Err() error
Err returns any errors that occurred behind the scenes during processing. Call this at the end of your iteration.
func (*BillableEventRows) Event ¶
func (ber *BillableEventRows) Event() (*eventio.BillableEvent, error)
Event returns the current row's BillableEvent. Call Next() to get the next row. You must call Next _before_ calling this method
func (*BillableEventRows) EventJSON ¶
func (ber *BillableEventRows) EventJSON() ([]byte, error)
EventJSON returns the JSON representation of the event directly from the db. If you are just going to marshal the object to JSON immediately, then this is probably more efficient.
func (*BillableEventRows) Next ¶
func (ber *BillableEventRows) Next() bool
Next moves the row cursor to the next iteration. Returns false if no more rows.
type CachedBillableEventRows ¶ added in v0.43.0
type CachedBillableEventRows struct { }
type Config ¶
type Config struct { VATRates []eventio.VATRate `json:"vat_rates"` // vat rate CurrencyRates []eventio.CurrencyRate `json:"currency_rates"` // exchange rates PricingPlans []eventio.PricingPlan `json:"pricing_plans"` // dataset to generate prices from IgnoreMissingPlans bool `json:"ignore_missing_plans"` // if true, will generate missing plans that emit "£0", useful for testing }
func LoadConfig ¶
func (*Config) AddCurrencyRate ¶
func (cfg *Config) AddCurrencyRate(c eventio.CurrencyRate)
func (*Config) AddPlan ¶
func (cfg *Config) AddPlan(p eventio.PricingPlan)
func (*Config) AddVATRate ¶
type EventStore ¶
type EventStore struct {
// contains filtered or unexported fields
}
func NewFromConfig ¶
func (*EventStore) Consolidate ¶ added in v0.43.0
func (e *EventStore) Consolidate(filter eventio.EventFilter) error
func (*EventStore) ConsolidateAll ¶ added in v0.43.0
func (e *EventStore) ConsolidateAll() error
func (*EventStore) ConsolidateFullMonths ¶ added in v0.43.0
func (e *EventStore) ConsolidateFullMonths(startAt string, endAt string) error
func (*EventStore) ForecastBillableEventRows ¶
func (s *EventStore) ForecastBillableEventRows(ctx context.Context, events []eventio.UsageEvent, filter eventio.EventFilter) (eventio.BillableEventRows, error)
func (*EventStore) ForecastBillableEvents ¶
func (s *EventStore) ForecastBillableEvents(input []eventio.UsageEvent, filter eventio.EventFilter) ([]eventio.BillableEvent, error)
func (*EventStore) GetBillableEventRows ¶
func (s *EventStore) GetBillableEventRows(ctx context.Context, filter eventio.EventFilter) (eventio.BillableEventRows, error)
GetBillableEventRows returns a handle to a resultset of BillableEvents. Use this to iterate over rows without buffering all into memory. You must call rows.Close when you are done to release the connection. Use GetBillableEvents if you intend on buffering everything into memory.
func (*EventStore) GetBillableEvents ¶
func (s *EventStore) GetBillableEvents(filter eventio.EventFilter) ([]eventio.BillableEvent, error)
GetBillableEvents returns a slice of billable events for the given filter. Due to the large number of results that can be returned it is recormended you use the GetBillableEventRows version to avoid buffering everything into memory
func (*EventStore) GetConsolidatedBillableEventRows ¶ added in v0.43.0
func (e *EventStore) GetConsolidatedBillableEventRows(ctx context.Context, filter eventio.EventFilter) (eventio.BillableEventRows, error)
func (*EventStore) GetConsolidatedBillableEvents ¶ added in v0.43.0
func (e *EventStore) GetConsolidatedBillableEvents(filter eventio.EventFilter) ([]eventio.BillableEvent, error)
func (*EventStore) GetCurrencyRates ¶ added in v0.57.0
func (s *EventStore) GetCurrencyRates(filter eventio.TimeRangeFilter) ([]eventio.CurrencyRate, error)
func (*EventStore) GetEvents ¶
func (s *EventStore) GetEvents(filter eventio.RawEventFilter) ([]eventio.RawEvent, error)
GetEvents returns the eventio.RawEvents filtered using eventio.RawEventFilter if present
func (*EventStore) GetPricingPlans ¶ added in v0.24.0
func (s *EventStore) GetPricingPlans(filter eventio.TimeRangeFilter) ([]eventio.PricingPlan, error)
func (*EventStore) GetTotalCost ¶ added in v0.65.0
func (s *EventStore) GetTotalCost() ([]eventio.TotalCost, error)
func (*EventStore) GetUsageEventRows ¶
func (s *EventStore) GetUsageEventRows(filter eventio.EventFilter) (eventio.UsageEventRows, error)
GetUsageEventRows returns a handle to a resultset of UsageEvents. Use this to iterate over rows without buffering all into memory. You must call rows.Close when you are done to release the connection. Use GetUsageEvents if you intend on buffering everything into memory.
func (*EventStore) GetUsageEvents ¶
func (s *EventStore) GetUsageEvents(filter eventio.EventFilter) ([]eventio.UsageEvent, error)
GetUsageEvents returns a slice of usage events for the given filter. Due to the large number of results that can be returned it is recommended you use the GetUsageEventRows version to avoid buffering everything into memory
func (*EventStore) GetVATRates ¶ added in v0.57.0
func (s *EventStore) GetVATRates(filter eventio.TimeRangeFilter) ([]eventio.VATRate, error)
func (*EventStore) Init ¶
func (s *EventStore) Init() error
Init initialises the database tables and functions
func (*EventStore) IsRangeConsolidated ¶ added in v0.43.0
func (e *EventStore) IsRangeConsolidated(filter eventio.EventFilter) (bool, error)
func (*EventStore) Refresh ¶
func (s *EventStore) Refresh() error
Refresh triggers regeneration of the cached normalized view of the event dat and rebuilds the billable components. Ideally you should do this once a day
func (*EventStore) StoreEvents ¶
func (s *EventStore) StoreEvents(events []eventio.RawEvent) error
type UsageEventRows ¶
type UsageEventRows struct {
// contains filtered or unexported fields
}
func (*UsageEventRows) Close ¶
func (ber *UsageEventRows) Close() error
Close ends the query connection. You must call this. So stick it in a defer.
func (*UsageEventRows) Err ¶
func (ber *UsageEventRows) Err() error
Err returns any errors that occurred behind the scenes during processing. Call this at the end of your iteration.
func (*UsageEventRows) Event ¶
func (ber *UsageEventRows) Event() (*eventio.UsageEvent, error)
Event returns the current row's UsageEvent. Call Next() to get the next row. You must call Next _before_ calling this method
func (*UsageEventRows) EventJSON ¶
func (ber *UsageEventRows) EventJSON() ([]byte, error)
EventJSON returns the JSON representation of the event directly from the db. If you are just going to marshal the object to JSON immediately, then this is probably more efficient.
func (*UsageEventRows) Next ¶
func (ber *UsageEventRows) Next() bool
Next moves the row cursor to the next iteration. Returns false if no more rows.