-
Notifications
You must be signed in to change notification settings - Fork 671
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
Conversation
Signed-off-by: Manuel Imperiale <[email protected]>
Signed-off-by: Manuel Imperiale <[email protected]>
I like this implementation. For now it looks maybe redundant, as version was functioning well, but I think in the future we will add some of the fields. For example, I think that On the other hand, I would like to hear from @nmarcetic and @dusanb94 does this change add the value, or maybe complicates things without particular benefit. @mteodor and @blokovi also - what do you think? |
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.
We should update Swagger YAML files as well
consumers/writers/api/transport.go
Outdated
@@ -1,6 +1,7 @@ | |||
// Copyright (c) Mainflux | |||
// SPDX-License-Identifier: Apache-2.0 | |||
|
|||
//go:build !test |
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.
Why do we have both these lines. Are they necessary?
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.
I don't know why, it was done by the editor. I removed this one and all others.
Signed-off-by: Manuel Imperiale <[email protected]>
@drasko I checked the code of the repo that you proposed and I prefered to use it as example than add it in the vendor. We were almost using nothing from there and the standard is not so complicated to follow. |
Signed-off-by: Manuel Imperiale <[email protected]>
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.
Just for reference, we should see if this can be used in Dockerfile for HEALTCHECK instruction:
https://docs.docker.com/engine/reference/builder/#healthcheck
We already use this instruction in VerneMQ Dockerfile
Signed-off-by: Manuel Imperiale <[email protected]>
Signed-off-by: Manuel Imperiale <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #1541 +/- ##
==========================================
+ Coverage 67.47% 69.08% +1.61%
==========================================
Files 139 134 -5
Lines 11321 11057 -264
==========================================
Hits 7639 7639
+ Misses 3051 2787 -264
Partials 631 631
Continue to review full report at Codecov.
|
I find this very interesting. Do we have to change our Dockerfile for this? What is K8s looking for in the response - only status code? |
Yes, change in Dockerfile is needed. That Docker healthcheck has not been integrated in the Kubernetes, there we can use Liveness and readiness probes |
http/api/logging.go
Outdated
// +build !test | ||
|
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.
Please don't remove test tags.
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.
Ok but can you explain me why this tags are not everywhere? For what this is needed?
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.
Replaced by the new one //go:build
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.
Ok but can you explain me why this tags are not everywhere? For what this is needed?
It is used to ignore logging and metrics for testing (coverage included) - it is used here: https://github.com/mainflux/mainflux/blob/6483969927adb71736b8d4ed7553f8c2988973ce/scripts/ci.sh#L98
Signed-off-by: Manuel Imperiale <[email protected]>
Signed-off-by: Manuel Imperiale <[email protected]>
Signed-off-by: Manuel Imperiale <[email protected]>
pkg/sdk/go/health_test.go
Outdated
@@ -24,14 +24,14 @@ func TestVersion(t *testing.T) { | |||
empty bool | |||
err error | |||
}{ | |||
"get version": { | |||
"get things service version": { |
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.
Please check all the response fields, not only Version.
Signed-off-by: Manuel Imperiale <[email protected]>
Signed-off-by: Manuel Imperiale <[email protected]>
Signed-off-by: Manuel Imperiale <[email protected]>
health.go
Outdated
|
||
const ( | ||
contentType = "Content-Type" | ||
contentTypeJSON = "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.
Content type can be
application/health+json
as mentioned in https://datatracker.ietf.org/doc/html/draft-inadarei-api-health-check-05#section-3
https://datatracker.ietf.org/doc/html/draft-inadarei-api-health-check-05#section-7
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.
done
Signed-off-by: Manuel Imperiale <[email protected]>
In this PR we have only the version of service and do not have any other health check status or metrics like uptime, CPU usage , other component status. Example Output : https://tools.ietf.org/id/draft-inadarei-api-health-check-04.html#rfc.section.5 It seems to be similar to the version endpoint |
@arvindh123 Indeed, for now we only have 3 standard fields: |
Makefile
Outdated
@@ -23,6 +28,9 @@ define make_docker | |||
--build-arg SVC=$(svc) \ | |||
--build-arg GOARCH=$(GOARCH) \ | |||
--build-arg GOARM=$(GOARM) \ | |||
--build-arg VERSION=$(shell git describe --abbrev=0 --tags) \ |
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.
Please check if you need to change our Dockerfile as well, as it is alpine go
, maybe you need to install Git into it (i.e. try to build Docker images, see if compilation will work).
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.
@drasko Compilation work, I already tested. There is no need to install git in the Dockerfile since you pass this values as arguments.
-X 'github.com/mainflux/mainflux.BuildTime=$(TIME)' \ | ||
-X 'github.com/mainflux/mainflux.Version=$(VERSION)' \ | ||
-X 'github.com/mainflux/mainflux.Commit=$(COMMIT)'" \ |
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.
By default, these (TIME
, VERSION
, COMMIT
) will be empty. Please set them like in make_dockers
.
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.
I we do so we have to install git in the Dockerfile. Maybe it's more understandable to do it like that:
go build -mod=vendor -ldflags "-s -w \
-X 'github.com/mainflux/mainflux.BuildTime=$(6)' \
-X 'github.com/mainflux/mainflux.Version=$(4)' \
-X 'github.com/mainflux/mainflux.Commit=$(5)'" \
-o ${BUILD_DIR}/mainflux-$(1) cmd/$(1)/main.go
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.
No need for that. You can set it as variables in the Makefile like so:
VERSION ?= $(shell git describe --abbrev=0 --tags)
COMMIT ?= $(shell git rev-parse HEAD)
TIME ?= $(shell date +%F_%T)
The ?=
will take care to set only if variables are empty, which will be the case for the local build, and won't be the case for Docker build.
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.
But I think we need those filled in the Docker build as well, otherwise /health
will not work correctly for our Docker images, right?
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.
Also, maybe it's better to have for TIME something like date --rfc-3339=seconds
rather than a custom format.
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.
@dusanb94 Let me try what you proposed. It's probably the way to go.
@drasko It is filled in the docker build. Here:
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(COMMIT) \
--build-arg TIME=$(TIME) \
and here:
ARG VERSION
ARG COMMIT
ARG TIME
Signed-off-by: Manuel Imperiale <[email protected]>
type: string | ||
description: Service version. | ||
example: 0.0.1 | ||
commit: |
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.
We cannot leave commit
. We must adhere to standard. If you have fields that are missing, we probably must work with standardization body and argument why we need those, so that they can rectify in the next version pf the draft. Otherwise please find the closest field and put commit information there (probably releaseId
).
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.
ok, where I put build_time
?
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.
That's a good question. Let me check.
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.
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.
I have opened an issue as well: inadarei/rfc-healthcheck#76
health.go
Outdated
// Version contains current service version. | ||
Version string `json:"version"` | ||
|
||
// Commit represents the service build time. |
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 is not correct. It is a Git commit hash.
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.
right
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.
Please fix
health.go
Outdated
// Version contains current service version. | ||
Version string `json:"version"` | ||
|
||
// Commit represents the service build time. |
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.
Please fix
Signed-off-by: Manuel Imperiale <[email protected]>
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.
LGTM
@manuio @dusanb94 I have merged this PR, I think it is very useful and that we have it. Once @inadarei or someone else reacts on inadarei/rfc-healthcheck#76 we'll see how to progress with https://github.com/mainflux/mainflux/issues/1549 |
* MF-1308 - Use IETF Health Check standard Signed-off-by: Manuel Imperiale <[email protected]> * Add nginx health endpoint Signed-off-by: Manuel Imperiale <[email protected]> * Rm github.com/nelkinda dependency Signed-off-by: Manuel Imperiale <[email protected]> * Check error Signed-off-by: Manuel Imperiale <[email protected]> * Replace Version by Health in the CLI and SDK Signed-off-by: Manuel Imperiale <[email protected]> * Fix typo Signed-off-by: Manuel Imperiale <[email protected]> * Use new build flag go:build Signed-off-by: Manuel Imperiale <[email protected]> * Revert wrong renaming Signed-off-by: Manuel Imperiale <[email protected]> * sdk health test Signed-off-by: Manuel Imperiale <[email protected]> * Add /health endpoint to openapi doc Signed-off-by: Manuel Imperiale <[email protected]> * Use const for description message Signed-off-by: Manuel Imperiale <[email protected]> * Add version and build time during build Signed-off-by: Manuel Imperiale <[email protected]> * Time format Signed-off-by: Manuel Imperiale <[email protected]> * Add version and commit using git and build args Signed-off-by: Manuel Imperiale <[email protected]> * Add comments Signed-off-by: Manuel Imperiale <[email protected]> * Add tests Signed-off-by: Manuel Imperiale <[email protected]> * Add missing api properties Signed-off-by: Manuel Imperiale <[email protected]> * Fix api Signed-off-by: Manuel Imperiale <[email protected]> * Use ./schemas/HealthInfo.yml as Signed-off-by: Manuel Imperiale <[email protected]> * Fix example Signed-off-by: Manuel Imperiale <[email protected]> * Use content type application/health+json Signed-off-by: Manuel Imperiale <[email protected]> * Set Makefile variables only if empty Signed-off-by: Manuel Imperiale <[email protected]> * Fix typo Signed-off-by: Manuel Imperiale <[email protected]> Signed-off-by: skovacevic <[email protected]>
Signed-off-by: Manuel Imperiale [email protected]
Resolves #1308
Resolved in UI repo here: mainflux/ui#233
Resolved in devops repo here: absmach/devops#97
Resolved in docs repo here: absmach/magistrala-docs#119
Since we wanted to have information about the build time and the corresponding commit hash of the version we added
build_time
andcommit
fields. However these fields are non standard and we should decide what to do about in this issue: https://github.com/mainflux/mainflux/issues/1549