Skip to content
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

Hot protocols improvements (for 662) #724

Merged
merged 7 commits into from
Jan 31, 2018
Merged

Conversation

hhexo
Copy link
Contributor

@hhexo hhexo commented Jan 30, 2018

Closes #662.

This change will require FDKs which handle the json function format to be updated.

This change moves some Fn-specific fields around in the JSON protocol structure, thus improving the handling of Fn-specific fields that would otherwise end up in FN-prefixed headers. The rationale for this is in #662.

Fn-specific stuff (Call ID, request url, etc) that used to be stored in the headers of the models.Call is now instead added by the protocol dispatchers at the right time, so that the model reflects what the user has originally provided. The HTTP protocol dispatcher still creates Fn-prefixed headers, because that's the only way it can pass information to the function, but the JSON protocol can provide the information directly in JSON fields.

@hhexo
Copy link
Contributor Author

hhexo commented Jan 30, 2018

I have just noticed that the default format is now missing call ID etc, because it's not going through the dispatchers and it was relying on the Fn-specific headers being set in the model. I'll fix that.

@hhexo
Copy link
Contributor Author

hhexo commented Jan 30, 2018

As for the others, there's no change in HTTP and the advertised changes in JSON:

HTTP
====

BEFORE:

Request foo: 1
Req: POST hello
Headers:
key:'Content-Type'  val:[application/x-www-form-urlencoded]
key:'Fn_call_id'  val:[01C53ZD26Q47WG600000000000]
key:'Content-Length'  val:[4]
key:'Accept'  val:[*/*]
key:'Fn_request_url'  val:[http://localhost:8080/r/myapp/fndump]
key:'User-Agent'  val:[curl/7.54.0]
key:'Fn_deadline'  val:[2018-01-30T16:47:04.711Z]
key:'Fn_method'  val:[POST]
Env:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=ac7d5a564da1
FN_PATH=/fndump
FN_FORMAT=http
FN_APP_NAME=myapp
FN_MEMORY=128
FN_TYPE=sync
HOME=/root
Body:
blah

AFTER:

Request foo: 1
Req: POST hello
Headers:
key:'Fn_call_id'  val:[01C53ZNTC0E7WG600000000000]
key:'Fn_deadline'  val:[2018-01-30T16:51:51.600Z]
key:'Fn_method'  val:[POST]
key:'Content-Type'  val:[application/x-www-form-urlencoded]
key:'User-Agent'  val:[curl/7.54.0]
key:'Content-Length'  val:[4]
key:'Accept'  val:[*/*]
key:'Fn_request_url'  val:[http://localhost:8080/r/myapp/fndump]
Env:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=ddomizio-Mac
FN_APP_NAME=myapp
FN_PATH=/fndump
FN_MEMORY=128
FN_FORMAT=http
FN_TYPE=sync
HOME=/root
Body:
blah


JSON
====

BEFORE:

{
"call_id":"01C53ZF8XJ47WGA00000000000"
,"content_type":"application/x-www-form-urlencoded"
,"body":"blah"
,"protocol":{"type":"sync"
,"request_url":"http://localhost:8080/r/myapp/fndump"
,"headers":{"Accept":["*/*"],"Content-Length":["4"],"Content-Type":["application/x-www-form-urlencoded"],"Fn_call_id":["01C53ZF8XJ47WGA00000000000"],"Fn_deadline":["2018-01-30T16:48:17.122Z"],"Fn_method":["POST"],"Fn_request_url":["http://localhost:8080/r/myapp/fndump"],"User-Agent":["curl/7.54.0"]}
}
}

AFTER:

{
"call_id":"01C53ZQ9DTE7WGA00000000000"
,"content_type":"application/x-www-form-urlencoded"
,"type":"sync"
,"deadline":"2018-01-30T16:52:39.786Z"
,"body":"blah"
,"protocol":{"type":"http"
,"method":"POST"
,"request_url":"http://localhost:8080/r/myapp/fndump"
,"headers":{"Accept":["*/*"],"Content-Length":["4"],"Content-Type":["application/x-www-form-urlencoded"],"User-Agent":["curl/7.54.0"]}
}
}

Type string `json:"type"`
Deadline string `json:"deadline"`
Body string `json:"body"`
Protocol *CallRequestHTTP `json:"protocol"`
Copy link
Member

Choose a reason for hiding this comment

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

First of all, this has to be documented. As follow-up, it is necessary to open issues against FDKs to adopt new changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added documentation in function-format.md. I will file issues on fdks.

if incomingReq.Deadline != ci.Deadline().String() {
t.Errorf("Request Deadline assertion mismatch: expected: %s, got %s",
ci.Deadline(), incomingReq.Deadline)
}
Copy link
Member

Choose a reason for hiding this comment

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

can you add method verification as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added method and request URL testing too.

@hhexo
Copy link
Contributor Author

hhexo commented Jan 30, 2018

I fixed the default protocol too, but there is a change there: the deadline used to be in FN_HEADER_Fn_deadline, whereas now it is in the FN_DEADLINE env var:

DEFAULT
=======

BEFORE:

Env: foo
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=ac7d5a564da1
FN_TYPE=sync
FN_HEADER_Fn_deadline=2018-01-30T16:45:14.619Z
FN_HEADER_Accept=*/*
FN_PATH=/fndump
FN_APP_NAME=myapp
FN_MEMORY=128
FN_CALL_ID=01C53Z9PPB47WG200000000000
FN_METHOD=POST
FN_HEADER_User-Agent=curl/7.54.0
FN_HEADER_Content-Length=4
FN_HEADER_Content-Type=application/x-www-form-urlencoded
FN_FORMAT=default
FN_REQUEST_URL=http://localhost:8080/r/myapp/fndump
HOME=/root
Body
blah

AFTER:

Env: foo
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=ddomizio-Mac
FN_PATH=/fndump
FN_DEADLINE=2018-01-30T17:28:21.772Z
FN_HEADER_Content-Length=4
FN_FORMAT=default
FN_APP_NAME=myapp
FN_MEMORY=128
FN_TYPE=sync
FN_METHOD=POST
FN_REQUEST_URL=http://localhost:8080/r/myapp/fndump
FN_CALL_ID=01C541RN6WE7WG200000000000
FN_HEADER_User-Agent=curl/7.54.0
FN_HEADER_Accept=*/*
FN_HEADER_Content-Type=application/x-www-form-urlencoded
HOME=/root
Body
blah

@denismakogon
Copy link
Member

Overall LGTM. One major concern, JSON format before this change was meant to be close nearly-compatible to CNCF OpenEvent structure, but with this change, we are about to make a step aside. @treeder made JSON proto as it is right now, so i'd like to know if we really want to make that type of changes.

If so, i recommend to do the following: make JSON protocol interface embeddable, so if we'd like to bring OpenEvent to Fn there would just one thing to adjust - actual data structure to serialize.

@treeder
Copy link
Contributor

treeder commented Jan 30, 2018

Our json format won't match openevent, which is fine. Once the dust settles on that, we'll just have another format, like openevent (or I think it's changing to cloudevent now).

@treeder
Copy link
Contributor

treeder commented Jan 30, 2018

LGTM

// something meaningful.
// This assumes StartedAt was set to something other than the default.
// If that isn't set either, then how many things have gone wrong?
// TODO: assert or panic in that case
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 let's just panic. if our tests don't catch this, our tests need more tests

@rdallman
Copy link
Contributor

LGTM. the amendments seem like only additions really at the top level with removal from the header bucket, so it won't hard break really.

@hhexo hhexo merged commit e753732 into master Jan 31, 2018
@kojustin kojustin deleted the i662-hot-protocol-improvements branch October 19, 2018 23:02
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.

JSON protocol improvements
4 participants