Skip to content

Commit

Permalink
Revert "very simple honeycomb integration"
Browse files Browse the repository at this point in the history
This reverts commit 86183b5.
  • Loading branch information
thraxil committed Feb 22, 2020
1 parent d423db1 commit f329ac5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 71 deletions.
21 changes: 9 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
GOBIN ?= go

cask: *.go
$(GOBIN) build .
go build .

test: cask
$(GOBIN) test .
go test .

install_deps:
$(GOBIN) get github.com/kelseyhightower/envconfig
$(GOBIN) get github.com/mitchellh/goamz/aws
$(GOBIN) get github.com/mitchellh/goamz/s3
$(GOBIN) get golang.org/x/oauth2
$(GOBIN) get github.com/prometheus/client_golang/prometheus
$(GOBIN) get github.com/prometheus/procfs
$(GOBIN) get github.com/hashicorp/memberlist
$(GOBIN) get -u github.com/honeycombio/beeline-go/...
go get github.com/kelseyhightower/envconfig
go get github.com/mitchellh/goamz/aws
go get github.com/mitchellh/goamz/s3
go get golang.org/x/oauth2
go get github.com/prometheus/client_golang/prometheus
go get github.com/prometheus/procfs
go get github.com/hashicorp/memberlist

cluster: cask
python run_cluster.py
Expand Down
39 changes: 3 additions & 36 deletions cask.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ import (
"time"

"github.com/hashicorp/memberlist"
beeline "github.com/honeycombio/beeline-go"
"github.com/honeycombio/beeline-go/wrappers/hnynethttp"
libhoney "github.com/honeycombio/libhoney-go"
"github.com/kelseyhightower/envconfig"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

func makeHandler(fn func(http.ResponseWriter, *http.Request, *site), s *site) http.HandlerFunc {
return hnynethttp.WrapHandlerFunc(func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
fn(w, r, s)
})
}
}

var (
Expand Down Expand Up @@ -83,9 +80,6 @@ type config struct {
SSLKey string `envconfig:"SSL_Key"`
ReadTimeout int `envconfig:"READ_TIMEOUT"`
WriteTimeout int `envconfig:"WRITE_TIMEOUT"`

HoneyWriteKey string `envconfig:"HONEYKEY"`
HoneyDataSet string `envconfig:"HONEYDATASET"`
}

func main() {
Expand Down Expand Up @@ -124,20 +118,11 @@ func main() {
log.Println("Base URL: " + c.BaseURL)
log.Println("=======================================")

if c.HoneyWriteKey != "" && c.HoneyDataSet != "" {
beeline.Init(beeline.Config{
WriteKey: c.HoneyWriteKey,
Dataset: c.HoneyDataSet,
ServiceName: "cask",
})
addCommonLibhoneyFields()
}

http.HandleFunc("/", prometheus.InstrumentHandler("root", makeHandler(indexHandler, s)))
http.HandleFunc("/local/", prometheus.InstrumentHandler("local", makeHandler(localHandler, s)))
http.HandleFunc("/file/", prometheus.InstrumentHandler("file", makeHandler(fileHandler, s)))
http.HandleFunc("/join/", prometheus.InstrumentHandler("join", makeHandler(joinHandler, s)))
http.HandleFunc("/config/", prometheus.InstrumentHandler("config", makeHandler(configHandler, s)))
http.HandleFunc("/config/", prometheus.InstrumentHandler("file", makeHandler(configHandler, s)))

http.HandleFunc("/favicon.ico", faviconHandler)
http.Handle("/metrics", promhttp.Handler())
Expand Down Expand Up @@ -203,21 +188,3 @@ func startMemberList(cluster *cluster, conf config) error {

return nil
}

// addCommonLibhoneyFields adds a few fields we want in all events
func addCommonLibhoneyFields() {
// TODO what other fields should we add here for extra color?
libhoney.AddDynamicField("meta.num_goroutines",
func() interface{} { return runtime.NumGoroutine() })
getAlloc := func() interface{} {
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
return mem.Alloc
}
libhoney.AddDynamicField("meta.memory_inuse", getAlloc)

startTime := time.Now()
libhoney.AddDynamicField("meta.process_uptime_sec", func() interface{} {
return time.Now().Sub(startTime) / time.Second
})
}
23 changes: 0 additions & 23 deletions views.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ import (
"net/http"
"strings"
"text/template"

beeline "github.com/honeycombio/beeline-go"
)

// read/write file requests that shall only touch
// the current node. No cluster interaction.
func localHandler(w http.ResponseWriter, r *http.Request, s *site) {
beeline.AddField(r.Context(), "Route", "local")
beeline.AddField(r.Context(), "Node", s.Node.UUID)
beeline.AddField(r.Context(), "Writeable", s.Node.Writeable)

secret := r.Header.Get("X-Cask-Cluster-Secret")
if !s.Cluster.CheckSecret(secret) {
log.Println("unauthorized local file request")
Expand All @@ -37,7 +31,6 @@ func localHandler(w http.ResponseWriter, r *http.Request, s *site) {
}
if len(parts) == 4 {
key := parts[2]
beeline.AddField(r.Context(), "key", key)
log.Printf("%s /local/%s/\n", r.Method, parts[2])
k, err := keyFromString(key)
if err != nil {
Expand Down Expand Up @@ -130,13 +123,9 @@ func serveDirect(w http.ResponseWriter, key key, s *site) bool {
}

func fileHandler(w http.ResponseWriter, r *http.Request, s *site) {
beeline.AddField(r.Context(), "Route", "file")
beeline.AddField(r.Context(), "Node", s.Node.UUID)
beeline.AddField(r.Context(), "Writeable", s.Node.Writeable)
parts := strings.Split(r.URL.String(), "/")
if len(parts) == 4 {
key := parts[2]
beeline.AddField(r.Context(), "key", key)
log.Printf("%s /file/%s/\n", r.Method, parts[2])
k, err := keyFromString(key)
if err != nil {
Expand Down Expand Up @@ -166,9 +155,6 @@ func fileHandler(w http.ResponseWriter, r *http.Request, s *site) {
}

func indexHandler(w http.ResponseWriter, r *http.Request, s *site) {
beeline.AddField(r.Context(), "Route", "index")
beeline.AddField(r.Context(), "Node", s.Node.UUID)
beeline.AddField(r.Context(), "Writeable", s.Node.Writeable)
if r.Method == "GET" {
clusterInfoHandler(w, r, s)
return
Expand All @@ -190,9 +176,6 @@ type clusterInfoPage struct {
}

func clusterInfoHandler(w http.ResponseWriter, r *http.Request, s *site) {
beeline.AddField(r.Context(), "Route", "clusterInfo")
beeline.AddField(r.Context(), "Node", s.Node.UUID)
beeline.AddField(r.Context(), "Writeable", s.Node.Writeable)
p := clusterInfoPage{
Title: "cluster status",
Cluster: s.Cluster,
Expand Down Expand Up @@ -240,9 +223,6 @@ func postFileHandler(w http.ResponseWriter, r *http.Request, s *site) {
}

func joinHandler(w http.ResponseWriter, r *http.Request, s *site) {
beeline.AddField(r.Context(), "Route", "join")
beeline.AddField(r.Context(), "Node", s.Node.UUID)
beeline.AddField(r.Context(), "Writeable", s.Node.Writeable)
if r.Method == "POST" {
if r.FormValue("url") == "" {
fmt.Fprint(w, "no url specified")
Expand Down Expand Up @@ -270,9 +250,6 @@ func joinHandler(w http.ResponseWriter, r *http.Request, s *site) {
}

func configHandler(w http.ResponseWriter, r *http.Request, s *site) {
beeline.AddField(r.Context(), "Route", "config")
beeline.AddField(r.Context(), "Node", s.Node.UUID)
beeline.AddField(r.Context(), "Writeable", s.Node.Writeable)
b, err := json.Marshal(s.Node)
if err != nil {
log.Println(err)
Expand Down

0 comments on commit f329ac5

Please sign in to comment.