Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions api/seqapi/v1/seq_api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ syntax = "proto3";

package seqapi.v1;

import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/ozontech/seq-ui/pkg/seqapi/v1;seqapi";

Expand Down Expand Up @@ -134,7 +134,7 @@ message SearchResponse {
repeated Event events = 1;
int64 total = 2;
optional Histogram histogram = 3;
bool partial_response = 4 [deprecated=true];
bool partial_response = 4 [deprecated = true];
repeated Aggregation aggregations = 5;
optional Error error = 6;
}
Expand All @@ -156,21 +156,21 @@ message GetHistogramRequest {

message GetHistogramResponse {
Histogram histogram = 1;
bool partial_response = 2 [deprecated=true];
bool partial_response = 2 [deprecated = true];
optional Error error = 3;
}

message GetAggregationRequest {
string query = 1;
google.protobuf.Timestamp from = 2;
google.protobuf.Timestamp to = 3;
string agg_field = 4 [deprecated=true];
string agg_field = 4 [deprecated = true];
repeated AggregationQuery aggregations = 5;
}

message GetAggregationResponse {
Aggregation aggregation = 1 [deprecated=true];
bool partial_response = 2 [deprecated=true];
Aggregation aggregation = 1 [deprecated = true];
bool partial_response = 2 [deprecated = true];
repeated Aggregation aggregations = 3;
optional Error error = 4;
}
Expand All @@ -190,6 +190,8 @@ message GetFieldsRequest {}

message GetFieldsResponse {
repeated Field fields = 1;
repeated Field system_fields = 2;
repeated Field pinned_fields = 3;
}

enum ExportFormat {
Expand Down Expand Up @@ -329,13 +331,13 @@ message DeleteAsyncSearchResponse {}
message GetEnvsRequest {}

message GetEnvsResponse {
message Env {
string env = 1;
uint32 max_search_limit = 2;
uint32 max_export_limit = 3;
uint32 max_parallel_export_requests = 4;
uint32 max_aggregations_per_request = 5;
uint32 seq_cli_max_search_limit = 6;
}
repeated Env envs = 1;
message Env {
string env = 1;
uint32 max_search_limit = 2;
uint32 max_export_limit = 3;
uint32 max_parallel_export_requests = 4;
uint32 max_aggregations_per_request = 5;
uint32 seq_cli_max_search_limit = 6;
}
repeated Env envs = 1;
}
10 changes: 7 additions & 3 deletions docs/en/02-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,15 @@ Config for `/seqapi` API handlers.

> The value must be passed in the duration format: `<number>(ms|s|m|h)`.

+ **`pinned_fields`** *`[]PinnedField`* *`default=[]`*
+ **`pinned_fields`** *`[]Field`* *`default=[]`*

List of fields which will be pinned in UI.
List of fields which will be displayed at the top of the event in UI.

`PinnedField` fields:
+ **`system_fields`** *`[]Field`* *`default=[]`*

List of fields which will be displayed at the bottom of the event in UI.

`Field` fields:

+ **`name`** *`string`* *`required`*

Expand Down
18 changes: 16 additions & 2 deletions docs/en/03-seq-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Seq API provides:

### `GET /fields`

Returns a list of [indexed fields](https://github.com/ozontech/seq-db/blob/main/docs/en/03-index-types.md), specified in the seq-db mapping file.
Returns a list of [indexed fields](https://github.com/ozontech/seq-db/blob/main/docs/en/03-index-types.md), specified in the seq-db mapping file, along with system and pinned fields from config.

**Auth:** NO

Expand All @@ -37,6 +37,18 @@ curl -X GET \
"name": "level",
"type": "keyword"
}
],
"system_fields": [
{
"name": "message",
"type": "keyword"
}
],
"pinned_fields": [
{
"name": "level",
"type": "keyword"
}
]
}
```
Expand Down Expand Up @@ -455,6 +467,8 @@ curl -X POST \

### `GET /fields/pinned`

> Deprecated. Pinned fields are now included in the `GET /fields` response.

Returns the list of fields that will be pinned in UI. Set in the `handlers.seq_api.pinned_fields` [config section](./02-configuration.md#seqapi).

**Auth:** NO
Expand Down Expand Up @@ -567,4 +581,4 @@ curl -X GET \
}
]
}
```
```
10 changes: 7 additions & 3 deletions docs/ru/02-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,15 @@ handlers:

> Значение должно быть передано в `duration`-формате: `<число>(ms|s|m|h)`.

+ **`pinned_fields`** *`[]PinnedField`* *`default=[]`*
+ **`pinned_fields`** *`[]Field`* *`default=[]`*

Список полей, которые будут закреплены в пользовательском интерфейсе.
Список полей, которые будут отображаться вверху события в интерфейсе.

Поля `PinnedField`:
+ **`system_fields`** *`[]Field`* *`default=[]`*

Список полей, которые будут отображаться внизу события в интерфейсе.

Поля `Field`:

+ **`name`** *`string`* *`required`*

Expand Down
18 changes: 16 additions & 2 deletions docs/ru/03-seq-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Seq API предоставляет:

### `GET /fields`

Возвращает список [индексированных полей](https://github.com/ozontech/seq-db/blob/main/docs/ru/03-index-types.md), указанных в mapping-файле seq-db.
Возвращает список [индексированных полей](https://github.com/ozontech/seq-db/blob/main/docs/ru/03-index-types.md), указанных в mapping-файле seq-db, а также системные и закрепленные поля из конфига.

**Авторизация:** НЕТ

Expand All @@ -37,6 +37,18 @@ curl -X GET \
"name": "level",
"type": "keyword"
}
],
"system_fields": [
{
"name": "message",
"type": "keyword"
}
],
"pinned_fields": [
{
"name": "level",
"type": "keyword"
}
]
}
```
Expand Down Expand Up @@ -455,6 +467,8 @@ curl -X POST \

### `GET /fields/pinned`

> Устарело. Закрепленные поля теперь включены в ответ `GET /fields`.

Возвращает список полей, которые будут закреплены в пользовательском интерфейсе. Устанавливается в [разделе конфигурации](./02-configuration.md#seqapi) `handlers.seq_api.pinned_fields`.

**Авторизация:** НЕТ
Expand Down Expand Up @@ -567,4 +581,4 @@ curl -X GET \
}
]
}
```
```
11 changes: 8 additions & 3 deletions internal/api/seqapi/v1/grpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type apiParams struct {
fieldsCache *fieldsCache
masker *mask.Masker
pinnedFields []*seqapi.Field
systemFields []*seqapi.Field
}

type API struct {
Expand Down Expand Up @@ -61,7 +62,8 @@ func New(
logger.Fatal("failed to init masking", zap.Error(err))
}

globalPinnedFields := parsePinnedFields(cfg.PinnedFields)
globalPinnedFields := parseFields(cfg.PinnedFields)
globalSystemFields := parseFields(cfg.SystemFields)

var params apiParams
var paramsByEnv map[string]apiParams
Expand All @@ -82,14 +84,16 @@ func New(
logger.Fatal("failed to init env masking", zap.Error(err))
}

envPinnedFields := parsePinnedFields(options.PinnedFields)
envPinnedFields := parseFields(options.PinnedFields)
envSystemFields := parseFields(options.SystemFields)

paramsByEnv[envName] = apiParams{
client: client,
options: options,
fieldsCache: envfCache,
masker: envMasker,
pinnedFields: envPinnedFields,
systemFields: envSystemFields,
}
}
} else {
Expand All @@ -105,6 +109,7 @@ func New(
fieldsCache: globalfCache,
masker: globalMasker,
pinnedFields: globalPinnedFields,
systemFields: globalSystemFields,
}
}

Expand All @@ -121,7 +126,7 @@ func New(
}
}

func parsePinnedFields(fields []config.PinnedField) []*seqapi.Field {
func parseFields(fields []config.Field) []*seqapi.Field {
res := make([]*seqapi.Field, len(fields))
for i, f := range fields {
res[i] = &seqapi.Field{
Expand Down
21 changes: 18 additions & 3 deletions internal/api/seqapi/v1/grpc/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,42 @@ func (a *API) GetFields(ctx context.Context, req *seqapi.GetFieldsRequest) (*seq
}

if params.fieldsCache == nil {
return params.client.GetFields(ctx, req)
resp, err := params.client.GetFields(ctx, req)
if err != nil {
return nil, err
}

resp.SystemFields = params.systemFields
resp.PinnedFields = params.pinnedFields
return resp, nil
}

fields, cached, isActual := params.fieldsCache.getFields()
if cached && isActual {
return &seqapi.GetFieldsResponse{
Fields: fields,
Fields: fields,
SystemFields: params.systemFields,
PinnedFields: params.pinnedFields,
}, nil
}

resp, err := params.client.GetFields(ctx, req)
if err != nil {
if cached {
logger.Error("can't get fields; use cached fields", zap.Error(err))
return &seqapi.GetFieldsResponse{Fields: fields}, nil
return &seqapi.GetFieldsResponse{
Fields: fields,
SystemFields: params.systemFields,
PinnedFields: params.pinnedFields,
}, nil
}

return nil, err
}

params.fieldsCache.setFields(resp.GetFields())
resp.SystemFields = params.systemFields
resp.PinnedFields = params.pinnedFields
return resp, nil
}

Expand Down
Loading
Loading