8000 Replay recorded requests by ReqUID by Amusement · Pull Request #864 · fission/fission · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 14 commits into from
Aug 17, 2018
Merged

Replay recorded requests by ReqUID #864

merged 14 commits into from
Aug 17, 2018

Conversation

Amusement
Copy link
Contributor
@Amusement Amusement commented Aug 15, 2018

This change is Reviewable

@@ -79,6 +80,13 @@ func MakeAPI() (*API, error) {
api.builderManagerUrl = "http://buildermgr"
}

u = os.Getenv("POD_NAMESPACE")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -50,6 +50,7 @@ type (
kubernetesClient *kubernetes.Clientset
storageServiceUrl string
builderManagerUrl string
podNamespace string
Copy link
Member

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.

10000
@@ -0,0 +1,34 @@
package client
Copy link
Member

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

vars := mux.Vars(r)
queriedID := vars["reqUID"]

routerUrl := fmt.Sprintf("http://router.%v", a.podNamespace)
Copy link
Member

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`)"}
Copy link
Member

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?

func ReplayByReqUID(routerUrl string, queriedID string) ([]byte, error) {
client := NewClient()
if client == nil {
return []byte{}, errors.New("failed to create redis client")
Copy link
Member

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...

"github.com/fission/fission/redis/build/gen"
)

func ReplayRequest(routerUrl string, request *redisCache.Request) ([]string, error) {
Copy link
Member

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?


func ReplayRequest(routerUrl string, request *redisCache.Request) ([]string, error) {
path := request.URL["Path"] // Includes slash prefix
payload := request.URL["Payload"]
Copy link
Member

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.

  1. 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

  1. Payload should be in redisCache.Request not redisCache.Request.URL

Copy link
Contributor Author
@Amusement Amusement left a 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.

  1. 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

  1. Payload should be in redisCache.Request not redisCache.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?


defer resp.Body.Close()

fmt.Println("Received: ", resp.Status)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line

if request.Method == http.MethodGet {
req, err = http.NewRequest("GET", targetUrl, nil)
if err != nil {
return []string{}, err
Copy link
Member
@life1347 life1347 Aug 17, 2018

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)

Copy link
Contributor Author
@Amusement Amusement left a 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.

@smruthi2187
Copy link
Contributor

From @Amusement and @life1347 's discussion, this is good to merge! 🎉

@smruthi2187 smruthi2187 merged commit 95eef49 into master Aug 17, 2018
@life1347 life1347 deleted the replay-only branch August 18, 2018 04:02
garyyeap pushed a commit to garyyeap/fission that referenced this pull request Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0