From c316a8a6323fe32bb040acd08225409e57bf9980 Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Wed, 13 Jan 2021 13:49:38 +0000 Subject: [PATCH 1/4] add getNode endpoint to get node address for trace ID --- route/route.go | 7 +++++++ route/route_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/route/route.go b/route/route.go index 9f17268c42..0d56d23d02 100644 --- a/route/route.go +++ b/route/route.go @@ -132,6 +132,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("/getNode/{traceID}", r.getNode).Name("return host given trace ID") // require an auth header for events and batches authedMuxxer := muxxer.PathPrefix("/1/").Methods("POST").Subrouter() @@ -199,6 +200,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) getNode(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") diff --git a/route/route_test.go b/route/route_test.go index ee26527a98..4c8bf62ca2 100644 --- a/route/route_test.go +++ b/route/route_test.go @@ -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" ) @@ -234,3 +236,35 @@ func TestUnmarshal(t *testing.T) { t.Error("Expecting", now, "Received", b) } } + +func TestGetNode(t *testing.T) { + req, _ := http.NewRequest("GET", "/getNode/123abcdef", nil) + req = mux.SetURLVars(req, map[string]string{"traceID": "123abcdef"}) + + rr := httptest.NewRecorder() + router := &Router{ + Sharder: &TestSharder{}, + } + + router.getNode(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 } From 02fc78365bbcf41eddc1c2dba572eeb7290c129b Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Wed, 13 Jan 2021 13:59:50 +0000 Subject: [PATCH 2/4] update route description --- route/route.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/route/route.go b/route/route.go index 0d56d23d02..4f66b68923 100644 --- a/route/route.go +++ b/route/route.go @@ -132,7 +132,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("/getNode/{traceID}", r.getNode).Name("return host given trace ID") + muxxer.HandleFunc("/getNode/{traceID}", r.getNode).Name("get node address for given trace ID") // require an auth header for events and batches authedMuxxer := muxxer.PathPrefix("/1/").Methods("POST").Subrouter() From c0013ecc8e6c5977698a2a962b96f533f3db6905 Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Thu, 14 Jan 2021 11:47:00 +0000 Subject: [PATCH 3/4] update getNode to debugTrace --- route/route.go | 4 ++-- route/route_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/route/route.go b/route/route.go index 4f66b68923..3dbdcf93ff 100644 --- a/route/route.go +++ b/route/route.go @@ -132,7 +132,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("/getNode/{traceID}", r.getNode).Name("get node address for given trace ID") + 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() @@ -200,7 +200,7 @@ func (r *Router) version(w http.ResponseWriter, req *http.Request) { w.Write([]byte(fmt.Sprintf(`{"source":"refinery","version":"%s"}`, r.versionStr))) } -func (r *Router) getNode(w http.ResponseWriter, req *http.Request) { +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()))) diff --git a/route/route_test.go b/route/route_test.go index 4c8bf62ca2..61bb621413 100644 --- a/route/route_test.go +++ b/route/route_test.go @@ -238,7 +238,7 @@ func TestUnmarshal(t *testing.T) { } func TestGetNode(t *testing.T) { - req, _ := http.NewRequest("GET", "/getNode/123abcdef", nil) + req, _ := http.NewRequest("GET", "/debug/trace/123abcdef", nil) req = mux.SetURLVars(req, map[string]string{"traceID": "123abcdef"}) rr := httptest.NewRecorder() @@ -246,7 +246,7 @@ func TestGetNode(t *testing.T) { Sharder: &TestSharder{}, } - router.getNode(rr, req) + router.debugTrace(rr, req) if body := rr.Body.String(); body != `{"traceID":"123abcdef","node":"http://localhost:12345"}` { t.Error(body) } From f1bdcb8264c27ed903bdc663fdb99e2f5422597d Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Fri, 15 Jan 2021 19:15:06 +0000 Subject: [PATCH 4/4] update test name to match debug/trace route --- route/route_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/route/route_test.go b/route/route_test.go index 61bb621413..c4e75a94ca 100644 --- a/route/route_test.go +++ b/route/route_test.go @@ -237,7 +237,7 @@ func TestUnmarshal(t *testing.T) { } } -func TestGetNode(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"})