Skip to content

Instantly share code, notes, and snippets.

View maplebed's full-sized avatar

Ben Hartshorne maplebed

View GitHub Profile
@maplebed
maplebed / smack_dogfood.go
Last active September 17, 2019 21:22
inserts a bunch of columns to a dataset, thwacking the DB insertion code into leaking something.
package main
import (
"fmt"
"sync"
libhoney "github.com/honeycombio/libhoney-go"
"github.com/honeycombio/libhoney-go/transmission"
)
@maplebed
maplebed / main.go
Last active September 12, 2019 00:23
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"
@maplebed
maplebed / subsample_spans.go
Created August 26, 2019 20:38
Sample traces at one rate, but within kept traces, drop specific spans at a higher rate. Can be confusing, but can also sometimes be useful.
const (
// beeline pre-sampling
shepherdOverallSampleRate = 3
triadSampleRate = 4
)
... initialization ...
// override the default sampler for the beeline
trace.GlobalConfig.SamplerHook = a.MakeSampler()
@maplebed
maplebed / beelineinit.go
Created July 23, 2019 23:28
Adding global fields to the beeline
client, err := libhoney.NewClient(libhoney.ClientConfig{
APIHost: url,
APIKey: writeKey,
Dataset: dataset,
Transmission: &transmission.Honeycomb{
MaxBatchSize: libhoney.DefaultMaxBatchSize,
MaxConcurrentBatches: libhoney.DefaultMaxConcurrentBatches,
PendingWorkCapacity: libhoney.DefaultPendingWorkCapacity,
BatchTimeout: libhoney.DefaultBatchTimeout,
DisableGzipCompression: b.DisableGzipCompression,
@maplebed
maplebed / circle_workflow.go
Created June 21, 2019 05:31
Sample code exercising the new endpoints to the go-circleci package introduced in a PR
package main
import (
"fmt"
"os"
circleci "github.com/jszwedko/go-circleci"
)
func main() {
@maplebed
maplebed / tmux.conf
Created February 20, 2019 18:45
My tmux config. I don't know what most of it means anymore. But it works for me.
# use UTF8
# set -g utf8
# set-window-option -g utf8 on
# make tmux display things in 256 colors
# set -g default-terminal "screen-256color"
set -g default-terminal "xterm-256color"
# set scrollback history to 30000 (30k)
set -g history-limit 30000
@maplebed
maplebed / gorilla_mux_playground.go
Created February 6, 2019 00:19
Play with this by sending requests for /customer, /customer/, and /customer/foo with curl:
package main
import (
"fmt"
"net/http"
"github.com/gorilla/mux"
)
func customersGetHandleFunc(w http.ResponseWriter, r *http.Request) {
@maplebed
maplebed / main.go
Created February 1, 2019 23:58
Test script to race the go beeline by sending supposedly synchronous spans asynchronously. It should work, though the resulting spans will have some marked as having been sent early by the parent. It shouldn't deadlock, which sadly does happen against the beeline at git revision 609a95f
package main
import (
"context"
"fmt"
"runtime"
"time"
beeline "github.com/honeycombio/beeline-go"
libhoney "github.com/honeycombio/libhoney-go"
@maplebed
maplebed / unpack_nested_json.go
Created January 25, 2019 22:13
turns deep json objects into flat objects with dotted keys
// unpackDeepEvent takes a parsed body (straight from json) and returns the
// unmodified original or a copy with any nested maps turned into dotted keys.
// (eg `"headers": {"a":5,"b":3}` turns in to `"headers.a":5,"headers.b":3`).
// Additionally returns a flag saying whether nested json was present, and an
// int indicating the depth actually unpacked.
func unpackDeepEvent(raw map[string]interface{}, maxDepth int) (map[string]interface{}, bool, int) {
unpacked := make(map[string]interface{}, len(raw))
nestedKeys := make(map[string]struct{})
var actualDepth int
for k, v := range raw {
@maplebed
maplebed / beeline_source.go
Last active October 5, 2018 17:23
An event source and an event sink to show libhoney's behavior in the face of a slow API server
package main
// source creates events as quickly as possible and sends them. Libhoney's queue
// quickly fills up and goroutine count stabalizes and it drops additional
// incoming events.
import (
"context"
"fmt"
"runtime"