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

App health #35

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

App health #35

wants to merge 15 commits into from

Conversation

seeker815
Copy link

@seeker815 seeker815 commented Dec 7, 2017

The branch has the following changes

  • Created a new check for Marathon App HTTP Checks
  • Added the Check to list of Checks for each App

@ashwanthkumar
Copy link
Owner

@seeker815 Quick couple of feedback

  • Please format the file using go fmt
  • Please add tests
  • Please don't use snake characters for variable names. Consider using camelCase like in all other files.

// and Check for 200 status code
func (h *AppHealth) Check(app marathon.Application) AppCheck {
host := maps.GetString(app.Labels, "router.hosts", "notDefined")
host_path := app.HealthChecks[0].Path
Copy link
Owner

@ashwanthkumar ashwanthkumar Dec 8, 2017

Choose a reason for hiding this comment

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

We should be checking for only HTTP type health check from the spec.

Copy link
Author

@seeker815 seeker815 Dec 25, 2017

Choose a reason for hiding this comment

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

@ashwanthkumar This is the first step, now we check for HTTP and if so carry on. If not HTTP, we give a mild warning and message...any other suggestions, commit below
408f173

// Checks App health status of App Endpoint by reading router.hosts
// and Check for 200 status code
func (h *AppHealth) Check(app marathon.Application) AppCheck {
host := maps.GetString(app.Labels, "router.hosts", "notDefined")
Copy link
Owner

Choose a reason for hiding this comment

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

Should we skip this change if router.hosts is not defined? Also that parameter name is also not configurable. Can we please make it so? Given this is an open source versions, others might / might not want to enable this check. So we also need an ability to disable the check (via another label? -- which is disabled by default?) What are your thoughts on it?

Copy link
Author

Choose a reason for hiding this comment

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

I think having another label to disable this check would be too verbose, would it be possible to do this while invoking the app at the beginning?


resp, err := http.Get(host_url)
if err != nil {
log.Fatal(err)
Copy link
Owner

Choose a reason for hiding this comment

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

log.Fatal kills the go process right? We don't want that. Please log the message and return the status as Failed.

Copy link
Author

Choose a reason for hiding this comment

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

Logging the message now and returning a Warning with the error status. Do we create a new flag for non-app failures?

if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
Copy link
Owner

Choose a reason for hiding this comment

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

Please move the defer right after the http.Get call.

Copy link
Author

@seeker815 seeker815 Dec 25, 2017

Choose a reason for hiding this comment

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

Defer is moved to the top right after we check for any errors

result = Pass
} else {
result = Critical
message = fmt.Sprintf("HTTP Response Status: , " + strconv.Itoa(resp.StatusCode), responseString)
Copy link
Owner

Choose a reason for hiding this comment

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

Why using + when using fmt.Sprintf?

Copy link
Author

Choose a reason for hiding this comment

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

Modified the sprintf format b8c6053

// Checks App health status of App Endpoint by reading router.hosts
// and Check for 200 status code
func (h *AppHealth) Check(app marathon.Application) AppCheck {
host := maps.GetString(app.Labels, "router.hosts", "notDefined")
Copy link
Owner

Choose a reason for hiding this comment

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

Also internally this router.hosts can also contain multiple dns names. So you might want to account for that as well.

Copy link
Author

Choose a reason for hiding this comment

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

Accounted for multiple router.hosts in this commit and it now checks the first dns name for HTTP check. I don't believe there is any need to check other hosts which will be taken care of in the dns check 9d95e85

Copy link
Owner

@ashwanthkumar ashwanthkumar left a comment

Choose a reason for hiding this comment

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

I also see the build failing may be because it's trying to talk to private network as part of the test. It would be great if we can fix that too.

func TestAppHealthGetHosts(t *testing.T) {
check := AppHealth{}
appLabels := make(map[string]string)
appLabels["router.hosts"] = "zeus.prod.indix.tv"
Copy link
Owner

Choose a reason for hiding this comment

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

Please avoid using real DNS names. We should instead mock the http client instance that we use inside AppHealth so they can be mocked in the tests.

Copy link
Author

Choose a reason for hiding this comment

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

Build fails due to private network, I will check and see how to fix this. Also will mock http client instance @ashwanthkumar
(something wrong with my github notifications, will fix that)

healthCheckProtocol := app.HealthChecks[0].Protocol
hostURL := strings.Join([]string{"http://", host, healthCheckPath}, "")
result := Pass
message := fmt.Sprintf("HTTP Status OK!!")
Copy link
Owner

Choose a reason for hiding this comment

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

Please avoid ! in the log statements.

result := Pass
message := fmt.Sprintf("HTTP Status OK!!")

if healthCheckProtocol == "HTTP" {
Copy link
Owner

Choose a reason for hiding this comment

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

Is it always capital cased? Should we either upper / lower case the healthCheckProtocol and check against the string to be sure?

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