Documentation ¶
Overview ¶
Cassandra backend based on counters. As long as counters in cassandra can not be TTLed, this backend performs periodic garbage collections.
The implementation is pretty straightforward:
* Every counter in every time period is represented as a separate row * There are two tables: hits_even and hits_odd * Every day is numbered as even or odd (day number since epoch) * Even day counters are stored in hits_even, odd in hits_odd * The table that is not currently updated gets truncated once a day
Memory backend, used mostly for testing, but may be extended to become more useful in the future. In this case it'll need garbage collection.
Index ¶
Constants ¶
const ( DefaultConnectTimeout = time.Duration(200) * time.Millisecond DefaultReplicationFactor = 3 DefaultCleanupHour = 0 DefaultCleanupMinute = 30 )
Standard dial and read timeouts, can be overriden when supplying proxy settings
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface { // Used to retreive time for current stats. // Creates mostly for test reasons so we can override time in tests timeutils.TimeProvider // Get count of the given key in the time period GetCount(key string, period time.Duration) (int64, error) // Updates hitcount of the given key, with the given increment UpdateCount(key string, period time.Duration, increment int64) error }
Stats backend, used to memorize counters for given keys to to request stats about upstreams and tokens
type CassandraBackend ¶
type CassandraBackend struct {
// contains filtered or unexported fields
}
func NewCassandraBackend ¶
func NewCassandraBackend(config *CassandraConfig, timeProvider timeutils.TimeProvider) (*CassandraBackend, error)
func (*CassandraBackend) UpdateCount ¶
func (*CassandraBackend) UtcNow ¶
func (b *CassandraBackend) UtcNow() time.Time
type CassandraConfig ¶
type CassandraConfig struct { Keyspace string Consistency gocql.Consistency Servers []string ConnectTimeout time.Duration ReplicationFactor int LaunchCleanup bool CleanupTime *CleanupTime }
type CleanupTime ¶
type FailingBackend ¶
type FailingBackend struct { }
All operation on this backend always fail
func (*FailingBackend) UpdateCount ¶
func (*FailingBackend) UtcNow ¶
func (b *FailingBackend) UtcNow() time.Time
type MemoryBackend ¶
type MemoryBackend struct { Hits map[string]int64 TimeProvider timeutils.TimeProvider }
func NewMemoryBackend ¶
func NewMemoryBackend(timeProvider timeutils.TimeProvider) (*MemoryBackend, error)
func (*MemoryBackend) UpdateCount ¶
func (*MemoryBackend) UtcNow ¶
func (b *MemoryBackend) UtcNow() time.Time