Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit f53610f

Browse files
authored
Fixing elastic fallback in security mode (#902)
This PR fixes some regressions with elastic fallback in security mode. before: <img width="1620" alt="image" src="https://github.com/user-attachments/assets/da408780-5a51-46fb-8a52-64d152f3cd75"> after: <img width="1721" alt="image" src="https://github.com/user-attachments/assets/82df7324-2a5b-470a-9b99-b122a5c07804">
1 parent 43a1eed commit f53610f

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

quesma/elasticsearch/index_management.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ type (
3434
}
3535
)
3636

37-
func NewIndexManagement(elasticsearchUrl string) IndexManagement {
37+
func NewIndexManagement(elasticsearch config.ElasticsearchConfiguration) IndexManagement {
3838
return &indexManagement{
39-
ElasticsearchUrl: elasticsearchUrl,
40-
indexResolver: NewIndexResolver(elasticsearchUrl),
39+
ElasticsearchUrl: elasticsearch.Url.String(),
40+
indexResolver: NewIndexResolver(elasticsearch),
4141
}
4242
}
4343

quesma/elasticsearch/index_resolver.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
package elasticsearch
44

55
import (
6-
"bytes"
6+
"context"
77
"encoding/json"
88
"io"
99
"net/http"
10+
"quesma/quesma/config"
1011
)
1112

1213
type (
@@ -15,7 +16,7 @@ type (
1516
}
1617
indexResolver struct {
1718
Url string
18-
httpClient *http.Client
19+
httpClient *SimpleClient
1920
}
2021
Sources struct {
2122
Indices []Index `json:"indices"`
@@ -37,10 +38,10 @@ type (
3738
}
3839
)
3940

40-
func NewIndexResolver(elasticsearchUrl string) IndexResolver {
41+
func NewIndexResolver(elasticsearch config.ElasticsearchConfiguration) IndexResolver {
4142
return &indexResolver{
42-
Url: elasticsearchUrl,
43-
httpClient: &http.Client{},
43+
Url: elasticsearch.Url.String(),
44+
httpClient: NewSimpleClient(&elasticsearch),
4445
}
4546
}
4647

@@ -52,11 +53,7 @@ func NormalizePattern(p string) string {
5253
}
5354

5455
func (im *indexResolver) Resolve(indexPattern string) (Sources, bool, error) {
55-
req, err := http.NewRequest("GET", im.Url+"/_resolve/index/"+indexPattern+"?expand_wildcards=open", bytes.NewBuffer([]byte{}))
56-
if err != nil {
57-
return Sources{}, false, err
58-
}
59-
response, err := im.httpClient.Do(req)
56+
response, err := im.httpClient.Request(context.Background(), "GET", "_resolve/index/"+indexPattern+"?expand_wildcards=open", []byte{})
6057
if err != nil {
6158
return Sources{}, false, err
6259
}

quesma/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func main() {
9090
tableDisco := clickhouse.NewTableDiscovery(&cfg, connectionPool, virtualTableStorage)
9191
schemaRegistry := schema.NewSchemaRegistry(clickhouse.TableDiscoveryTableProviderAdapter{TableDiscovery: tableDisco}, &cfg, clickhouse.SchemaTypeAdapter{})
9292

93-
im := elasticsearch.NewIndexManagement(cfg.Elasticsearch.Url.String())
93+
im := elasticsearch.NewIndexManagement(cfg.Elasticsearch)
9494

9595
connManager := connectors.NewConnectorManager(&cfg, connectionPool, phoneHomeAgent, tableDisco)
9696
lm := connManager.GetConnector()

quesma/quesma/functionality/resolve/resolve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func HandleResolve(pattern string, sr schema.Registry, cfg *config.QuesmaConfigu
4242
// Combine results from both schema.Registry and Elasticsearch:
4343

4444
// todo avoid creating new instances all the time
45-
sourcesFromElastic, _, err := elasticsearch.NewIndexResolver(cfg.Elasticsearch.Url.String()).Resolve(normalizedPattern)
45+
sourcesFromElastic, _, err := elasticsearch.NewIndexResolver(cfg.Elasticsearch).Resolve(normalizedPattern)
4646
if err != nil {
4747
return elasticsearch.Sources{}, err
4848
}

quesma/table_resolver/rules.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,12 @@ func (r *tableRegistryImpl) makeCheckIfPatternMatchesAllConnectors(pipeline stri
197197
}
198198

199199
// but maybe we should also check against the actual indexes ??
200-
201-
if r.conf.AutodiscoveryEnabled {
202-
203-
for indexName := range r.elasticIndexes {
204-
if util.IndexPatternMatches(pattern, indexName) {
205-
matchedElastic = append(matchedElastic, indexName)
206-
}
200+
for indexName := range r.elasticIndexes {
201+
if util.IndexPatternMatches(pattern, indexName) {
202+
matchedElastic = append(matchedElastic, indexName)
207203
}
208-
204+
}
205+
if r.conf.AutodiscoveryEnabled {
209206
for tableName := range r.clickhouseIndexes {
210207
if util.IndexPatternMatches(pattern, tableName) {
211208
matchedClickhouse = append(matchedClickhouse, tableName)

quesma/table_resolver/table_resolver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ func (r *tableRegistryImpl) updateIndexes() {
171171
name: index.Name,
172172
}
173173
}
174+
for _, index := range sources.DataStreams {
175+
elasticIndexes[index.Name] = table{
176+
name: index.Name,
177+
}
178+
}
174179

175180
logger.Info().Msgf("Elastic tables updated: %v", elasticIndexes)
176181
r.elasticIndexes = elasticIndexes

0 commit comments

Comments
 (0)