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

Commit 7e4022a

Browse files
authored
Moving dependencies needed by routerV2 to v2 (#1066)
1 parent 0ba6514 commit 7e4022a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+356
-345
lines changed

quesma/clickhouse/quesma_communicator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"quesma/end_user_errors"
1212
"quesma/logger"
1313
"quesma/model"
14-
"quesma/tracing"
14+
tracing "quesma_v2/core/tracing"
1515
"strconv"
1616
"strings"
1717
"sync/atomic"

quesma/ingest/common_table_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"quesma/quesma/types"
1616
"quesma/schema"
1717
"quesma/table_resolver"
18-
"quesma_v2/core/mux"
18+
mux "quesma_v2/core"
1919
"testing"
2020
)
2121

quesma/ingest/ingest_validator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"quesma/quesma/types"
1414
"quesma/table_resolver"
1515
"quesma/util"
16-
"quesma_v2/core/mux"
16+
mux "quesma_v2/core"
1717
"strings"
1818
"testing"
1919
)

quesma/ingest/insert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"quesma/schema"
1616
"quesma/table_resolver"
1717
"quesma/util"
18-
"quesma_v2/core/mux"
18+
mux "quesma_v2/core"
1919
"slices"
2020
"strconv"
2121
"strings"

quesma/ingest/processor.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"quesma/table_resolver"
2525
"quesma/telemetry"
2626
"quesma/util"
27-
"quesma_v2/core/mux"
27+
"quesma_v2/core"
2828
"slices"
2929
"sort"
3030
"strings"
@@ -696,7 +696,7 @@ func (lm *IngestProcessor) ProcessInsertQuery(ctx context.Context, tableName str
696696
jsonData []types.JSON, transformer jsonprocessor.IngestTransformer,
697697
tableFormatter TableColumNameFormatter) error {
698698

699-
decision := lm.tableResolver.Resolve(mux.IngestPipeline, tableName)
699+
decision := lm.tableResolver.Resolve(quesma_api.IngestPipeline, tableName)
700700

701701
if decision.Err != nil {
702702
return decision.Err
@@ -712,10 +712,10 @@ func (lm *IngestProcessor) ProcessInsertQuery(ctx context.Context, tableName str
712712

713713
for _, connectorDecision := range decision.UseConnectors {
714714

715-
var clickhouseDecision *mux.ConnectorDecisionClickhouse
715+
var clickhouseDecision *quesma_api.ConnectorDecisionClickhouse
716716

717717
var ok bool
718-
if clickhouseDecision, ok = connectorDecision.(*mux.ConnectorDecisionClickhouse); !ok {
718+
if clickhouseDecision, ok = connectorDecision.(*quesma_api.ConnectorDecisionClickhouse); !ok {
719719
continue
720720
}
721721

quesma/logger/logger.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010
"net/http"
1111
"os"
1212
"quesma/stats/errorstats"
13-
"quesma/tracing"
13+
asyncQueryTracing "quesma/tracing"
14+
tracing "quesma_v2/core/tracing"
1415
"time"
1516
)
1617

@@ -41,7 +42,7 @@ const (
4142
var logger zerolog.Logger
4243

4344
// InitLogger returns channel where log messages will be sent
44-
func InitLogger(cfg Configuration, sig chan os.Signal, doneCh chan struct{}, asyncQueryTraceLogger *tracing.AsyncTraceLogger) <-chan LogWithLevel {
45+
func InitLogger(cfg Configuration, sig chan os.Signal, doneCh chan struct{}, asyncQueryTraceLogger *asyncQueryTracing.AsyncTraceLogger) <-chan LogWithLevel {
4546
zerolog.TimeFieldFormat = time.RFC3339Nano // without this we don't have milliseconds timestamp precision
4647
var output io.Writer = zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: time.StampMilli}
4748
if os.Getenv("GO_ENV") == "production" { // ConsoleWriter is slow, disable it in production

quesma/quesma/dual_write_proxy.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import (
2727
"quesma/schema"
2828
"quesma/table_resolver"
2929
"quesma/telemetry"
30-
"quesma/tracing"
3130
"quesma/util"
32-
"quesma_v2/core/mux"
31+
quesma_api "quesma_v2/core"
3332
"quesma_v2/core/routes"
33+
tracing "quesma_v2/core/tracing"
3434
"strconv"
3535
"strings"
3636
"sync/atomic"
@@ -68,7 +68,7 @@ func (c *simultaneousClientsLimiter) ServeHTTP(w http.ResponseWriter, r *http.Re
6868

6969
type dualWriteHttpProxy struct {
7070
routingHttpServer *http.Server
71-
elasticRouter *mux.PathRouter
71+
elasticRouter *quesma_api.PathRouter
7272
indexManagement elasticsearch.IndexManagement
7373
logManager *clickhouse.LogManager
7474
publicPort util.Port
@@ -101,9 +101,9 @@ func newDualWriteProxy(schemaLoader clickhouse.TableDiscovery, logManager *click
101101
Transport: tr,
102102
Timeout: time.Minute, // should be more configurable, 30s is Kibana default timeout
103103
}
104-
routerInstance := router{phoneHomeAgent: agent, config: config, quesmaManagementConsole: quesmaManagementConsole, httpClient: client, requestPreprocessors: processorChain{}}
104+
routerInstance := router{phoneHomeAgent: agent, config: config, quesmaManagementConsole: quesmaManagementConsole, httpClient: client, requestPreprocessors: quesma_api.ProcessorChain{}}
105105
routerInstance.
106-
registerPreprocessor(NewTraceIdPreprocessor())
106+
registerPreprocessor(quesma_api.NewTraceIdPreprocessor())
107107

108108
agent.FailedRequestsCollector(func() int64 {
109109
return routerInstance.failedRequests.Load()
@@ -192,7 +192,7 @@ func responseFromElastic(ctx context.Context, elkResponse *http.Response, w http
192192
elkResponse.Body.Close()
193193
}
194194

195-
func responseFromQuesma(ctx context.Context, unzipped []byte, w http.ResponseWriter, quesmaResponse *mux.Result, zip bool) {
195+
func responseFromQuesma(ctx context.Context, unzipped []byte, w http.ResponseWriter, quesmaResponse *quesma_api.Result, zip bool) {
196196
id := ctx.Value(tracing.RequestIdCtxKey).(string)
197197
logger.Debug().Str(logger.RID, id).Msg("responding from Quesma")
198198

@@ -217,14 +217,14 @@ func responseFromQuesma(ctx context.Context, unzipped []byte, w http.ResponseWri
217217

218218
type router struct {
219219
config *config.QuesmaConfiguration
220-
requestPreprocessors processorChain
220+
requestPreprocessors quesma_api.ProcessorChain
221221
quesmaManagementConsole *ui.QuesmaManagementConsole
222222
phoneHomeAgent telemetry.PhoneHomeAgent
223223
httpClient *http.Client
224224
failedRequests atomic.Int64
225225
}
226226

227-
func (r *router) registerPreprocessor(preprocessor RequestPreprocessor) {
227+
func (r *router) registerPreprocessor(preprocessor quesma_api.RequestPreprocessor) {
228228
r.requestPreprocessors = append(r.requestPreprocessors, preprocessor)
229229
}
230230

@@ -233,7 +233,7 @@ func (r *router) errorResponse(ctx context.Context, err error, w http.ResponseWr
233233

234234
msg := "Internal Quesma Error.\nPlease contact support if the problem persists."
235235
reason := "Failed request."
236-
result := mux.ServerErrorResult()
236+
result := quesma_api.ServerErrorResult()
237237

238238
// if error is an error with user-friendly message, we should use it
239239
var endUserError *end_user_errors.EndUserError
@@ -243,7 +243,7 @@ func (r *router) errorResponse(ctx context.Context, err error, w http.ResponseWr
243243

244244
// we treat all `Q1xxx` errors as bad requests here
245245
if endUserError.ErrorType().Number < 2000 {
246-
result = mux.BadReqeustResult()
246+
result = quesma_api.BadReqeustResult()
247247
}
248248
}
249249

@@ -286,13 +286,13 @@ func (*router) closedIndexResponse(ctx context.Context, w http.ResponseWriter, p
286286

287287
}
288288

289-
func (r *router) reroute(ctx context.Context, w http.ResponseWriter, req *http.Request, reqBody []byte, router *mux.PathRouter, logManager *clickhouse.LogManager) {
289+
func (r *router) reroute(ctx context.Context, w http.ResponseWriter, req *http.Request, reqBody []byte, router *quesma_api.PathRouter, logManager *clickhouse.LogManager) {
290290
defer recovery.LogAndHandlePanic(ctx, func(err error) {
291291
w.WriteHeader(500)
292292
w.Write(queryparser.InternalQuesmaError("Unknown Quesma error"))
293293
})
294294

295-
quesmaRequest, ctx, err := r.preprocessRequest(ctx, &mux.Request{
295+
quesmaRequest, ctx, err := r.preprocessRequest(ctx, &quesma_api.Request{
296296
Method: req.Method,
297297
Path: strings.TrimSuffix(req.URL.Path, "/"),
298298
Params: map[string]string{},
@@ -316,7 +316,7 @@ func (r *router) reroute(ctx context.Context, w http.ResponseWriter, req *http.R
316316
}
317317

318318
if handler != nil {
319-
quesmaResponse, err := recordRequestToClickhouse(req.URL.Path, r.quesmaManagementConsole, func() (*mux.Result, error) {
319+
quesmaResponse, err := recordRequestToClickhouse(req.URL.Path, r.quesmaManagementConsole, func() (*quesma_api.Result, error) {
320320
return handler(ctx, quesmaRequest)
321321
})
322322

@@ -367,7 +367,7 @@ func (r *router) reroute(ctx context.Context, w http.ResponseWriter, req *http.R
367367
}
368368

369369
for _, connector := range decision.UseConnectors {
370-
if _, ok := connector.(*mux.ConnectorDecisionElastic); ok {
370+
if _, ok := connector.(*quesma_api.ConnectorDecisionElastic); ok {
371371
// this is desired elastic call
372372
sendToElastic = true
373373
break
@@ -400,7 +400,7 @@ func (r *router) reroute(ctx context.Context, w http.ResponseWriter, req *http.R
400400
}
401401
}
402402

403-
func (r *router) preprocessRequest(ctx context.Context, quesmaRequest *mux.Request) (*mux.Request, context.Context, error) {
403+
func (r *router) preprocessRequest(ctx context.Context, quesmaRequest *quesma_api.Request) (*quesma_api.Request, context.Context, error) {
404404
var err error
405405
var processedRequest = quesmaRequest
406406
for _, preprocessor := range r.requestPreprocessors {
@@ -474,7 +474,7 @@ func isIngest(path string) bool {
474474
return strings.HasSuffix(path, routes.BulkPath) // We may add more methods in future such as `_put` or `_create`
475475
}
476476

477-
func recordRequestToClickhouse(path string, qmc *ui.QuesmaManagementConsole, requestFunc func() (*mux.Result, error)) (*mux.Result, error) {
477+
func recordRequestToClickhouse(path string, qmc *ui.QuesmaManagementConsole, requestFunc func() (*quesma_api.Result, error)) (*quesma_api.Result, error) {
478478
statName := ui.RequestStatisticKibana2Clickhouse
479479
if isIngest(path) {
480480
statName = ui.RequestStatisticIngest2Clickhouse

quesma/quesma/dual_write_proxy_v2.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ import (
2727
"quesma/schema"
2828
"quesma/table_resolver"
2929
"quesma/telemetry"
30-
"quesma/tracing"
3130
"quesma/util"
32-
"quesma_v2/core/mux"
31+
quesma_api "quesma_v2/core"
32+
tracing "quesma_v2/core/tracing"
33+
3334
"quesma_v2/core/routes"
3435
"strconv"
3536
"strings"
@@ -102,9 +103,9 @@ func newDualWriteProxyV2(schemaLoader clickhouse.TableDiscovery, logManager *cli
102103
Transport: tr,
103104
Timeout: time.Minute, // should be more configurable, 30s is Kibana default timeout
104105
}
105-
routerInstance := routerV2{phoneHomeAgent: agent, config: config, quesmaManagementConsole: quesmaManagementConsole, httpClient: client, requestPreprocessors: processorChain{}}
106+
routerInstance := routerV2{phoneHomeAgent: agent, config: config, quesmaManagementConsole: quesmaManagementConsole, httpClient: client, requestPreprocessors: quesma_api.ProcessorChain{}}
106107
routerInstance.
107-
registerPreprocessor(NewTraceIdPreprocessor())
108+
registerPreprocessor(quesma_api.NewTraceIdPreprocessor())
108109
agent.FailedRequestsCollector(func() int64 {
109110
return routerInstance.failedRequests.Load()
110111
})
@@ -181,7 +182,7 @@ func responseFromElasticV2(ctx context.Context, elkResponse *http.Response, w ht
181182
elkResponse.Body.Close()
182183
}
183184

184-
func responseFromQuesmaV2(ctx context.Context, unzipped []byte, w http.ResponseWriter, quesmaResponse *mux.Result, zip bool) {
185+
func responseFromQuesmaV2(ctx context.Context, unzipped []byte, w http.ResponseWriter, quesmaResponse *quesma_api.Result, zip bool) {
185186
id := ctx.Value(tracing.RequestIdCtxKey).(string)
186187
logger.Debug().Str(logger.RID, id).Msg("responding from Quesma")
187188

@@ -206,14 +207,14 @@ func responseFromQuesmaV2(ctx context.Context, unzipped []byte, w http.ResponseW
206207

207208
type routerV2 struct {
208209
config *config.QuesmaConfiguration
209-
requestPreprocessors processorChain
210+
requestPreprocessors quesma_api.ProcessorChain
210211
quesmaManagementConsole *ui.QuesmaManagementConsole
211212
phoneHomeAgent telemetry.PhoneHomeAgent
212213
httpClient *http.Client
213214
failedRequests atomic.Int64
214215
}
215216

216-
func (r *routerV2) registerPreprocessor(preprocessor RequestPreprocessor) {
217+
func (r *routerV2) registerPreprocessor(preprocessor quesma_api.RequestPreprocessor) {
217218
r.requestPreprocessors = append(r.requestPreprocessors, preprocessor)
218219
}
219220

@@ -222,7 +223,7 @@ func (r *routerV2) errorResponseV2(ctx context.Context, err error, w http.Respon
222223

223224
msg := "Internal Quesma Error.\nPlease contact support if the problem persists."
224225
reason := "Failed request."
225-
result := mux.ServerErrorResult()
226+
result := quesma_api.ServerErrorResult()
226227

227228
// if error is an error with user-friendly message, we should use it
228229
var endUserError *end_user_errors.EndUserError
@@ -232,7 +233,7 @@ func (r *routerV2) errorResponseV2(ctx context.Context, err error, w http.Respon
232233

233234
// we treat all `Q1xxx` errors as bad requests here
234235
if endUserError.ErrorType().Number < 2000 {
235-
result = mux.BadReqeustResult()
236+
result = quesma_api.BadReqeustResult()
236237
}
237238
}
238239

@@ -275,7 +276,7 @@ func (*routerV2) closedIndexResponse(ctx context.Context, w http.ResponseWriter,
275276

276277
}
277278

278-
func (r *routerV2) elasticFallback(decision *mux.Decision,
279+
func (r *routerV2) elasticFallback(decision *quesma_api.Decision,
279280
ctx context.Context, w http.ResponseWriter,
280281
req *http.Request, reqBody []byte, logManager *clickhouse.LogManager) {
281282

@@ -306,7 +307,7 @@ func (r *routerV2) elasticFallback(decision *mux.Decision,
306307
}
307308

308309
for _, connector := range decision.UseConnectors {
309-
if _, ok := connector.(*mux.ConnectorDecisionElastic); ok {
310+
if _, ok := connector.(*quesma_api.ConnectorDecisionElastic); ok {
310311
// this is desired elastic call
311312
sendToElastic = true
312313
break
@@ -338,13 +339,13 @@ func (r *routerV2) elasticFallback(decision *mux.Decision,
338339
}
339340
}
340341

341-
func (r *routerV2) reroute(ctx context.Context, w http.ResponseWriter, req *http.Request, reqBody []byte, searchRouter *mux.PathRouter, ingestRouter *mux.PathRouter, logManager *clickhouse.LogManager) {
342+
func (r *routerV2) reroute(ctx context.Context, w http.ResponseWriter, req *http.Request, reqBody []byte, searchRouter *quesma_api.PathRouter, ingestRouter *quesma_api.PathRouter, logManager *clickhouse.LogManager) {
342343
defer recovery.LogAndHandlePanic(ctx, func(err error) {
343344
w.WriteHeader(500)
344345
w.Write(queryparser.InternalQuesmaError("Unknown Quesma error"))
345346
})
346347

347-
quesmaRequest, ctx, err := r.preprocessRequest(ctx, &mux.Request{
348+
quesmaRequest, ctx, err := r.preprocessRequest(ctx, &quesma_api.Request{
348349
Method: req.Method,
349350
Path: strings.TrimSuffix(req.URL.Path, "/"),
350351
Params: map[string]string{},
@@ -358,8 +359,8 @@ func (r *routerV2) reroute(ctx context.Context, w http.ResponseWriter, req *http
358359
}
359360

360361
quesmaRequest.ParsedBody = types.ParseRequestBody(quesmaRequest.Body)
361-
var handler mux.Handler
362-
var decision *mux.Decision
362+
var handler quesma_api.Handler
363+
var decision *quesma_api.Decision
363364
searchHandler, searchDecision := searchRouter.Matches(quesmaRequest)
364365
if searchDecision != nil {
365366
decision = searchDecision
@@ -381,7 +382,7 @@ func (r *routerV2) reroute(ctx context.Context, w http.ResponseWriter, req *http
381382
}
382383

383384
if handler != nil {
384-
quesmaResponse, err := recordRequestToClickhouseV2(req.URL.Path, r.quesmaManagementConsole, func() (*mux.Result, error) {
385+
quesmaResponse, err := recordRequestToClickhouseV2(req.URL.Path, r.quesmaManagementConsole, func() (*quesma_api.Result, error) {
385386
return handler(ctx, quesmaRequest)
386387
})
387388

@@ -408,7 +409,7 @@ func (r *routerV2) reroute(ctx context.Context, w http.ResponseWriter, req *http
408409
}
409410
}
410411

411-
func (r *routerV2) preprocessRequest(ctx context.Context, quesmaRequest *mux.Request) (*mux.Request, context.Context, error) {
412+
func (r *routerV2) preprocessRequest(ctx context.Context, quesmaRequest *quesma_api.Request) (*quesma_api.Request, context.Context, error) {
412413
var err error
413414
var processedRequest = quesmaRequest
414415
for _, preprocessor := range r.requestPreprocessors {
@@ -482,7 +483,7 @@ func isIngestV2(path string) bool {
482483
return strings.HasSuffix(path, routes.BulkPath) // We may add more methods in future such as `_put` or `_create`
483484
}
484485

485-
func recordRequestToClickhouseV2(path string, qmc *ui.QuesmaManagementConsole, requestFunc func() (*mux.Result, error)) (*mux.Result, error) {
486+
func recordRequestToClickhouseV2(path string, qmc *ui.QuesmaManagementConsole, requestFunc func() (*quesma_api.Result, error)) (*quesma_api.Result, error) {
486487
statName := ui.RequestStatisticKibana2Clickhouse
487488
if isIngestV2(path) {
488489
statName = ui.RequestStatisticIngest2Clickhouse

quesma/quesma/elastic_http_frontend_connector.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ import (
99
"quesma/frontend_connectors"
1010
"quesma/quesma/recovery"
1111
"quesma/telemetry"
12-
"quesma_v2/core/mux"
12+
"quesma_v2/core"
1313
)
1414

1515
type ElasticHttpFrontendConnector struct {
1616
*frontend_connectors.BasicHTTPFrontendConnector
1717
routerInstance *routerV2
18-
searchRouter *mux.PathRouter
19-
ingestRouter *mux.PathRouter
18+
searchRouter *quesma_api.PathRouter
19+
ingestRouter *quesma_api.PathRouter
2020
logManager *clickhouse.LogManager
2121
agent telemetry.PhoneHomeAgent
2222
}
2323

2424
func NewElasticHttpFrontendConnector(endpoint string,
2525
routerInstance *routerV2,
26-
searchRouter *mux.PathRouter,
27-
ingestRouter *mux.PathRouter,
26+
searchRouter *quesma_api.PathRouter,
27+
ingestRouter *quesma_api.PathRouter,
2828
logManager *clickhouse.LogManager,
2929
agent telemetry.PhoneHomeAgent) *ElasticHttpFrontendConnector {
3030
return &ElasticHttpFrontendConnector{

0 commit comments

Comments
 (0)