meteorhacks / cluster

Clustering solution for Meteor with load balancing and service discovery
https://meteorhacks.com/cluster-a-different-kind-of-load-balancer-for-meteor.html
MIT License
632 stars 80 forks source link

Naming Microservices the same on different severs causing issue? #102

Open madhan5000 opened 9 years ago

madhan5000 commented 9 years ago

@arunoda First off, Thanks for this wonderful package!!

I encountered a strange issue and I thought I would report it here. Here is my set up. I have an app configured as Microservice using Cluster package's JS API deployed on 2 different servers (with Local MongoDB installations). They connect to a central db CENTRAL_CLUSTER (A separate mongo database without oplog configured)

  Cluster.connect(process.env.CENTRAL_CLUSTER);
  Cluster.register('tracker',{endpoint:process.env.ROOT_URL});

when the apps come up the output looks like this on both machines (mup logs -f)

//Server 1
Cluster: connecting to 'mongodb' discovery backend
Cluster: with options:  undefined
Cluster: registering this node as service 'tracker'
Cluster:    endpoint url = http://<server1>
Cluster:    balancer url = undefined

//Server 2
Cluster: connecting to 'mongodb' discovery backend
Cluster: with options:  undefined
Cluster: registering this node as service 'tracker'
Cluster:    endpoint url = http://<server2>
Cluster:    balancer url = undefined

Database entries on CENTRAL_CLUSTER database looks like this

{
    "_id" : ObjectId("56341c11b03bad5bdfe296fe"),
    "endpoint" : "http://<server1>",
    "serviceName" : "tracker",
    "timestamp" : ISODate("2015-11-06T16:15:12.817Z"),
    "pingInterval" : 5000,
    "endpointHash" : "bcc036677f4bd51b4b4655fff66da37e1c9ab89d",
    "balancer" : null
  }
{
    "_id" : ObjectId("563cd1b2b03bad5bdfe29700"),
    "endpoint" : "http://<server2>",
    "serviceName" : "tracker",
    "timestamp" : ISODate("2015-11-06T16:30:23.456Z"),
    "pingInterval" : 5000,
    "endpointHash" : "bcc036677f4bd51b4b4655fff66da37e1c9ab89d",
    "balancer" : null
  }

Microservices have a method exposed via simple:rest

Meteor.method('record',function(data){
  data.server = process.env.ROOT_URL;
  Tracker.insert(data); //inserts in to local database
}
return {status:"ok"};
},{url:'/a/record'});

The issue being AJAX call made to one server and the data ends up in other database?. It looks like load balancing even though balancer is set to NULL?.

 //Database entry in Tracker collection on Server 1 (AJAX call was made to server 2)
  {
    "_id"   : ObjectId("7b6d0ccef9a7509dd0a0a855"),
    "url"    : " ",
    "date" : "2015-11-06T16:16:18.293Z",
    "timestamp" : 1446826578293.0000000000000000,
    "app"     : "tracker",
    "token"  : "SERVER2_TOKEN", //Token belongs to server 2
    "server" : "server1" //<- Note AJAX call was made to server 2
 }

When I set unique names to them (via mup), the issue seems to go away??

 Cluster.register(process.env.APP_NAME,{endpoint:process.env.ROOT_URL});

Is this a bug or my understanding is wrong? I would imagine name of the service should not matter here as we have unique endpointHash??

BTW, I also saw some CORS errors, which went away after I uniquely named the Microservices.

Thanks for looking in to it.