hootsuite / healthchecks

A go implementation of the Health Checks API used for microservice exploration, documentation and monitoring.
Other
132 stars 10 forks source link

Issue with http status handler #12

Open mohankumaru opened 4 years ago

mohankumaru commented 4 years ago

The following is the code to register "elastic" endpoint, the http service is running in port 9200 and in localhost.

elastic := healthchecks.StatusEndpoint{
    Name: "elastic Service",
    Slug: "elastic",
    Type: "external",
    IsTraversable: true,
    StatusCheck: httpsc.HttpStatusChecker{
      BaseUrl: "http://localhost:9200",
    },
    TraverseCheck: nil,
  }

statusEndpoints := []healthchecks.StatusEndpoint{ elastic}
 http.Handle("/status/", healthchecks.Handler(statusEndpoints, "about.json", "version.txt", nil))

  http.ListenAndServe(":3333", nil)

So, the command, "http://localhost:3333/status/elastic" , throws the below error.

["CRIT",{"description":"elastic Service","result":"CRIT","details":"Invalid response. Code: 405, Body: {\"error\":\"Incorrect HTTP method for uri [/status/aggregate] and method [GET], allowed: [POST]\",\"status\":405}"}]

the above error is expected, because i checked http.go file , i see that internally HTTPstatuschecker performs GET on http://localhost:9200/status/aggregate, which obviously throws 405.

Does above handler looks good or am I missing anything.

Regards, Mohan

HootAdam commented 4 years ago

Hi @mohankumaru,

Yes you are correct, the default health checker for an HTTP service makes a GET request against the /status/aggregate endpoint of the service being checked. This is because it assumes the service implements the health checks API, which specifies this request as a GET request. See the API specification here. Because of this, the response you are seeing would be expected if the elastic service you want to health check only supports POST requests. I think you have two options: 1) Update the elastic service so that it supports the health checks API. Once the service supports the API, this error would go away. If you can't do this because elastic is something you can't extend, then see option 2. 2) Write a custom status check that checks against some other API endpoint on the elastic service using a POST request. To move forward with this option, see the Writing a StatusCheck section of the README

mohankumaru commented 4 years ago

Hi @HootAdam ,

Thank you for your reply. I followed 2nd approach you suggested. I have some confusion regarding node traversal. I will give you a scenario, can you explain how to form a graph out of that.

Ex. lets say there are four services in a product , s1, s2, s3, s4 and s2 and s4 are dependent on s1.

can you please explain in detail how to form the tree out of this.

HootAdam commented 4 years ago

To form a graph and traverse to nodes in the graph, each node you want to traverse to must implement the Health Checks API, specifically the traverse endpoint. See the docs here.

The easiest way to do this is to use the go healthchecks framework and register your services / dependencies like shown here.

To learn more, check out the demo/test project we have at https://github.com/hootsuite/microservice-graph-explorer-test. It wires up services and allows traversal.