Skip to content

Unique Bus ID When Deployed To Kubernetes #222

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

Closed
ryanjbaxter opened this issue Mar 18, 2020 · 5 comments
Closed

Unique Bus ID When Deployed To Kubernetes #222

ryanjbaxter opened this issue Mar 18, 2020 · 5 comments
Assignees

Comments

@ryanjbaxter
Copy link
Contributor

When we deploy an app to Kubernetes we should try to come up with an ID to use that is unique to the container

@spencergibb
Copy link
Member

See

// TODO: move this to commons
// @checkstyle:off
private String getDefaultServiceId(ConfigurableEnvironment environment) {
return "${vcap.application.name:${spring.application.name:application}}:${vcap.application.instance_index:${spring.application.index:${local.server.port:${server.port:0}}}}:${vcap.application.instance_id:${random.value}}";
}
// @checkstyle:on

I wonder if we take this opportunity to move that to commons

@ryanjbaxter
Copy link
Contributor Author

Probably a good idea to move to commons

@ryanjbaxter
Copy link
Contributor Author

@spencergibb I was looking into this a bit....

  1. After googling a bit I didn't see an obvious way to get a container id when running in a pod

  2. I took a step back and thought if we just had a better way of generating a unique id (as opposed to it including a random number) it wouldn't really matter if we could access something like a container id in a pod

So I was poking around commons and found this code which is quite similar to what we have in bus already

https://github.com/spring-cloud/spring-cloud-commons/blob/master/spring-cloud-commons/src/main/java/org/springframework/cloud/commons/util/IdUtils.java#L37-L56

It uses spring.application.instance_id which we dont use in bus, could this possible solve the problem? Would that id be the same after context refreshes? I suppose I could just test it out, but wondering if you know off the top of your head. I also just read in an old blog post that spring.application.instance_id would only be set when running in Cloud Foundry 😠

@spencergibb
Copy link
Member

yeah, instance_id is gonna have the same problem.

My thought was a new random property source that, given a key, cached the random value.

cloudrandom.app.long would only ever generate 1 random long for the app key.

@ryanjbaxter
Copy link
Contributor Author

This was implemented in spring-cloud/spring-cloud-commons#719

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants