If it won't be simple, it simply won't be. [Hire me, source code] by Miki Tebeka, CEO, 353Solutions

Thursday, December 31, 2015

Using HAProxy to Prevent Deletes from Elasticsearch

At one of my clients, we wanted something quick and dirty to prevent deletes from Elasticsearch (shield is too expensive and would take too much time to integrate with our systems - we'll fix this technical debt later).

The quick solution was to place HAProxy in front of Elasticsearch and use its acl mechanism to prevent HTTP DELETE. Works like a charm.

Here's the HAProxy configuration and the docker-compose setup file I used to test the configuration.
elastic:
image: elasticsearch
haproxy:
image: haproxy
volumes:
- ${PWD}:/usr/local/etc/haproxy
links:
- elastic
ports:
- "9200:9200"
# Based on http://j.mp/1YHQFgZ
# vim: ft=haproxy
defaults
timeout connect 5000
timeout client 10000
timeout server 10000
frontend elastic
bind :9200
mode http
acl is_delete method DELETE
http-request deny if is_delete
default_backend elastic
backend elastic
mode http
option forwardfor
balance source
option httpclose
server es1 elastic:9200 weight 1 check inter 1000 rise 5 fall 1
view raw haproxy.cfg hosted with ❤ by GitHub

Tuesday, December 22, 2015

Python's deque for Go

Working on a Go project with my friend Fabrizio, I've investigated ways to have a faster data structure to store history items with append and pop.

Got the idea to try implementing Python's deque in Go. The C implementation is pretty easy to read. The result is deque for Go, which implement a subset of the features from Python's deque but enough for our needs. And it's pretty fast too:

$ make compare
Git head is 765f6b0
cd compare && go test -run NONE -bench . -v
testing: warning: no tests to run
PASS
BenchmarkHistAppend-4  3000000        517 ns/op
BenchmarkHistList-4    2000000        702 ns/op
BenchmarkHistQueue-4   3000000        576 ns/op
BenchmarkHistDeque-4   3000000        423 ns/op
ok   _/home/miki/Projects/go/src/github.com/tebeka/deque/compare 8.505s

Blog Archive