-
Notifications
You must be signed in to change notification settings - Fork 102
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
Move health checks to kubernetes package and extract logging #1677
Conversation
…is is a hotfix to not spam stdout in the CLI Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
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.
The pkg/engine
where health resides should NOT be accessible to the CLI. it is for the manager. clog is a client util for controlling verbosity which should not be used or introduced at the server.
and we shouldn't init-ing what was designed to be client libs in the manager.
The output of the server logs include date and time output and are directed to stderr... those are lost when using clog because the output experience of clog is for end users not for logs.
further analysis... This file (being sub package to engine) as engine errors... what is the cli suppose to do with that and why? It appears that all "log" messages are the result of a return... perhaps the calling code should be responsible for what to log... or a wrapping function (1 for client and 1 for server). I would suggest
It makes sense that the client and the server will need kubernetes lib |
the |
It's rather the other way around - In the hindsight, it is lamentable that we use two different loggers on the client and server-side. I'd rather we would consolidate to ease code reuse. |
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com> # Conflicts: # pkg/engine/health/health.go
Agreed - We have a single code base for both manager and cli, I think we should use a common logging solution. |
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com> # Conflicts: # pkg/engine/health/health.go
Fun fact: I ran into just now:
works great except for "CRD * is now healthy" part which looks weird 🤷 |
Some additional findings - maybe it'd be better to make a new issue out of this, but we have a discussion here already. I've looked at
So, we could either
|
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
I have refactored the code to look like this, the resource package is still in the engine, although it would make sense to move it in a different PR. |
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 is a lot of work here that is moving in the right direction...
It is great that a shared resource "status"/"health" is moved outside of the engine code path...
The shared resource needs to be agnostic to the calling code. It currently id not. it specifically has clog code in the health.go.
If we were to break this 1 project into 3 projects.... one might expect:
- cli project
- manager project
- shared project
one would also expect that
- cli has clog
- manager has a server logger
- shared code would either NOT log (allowing logging by calling code) or a shared logger (which we should avoid for now... it comes with it's own set of additional challenges)
after further review... it looks like perhaps that was 1 leftover mistake... all references except the 1 are removed... I will look into refactoring (see if the condition is captured) etc. |
Signed-off-by: Ken Sipe <kensipe@gmail.com>
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.
a few non-breaking nits...
first kudos for:
- nice work on reducing the scope of
toUnstructured
!!! 👏 - nice teasing apart cli and manager code
nits:
- the v1beta1 -> kudoapi can we not add it here... it is a separate concern
- adding return var names would make it much easier to read...
- godocs for
isHealthy
would be much appreciated... especially around calling code expectations
nice work
pkg/kubernetes/status/health.go
Outdated
} | ||
} | ||
return false, "" | ||
return false, "", nil | ||
} | ||
|
||
func IsDeleted(client client.Client, discovery discovery.CachedDiscoveryInterface, objs []runtime.Object) error { |
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.
all these status APIs have changed to bool, msg, error
except this one. It is odd to have an IsXYZ
without a bool... or no error means yes.
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.
To be honest, I wasn't fully sure if I should move this as well - It has a different signature, uses a client and fetches resources, works on a slice of objects, etc...
But I think it makes sense. I'll refactor it to work on a single object and adjust the signature to match the others.
pkg/kubernetes/status/health.go
Outdated
objUnstructured := &unstructured.Unstructured{Object: unstructMap} | ||
// IsHealthy returns whether an object is healthy and a corresponding message | ||
// Must be implemented for each type. | ||
func IsHealthy(obj runtime.Object) (bool, string, error) { |
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.
could we add more godoc here... developer less familiar needs to read all code to understand you signature. rules would also be helpful... there is a lot of complexity here... rules like: is it possible for bool to be true with an error? I would think not. Is there a case of a string being empty other than error?
IMO it would also be helpful to provide name variables here which would help with context. (healthy bool, msg string, err error)
is more readable to me... otherwise it is a hunt for what is the string.
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.
Let's also mention that only certain common objects are checked for health. Unknown objects will be considered healthy by default.
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.
LGTM! Some small suggestions plus the nits @kensipe mentioned.
pkg/kubernetes/status/health.go
Outdated
objUnstructured := &unstructured.Unstructured{Object: unstructMap} | ||
// IsHealthy returns whether an object is healthy and a corresponding message | ||
// Must be implemented for each type. | ||
func IsHealthy(obj runtime.Object) (bool, string, error) { |
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.
Let's also mention that only certain common objects are checked for health. Unknown objects will be considered healthy by default.
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
The CLI now shares code with the manager which used a simple log - this is a hotfix to not spam stdout in the CLI.
We need a better solution to handle logging in code that is used by CLI and the manager though.
What this PR does / why we need it:
Fixes #1672
Signed-off-by: Andreas Neumann aneumann@mesosphere.com