Unable to create Http Health Check from config fil

2019-08-18 15:26发布

问题:

I have been trying to create a http health check for a REST service using the config file.

While loading the consul, it read the service details from the config file and that is reflected in 8500 Web UI.

But it did not add the health check details for that service.

No error is displayed too when the health check is along with the service definition (Case 1).

But it notified an error when tried to give the health check config seperatly. (Case 2)

However I can able to successfully add a http health check when added via rest api. (Case 3)

Health Check with service details:- (Case 1)

{
"service": {
"id":"somename",
"name":"nameofthissevice",
"service": "myservice",
"address": "127.0.0.1",
"port": 62133,
"enableTagOverride": false,
"check": {      
"HTTP": "http://127.0.0.1:62133/Service1.svc/MyService/PingMe",
"Interval": "5s"    
}
}
}

Health Check config alone:- (Case 2)

"check": {    
"http": "http://127.0.0.1:62133/Service1.svc/MyService/PingMe",
"interval": "5s",
"timeout": "150s",
"ttl" : "100s"
}

Health Check via Code in C#:- (Case 3)

var check = new AgentServiceCheck()
        {
            Interval = TimeSpan.FromSeconds(10),
            HTTP = "http://127.0.0.1:62133/Service1.svc/MyService/PingMe",
            DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(10)
        };

var srv = new AgentServiceRegistration()
        {
            XXXXX,
            Check = check
        };

var result = client.Agent.ServiceRegister(srv).GetAwaiter().GetResult();            

I am using Consul V.0.9.0 for windows.

Here is my consul log.

==> Consul agent running!
Version: 'v0.9.0'
Node ID: 'd0afc715-46d0-6087-27e9-a388cc274bd2'
Node name: 'BETA-PC'
Datacenter: 'dc1'
Server: true (bootstrap: false)
Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600)
Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false

==> Log data will now stream in as it occurs:

2017/08/11 00:18:23 [DEBUG] Using random ID "d0afc715-46d0-6087-27e9-a388cc274bd2" as node ID                                                     
2017/08/11 00:18:23 [DEBUG] agent: restored service definition "somename" from "services\\ServiceRegister.json"                                   
2017/08/11 00:18:23 [WARN] raft: Heartbeat timeout from "" reached, starting election                                                             
2017/08/11 00:18:23 [INFO] consul: member 'BETA-PC' joined, marking health alive                                                                  
2017/08/11 00:18:24 [INFO] agent: Synced service 'somename'                                                                                       
2017/08/11 00:18:24 [DEBUG] agent: Node info in sync                                                                                              
2017/08/11 00:22:33 [DEBUG] http: Request GET /v1/internal/ui/nodes?dc=dc1&token=<hidden> (0s) from=127.0.0.1:52479                               
2017/08/11 00:22:33 [DEBUG] http: Request GET /v1/catalog/datacenters (37.0021ms) from=127.0.0.1:52478                                            
2017/08/11 00:22:33 [DEBUG] http: Request GET /v1/coordinate/nodes?dc=dc1&token=<hidden> (14.0008ms) from=127.0.0.1:52480                         
2017/08/11 00:22:33 [DEBUG] http: Request GET /v1/internal/ui/services?dc=dc1&token=<hidden> (0s) from=127.0.0.1:52480                            
2017/08/11 00:22:33 [DEBUG] http: Request GET /v1/health/service/myservice?dc=dc1&token=<hidden> (1.0001ms) from=127.0.0.1:52480            

Could anyone give some info on this one.

Thx

回答1:

case 1 has upper case HTTP key which seems like a mistake - https://www.consul.io/docs/agent/checks.html

case 2 - if this is your entire check file, the JSON is invalid (wrap it with { }). you may also want to link it to the service by specifying a service_id



标签: c# consul