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

change content-type of performance tests to application/json #2010

Merged
merged 2 commits into from
Oct 8, 2019

Conversation

capri-xiyue
Copy link
Contributor

@capri-xiyue capri-xiyue commented Oct 8, 2019

Fixes #2009

Proposed Changes

  • change content-type of performance tests to application/json

Release Note

None

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Oct 8, 2019
@capri-xiyue
Copy link
Contributor Author

/assign @grantr

@chizhg
Copy link
Member

chizhg commented Oct 8, 2019

/retest

@slinkydeveloper
Copy link
Contributor

@capri-xiyue why this change?

Copy link
Contributor

@slinkydeveloper slinkydeveloper left a comment

Choose a reason for hiding this comment

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

If you want to change the content type to application/json, then you must quote the body string to make the json valid. An unquoted string is not a valid application/json body

@capri-xiyue
Copy link
Contributor Author

/retest

@capri-xiyue
Copy link
Contributor Author

@capri-xiyue why this change?

FYI #2009. Currently cloudevents sdk doesn't support Content-type "text/plain"

@capri-xiyue
Copy link
Contributor Author

If you want to change the content type to application/json, then you must quote the body string to make the json valid. An unquoted string is not a valid application/json body

@slinkydeveloper, this is how the performance test sends cloudevents
`func (cet CloudEventsTargeter) VegetaTargeter() vegeta.Targeter {
return func(t *vegeta.Target) error {
t.Method = http.MethodPost
t.URL = cet.sinkUrl

	t.Header = make(http.Header)

	t.Header.Set("Ce-Id", uuid.New().String())
	t.Header.Set("Ce-Type", cet.eventType)
	t.Header.Set("Ce-Source", cet.eventSource)
	t.Header.Set("Ce-Specversion", "0.2")

	t.Header.Set("Content-Type", "application/json")

	t.Body = []byte(generateRandString(cet.msgSize))

	return nil
}

}`
What do you mean by "you must quote the body string to make the json valid"? I thought the packge vegeta shoud be able to handle this.

@capri-xiyue
Copy link
Contributor Author

/assign @grantr

@slinkydeveloper
Copy link
Contributor

FYI #2009. Currently cloudevents sdk doesn't support Content-type "text/plain"

The reason I avoided json is to avoid the additional parsing step the receiver does when it receives the message. Maybe can we use a binary format like application/octet-stream to avoid parsing at all?

@slinkydeveloper
Copy link
Contributor

If you want to change the content type to application/json, then you must quote the body string to make the json valid. An unquoted string is not a valid application/json body

@slinkydeveloper, this is how the performance test sends cloudevents
`func (cet CloudEventsTargeter) VegetaTargeter() vegeta.Targeter {
return func(t *vegeta.Target) error {
t.Method = http.MethodPost
t.URL = cet.sinkUrl

	t.Header = make(http.Header)

	t.Header.Set("Ce-Id", uuid.New().String())
	t.Header.Set("Ce-Type", cet.eventType)
	t.Header.Set("Ce-Source", cet.eventSource)
	t.Header.Set("Ce-Specversion", "0.2")

	t.Header.Set("Content-Type", "application/json")

	t.Body = []byte(generateRandString(cet.msgSize))

	return nil
}

}`
What do you mean by "you must quote the body string to make the json valid"? I thought the packge vegeta shoud be able to handle this.

This one:

t.Body = []byte(generateRandString(cet.msgSize))

Should be:

t.Body = []byte("\"" + generateRandString(cet.msgSize) + "\"")

@capri-xiyue
Copy link
Contributor Author

FYI #2009. Currently cloudevents sdk doesn't support Content-type "text/plain"

The reason I avoided json is to avoid the additional parsing step the receiver does when it receives the message. Maybe can we use a binary format like application/octet-stream to avoid parsing at all?

@slinkydeveloper Currently cloudevents sdk-go only supports only supports type as follows:
"", "application/json" and "text/json" and "application/xml" and "text/xml".
application/octet-stream is not supported by cloudevents sdk-go. I've already created cloudevents/sdk-go#232 to further track the Content-type support issues in cloudevents sdk-go.

@grantr
Copy link
Contributor

grantr commented Oct 8, 2019

The request body should be valid given the content-type, so we should add the quotes. When cloudevents/sdk-go#232 is fixed we can change the content-type back.

@knative-prow-robot knative-prow-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. area/test-and-release Test infrastructure, tests or release labels Oct 8, 2019
Copy link
Contributor

@grantr grantr left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 8, 2019
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: capri-xiyue, grantr

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 8, 2019
@knative-prow-robot knative-prow-robot merged commit b2e44b5 into knative:master Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/test-and-release Test infrastructure, tests or release cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change Content-Type to those Content-Type that cloud sdk-go supports
6 participants