-
Notifications
You must be signed in to change notification settings - Fork 137
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
[#3537] Get K8s container id via K8s API. #3546
[#3537] Get K8s container id via K8s API. #3546
Conversation
Can be tested with these adaptations to the Hono Helm chart: eclipse/packages#509 (K8s API will only be used if Cgroups v2 is used). |
Note that the K8s API request handling is synchronous here. On application startup, the Call stackorg.eclipse.hono.client.command.KubernetesContainerUtil.getContainerId(KubernetesContainerUtil.java:81) When deploying Hono on Minikube on my local machine, I see that the A further optimization could be to defer the EDIT: PR got changed now, determining the id on a vert.x worker thread. |
I would very much prefer this. My concern is that if you don't refactor this now, it will never get refactored accordingly ... |
Ok, I'll have a closer look here. |
Not yet. I have created #3547 |
5274852
to
ad5b26b
Compare
@sophokles73 I've updated the PR, letting the container id be determined on a vert.x worker thread now. |
/** | ||
* Provides information about the Kubernetes container if this application is running in Kubernetes. | ||
*/ | ||
public class KubernetesContainerInfoProvider { |
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.
final ?
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 would mean it can't be mocked anymore (in ProtocolAdapterCommandConsumerFactoryTest
).
return Future.succeededFuture(containerId); | ||
} | ||
final Promise<String> containerIdPromise = Promise.promise(); | ||
if (!containerIdPromiseRef.compareAndSet(null, containerIdPromise)) { |
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.
if this is such an expensive operation and you anticipate this operation to be invoked concurrently/multiple times, wouldn't it make sense to cache the result?
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 result is already cached via the containerId
field value.
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.
Ah, my bad
if (containerId != null) { | ||
return Future.succeededFuture(containerId); | ||
} | ||
final Context currentContext = Vertx.currentContext(); |
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.
How about passing a Context into the method instead of relying on the static method to obtain the context? That way, it would also be much easier to test this method, right?
Or maybe it would make even more sense to pass a Vertx instance to the getInstance method?
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've now added a context
parameter to the getContainerId()
method.
@calohmn IMHO we also should backport this to 2.4.x and 2.3.x |
ad5b26b
to
191fda0
Compare
Yes, we can do that. |
return Future.succeededFuture(containerId); | ||
} | ||
final Promise<String> containerIdPromise = Promise.promise(); | ||
if (!containerIdPromiseRef.compareAndSet(null, containerIdPromise)) { |
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.
Ah, my bad
* @param context The context. | ||
* @throws NullPointerException if context is {@code null}. | ||
*/ | ||
void setContext(final Context context) { |
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.
is there a particular reason why you do not want to pass in a Vertx instance to the constructor as we do in most other services?
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, that is the better solution. I've changed it now.
191fda0
to
4d2bcaf
Compare
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
This fixes #3537 .