Open iwikus opened 1 month ago
Good idea 👍 Will test it. I initially thought the mmdb lookup is (much) more efficient than others. But with the overhead of the backend request and the HAProxy map_ip being very fast, this can be a good option.
We should compare the memory consumption though. Could be relevant for small VPS setups. 🤔
Please reach out if you have any questions about IPinfo. I mentioned in @iwikus's blog that the size of the database will be smaller because the issue of smaller ranges resulting in a bigger file size is a known issue for us. However, it will not be significantly smaller compared to other databases. I believe an MMDB-based solution is the optimal choice because it is both fast and compact. However, I am not very familiar with the project so I am not sure which option would be the best fit.
From what I see from a first view:
As described in https://github.com/haproxy/haproxy/issues/223 they will use loads of RAM.
As for the performance - I will try to find some time for benchmarks. Not sure how performant it is with (global-) large-scale DBs. Source references: https://github.com/haproxy/haproxy/blob/master/src/map.c#L1221 https://github.com/haproxy/haproxy/blob/master/src/pattern.c#L1016 https://github.com/haproxy/haproxy/blob/master/src/pattern.c#L956 https://github.com/haproxy/haproxy/blob/master/src/pattern.c#L988
Regarding the pure-LUA implementation - this would be nice to have. But I have not found time to test it, as https://github.com/anjia0532/lua-resty-maxminddb seems to have some nginx-specific (resty) code in it. Changes to the script might be needed.
I still did not get into testing that lua code... But for memory consumption I did not see any problem - with 20MB TXT map file for countries (ipv4 & ipv6 together), HAproxy is using less then 512MB ram.
Hi, I was searching if there is any lua geoip plugin for HAproxy and found this your project. I see you have implemented it by doing lookups to location service or (untested) lua mmdb library. For the the first option, this is possible do it other and I think more easy way, since there you need to do that caching for performance reasons.
Using geoip database or ipinfo it is posible to generate geoip.txt with all ip ranges and countries - I am doing it here (big file) http://iwik.org/ipcountry/geoip.txt Just yesterday have switched source of data and details are here on my blog https://blog.erben.sk/2024/09/14/new-country-ip-ranges-generator/ including link to source. And you can use it for ACL like this
Or in frontend part, set variable
http-response set-header geoip-countrycode %[src,map_ip(/etc/haproxy/geoip.txt)]
Or just in custom logformat (end of this huge line)
Anyway, when I find some time, I will try doing some test with that lua mmdb library.