Skip to content

Commit

Permalink
Merge branch 'main' into mike/otlp
Browse files Browse the repository at this point in the history
* main:
  Add /debug/trace/{traceID} endpoint (#204)

# Conflicts:
#	route/route_test.go
  • Loading branch information
MikeGoldsmith committed Jan 22, 2021
2 parents 260f71f + becd6a2 commit 5045de7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (r *Router) LnS(incomingOrPeer string) {
muxxer.HandleFunc("/alive", r.alive).Name("local health")
muxxer.HandleFunc("/panic", r.panic).Name("intentional panic")
muxxer.HandleFunc("/version", r.version).Name("report version info")
muxxer.HandleFunc("/debug/trace/{traceID}", r.debugTrace).Name("get debug information for given trace ID")

// require an auth header for events and batches
authedMuxxer := muxxer.PathPrefix("/1/").Methods("POST").Subrouter()
Expand Down Expand Up @@ -245,6 +246,12 @@ func (r *Router) version(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(fmt.Sprintf(`{"source":"refinery","version":"%s"}`, r.versionStr)))
}

func (r *Router) debugTrace(w http.ResponseWriter, req *http.Request) {
traceID := mux.Vars(req)["traceID"]
shard := r.Sharder.WhichShard(traceID)
w.Write([]byte(fmt.Sprintf(`{"traceID":"%s","node":"%s"}`, traceID, shard.GetAddress())))
}

// event is handler for /1/event/
func (r *Router) event(w http.ResponseWriter, req *http.Request) {
r.Metrics.IncrementCounter(r.incomingOrPeer + "_router_event")
Expand Down
35 changes: 35 additions & 0 deletions route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"testing"
"time"

"github.com/gorilla/mux"
"github.com/honeycombio/refinery/sharder"
"github.com/klauspost/compress/zstd"
"github.com/vmihailenco/msgpack/v4"
"google.golang.org/grpc/metadata"
Expand Down Expand Up @@ -236,6 +238,7 @@ func TestUnmarshal(t *testing.T) {
}
}

<<<<<<< HEAD
func TestGetAPIKeyAndDatasetFromMetadataCaseInsensitive(t *testing.T) {
const (
apiKeyValue = "test-apikey"
Expand Down Expand Up @@ -357,3 +360,35 @@ func TestGetSampleRateFromAttributes(t *testing.T) {
})
}
}

func TestDebugTrace(t *testing.T) {
req, _ := http.NewRequest("GET", "/debug/trace/123abcdef", nil)
req = mux.SetURLVars(req, map[string]string{"traceID": "123abcdef"})

rr := httptest.NewRecorder()
router := &Router{
Sharder: &TestSharder{},
}

router.debugTrace(rr, req)
if body := rr.Body.String(); body != `{"traceID":"123abcdef","node":"http://localhost:12345"}` {
t.Error(body)
}
}

type TestSharder struct{}

func (s *TestSharder) MyShard() sharder.Shard { return nil }

func (s *TestSharder) WhichShard(string) sharder.Shard {
return &TestShard{
addr: "http://localhost:12345",
}
}

type TestShard struct {
addr string
}

func (s *TestShard) Equals(other sharder.Shard) bool { return true }
func (s *TestShard) GetAddress() string { return s.addr }

0 comments on commit 5045de7

Please sign in to comment.