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

Discovery metadata #56

Closed
wants to merge 1 commit into from

Conversation

jmnarloch
Copy link
Contributor

This pull request introduces the metadata map that can be associated with each service instance registered within discovery service (currently covered by Eureka and Zookeper, Consul is planned to have such support in version 2.0) allowing to use that information on the client side.

I had to also align the version with latest spring boot snapshot where some class has been renamed, this is way there are two commits.

@jmnarloch
Copy link
Contributor Author

Probably it's worth getting back to the issue despite the spring-cloud/spring-cloud-netflix#419 and #41

My idea is simply, if the backing discovery service can provide the client with the metadata (like Eureka and Zookeeper) we can cover that, for Consul it could return the tags information for version 1.x and when version 2.0 will be covered the metadata could be provided from there (issues: hashicorp/consul#1131, hashicorp/consul#697, hashicorp/consul#1107).

@spencergibb
Copy link
Member

At a glance, I think I like this better than #41.

@jmnarloch
Copy link
Contributor Author

The only question is whether a "static" Map would be sufficient and won't be a need to do some lookup on the fly and there therefor introduce some InstanceMetadata abstraction.

@spencergibb
Copy link
Member

When you say, "static" map, do you mean just a java.util.Map?

@jmnarloch
Copy link
Contributor Author

Yes, exactly. I was only deliberating whether introducing there would be a need to introduce some wrapper on top of the map, for instance if you could declare some interface (let's call if InstanceMetadata) then the implementation could have much more flexibility. Although I not sure whether there will be ever need for that, so for now I just propose simple key/value map for storing the metadata.

@@ -116,7 +113,8 @@ LoadBalancerClient loadBalancerClient() {

@Override
public ServiceInstance choose(String serviceId) {
return new DefaultServiceInstance(serviceId, serviceId, random.nextInt(40000), false);
return new DefaultServiceInstance(serviceId, serviceId, random.nextInt(40000),
false, Collections.<String, String>emptyMap());
Copy link
Member

Choose a reason for hiding this comment

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

I think DefaultServiceInstance needs to retain the original constructor signature as well as the new one. Hadn't noticed this before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks for noticing.

@spencergibb
Copy link
Member

Thanks @jmnarloch!

@spencergibb
Copy link
Member

@jmnarloch so I started looking at this. The two netflix implementations in EurekaDiscoveryClient were simple to implement. I ran into trouble in RibbonLoadBalancerClient. The ribbon Server doesn't even expose the underlying InstanceInfo where the metadata is located. Wondering if you had any thoughts?

@spencergibb
Copy link
Member

I'd have to do something like this

    protected RibbonServer(String serviceId, Server server, boolean secure) {
        this.serviceId = serviceId;
        this.server = server;
        this.secure = secure;

        if (this.server instanceof DiscoveryEnabledServer) {
            Field instanceInfoField = ReflectionUtils.findField(DiscoveryEnabledServer.class, "instanceInfo");
            ReflectionUtils.makeAccessible(instanceInfoField);
            try {
                InstanceInfo instanceInfo = (InstanceInfo) instanceInfoField.get(this.server);
                this.metadata = instanceInfo.getMetadata();
            } catch (IllegalAccessException e) {
                log.error("Error getting instanceInfo for serviceId: "+serviceId, e);
            }
        }
    }

@dsyer @adriancole @marcingrzejszczak thoughts?

@spencergibb
Copy link
Member

The above stinks because it won't work for s-c-zk and s-c-consul, which will use RibbonServer but not DiscoveryEnabledServer.

@spencergibb
Copy link
Member

Actually we already have a ServerIntrospector abstraction we could add Map<String, String> getMetadata(Server server).

@spencergibb
Copy link
Member

And there is a DiscoveryEnabledServer.getInstanceInfo method, so no reflection needed, I'm happy.

spencergibb added a commit that referenced this pull request Dec 22, 2015
* discovery-metadata:
  Introduced ServiceInstance metadata map.
@spencergibb spencergibb added this to the 1.1.0 milestone Dec 22, 2015
@spencergibb spencergibb self-assigned this Dec 22, 2015
@spencergibb
Copy link
Member

Closed with some polish via aa2ddce

@marcingrzejszczak
Copy link
Contributor

The metadata feature is a very good idea. It can be combined together with the "dependency" approach that we have in Zookeeper.

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

Successfully merging this pull request may close these issues.

3 participants