-
Notifications
You must be signed in to change notification settings - Fork 11
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
add support for doing HTTP request against instances. #57
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice feature, thanks, I'm glad to see in main :)
4f09f13
to
533f4d2
Compare
checkPort := "80" | ||
|
||
if port == "" { | ||
uri = fmt.Sprintf("http://%s%s", i.IpAddress, path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to make protocol configurable?
|
||
log.Debugf("[GET_URL] Making HTTP request to %s", uri) | ||
client := http.Client{ | ||
Timeout: 3 * time.Second, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to make timeout configurable?
} | ||
|
||
// GetUrl returns the result of an HTTP request to the instance | ||
func (i Instance) GetUrl(path string, port string) RemoteResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name doesn't represents all the functionality defined in the function.
log.Error("[GET_URL] Error reading response body", err) | ||
} | ||
|
||
if resp.Header.Get("Content-Type") == "application/json" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe json unmarshalling is out of the scope of this function
if err != nil { | ||
log.Infof("Error making TCP connection to %s -> %s", net.JoinHostPort(host, port), err) | ||
} | ||
if conn != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if conn == nil
should be a bit more goish
This adds support for doing an HTTP GET to a cloud instance using the instance's network IP.
This facilitates checking instance healthchecks and running services in order to determine whether an instance should be acted upon.
For performance reasons, there is a TCP port check leading up to the HTTP request. The HTTP request is only executed if the instance is found to be listening on the requested port.
Example use case:
"{status: "active"}"
or"{status: "failed"}"