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

Return info msg for /health endpoint #1465

Merged
merged 7 commits into from
Apr 13, 2019

Conversation

stefanvassilev
Copy link
Contributor

Short description of the changes

  • Return 200 OK for status ready
  • Return Json containing time startedAt and upTime statistics

Resolves #1450

},
Ready: {
statusCode: http.StatusOK,
StatusMsg: "up",
Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps Server available

assert.Equal(t, hc.upTimeStats.UpTime, hr.upTimeStats.UpTime)
assert.True(t, hc.upTimeStats.StartedAt.Equal(hr.upTimeStats.StartedAt))

time.Sleep(300)
Copy link
Contributor

Choose a reason for hiding this comment

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

this will add an extra 5 minutes for each test run which is overkill

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those are Nanosecond. I wanted to check the case where some time's passed and the service went down, that the uptime does not get incremented.

})
}

func (hc *HealthCheck) createRespBody(resp healthCheckResponse) []byte {

Copy link
Contributor

Choose a reason for hiding this comment

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

rm newline

Unavailable: http.StatusServiceUnavailable,
Ready: http.StatusNoContent,
upTimeStats: upTimeStats{
StartedAt: time.Now(),
Copy link
Contributor

Choose a reason for hiding this comment

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

technically, shouldn't this be set when the sever is first set to ready?

@codecov
Copy link

codecov bot commented Apr 8, 2019

Codecov Report

Merging #1465 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1465      +/-   ##
==========================================
+ Coverage   99.82%   99.82%   +<.01%     
==========================================
  Files         173      173              
  Lines        8179     8203      +24     
==========================================
+ Hits         8165     8189      +24     
  Misses          7        7              
  Partials        7        7
Impacted Files Coverage Δ
pkg/healthcheck/handler.go 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 48555a8...b84001d. Read the comment docs.

@@ -105,7 +105,7 @@ func (h *clientHandler) isInitialized() bool {
func httpHealthCheck(logger *zap.Logger, service, healthURL string) {
for i := 0; i < 240; i++ {
res, err := http.Get(healthURL)
if err == nil && res.StatusCode == 204 {
if err == nil && res.StatusCode == 200 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say that the most appropriate is to check if the response is a 2xx class. That's what monitoring solutions do.

@@ -94,5 +136,8 @@ func (hc *HealthCheck) Get() Status {

// Ready is a shortcut for Set(Ready) (kept for backwards compatibility)
func (hc *HealthCheck) Ready() {
hc.upTimeStats = upTimeStats{
StartedAt: time.Now(),
Copy link
Contributor

Choose a reason for hiding this comment

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

The process' start time is recorded as a metric:

# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.
# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.55480578686e+09

Should we add this one as well?

Copy link
Contributor Author

@stefanvassilev stefanvassilev Apr 9, 2019

Choose a reason for hiding this comment

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

Should I add this as well? This would introduce a new dependency to https://github.com/shirou/gopsutil as well

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant the other way around, to add the "Started At" as a metric.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where should I add it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like the handler isn't receiving a metrics object. Perhaps it's better to open a follow-up issue for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps a follow-up issue of what should be done would be more helpful, as on my local build the /metrics endpoint does not return any process information. :)

Return 200 OK for status `ready` and `upTimeStats`

Resolves jaegertracing#1450

Signed-off-by: stefan vassilev <stefanvassilev1@gmail.com>
Signed-off-by: stefan vassilev <stefanvassilev1@gmail.com>
Signed-off-by: stefan vassilev <stefanvassilev1@gmail.com>
Signed-off-by: stefan vassilev <stefanvassilev1@gmail.com>
stefanvassilev and others added 3 commits April 11, 2019 23:40
Signed-off-by: stefan vassilev <stefanvassilev1@gmail.com>
Signed-off-by: stefan vassilev <stefanvassilev1@gmail.com>
Signed-off-by: Yuri Shkuro <ys@uber.com>
@@ -46,23 +48,43 @@ func (s Status) String() string {
}
}

type upTimeStats struct {
StartedAt time.Time `json:"startedAt"`
UpTime string `json:"upTime"`
Copy link
Member

Choose a reason for hiding this comment

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

uptime is one word, no need to capitalize T (fields and struct name)

@@ -94,5 +136,8 @@ func (hc *HealthCheck) Get() Status {

// Ready is a shortcut for Set(Ready) (kept for backwards compatibility)
func (hc *HealthCheck) Ready() {
hc.upTimeStats = upTimeStats{
Copy link
Member

Choose a reason for hiding this comment

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

race condition

@yurishkuro yurishkuro merged commit 54416c6 into jaegertracing:master Apr 13, 2019
@yurishkuro
Copy link
Member

Thanks for the PR!

code98 added a commit to code98/jaeger that referenced this pull request Apr 14, 2019
Return info msg for `/health` endpoint (jaegertracing#1465)
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.

Return uptime or something similar for /health endpoint
4 participants