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

Registering multiple services from same node/instance with same name #562

Closed
rushi47 opened this issue Feb 3, 2021 · 11 comments
Closed

Comments

@rushi47
Copy link

rushi47 commented Feb 3, 2021

Hello Team,

Am trying to register multiple service definition for same service from single instance.
So lets there is service_name : X am trying to register it with

service_name: x
ip: a
port: 80 

from the same node

service_name: x
ip: a
port: 40

This is how it looks in puppet code,

$multi_port = [80, 40]

 $multi_port.each | $port | {

    consul::service { $app_name:
      checks              => $checks,
      port                => $port,
      tags                => $tags,
      meta                => $metadata,
    }
 
 }

when i try to do this i get error duplicate class it can be define multiple times.
I guess it can be limitation from puppet as well but if we change implementation of consul::service to function or define resource type it can be called multiple times.

@solarkennedy
Copy link
Contributor

Make the title of the consul::service be ${app_name}_${port}.

@rushi47
Copy link
Author

rushi47 commented Feb 4, 2021

@solarkennedy Thanks for reply, we already use it few places but we dont want to do it cause it creates lot of mess.
This is basic functionality from consul end, and it can be handled on tag level when ports are different and extra information needs to be added.

One more thing i noticed is the Service ID, basically it is created with Service name which is kinda of wrong, cause when you try to register same service with different configuration (like explained in above example) from same node it will overwrite the existing service with latest config instead of adding new service to catalogue, either service id needs to be generated randomly with some logic or overhead should be off loaded to consul as it takes care of it and createsservice id on its own.

@rushi47
Copy link
Author

rushi47 commented Feb 4, 2021

Can we expect fix for this any time soon @solarkennedy, it will be great help ?

@solarkennedy
Copy link
Contributor

I can imagine (PRs welcome) a fix for Service ID.
But there will never be a fix for the puppet language requiring unique names of resources.

@rushi47
Copy link
Author

rushi47 commented Feb 5, 2021

@solarkennedy correct me if am wrong, i was thinking(suggesting) https://github.com/solarkennedy/puppet-consul/blob/master/manifests/install.pp#L5 this part changing it to defined resource or function.
(It might be a lot of effort to change it though, am not sure).

@solarkennedy
Copy link
Contributor

I'm confused, do you intend to install consul multiple times? or configure multiple consul services on the same port?

@rushi47
Copy link
Author

rushi47 commented Apr 28, 2021

@solarkennedy am just trying to register multiple services from same machine, port can be same, name can be same. The issue is with ID of service if it's unique (by default if you don't provide consul generates random uuid) you can register multiple services on same agent with same name same port but technically they will be different cause of ID. But as of now in module we use service name as ID and that's the problem.

@rushi47
Copy link
Author

rushi47 commented Apr 28, 2021

Also sorry for late reply, hope you're well in this difficult times :).

@solarkennedy
Copy link
Contributor

You are right, in puppet each thing must be unique.

How about making your "app_name" have the port in it?

consul::service { "my_app_port_42":
  service => "my_app",
  port => 42,
}

consul::service { "my_app_port_43":
  service => "my_app",
  port => 43,
}

If you want you can specify the id directly too, but in this case you don't have to, it defaults to the title.
Here are all the available params:
https://github.com/solarkennedy/puppet-consul/blob/master/manifests/service.pp#L1

@rushi47
Copy link
Author

rushi47 commented Apr 29, 2021

@solarkennedy Hey kyle yes i do it already, problem with this approach is, the services from other end need to do multiple calls, lets say if service is having multiple ports.
Take this example,

I have proxysql and it's running on multiple ports lets assume 8080, 8081, 8092
Now if i register each proxysql with name-port combination: proxysql-8081, proxysql-8082.

When i want to discover proxysql, I can't get catalog by simply looking for service with proxysql name, i will need to do multiple calls with name-port combination also to make those calls i should know the ports beforehand which beats the whole purpose of service discovery from my opinion.

@rushi47
Copy link
Author

rushi47 commented Apr 29, 2021

Yes Adding ID should do the job :) and i can see it's over writable this should help, thanks.

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

No branches or pull requests

2 participants