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

Fix intention of support for fallback protocol and add tests for probe/cri/registry #3392

Merged
merged 3 commits into from
Nov 12, 2018

Conversation

gotjosh
Copy link
Contributor

@gotjosh gotjosh commented Oct 15, 2018

Hey all 👋,

First of all, thank you for making such a great project! Found it via Hacktoberfest and immediately jumped into the bandwagon for helping out. Love the current organisation/labelling of the issues. Super helpful for us newcomers.

Figured I should get this PR out sooner rather than later to start getting some feedback. While stressing the different code paths with the tests, I noticed there was one case that no matter what I do, I couldn't get an error to bubble up: The case where the scheme is "".

I'm not sure if this is some sort of 🐞 or am I missing something (?), but I ended up refactoring (to the best of my very limited Go knowledge and understanding of the project) some bits to make it so that it complies with what I think the intention was.

From what I read, the assumption was that we don't support URLs were the scheme is not specified but we're supporting them anyways when we use the fallback protocol. The branch is the more natural thing to miss, so I optimised for supporting the case (feedback is very very welcome).

The last commit is very optional, I'm not familiar with Go (in fact, this is my first PR ever). I'm happy to take it out if this is not the way we do things in Goland.

As for the tests they cover:

Unhappy path tests try to cover three scenarios

  • When the endpoint URL scheme is not explicitly supported e.g. HTTP
  • When the endpoint URL scheme is TCP which is also not supported
  • When we fail to parse the given URL (to extract the scheme)

The happy path covers two scenarios

  • When we specify the supported scheme in the URL which is an unix
    socket e.g. unix///var/run/dockershim.sock
  • When we pass a socket address but fail to specify the scheme but our registry attempts
    to use the fallback protocol e.g. var/run/dockershim.sock

Solves #3302

@gotjosh gotjosh force-pushed the add-tests-to-probe-cri branch from 36424df to 9b99cf9 Compare October 15, 2018 20:46
@gotjosh
Copy link
Contributor Author

gotjosh commented Oct 19, 2018

@bboreham gentle nudge (I completely understand if you've been or still are short on time)

As I'd like to try and add some tests for the reporter but I'd like to know whenever I'm on the right track or not.

@errordeveloper
Copy link
Contributor

This generally LGTM, but I'm not actively contributing to scope, but considering this change is adding a test that was previously missing, it looks like a good one to me!

But I'm not very sure why CI is failing with an error message that doesn't seem to relate to changes here in any way:

goveralls -repotoken $COVERALLS_REPO_TOKEN -coverprofile=profile.cov -service=circleci
exit status 2: warning: no packages being tested depend on github.com/weaveworks/scope/app/multitenant
warning: no packages being tested depend on github.com/weaveworks/scope/cri/runtime
warning: no packages being tested depend on github.com/weaveworks/scope/extras/copyreport
warning: no packages being tested depend on github.com/weaveworks/scope/extras/dialer/src
warning: no packages being tested depend on github.com/weaveworks/scope/extras/example/searchapp
warning: no packages being tested depend on github.com/weaveworks/scope/extras/example/shout
warning: no packages being tested depend on github.com/weaveworks/scope/extras/fixprobe
warning: no packages being tested depend on github.com/weaveworks/scope/probe/appclient
warning: no packages being tested depend on github.com/weaveworks/scope/probe/cri
warning: no packages being tested depend on github.com/weaveworks/scope/probe/plugins
warning: no packages being tested depend on github.com/weaveworks/scope/prog
warning: no packages being tested depend on github.com/weaveworks/scope/prog/externalui
warning: no packages being tested depend on github.com/weaveworks/scope/prog/staticui
warning: no packages being tested depend on github.com/weaveworks/scope/render/expected
warning: no packages being tested depend on github.com/weaveworks/scope/test
warning: no packages being tested depend on github.com/weaveworks/scope/test/fixture
warning: no packages being tested depend on github.com/weaveworks/scope/test/utils
warning: no packages being tested depend on github.com/weaveworks/scope/test/weave
warning: no packages being tested depend on github.com/weaveworks/scope/tools/cover
warning: no packages being tested depend on github.com/weaveworks/scope/tools/runner
warning: no packages being tested depend on github.com/weaveworks/scope/tools/socks
# github.com/weaveworks/scope/probe/docker
/tmp/go-build431662974/github.com/weaveworks/scope/probe/docker/_obj/container.go:328:17: undefined: namespaceIPAddresses
# github.com/weaveworks/scope/vendor/github.com/weaveworks/tcptracer-bpf/vendor/github.com/iovisor/gobpf/elf
In file included from vendor/github.com/weaveworks/tcptracer-bpf/vendor/github.com/iovisor/gobpf/elf/elf.go:52:0:
./include/bpf.h:12:30: fatal error: linux/bpf_common.h: No such file or directory
 #include <linux/bpf_common.h>
                              ^
compilation terminated.
# github.com/weaveworks/scope/vendor/github.com/google/gopacket/pcap
vendor/github.com/google/gopacket/pcap/pcap.go:22:18: fatal error: pcap.h: No such file or directory
 #include <pcap.h>
                  ^
compilation terminated.
FAIL	github.com/weaveworks/scope/app [build failed]

Exited with code 1

Could you rebase and force re-running the CI that way?

@gotjosh gotjosh force-pushed the add-tests-to-probe-cri branch from 9b99cf9 to 3cc641d Compare November 1, 2018 12:23
@gotjosh
Copy link
Contributor Author

gotjosh commented Nov 1, 2018

@errordeveloper have rebased now but seems to be the same error.

@bboreham
Copy link
Collaborator

bboreham commented Nov 1, 2018

The integration tests only run on branches in the main repo, to avoid exposing credentials to all comers.
As workaround, anyone with permission to the main repo can push the branch there to have them run.
(but take a look at the PR first)

@bboreham
Copy link
Collaborator

bboreham commented Nov 1, 2018

@gotjosh The code looks ok, but clearly it is doing more than adding a test (and a refactor), so rather than have me guess what that is, could you state it?

I imagine it relates to what you are saying about protocols, but it's better all round if you change the commit message to say what you fixed.

@gotjosh
Copy link
Contributor Author

gotjosh commented Nov 1, 2018

Hey, @bboreham thanks for taking a look and the feedback! 🙌

Are there any particular lines/sections that you would like to document/state as part of the commit message? As part of the PR body, I tried to convey the intention of the first commit in detail perhaps it's just a matter of adding some bits from the description into the commit message. Another thing that occurs to me is that I could split the tests and the changes on two different commits, I'll get tha sorted straight away.

The main reasoning behind the change is:

While stressing the different code paths with the tests, I noticed there was one case that no matter what I do, I couldn't get an error to bubble up: The case where the scheme is "".

I'm not sure if this is some sort of 🐞 or am I missing something (?), but I ended up refactoring (to the best of my very limited Go knowledge and understanding of the project) some bits to make it so that it complies with what I think the intention was.

From what I read, the assumption was that we don't support URLs were the scheme is not specified but we're supporting them anyways when we use the fallback protocol. The branch is the more natural thing to miss, so I optimised for supporting the case (feedback is very very welcome).

Unhappy path tests try to cover three scenarios:

- When the endpoint URL scheme is not explicitly supported e.g. HTTP
- When the endpoint URL scheme is TCP which is also not supported
- When the fail to parse the given URL (to extract the scheme)

The happy path covers two scenarios:

- When we specify the supported scheme in the URL which is an unix
socket e.g. unix///var/run/dockershim.sock
- When we pass a socket address but fail to specify the scheme but our registry attempts
to use the fallback protocol e.g. var/run/dockershim.sock
When we receive an endpoint address without a protocol, our code states we
don't support them and that the format is deprecated.

In reality it was not the case, e.g:

When we received an address in the form of `127.0.0.1`, we'd attempt to
parse the scheme from it, we'd realise is does have one (would be
equivalent to "") and our function `parseEndpoint` would return `"", "", fmt.Error`.

Then, our `parseEndpointWithFallbackProtocol` would use the
fallback protocol (unix) and attempt to connect to `unix://127.0.0.1`.

This meant two things:

1. The error returned from `parseEndpoint` would never be thrown
2. We would connect anyways since the address is valid

This commit changes the assertion logic to match the intention of using
a fallback protocol when one is not supplied.
Also, extracts strings into constants
@gotjosh gotjosh force-pushed the add-tests-to-probe-cri branch from 3cc641d to fbb0277 Compare November 1, 2018 20:42
@gotjosh gotjosh changed the title Add tests for probe/cri/registry Fix intention of support for fallback protocols and add tests for probe/cri/registry Nov 1, 2018
@gotjosh gotjosh changed the title Fix intention of support for fallback protocols and add tests for probe/cri/registry Fix intention of support for fallback protocol and add tests for probe/cri/registry Nov 1, 2018
@satyamz
Copy link
Contributor

satyamz commented Nov 2, 2018

Hi @gotjosh Changes looks good to me. I have triggered the integration tests for latest commits.
Thanks for the change.

@bboreham bboreham merged commit 6356f5c into weaveworks:master Nov 12, 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.

4 participants