Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kingluo/lua-resty-ffi-etcd
openresty etcd client library
https://github.com/kingluo/lua-resty-ffi-etcd
etcd-client etcdv3 golang luajit nginx openresty
Last synced: about 1 month ago
JSON representation
openresty etcd client library
- Host: GitHub
- URL: https://github.com/kingluo/lua-resty-ffi-etcd
- Owner: kingluo
- License: bsd-3-clause
- Created: 2023-05-21T12:20:48.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-05-21T15:11:33.000Z (over 1 year ago)
- Last Synced: 2024-11-15T04:10:29.939Z (about 2 months ago)
- Topics: etcd-client, etcdv3, golang, luajit, nginx, openresty
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lua-resty-ffi-etcd
The openresty etcd client library.
It encapsulates the etcd official [go client library](https://pkg.go.dev/go.etcd.io/etcd/client/v3).
## Background
If you access etcd directly using bare HTTP/GRPC, you will face the following problems:
* [smart load balancer](https://etcd.io/docs/v3.5/learning/design-client/) for multi-nodes etcd cluster
* Sync cluster membership changes, e.g. replace a stale node
* Full-featured node health check based on etcd client design
* Conditional retry
* Compose low-level APIs to do some high-level stuff like authentication
* Lack of support for additional features like [grpc-proxy](https://etcd.io/docs/v3.5/op-guide/grpc_proxy/#client-endpoint-synchronization-and-name-resolution)
* Keep up-to-date with etcd official server code changes and fix bugs yourselfSince etcd has an brilliant and active official go client, why not encapsulate it so that we could reuse it in openresty?
[lua-resty-ffi](https://github.com/kingluo/lua-resty-ffi) provides an efficient and generic API to do hybrid programming
in openresty with mainstream languages (Go, Python, Java, Rust, Nodejs).`lua-resty-ffi-etcd = lua-resty-ffi + go-etcd`
## Synopsis
```lua
local etcd = require("resty.ffi.etcd")
local inspect = require("inspect")local client = etcd.new{
endpoints = {
"httpbin.local:2379",
},
}
local watch = client:watch{
key = "/apisix/",
is_prefix = true,
}
local ok, res = watch:recv()
assert(ok, "watch:recv failed")
ngx.say(inspect(res))
```## Demo
```bash
# install lua-resty-ffi
# https://github.com/kingluo/lua-resty-ffi#install-lua-resty-ffi-via-luarocks
# set `OR_SRC` to your openresty source path
luarocks config variables.OR_SRC /tmp/tmp.Z2UhJbO1Si/openresty-1.21.4.1
luarocks install lua-resty-fficd /opt
git clone https://github.com/kingluo/lua-resty-ffi-etcd
cd /opt/lua-resty-ffi-etcd
makecd /opt/lua-resty-ffi-etcd/demo
# run nginx
LD_LIBRARY_PATH=/opt/lua-resty-ffi-etcd:/usr/local/lib/lua/5.1 \
nginx -p $PWD -c nginx.conf# in another terminal, run demo
curl localhost:20000/demo/watch
```### Benchmark
![etcd_benchmark](etcd_benchmark.svg)
https://github.com/kingluo/etcd-benchmark
The overhead of encapsulation is approximately `20%`. Of course, there is improvement room.
### TODO
* [x] Watcher
* [ ] KV
* [ ] Lease