Skip to content

Commit

Permalink
Handle 'allow_no_indices' and 'ignore_unavailable' query params for /…
Browse files Browse the repository at this point in the history
…field_caps (#128)

Fixes data view management/settings panel in Kibana. Since we don't
close/open indices, both options behave the same

Depends on:
- #126
  • Loading branch information
pivovarit authored May 16, 2024
1 parent 43034fa commit dcaf11b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions quesma/quesma/field_caps.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"mitmproxy/quesma/clickhouse"
"mitmproxy/quesma/elasticsearch"
"mitmproxy/quesma/model"
Expand Down Expand Up @@ -182,6 +183,18 @@ func handleFieldCapsIndex(ctx context.Context, indexes []string, tables clickhou
return json.Marshal(fieldCapsResponse)
}

func EmptyFieldCapsResponse() []byte {
var response = model.FieldCapsResponse{
Fields: make(map[string]map[string]model.FieldCapability),
Indices: []string{},
}
if serialized, err := json.Marshal(response); err != nil {
panic(fmt.Sprintf("Failed to serialize empty field caps response: %v, this should never happen", err))
} else {
return serialized
}
}

func isInternalColumn(col *clickhouse.Column) bool {
return col.Name == clickhouse.AttributesKeyColumn || col.Name == clickhouse.AttributesValueColumn
}
Expand Down
5 changes: 4 additions & 1 deletion quesma/quesma/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,13 @@ func configureRouter(cfg config.QuesmaConfiguration, lm *clickhouse.LogManager,
return elasticsearchQueryResult(string(responseBody), httpOk), nil
})

router.RegisterPathMatcher(routes.FieldCapsPath, []string{"GET", "POST"}, matchedAgainstPattern(cfg), func(ctx context.Context, body string, _ string, params map[string]string, _ http.Header, _ url.Values) (*mux.Result, error) {
router.RegisterPathMatcher(routes.FieldCapsPath, []string{"GET", "POST"}, matchedAgainstPattern(cfg), func(ctx context.Context, body string, _ string, params map[string]string, _ http.Header, queryParams url.Values) (*mux.Result, error) {
responseBody, err := handleFieldCaps(ctx, params["index"], []byte(body), lm)
if err != nil {
if errors.Is(errIndexNotExists, err) {
if queryParams.Get("allow_no_indices") == "true" || queryParams.Get("ignore_unavailable") == "true" {
return elasticsearchQueryResult(string(EmptyFieldCapsResponse()), httpOk), nil
}
return &mux.Result{StatusCode: 404}, nil
} else {
return nil, err
Expand Down

0 comments on commit dcaf11b

Please sign in to comment.