mesosphere / marathon-lb

Marathon-lb is a service discovery & load balancing tool for DC/OS
Apache License 2.0
450 stars 300 forks source link

NBSRV rule for an APP to failover Haproxy #651

Open raghu999 opened 5 years ago

raghu999 commented 5 years ago

Hi We want to use nbsrv for few apps to failover the haproxy , We tried adding via label "HAPROXY_0_FRONTEND_HEAD": " \nfrontend {backend}\n acl mobile_fail nbsrv(backend) lt 1/n monitor fail if mobile_fail/n”, But once we stop the application the acl is also getting removed from the haproxy config(I think this is working as designed) which will not work for our usecase.

As we do not want the config to be removed after the app is suspended (or) destroyed we added the same rule in the globalconfig using HAPROXY_HTTPS_FRONTEND_HEAD template.

frontend marathon_https_in
  bind *:443 ssl {sslCerts}
  mode http
  acl mobile_fail nbsrv(mobile_10166) lt 1
  monitor fail if mobile_fail
  monitor-uri /vip_status

The template is working as expected and getting reflected in the haproxy config, But once we stop the mobile app marathon-lb stops working with the following error and is failing to reload the configs for other applications.

2019-10-02 16:59:24,061 marathon_lb: checking config with command: ['haproxy', '-f', '/tmp/tmplm9fj4db', '-c']
[ALERT] 274/165924 (212) : parsing [/tmp/tmplm9fj4db:105] : unable to find backend 'mobile_10166' referenced in arg 1 of ACL keyword 'nbsrv' in proxy 'marathon_https_in'.
[ALERT] 274/165924 (212) : Fatal errors found in configuration.
2019-10-02 16:59:24,288 marathon_lb: haproxy returned non-zero when checking config
2019-10-02 16:59:24,288 marathon_lb: skipping reload: config/map not valid
2019-10-02 16:59:24,288 marathon_lb: got apps ['/capsre-marathon-lb-v1.12.0']
2019-10-02 16:59:24,297 marathon_lb: generating config
2019-10-02 16:59:24,297 marathon_lb: HAProxy dir is /marathon-lb
2019-10-02 16:59:24,297 marathon_lb: Unexpected error!
Traceback (most recent call last):
  File "/marathon-lb/marathon_lb.py", line 1729, in make_config_valid_and_regenerate
    group_https_by_vhost)
TypeError: generateAndValidateTempConfig() takes 5 positional arguments but 6 were given

Can someone please help us here to understand if this feature is supported by marathon-lb.

paambaati commented 5 years ago

@raghu999 How is the mobile_10166 backend defined?

raghu999 commented 5 years ago

@paambaati Below are the labels we give to mobile application.


 "labels": {
    "HAPROXY_0_REDIRECT_TO_HTTPS_WITH_PATH": "true,/mobile",
    "HAPROXY_0_REDIRECT_TO_HTTPS": "true",
    "HAPROXY_GROUP": "external",
    "HAPROXY_0_PORT": "10166",
    "HAPROXY_0_PATH": "-i /mobile",
    "HAPROXY_0_BACKEND_REDIRECT_HTTP_TO_HTTPS_WITH_PATH": " redirect scheme https code 301 if path_{backend} \n",
    "HAPROXY_0_VHOST": "mobile-useast.example.net",
    "HAPROXY_0_HTTPS_FRONTEND_ACL_ONLY_WITH_PATH": "  acl path_{backend} path_beg {path}\n  use_backend {backend} if path_{backend}\n"
  }```