Documentation
¶
Overview ¶
Package HKSample does sampling by hashing the key given to it, then it sees if the key is within the sampling buckets.
This way we guarantee that if a different system uses HKSample, it'll always pick the same events the previous systems picked.
## Key Features:
- No extra metadata to carry in every message you send. - No need for communications between systems to sample/pick the same events/sessions. - Tested in real world scenarios, against millions of events.
## Why i made this library?
I needed it to build a tracing system that samples a complete session/flow, to gain visiblity on a data pipeline that receives events/messages with a single key/id identifying a complete session.
## Installation
go get github.com/lafikl/hksample
## Example
hk := NewHKSample(.20) key := []byte(`5efe2993-6b3d-48e2-ac94-1afd543d9190`) if hk.Sample(key) { log.Printf("Sampled: %s", key) }
## Documentation [GoDoc](https://godoc.org/github.com/lafikl/hksample)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HKSample ¶
type HKSample struct {
// contains filtered or unexported fields
}
func NewHKSample ¶
NewHKSample returns a new instance HKSample percent should be given as a fraction, for example:
NewHKSample(.20) // 20%
func (*HKSample) Sample ¶
Sample returns true if the supplied key falls into the buckets within the given threshold/percentage
func (*HKSample) SampleString ¶
SampleString is the same as Sample but it takes a string