-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We can leverage the Websequence Diagram JS library to automatically generate the UML request sequence graphs. Ideally we'd use NSQ or another queue system to push to in async fashion. To keep things simple the Trace server is in-memory, and available via HTTP reqeusts. #2
- Loading branch information
Showing
18 changed files
with
177 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
"log" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/nu7hatch/gouuid" | ||
) | ||
|
||
func NewTraceID() string { | ||
t, _ := uuid.NewV4() | ||
return t.String() | ||
} | ||
|
||
func post(traceID string, msg string) { | ||
_, err := http.PostForm("http://localhost:5001", url.Values{ | ||
"traceId": {traceID}, | ||
"msg": {msg}, | ||
}) | ||
if err != nil { | ||
log.Panic("Could not connect") | ||
} | ||
} | ||
|
||
func Req(traceID string, from string, to string, action string) { | ||
msg := fmt.Sprintf("%v->%v: %v\n", from, to, action) | ||
post(traceID, msg) | ||
} | ||
|
||
func Rep(traceID string, from string, to string, startTime time.Time) { | ||
elapsedTime := time.Since(startTime) | ||
msg := fmt.Sprintf("%v-->%v: %v\n", from, to, elapsedTime) | ||
post(traceID, msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
// newServer returns a trace server with an | ||
// initialzed slice of events | ||
func newServer() *traceServer { | ||
s := &traceServer{} | ||
s.events = make(map[string][]string) | ||
return s | ||
} | ||
|
||
type traceServer struct { | ||
events map[string][]string | ||
} | ||
|
||
func (s traceServer) requestHandler(w http.ResponseWriter, r *http.Request) { | ||
if r.Method == "POST" { | ||
r.ParseForm() | ||
|
||
traceID := r.PostFormValue("traceId") | ||
if traceID == "" { | ||
http.Error(w, "Param traceId required", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
msg := r.PostFormValue("msg") | ||
if msg == "" { | ||
http.Error(w, "Param msg required", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
s.events[traceID] = append(s.events[traceID], msg) | ||
} else { | ||
traceID := r.URL.Query().Get("traceId") | ||
if traceID == "" { | ||
http.Error(w, "Param traceID required", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
fmt.Fprintln(w, "<div class=wsd wsd_style=\"default\" ><pre>") | ||
for _, msg := range s.events[traceID] { | ||
fmt.Fprintln(w, msg) | ||
} | ||
fmt.Fprintln(w, "</pre></div>") | ||
fmt.Fprintln(w, "<script type=\"text/javascript\" src=\"http://www.websequencediagrams.com/service.js\"></script>") | ||
} | ||
} | ||
|
||
func main() { | ||
var port = flag.String("port", "5001", "The server port") | ||
flag.Parse() | ||
|
||
s := newServer() | ||
http.HandleFunc("/", s.requestHandler) | ||
log.Fatal(http.ListenAndServe(":"+*port, nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.