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

[WIP] Issue36 - Eureka integration #46

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions discovery/eureka.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ func NewEurekaClient(eurekaUrl string) (ec EurekaClient, err error) {

var errNoIpsFound = errors.New("No IPs associated to the requested App name")
dcaba marked this conversation as resolved.
Show resolved Hide resolved

// TODO: Probably we should break this function
func (ec EurekaClient) GetIPs(appName string) ([]string, error) {
eurekaAppUrl := ec.eurekaUrl + "/v2/apps/" + appName
//resp, err := http.Get(eurekaAppUrl, "application/json; charset=utf-8")
// can we reuse the client but starting from 0 in terms of timeout? to review
httpclient := http.Client{Timeout: time.Second * eurekaClientTimeoutInSeconds}
resp, err := httpclient.Get(eurekaAppUrl)
req, err := http.NewRequest("GET", eurekaAppUrl, nil)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why did you change from httpclient.Get to http.NewRequest + httpclient.Do?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because I'm trying to add a request header, and the Get method does not allow me so

if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
resp, err := httpclient.Do(req)
if serr, ok := err.(net.Error); ok && serr.Timeout() {
return []string{},errEurekaTimesOut
} else if err != nil {
Expand All @@ -56,6 +62,7 @@ func (ec EurekaClient) GetIPs(appName string) ([]string, error) {
return []string{},errEurekaUnexpectedHttpResponseCode
}
body, err := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
fmt.Println("Response from eureka:", string(body))
// parsing to get the right data will be done like this: https://stackoverflow.com/a/35665161
return nil, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guessed you will return the string array with the IPs here instead of nil...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

WIP, WIP, WIP... ;)

}
8 changes: 5 additions & 3 deletions discovery/eureka_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ func TestMain(m *testing.M) {
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
Copy link
Collaborator

Choose a reason for hiding this comment

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

this resource is the Eureka container running, isn't it? a more descriptive name could be great 😄

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍 . I was following the examples to strictly 😸

Repository: "netflixoss/eureka",
Tag: "1.3.1",
PortBindings: map[dc.Port][]dc.PortBinding{
dc.Port(strconv.Itoa(eurekaTestPort) + "/tcp"): {{HostIP: "", HostPort: strconv.Itoa(eurekaTestPort)}},
//Repository: "containers.schibsted.io/spt-infrastructure/eureka-docker",
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is this comment for? own testing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

WIP. Comparing the (old) public version in eureka with one that is newer, but not public...

//Tag: "latest",
PortBindings: map[dc.Port][]dc.PortBinding{
dc.Port(strconv.Itoa(eurekaTestPort) + "/tcp"): {{HostIP: "", HostPort: strconv.Itoa(eurekaTestPort)}},
},
})
if err != nil {
Expand Down Expand Up @@ -99,7 +101,7 @@ func TestEurekaClientValidApp(t *testing.T) {
t.Fatal("Eureka returned an error when requesting the IPs:", err)
}
if len(ipsFromEureka) != 1 || ipsFromEureka[0] != ipAddr {
t.Fatal("Eureka returned a set of IPs we did not expect for our service:", ipsFromEureka )
t.Fatal("Eureka returned a set of IPs we did not expect for our service:", ipsFromEureka)
}

}
Expand Down