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

kuma-cp: generate HTTP-specific outbound listeners for services tagged with protocol: http #585

Merged
merged 4 commits into from
Feb 18, 2020

Conversation

yskopets
Copy link
Contributor

Summary

  • generate HTTP-specific outbound listeners for services tagged with protocol: http

@yskopets yskopets force-pushed the feature/generate-outbound-listeners-for-http-traffic branch 7 times, most recently from bb1cb8a to f24dbd0 Compare February 15, 2020 13:20
@yskopets yskopets changed the base branch from refactoring/refactor-envoy-config-generators to ci/refactor-e2e-minikube-setup February 15, 2020 13:27
@yskopets yskopets changed the base branch from ci/refactor-e2e-minikube-setup to refactoring/introduce-filter-chain-builder February 15, 2020 13:27
@yskopets yskopets force-pushed the feature/generate-outbound-listeners-for-http-traffic branch 3 times, most recently from 676917a to e3ddf95 Compare February 15, 2020 15:47
@yskopets yskopets marked this pull request as ready for review February 15, 2020 15:52
@yskopets yskopets requested review from a team and jakubdyszkiewicz February 15, 2020 15:52
@yskopets yskopets added this to the 0.4.0 milestone Feb 15, 2020
// a common protocol between HTTP and TCP is TCP,
// a common protocol between GRPC and HTTP2 is HTTP2,
// a common protocol between HTTP and HTTP2 is TCP.
func GetCommonProtocol(one, another mesh_core.Protocol) mesh_core.Protocol {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this function is public?

I found that we expose many methods as public even if those are used only in one place internally. Then we write tests to those methods which creates tests duplication and makes refactor harder.
In this case, tests for InterServiceProtocol would be enough and it would cover GetCommonProtocol just fine.

Copy link
Contributor Author

@yskopets yskopets Feb 17, 2020

Choose a reason for hiding this comment

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

It's been made public mostly for convenience in unit testing.

We don't write unit tests only because a function is public. We write unit tests when we want to test a function in isolation (because we see a value in doing it this way instead of testing indirectly).

Exporting a function makes unit testing simpler. However, it's not a pre-requirement.

I've renamed GetCommonProtocol into getCommonProtocol and updated unit test.

Copy link
Contributor

Choose a reason for hiding this comment

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

I write tests to check functionality, not functions. At least that is what I did until I started writing in Go. The convention of putting tests next to the file kind of tries to force you to write tests to functions.

The problem I have with this approach is that when I want to change the functionality I need to now change tests of two functions. Refactor is harder because if I change anything in the code I need to change functions tests since they are 1:1. Tests should help me refactor code whenever I want, not make it harder.

Exporting a function makes unit testing simpler. However, it's not a pre-requirement.

I don't think we should ever make function public just for the sake of simpler testing. Proper encapsulation makes my reasoning about code much better. I instantly know something is local to this package. Once I see something is public I check where in the other parts of the system it is used.

@@ -162,6 +162,5 @@ networking:
- interface: {{ IP }}:{{ PUBLIC_PORT }}:{{ LOCAL_PORT }}
tags:
service: kuma-example-backend
protocol: http
Copy link
Contributor

Choose a reason for hiding this comment

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

What was a problem here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

e2e test is expecting TcpProxy to be configured.

But adding protocol: http turns TcpProxy into HttpConnectionManager.

We need to test both scenarios:

  1. when a user does add protocol: http
  2. when a user does NOT add protocol: http

That's why I removed protocol: http to restore original e2e test for TCP case.

I will add an e2e test for HTTP case in a separate PR.

@yskopets yskopets force-pushed the feature/generate-outbound-listeners-for-http-traffic branch from 0c06b96 to 7f50e0a Compare February 17, 2020 15:54
@yskopets yskopets force-pushed the refactoring/introduce-filter-chain-builder branch from 9675229 to 38f9afd Compare February 18, 2020 22:36
@yskopets yskopets force-pushed the feature/generate-outbound-listeners-for-http-traffic branch from 7f50e0a to 55077e2 Compare February 18, 2020 23:02
@yskopets yskopets changed the base branch from refactoring/introduce-filter-chain-builder to master February 18, 2020 23:03
@yskopets yskopets merged commit 805116c into master Feb 18, 2020
@devadvocado devadvocado deleted the feature/generate-outbound-listeners-for-http-traffic branch March 30, 2020 13:16
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.

2 participants