-
Notifications
You must be signed in to change notification settings - Fork 3.4k
statedb: Add REST API for statedb queries #28872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
statedb: Add REST API for statedb queries #28872
Conversation
72d86e4
to
3ad7e57
Compare
/test |
I was planning to originally build this on top of #28729 with gRPC so there'd be proper streaming RPC goodness. I decided in the end to split this off from that since we need to have proper discussions on if/how/when to introduce competition to go-swagger/openapi and how we'd migrate. |
3ad7e57
to
f63258f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc changes look good. I took a brief look at the rest, and it didn't raise any red flag to me. Nice addition, thanks!
/test |
f63258f
to
133f769
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joamaki Very cool. Nice work!
65e8844
to
dc13ca1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, looks good on my end 👍
/test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joamaki Thank you for the updates! This is a great addition!
I think the TabWriter may need some TLC ie what if the output warrants custom cols or different columns ordering, etc...
But we can cross that bridge if we ever get there...
dc13ca1
to
6bd1955
Compare
/test |
This implements support for remotely querying the contents of StateDB tables over the REST API. It is implemented in terms of raw queries, e.g. the table, index names and the key []byte is transferred to the server which then performs the query against the given table and index. This allows reuse of the Index[Obj, Key] types and thus provides the same experience as server side: table := statedb.NewRemoteTable[*tables.Device](client, "devices") // Query devices by revision, least recently changed objects first. iter, err := table.LowerBound(ctx, statedb.ByRevision[*tables.Device](0)) for device, revision, ok := iter.Next(); ok; device, revision, ok = iter.Next { ... } // Find devices by name: all devices that start with "e": iter, err = table.LowerBound(ctx, tables.DeviceNameIndex("e")) // Exact matches: iter, err = table.Get(ctx, tables.DeviceNameIndex("eth0")) if device, revision, ok := iter.Next(); ok { ... } On top of this API a generic utility is implemented in cilium-dbg/cmd/statedb.go to allow adding the ability to pretty-print the contents of any table whose object implements 'statedb.TableWritable': // "cilium-dbg statedb devices" statedbTableCommand[*tables.Device]("devices") Example output: root@kind-worker:/home/cilium# cilium statedb devices Name Index Selected Type MTU HWAddr Flags Addresses lxc4446c55b3291 8 false veth 1500 46:b9:9b:85:c2:e2 up|broadcast|multicast fe80::44b9:9bff:fe85:c2e2 lo 1 false device 65536 up|loopback 127.0.0.1, ::1 lxc_health 71 false veth 1500 06:d8:63:ff:20:3b up|broadcast|multicast fe80::4d8:63ff:feff:203b cilium_host 3 false veth 1500 66:e0:0e:19:a6:9f up|broadcast|multicast 10.244.1.186 Since go-swagger does not provide an easy way to implement proper streaming APIs this does not add support for delete events (DeleteTracker). Implementing this is more involved and would require registering a DeleteTracker and keeping it alive with some sort of keepalive mechanism. Signed-off-by: Jussi Maki <jussi@isovalent.com>
6bd1955
to
4e81177
Compare
/test |
This implements support for remotely querying the contents of StateDB tables over the REST API. It is implemented in terms of raw queries, e.g. the table, index names and the key []byte is transferred to the server which then performs the query against the given table and index. This allows reuse of the Index[Obj, Key] types and thus provides the same experience as server side:
On top of this API a generic utility is implemented in cilium-dbg/cmd/statedb.go to allow adding the ability to pretty-print the contents of any table whose object implements 'statedb.TabWritable':
Example output:
Since go-swagger does not provide an easy way to implement proper streaming APIs this does not add support for delete events (DeleteTracker). Implementing this is more involved and would require registering a DeleteTracker and keeping it alive with some sort of keepalive mechanism.