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

MF-1308 - Use IETF Health Check standard #1541

Merged
merged 30 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b91a6ce
MF-1308 - Use IETF Health Check standard
manuio Jan 10, 2022
a12d4fc
Add nginx health endpoint
manuio Jan 10, 2022
c7f534b
Rm github.com/nelkinda dependency
manuio Jan 11, 2022
794e871
Check error
manuio Jan 11, 2022
247d5b4
Replace Version by Health in the CLI and SDK
manuio Jan 11, 2022
f439983
Fix typo
manuio Jan 11, 2022
24e8cf5
Use new build flag go:build
manuio Jan 13, 2022
775dd7c
Fix conflicts
manuio Jan 13, 2022
848982a
Revert wrong renaming
manuio Jan 13, 2022
4c06dee
sdk health test
manuio Jan 13, 2022
ecdefa1
Add /health endpoint to openapi doc
manuio Jan 13, 2022
f92c147
Use const for description message
manuio Jan 13, 2022
784d43f
Merge branch 'master' into health
manuio Jan 15, 2022
85d8625
Add version and build time during build
manuio Jan 17, 2022
a285f83
Merge branch 'health' of http://github.com/manuio/mainflux into health
manuio Jan 17, 2022
0772600
Merge branch 'master' into health
manuio Jan 18, 2022
438eef9
Merge branch 'master' into health
manuio Jan 18, 2022
c9d3111
Time format
manuio Jan 18, 2022
57cca96
Add version and commit using git and build args
manuio Jan 19, 2022
7d6f4dc
Add comments
manuio Jan 19, 2022
2ba2345
Add tests
manuio Jan 19, 2022
4b87bfc
Add missing api properties
manuio Jan 19, 2022
19be83b
Fix api
manuio Jan 19, 2022
3517aeb
Use ./schemas/HealthInfo.yml as
manuio Jan 19, 2022
a4b7c0f
Fix example
manuio Jan 19, 2022
36727bb
Merge branch 'master' into health
manuio Jan 19, 2022
2cc816a
Use content type application/health+json
manuio Jan 19, 2022
d47bdc6
Merge branch 'health' of http://github.com/manuio/mainflux into health
manuio Jan 19, 2022
d3c3638
Set Makefile variables only if empty
manuio Jan 20, 2022
42de5ef
Fix typo
manuio Jan 24, 2022
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
3 changes: 2 additions & 1 deletion auth/api/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
)

// MakeHandler returns a HTTP handler for API endpoints.
func MakeHandler(svc auth.Service, tracer opentracing.Tracer) http.Handler {
mux := bone.New()
mux = keys.MakeHandler(svc, mux, tracer)
mux = groups.MakeHandler(svc, mux, tracer)
mux = policies.MakeHandler(svc, mux, tracer)
mux.GetFunc("/version", mainflux.Version("auth"))
mux.GetFunc("/health", mainflux.Health("auth"))
mux.Handle("/metrics", promhttp.Handler())
return mux
}
2 changes: 1 addition & 1 deletion bootstrap/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func MakeHandler(svc bootstrap.Service, reader bootstrap.ConfigReader) http.Hand
encodeResponse,
opts...))

r.GetFunc("/version", mainflux.Version("bootstrap"))
r.GetFunc("/health", mainflux.Health("bootstrap"))
r.Handle("/metrics", promhttp.Handler())

return r
Expand Down
2 changes: 1 addition & 1 deletion certs/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func MakeHandler(svc certs.Service) http.Handler {
))

r.Handle("/metrics", promhttp.Handler())
r.GetFunc("/version", mainflux.Version("certs"))
r.GetFunc("/health", mainflux.Health("certs"))

return r
}
Expand Down
2 changes: 1 addition & 1 deletion coap/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
//MakeHTTPHandler creates handler for version endpoint.
func MakeHTTPHandler() http.Handler {
b := bone.New()
b.GetFunc("/version", mainflux.Version(protocol))
b.GetFunc("/health", mainflux.Health(protocol))
b.Handle("/metrics", promhttp.Handler())

return b
Expand Down
2 changes: 1 addition & 1 deletion consumers/notifiers/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func MakeHandler(svc notifiers.Service, tracer opentracing.Tracer) http.Handler
opts...,
))

mux.GetFunc("/version", mainflux.Version("notifier"))
mux.GetFunc("/health", mainflux.Health("notifier"))
mux.Handle("/metrics", promhttp.Handler())

return mux
Expand Down
3 changes: 2 additions & 1 deletion consumers/writers/api/transport.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0

//go:build !test
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have both these lines. Are they necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know why, it was done by the editor. I removed this one and all others.

// +build !test

package api
Expand All @@ -16,7 +17,7 @@ import (
// MakeHandler returns a HTTP API handler with version and metrics.
func MakeHandler(svcName string) http.Handler {
r := bone.New()
r.GetFunc("/version", mainflux.Version(svcName))
r.GetFunc("/health", mainflux.Health(svcName))
r.Handle("/metrics", promhttp.Handler())

return r
Expand Down
2 changes: 1 addition & 1 deletion docker/nginx/nginx-key.conf
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ http {
proxy_pass http://auth:${MF_AUTH_HTTP_PORT};
}

location /version {
location /health {
include snippets/proxy-headers.conf;
proxy_pass http://things:${MF_THINGS_HTTP_PORT};
}
Expand Down
2 changes: 1 addition & 1 deletion docker/nginx/nginx-x509.conf
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ http {
proxy_pass http://auth:${MF_AUTH_HTTP_PORT};
}

location /version {
location /health {
include snippets/proxy-headers.conf;
proxy_pass http://things:${MF_THINGS_HTTP_PORT};
}
Expand Down
49 changes: 49 additions & 0 deletions health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0

package mainflux

import (
"encoding/json"
"net/http"

"github.com/nelkinda/http-go/header"
)

const (
version string = "0.12.1"
contentType string = "application/json"
svcStatus string = "pass"
)

// HealthInfo contains version endpoint response.
type HealthInfo struct {
// Status contains service status.
Status string `json:"status"`

// Version contains service current version.
Version string `json:"version"`

// Description contains service description.
Description string `json:"description"`
}

// Health exposes an HTTP handler for retrieving service health.
func Health(service string) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add(header.ContentType, contentType)
if r.Method != http.MethodGet && r.Method != http.MethodHead {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}

res := HealthInfo{
Status: svcStatus,
Description: service,
Version: version,
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be good to have timestamp of build so that when debugging deployment by querying the health you can confirm that right version is deployed

Copy link
Contributor Author

@manuio manuio Jan 13, 2022

Choose a reason for hiding this comment

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

It should be covered by @blokovi proposition. There is an issue about: https://github.com/mainflux/mainflux/issues/1543

Copy link
Contributor

Choose a reason for hiding this comment

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

@mteodor there is a way to put timestamp and Git hash during the compilation phase. We had this before. I think it would make sense to add it back.

}

w.WriteHeader(http.StatusOK)
_ = json.NewEncoder(w).Encode(res)
})
}
2 changes: 1 addition & 1 deletion http/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func MakeHandler(svc adapter.Service, tracer opentracing.Tracer) http.Handler {
opts...,
))

r.GetFunc("/version", mainflux.Version("http"))
r.GetFunc("/health", mainflux.Health("http"))
r.Handle("/metrics", promhttp.Handler())

return r
Expand Down
2 changes: 1 addition & 1 deletion lora/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// MakeHandler returns a HTTP handler for API endpoints.
func MakeHandler() http.Handler {
r := bone.New()
r.GetFunc("/version", mainflux.Version("lora-adapter"))
r.GetFunc("/health", mainflux.Health("lora-adapter"))
r.Handle("/metrics", promhttp.Handler())

return r
Expand Down
2 changes: 1 addition & 1 deletion opcua/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func MakeHandler(svc opcua.Service) http.Handler {
opts...,
))

r.GetFunc("/version", mainflux.Version("opcua-adapter"))
r.GetFunc("/health", mainflux.Health("opcua-adapter"))
r.Handle("/metrics", promhttp.Handler())

return r
Expand Down
12 changes: 6 additions & 6 deletions pkg/sdk/go/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/mainflux/mainflux/pkg/errors"
)

type version struct {
Value string `json:"version"`
type health struct {
Version string `json:"version"`
}

func (sdk mfSDK) Version() (string, error) {
url := fmt.Sprintf("%s/version", sdk.thingsURL)
url := fmt.Sprintf("%s/health", sdk.thingsURL)

resp, err := sdk.client.Get(url)
if err != nil {
Expand All @@ -34,10 +34,10 @@ func (sdk mfSDK) Version() (string, error) {
return "", errors.Wrap(ErrFetchVersion, errors.New(resp.Status))
}

var ver version
if err := json.Unmarshal(body, &ver); err != nil {
var h health
if err := json.Unmarshal(body, &h); err != nil {
return "", err
}

return ver.Value, nil
return h.Version, nil
}
2 changes: 1 addition & 1 deletion provision/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func MakeHandler(svc provision.Service) http.Handler {
))

r.Handle("/metrics", promhttp.Handler())
r.GetFunc("/version", mainflux.Version("provision"))
r.GetFunc("/health", mainflux.Health("provision"))

return r
}
Expand Down
2 changes: 1 addition & 1 deletion readers/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func MakeHandler(svc readers.MessageRepository, tc mainflux.ThingsServiceClient,
opts...,
))

mux.GetFunc("/version", mainflux.Version(svcName))
mux.GetFunc("/health", mainflux.Health(svcName))
mux.Handle("/metrics", promhttp.Handler())

return mux
Expand Down
2 changes: 1 addition & 1 deletion things/api/things/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func MakeHandler(tracer opentracing.Tracer, svc things.Service) http.Handler {
opts...,
))

r.GetFunc("/version", mainflux.Version("things"))
r.GetFunc("/health", mainflux.Health("things"))
r.Handle("/metrics", promhttp.Handler())

return r
Expand Down
2 changes: 1 addition & 1 deletion twins/api/http/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func MakeHandler(tracer opentracing.Tracer, svc twins.Service) http.Handler {
opts...,
))

r.GetFunc("/version", mainflux.Version("twins"))
r.GetFunc("/health", mainflux.Health("twins"))
r.Handle("/metrics", promhttp.Handler())

return r
Expand Down
2 changes: 1 addition & 1 deletion users/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func MakeHandler(svc users.Service, tracer opentracing.Tracer) http.Handler {
opts...,
))

mux.GetFunc("/version", mainflux.Version("users"))
mux.GetFunc("/health", mainflux.Health("users"))
mux.Handle("/metrics", promhttp.Handler())

return mux
Expand Down
31 changes: 0 additions & 31 deletions version.go

This file was deleted.