-
Notifications
You must be signed in to change notification settings - Fork 788
Replay recorded requests by ReqUID #864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
controller/api.go
Outdated
@@ -79,6 +80,13 @@ func MakeAPI() (*API, error) { | |||
api.builderManagerUrl = "http://buildermgr" | |||
} | |||
|
|||
u = os.Getenv("POD_NAMESPACE") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, we already did this at L40. You can remove this
https://github.com/fission/fission/pull/864/files?utf8=%E2%9C%93&diff=split#diff-f00d7ac7727a4b9d850826c85fb27520R40
controller/api.go
Outdated
@@ -50,6 +50,7 @@ type ( | |||
kubernetesClient *kubernetes.Clientset | |||
storageServiceUrl string | |||
builderManagerUrl string | |||
podNamespace string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In same package you can access podNamespace
directly without putting it int the structure.
@@ -0,0 +1,34 @@ | |||
package client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add License here and other files
controller/replayAPI.go
Outdated
vars := mux.Vars(r) | ||
queriedID := vars["reqUID"] | ||
|
||
routerUrl := fmt.Sprintf("http://router.%v", a.podNamespace) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can access podNamespace
directly
fission/main.go
Outdated
@@ -225,6 +225,9 @@ func main() { | |||
{Name: "view", Usage: "View existing records", Flags: []cli.Flag{filterTimeTo, filterTimeFrom, filterFunction, filterTrigger, verbosityFlag, vvFlag}, Action: recordsView}, | |||
} | |||
|
|||
// Replay records | |||
reqIDFlag := cli.StringFlag{Name: "reqUID", Usage: "Replay a particular request by providing the reqUID (to view reqUIDs, do `fission records view`)"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use lower case flag requid
here?
redis/redisApi.go
Outdated
func ReplayByReqUID(routerUrl string, queriedID string) ([]byte, error) { | ||
client := NewClient() | ||
if client == nil { | ||
return []byte{}, errors.New("failed to create redis client") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can return nil for empty slice like this return nil, err...
replayer/replay.go
Outdated
"github.com/fission/fission/redis/build/gen" | ||
) | ||
|
||
func ReplayRequest(routerUrl string, request *redisCache.Request) ([]string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to put this function here? Looks like it's only being in redis/redisApi.go, can we put this the function there as well or redis/replayer/replay.go
?
replayer/replay.go
Outdated
|
||
func ReplayRequest(routerUrl string, request *redisCache.Request) ([]string, error) { | ||
path := request.URL["Path"] // Includes slash prefix | ||
payload := request.URL["Payload"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suddenly found some problem I didn't notice for the record PR. You file an issue to address these problem later.
- Lost some of the structure fields in original request.
For example,RawPath
in url is not included.
https://golang.org/src/net/url/url.go?s=9021:9537#L323
type URL struct {
Scheme string
Opaque string // encoded opaque data
User *Userinfo // username and password information
Host string // host or host:port
Path string // path (relative paths may omit leading slash)
RawPath string // encoded path hint (see EscapedPath method)
ForceQuery bool // append a query ('?') even if RawQuery is empty
RawQuery string // encoded query values, without '?'
Fragment string // fragment for references, without '#'
}
We better to embed the whole url.Url object in the redisCache.Request
directly.
Also, we lost some of fields in the original request structure like RemoteAddr
Trailer
. https://github.com/golang/go/blob/master/src/net/http/request.go#L106-L320
- Payload should be in
redisCache.Request
notredisCache.Request.URL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 7 files reviewed, 8 unresolved discussions (waiting on @life1347 and @Amusement)
controller/api.go, line 53 at r1 (raw file):
Previously, life1347 (Ta-Ching Chen) wrote…
In same package you can access
podNamespace
directly without putting it int the structure.
Cool tip 👍
controller/api.go, line 83 at r1 (raw file):
Previously, life1347 (Ta-Ching Chen) wrote…
In fact, we already did this at L40. You can remove this
https://github.com/fission/fission/pull/864/files?utf8=%E2%9C%93&diff=split#diff-f00d7ac7727a4b9d850826c85fb27520R40
Done.
controller/replayAPI.go, line 16 at r1 (raw file):
Previously, life1347 (Ta-Ching Chen) wrote…
You can access
podNamespace
directly
Done.
controller/client/replayer.go, line 1 at r1 (raw file):
Previously, life1347 (Ta-Ching Chen) wrote…
Add License here and other files
Done.
fission/main.go, line 229 at r1 (raw file):
Previously, life1347 (Ta-Ching Chen) wrote…
Could we use lower case flag
re 8000 quid
here?
Done.
redis/redisApi.go, line 344 at r1 (raw file):
Previously, life1347 (Ta-Ching Chen) wrote…
You can return nil for empty slice like this
return nil, err...
Done.
replayer/replay.go, line 13 at r1 (raw file):
Previously, life1347 (Ta-Ching Chen) wrote…
Any reason to put this function here? Looks like it's only being in redis/redisApi.go, can we put this the function there as well or
redis/replayer/replay.go
?
Good point. Moved it to redis/redisApi.go
.
replayer/replay.go, line 15 at r1 (raw file):
Previously, life1347 (Ta-Ching Chen) wrote…
I suddenly found some problem I didn't notice for the record PR. You file an issue to address these problem later.
- Lost some of the structure fields in original request.
For example,RawPath
in url is not included.
https://golang.org/src/net/url/url.go?s=9021:9537#L323type URL struct { Scheme string Opaque string // encoded opaque data User *Userinfo // username and password information Host string // host or host:port Path string // path (relative paths may omit leading slash) RawPath string // encoded path hint (see EscapedPath method) ForceQuery bool // append a query ('?') even if RawQuery is empty RawQuery string // encoded query values, without '?' Fragment string // fragment for references, without '#' }
We better to embed the whole url.Url object in the
redisCache.Request
directly.
Also, we lost some of fields in the original request structure likeRemoteAddr
Trailer
. https://github.com/golang/go/blob/master/src/net/http/request.go#L106-L320
- Payload should be in
redisCache.Request
notredisCache.Request.URL
In fact this was the first issue I filed under this project. You can view/add to it it here: #800. Yes, it is concerning that we are losing information but I was not able to find an existing standard Protobuf format that fully saves Golang HTTP requests.
As for point #2, I inspected some requests and saw that the Form and PostForm fields are almost never being stored (are always empty). I can remove those fields and add a new one called Payload in redisCache.Request
, and save the payload there. Would that be better?
controller/client/replayer.go
Outdated
|
||
defer resp.Body.Close() | ||
|
||
fmt.Println("Received: ", resp.Status) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this line
redis/redisApi.go
Outdated
if request.Method == http.MethodGet { | ||
req, err = http.NewRequest("GET", targetUrl, nil) | ||
if err != nil { | ||
return []string{}, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil should be enough (here and other return)
Iterating iterating solidifying replayer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 7 files reviewed, 9 unresolved discussions (waiting on @life1347)
redis/redisApi.go, line 395 at r2 (raw file):
Previously, life1347 (Ta-Ching Chen) wrote…
return nil should be enough (here and other return)
Done.
From @Amusement and @life1347 's discussion, this is good to merge! 🎉 |
This change is