eventstore

package
v0.143.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 18 Imported by: 3

Documentation

Index

Constants

View Source
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 = 700 * time.Minute
	DefaultStoreTimeout   = 45 * time.Second
	DefaultQueryTimeout   = 45 * time.Second
)
View Source
const (
	DummyOrgGUID   = "00000001-0000-0000-0000-000000000000"
	DummyOrgName   = "my-org"
	DummySpaceGUID = "00000001-0001-0000-0000-000000000000"
	DummySpaceName = "my-space"
)
View Source
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 LoadConfig(filename string) (Config, error)

func (*Config) AddCurrencyRate

func (cfg *Config) AddCurrencyRate(c eventio.CurrencyRate)

func (*Config) AddPlan

func (cfg *Config) AddPlan(p eventio.PricingPlan)

func (*Config) AddVATRate

func (cfg *Config) AddVATRate(v eventio.VATRate)

type EventStore

type EventStore struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, db *sql.DB, logger lager.Logger, cfg Config) *EventStore

func NewFromConfig

func NewFromConfig(ctx context.Context, db *sql.DB, logger lager.Logger, filename string) (*EventStore, error)

func (*EventStore) Consolidate added in v0.43.0

func (s *EventStore) Consolidate(filter eventio.EventFilter) error

func (*EventStore) ConsolidateAll added in v0.43.0

func (s *EventStore) ConsolidateAll() error

func (*EventStore) ConsolidateFullMonths added in v0.43.0

func (s *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 (s *EventStore) GetConsolidatedBillableEventRows(ctx context.Context, filter eventio.EventFilter) (eventio.BillableEventRows, error)

func (*EventStore) GetConsolidatedBillableEvents added in v0.43.0

func (s *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 (s *EventStore) IsRangeConsolidated(filter eventio.EventFilter) (bool, error)

func (*EventStore) Ping added in v0.124.0

func (s *EventStore) Ping() error

func (*EventStore) RecordPeriodicMetrics added in v0.132.0

func (s *EventStore) RecordPeriodicMetrics() 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL