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

Use difflib to log haproxy config changes #666

Closed eLvErDe closed 4 years ago

eLvErDe commented 4 years ago

Will generate nice log like this:

marathon_lb: running config is different from generated config - reloading
marathon_lb: ---
marathon_lb: +++
marathon_lb: @@ -1041,11 +1041,6 @@
marathon_lb:    mode tcp
marathon_lb:    use_backend platform_proj_37226
marathon_lb:
marathon_lb: -frontend platform_proj_37360
marathon_lb: -  bind *:37360
marathon_lb: -  mode tcp
marathon_lb: -  use_backend platform_proj_37360
marathon_lb: -
marathon_lb:  frontend platform_proj_38903
marathon_lb:    bind *:38903
marathon_lb:    mode tcp
marathon_lb: @@ -3106,11 +3101,6 @@
marathon_lb:    mode tcp
marathon_lb:    server server.com.10_1_1_1_31077 10.1.1.1:31077 id 4244
marathon_lb:
marathon_lb: -backend platform_proj_37360
marathon_lb: -  balance roundrobin
marathon_lb: -  mode tcp
marathon_lb: -  server server2.com_192_168_1_1_31784 192.168.1.1:31784 id 17977
marathon_lb: -
marathon_lb:  backend platform_proj_38903
marathon_lb:    balance roundrobin
marathon_lb:    mode tcp

Which is very helpful for auditing and debugging !

mesosphere-ci commented 4 years ago

Can one of the admins verify this patch?

mesosphere-ci commented 4 years ago

Can one of the admins verify this patch?

mesosphere-ci commented 4 years ago

Can one of the admins verify this patch?

mesosphere-ci commented 4 years ago

Can one of the admins verify this patch?

jkoelker commented 4 years ago

ok to test

jkoelker commented 4 years ago

Thanks for this awesome PR! I hope you don't mind but I fixed a small lint issue and force pushed back to your branch to get some of the tests to pass (the others will still fail).

eLvErDe commented 4 years ago

I don't know what you changed, can you point me to the difference ? I've deployed my own patch in prod so if there's a potential bug I'd be happy to know :D

jkoelker commented 4 years ago

No bug, just a silly strict linter:

diff --git a/marathon_lb.py b/marathon_lb.py
index e875e7f703f4..c822eb6814c5 100755
--- a/marathon_lb.py
+++ b/marathon_lb.py
@@ -1509,9 +1509,9 @@ def compareWriteAndReloadConfig(config, config_file, domain_map_array,
                 "running config is different from generated config"
                 " - reloading")
             for hunk in difflib.unified_diff(
-                    runningConfig.splitlines(),
-                    config.splitlines()
-                ):
+                runningConfig.splitlines(),
+                config.splitlines()
+            ):
                 logger.info(hunk)
             if writeConfigAndValidate(
                     config, config_file, domain_map_string, domain_map_file,
eLvErDe commented 4 years ago

Oh ok. I noticed the style was somehow very different to mine so I just tried to match what was there. I'm using Black with line-length 160 so... ;)