Public API
Introduction
seq-db consists of 2 components - proxy and store:
- seq-db proxy and seq-db store communicate via internal seq-db store gRPC API.
- Querying logs is done via seq-db proxy gRPC API.
- Ingesting logs is done via Elasticsearch compatible HTTP API
- For debugging purposes, seq-db proxy has
HTTP API
similar togRPC API
This document describes seq-db ingestion API
and seq-db search API
Bulk HTTP API
seq-db is compatible with Elasticsearch bulk API
/
Returns a hardcoded ES response that specifies the Elasticsearch version used. This feature allows the usage of seq-db as an Elasticsearch output for logstash, filebeat, and other log shippers.
Example request:
curl -X GET http://localhost:9002/
Example successful response:
{
"cluster_name": "seq-db",
"version": {
"number": "8.9.0"
}
}
/_bulk
Receives body, parses it to docs and metas and writes to stores via internal API.
Example request:
curl -X POST http://localhost:9002/_bulk -d '
{"index":""}
{"k8s_pod":"seq-proxy", "request_time": "5", "time": "2024-12-23T18:00:36.357Z"}
{"index":""}
{"k8s_pod":"seq-proxy", "request_time": "6"}
{"index":""}
{"k8s_pod":"seq-proxy", "request_time": "7"}
{"index":""}
{"k8s_pod":"seq-proxy", "request_time": "8"}
{"index":""}
{"k8s_pod":"seq-proxy", "request_time": "9"}
{"index":""}
{"k8s_pod":"seq-db", "request_time": "10"}
{"index":""}
{"k8s_pod":"seq-db", "request_time": "11"}
{"index":""}
{"k8s_pod":"seq-db", "request_time": "12"}
{"index":""}
{"k8s_pod":"seq-db", "request_time": "13"}
{"index":""}
{"k8s_pod":"seq-db", "request_time": "14"}
'
Example successful response:
{
"took": 11,
"errors": false,
"items": [
{ "create": { "status": 201 } },
{ "create": { "status": 201 } },
{ "create": { "status": 201 } },
{ "create": { "status": 201 } },
{ "create": { "status": 201 } },
{ "create": { "status": 201 } },
{ "create": { "status": 201 } },
{ "create": { "status": 201 } },
{ "create": { "status": 201 } },
{ "create": { "status": 201 } }
]
}
One can notice that index
field is left empty. seq-db ignores data passed in this field, since it uses mapping
for field indexing. You can find more information about mapping in relevant document
Example rate-limited response
There should not be more than consts.IngestorMaxInflightBulks
requests at the same time (32 by default), otherwise
request is rate-limited and seq-db will response with 429
status code.
Example error response
In case of error seq-db returns 500
status code and the error message.
E.g. if we try to ingest corrupted json
curl -v -X POST http://localhost:9002/_bulk -d '
{"index":""}
{"k8s_pod":"seq-proxy", "request_time": "123}
'
We get
processing doc: unexpected end of string near `", "request_time": "123`
^
Search gRPC API
/Search
Document search method by request. Takes in query in seq-ql format and returns list of satisfying documents.
Example request:
grpcurl -plaintext -d '
{
"query": {
"from": "2020-01-01T00:00:00Z",
"to": "2030-01-01T00:00:00Z",
"query": "k8s_pod:seq-db"
},
"size": 2,
"with_total": true
}' localhost:9004 seqproxyapi.v1.SeqProxyApi/Search
Example successful response:
{
"total": "5",
"docs": [
{
"id": "0593adf493010000-d901eee224290dc6",
"data": "eyJrOHNfcG9kIjoic2VxLWRiIiwgInJlcXVlc3RfdGltZSI6ICIxMyJ9",
"time": "2024-12-23T18:00:36.357Z"
},
{
"id": "0593adf493010000-d9013865e424dba1",
"data": "eyJrOHNfcG9kIjoic2VxLWRiIiwgInJlcXVlc3RfdGltZSI6ICIxMSJ9",
"time": "2024-12-23T18:00:36.357Z"
}
],
"error": {
"code": "ERROR_CODE_NO"
}
}
data
field contains original document in base64 format. If we try to decode it
echo 'eyJrOHNfcG9kIjoic2VxLWRiIiwgInJlcXVlc3RfdGltZSI6ICIxMyJ9' | base64 -d | jq
we get
{
"k8s_pod": "seq-db",
"request_time": "13"
}
/GetAggregation
Агрегации позволяют вычислять статистические значения (сумма, среднее, максимум, минимум, квантиль, уникальность, количество) по полям документов, соответствующим запросу.
Агрегации можно вызывать двумя способами:
- через отдельный gRPC обработчик:
GetAggregation
- вместе с поиском и гистограммами:
ComplexSearch
В примерах используется API
GetAggregation
, которая по структуре запроса и ответа совпадает сComplexSearch
.
Поддерживаемые функции агрегации:
AGG_FUNC_SUM
— сумма значений поляAGG_FUNC_AVG
— среднее значение поляAGG_FUNC_MIN
— минимальное значение поляAGG_FUNC_MAX
— максимальное значение поляAGG_FUNC_QUANTILE
— вычисление квантилей для поляAGG_FUNC_UNIQUE
— вычисление уникальных значений поляAGG_FUNC_COUNT
— подсчёт количества документов по группе
Примеры агрегаций
Исходные документы:
{"service": "svc1", "latency": 100}
{"service": "svc1", "latency": 300}
{"service": "svc2", "latency": 400}
{"service": "svc2", "latency": 200}
{"service": "svc3", "latency": 500}