Skip to content

Instantly share code, notes, and snippets.

@maplebed
Last active September 12, 2019 00:23
Show Gist options
  • Save maplebed/c49b79e5f21a5878bb2874fbce6e637a to your computer and use it in GitHub Desktop.
Save maplebed/c49b79e5f21a5878bb2874fbce6e637a to your computer and use it in GitHub Desktop.
A small program to send events to Honeycomb with a random delay over the past 5 minutes, used to illustrate the problem of undestanding when data is delayed in arrival vs. when the service is actually suffering a drop in throughput.
package main
import (
"fmt"
"math/rand"
"os"
"sync"
"time"
libhoney "github.com/honeycombio/libhoney-go"
)
func main() {
rand.Seed(time.Now().UTC().UnixNano())
wk := os.Getenv("HONEYCOMB_APIKEY")
if wk == "" {
fmt.Println("please configure a writekey with the environment variable $HONEYCOMB_APIKEY")
}
conf := libhoney.Config{
APIKey: wk,
Dataset: "delayedevents",
}
libhoney.Init(conf)
wg := sync.WaitGroup{}
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
for {
fmt.Printf(".")
sendEvent()
}
}()
}
// we never stop the wait groups so this will never finish.
// aka pause here until we're killed
wg.Wait()
}
func sendEvent() {
ev := libhoney.NewEvent()
// shove the event back somewhere in to the last 5 minutes with 40sec of missing data at the leading edge
ev.Timestamp = time.Now().Add(-1 * (time.Duration(rand.Intn(300)) * time.Second) - 40*time.Second)
ev.AddField("foo", 3)
ev.Send()
time.Sleep((time.Duration(rand.Intn(200)) * time.Millisecond))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment