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

Use apis.HTTP() #3830

Merged
merged 3 commits into from
Aug 28, 2020
Merged

Use apis.HTTP() #3830

merged 3 commits into from
Aug 28, 2020

Conversation

skonto
Copy link
Contributor

@skonto skonto commented Aug 13, 2020

Fixes #3623

Proposed Changes

  • Use apis.HTTP() instead of apis.ParseURL() in the code base.
  • All instances are replaced except from a few where ParseURL is a better fit eg. when we want to check the uri format and report an error or do a parsing to fill in URI's fields like scheme, host, path etc.
    Left untouched:
$grep -R "apis.ParseURL(" ./
./test/lib/resources/eventing.go:	apisURI, _ := apis.ParseURL(uri)
./test/lib/resources/eventing.go:	apisURI, _ := apis.ParseURL(uri)
./pkg/mtbroker/filter/filter_handler_test.go:					url, err := apis.ParseURL(s.URL)
./pkg/inmemorychannel/message_dispatcher_test.go:	url, err := apis.ParseURL(str)
./pkg/apis/sources/v1alpha1/apiserver_lifecycle.go:		if u, err := apis.ParseURL(uri); err != nil {
./pkg/apis/sources/v1alpha1/apiserver_lifecycle.go:	if u, err := apis.ParseURL(uri); err != nil {
./pkg/apis/sources/v1beta1/ping_lifecycle_test.go:	exampleUri, _ := apis.ParseURL("uri://example")
./pkg/apis/sources/v1beta1/ping_lifecycle_test.go:	exampleUri, _ := apis.ParseURL("uri://example")
./pkg/apis/sources/v1beta1/ping_lifecycle_test.go:	exampleUri, _ := apis.ParseURL("uri://example")
./pkg/apis/sources/v1alpha2/ping_lifecycle_test.go:	exampleUri, _ := apis.ParseURL("uri://example")
./pkg/apis/sources/v1alpha2/ping_lifecycle_test.go:	exampleUri, _ := apis.ParseURL("uri://example")
./pkg/apis/sources/v1alpha2/ping_lifecycle_test.go:	exampleUri, _ := apis.ParseURL("uri://example")
./pkg/apis/sources/v1alpha2/apiserver_lifecycle_test.go:	sink, _ := apis.ParseURL("uri://example")
./pkg/apis/sources/v1alpha2/apiserver_lifecycle_test.go:	sink, _ := apis.ParseURL("uri://example")
./pkg/reconciler/mtbroker/trigger/trigger_test.go:	u, _ := apis.ParseURL(sinkURI)
./pkg/reconciler/source/duck/duck_test.go:	ceSourceURL, _ := apis.ParseURL(ceSource)
./pkg/reconciler/source/duck/duck.go:		sourceURL, err := apis.ParseURL(attrib.Source)
./pkg/reconciler/source/duck/duck.go:		schemaURL, err := apis.ParseURL(schema)
./pkg/reconciler/testing/v1beta1/trigger.go:	uri, _ := apis.ParseURL(rawurl)
./pkg/reconciler/testing/v1beta1/trigger.go:	uri, _ := apis.ParseURL(rawuri)
./pkg/reconciler/testing/v1beta1/trigger.go:		u, _ := apis.ParseURL(uri)
./pkg/reconciler/testing/v1/trigger.go:	uri, _ := apis.ParseURL(rawurl)
./pkg/reconciler/testing/v1/trigger.go:	uri, _ := apis.ParseURL(rawuri)
./pkg/reconciler/testing/v1/trigger.go:		u, _ := apis.ParseURL(uri)
./pkg/reconciler/pingsource/resources/receive_adapter_test.go:	exampleUri, _ := apis.ParseURL("uri://example")

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Aug 13, 2020
@knative-prow-robot knative-prow-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 13, 2020
@knative-prow-robot knative-prow-robot added area/test-and-release Test infrastructure, tests or release needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 13, 2020
@knative-prow-robot
Copy link
Contributor

Welcome @skonto! It looks like this is your first PR to knative/eventing 🎉

@knative-prow-robot
Copy link
Contributor

Hi @skonto. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@skonto skonto changed the title Use apis.HTTP() [WIP]Use apis.HTTP() Aug 13, 2020
@knative-prow-robot knative-prow-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 13, 2020
@skonto skonto force-pushed the apis_http branch 4 times, most recently from c5d0352 to 1738cf4 Compare August 13, 2020 15:15
@pierDipi
Copy link
Member

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 13, 2020
@skonto skonto changed the title [WIP]Use apis.HTTP() Use apis.HTTP() Aug 13, 2020
@knative-prow-robot knative-prow-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Aug 13, 2020
@lionelvillard
Copy link
Member

/test pull-knative-eventing-integration-tests

@knative-test-reporter-robot

The following jobs failed:

Test name Triggers Retries
pull-knative-eventing-integration-tests 2020-08-13 16:24:29.258 +0000 UTC 1/3

Failed non-flaky tests preventing automatic retry of pull-knative-eventing-integration-tests:

test/e2e.TestBrokerChannelFlowV1Beta1BrokerV1/InMemoryChannel-messaging.knative.dev/v1beta1
test/e2e.TestBrokerChannelFlowV1Beta1BrokerV1/InMemoryChannel-messaging.knative.dev/v1
test/e2e.TestBrokerChannelFlowV1Beta1BrokerV1/Channel-messaging.knative.dev/v1beta1
test/e2e.TestBrokerChannelFlowTriggerV1BrokerV1/Channel-messaging.knative.dev/v1beta1
test/e2e.TestBrokerChannelFlowTriggerV1BrokerV1/InMemoryChannel-messaging.knative.dev/v1
test/e2e.TestBrokerChannelFlowTriggerV1BrokerV1/InMemoryChannel-messaging.knative.dev/v1beta1
test/e2e.TestBrokerChannelFlowTriggerV1Beta1BrokerV1Beta1/InMemoryChannel-messaging.knative.dev/v1beta1
test/e2e.TestBrokerChannelFlowTriggerV1Beta1BrokerV1Beta1/Channel-messaging.knative.dev/v1

and 6 more.

Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

I think there are some changes in the meaning of some replacements, for example here https://github.com/knative/eventing/pull/3830/files#diff-ab0df0c2544da80554e8826de8aa0d11R404

@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 16, 2020
@skonto
Copy link
Contributor Author

skonto commented Aug 24, 2020

@pierDipi correct will fix.

@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 25, 2020
@skonto
Copy link
Contributor Author

skonto commented Aug 25, 2020

unit tests pass locally but the CI reports:

=== Failed
=== FAIL: pkg/reconciler/inmemorychannel/dispatcher  (0.00s)
=== CONT  
    testing.go:954: race detected during execution of test
FAIL
FAIL	knative.dev/eventing/pkg/reconciler/inmemorychannel/dispatcher	4.281s

@skonto
Copy link
Contributor Author

skonto commented Aug 25, 2020

/retest

@skonto
Copy link
Contributor Author

skonto commented Aug 25, 2020

@pierDipi fixed cases where a raw uri needs to be parsed, LMKWYT.

@pierDipi
Copy link
Member

/assign

Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

Thanks @skonto!

I left some comments.

Comment on lines 52 to 53
sink, _ := apis.ParseURL("uri://example")
sink := apis.HTTP("example")
sink.Scheme = "uri"
Copy link
Member

Choose a reason for hiding this comment

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

We set the scheme to http and then reset it to uri.
I think it's better to leave as it was before because the scheme isn't HTTP.

Copy link
Contributor Author

@skonto skonto Aug 27, 2020

Choose a reason for hiding this comment

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

Initially I thought from the description that we should use HTTP() everywhere but it is not the case. I will update it.

Comment on lines 201 to 203
sink, _ := apis.ParseURL("uri://example")
sink := apis.HTTP("example")
sink.Scheme = "uri"
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

Comment on lines 93 to 94
// Set path
sinkTargetURI.Path = sinkURIReference
Copy link
Member

@pierDipi pierDipi Aug 27, 2020

Choose a reason for hiding this comment

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

I found complicated figuring out the full URL because it's not set in one place.
What if we use something like:

sinkTargetURI = func() apis.URL {
    u := apis.HTTP(sinkDNS)
    u.Path = sinkURIReference
    return u
}()

or

sinkTargetURI = targetURL(sinkDNS, sinkURIReference)

// ...

func targetURL(host, path string) apis.URL {
   u := apis.HTTP(host)
   u.Path = path
   return u
}

Comment on lines 46 to 47
exampleUri, _ := apis.ParseURL("uri://example")
exampleUri := apis.HTTP("example")
exampleUri.Scheme = "uri"
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@skonto
Copy link
Contributor Author

skonto commented Aug 28, 2020

@pierDipi I updated the PR (also there were a couple of more places where I was setting the scheme in a different statement).

Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

Thank you!

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 28, 2020
@lionelvillard
Copy link
Member

neat!
/approve

@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lionelvillard, pierDipi, skonto

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 Aug 28, 2020
@knative-prow-robot knative-prow-robot merged commit daaf561 into knative:master Aug 28, 2020
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use apis.HTTP() instead of apis.ParseURL() in the codebase
6 participants