@@ -22,9 +22,9 @@ import (
2222 "quesma/quesma/types"
2323 "quesma/quesma/ui"
2424 "quesma/schema"
25- "quesma/telemetry"
2625 "quesma/util"
2726 quesma_api "quesma_v2/core"
27+ "quesma_v2/core/diag"
2828 "quesma_v2/core/routes"
2929 "quesma_v2/core/tracing"
3030 "strings"
@@ -72,15 +72,20 @@ func responseFromQuesmaV2(ctx context.Context, unzipped []byte, w http.ResponseW
7272}
7373
7474type RouterV2 struct {
75- Config * config.QuesmaConfiguration
76- RequestPreprocessors quesma_api.ProcessorChain
77- QuesmaManagementConsole * ui.QuesmaManagementConsole
78- PhoneHomeAgent telemetry.PhoneHomeAgent
79- HttpClient * http.Client
80- FailedRequests atomic.Int64
75+ Config * config.QuesmaConfiguration
76+ RequestPreprocessors quesma_api.ProcessorChain
77+
78+ HttpClient * http.Client
79+ FailedRequests atomic.Int64
80+
81+ diagnostic diag.Diagnostic
8182}
8283
83- func NewRouterV2 (config * config.QuesmaConfiguration , qmc * ui.QuesmaManagementConsole , agent telemetry.PhoneHomeAgent ) * RouterV2 {
84+ func (r * RouterV2 ) InjectDiagnostic (s diag.Diagnostic ) {
85+ r .diagnostic = s
86+ }
87+
88+ func NewRouterV2 (config * config.QuesmaConfiguration ) * RouterV2 {
8489 tr := & http.Transport {
8590 TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
8691 }
@@ -91,11 +96,9 @@ func NewRouterV2(config *config.QuesmaConfiguration, qmc *ui.QuesmaManagementCon
9196 requestProcessors := quesma_api.ProcessorChain {}
9297 requestProcessors = append (requestProcessors , quesma_api .NewTraceIdPreprocessor ())
9398 return & RouterV2 {
94- Config : config ,
95- RequestPreprocessors : requestProcessors ,
96- QuesmaManagementConsole : qmc ,
97- PhoneHomeAgent : agent ,
98- HttpClient : client ,
99+ Config : config ,
100+ RequestPreprocessors : requestProcessors ,
101+ HttpClient : client ,
99102 }
100103}
101104
@@ -258,7 +261,7 @@ func (r *RouterV2) Reroute(ctx context.Context, w http.ResponseWriter, req *http
258261 }
259262 dispatcher := & quesma_api.Dispatcher {}
260263 if handlersPipe != nil {
261- quesmaResponse , err := recordRequestToClickhouseV2 (req .URL .Path , r .QuesmaManagementConsole , func () (* quesma_api.Result , error ) {
264+ quesmaResponse , err := recordRequestToClickhouseV2 (req .URL .Path , r .diagnostic . DebugInfoCollector () , func () (* quesma_api.Result , error ) {
262265 var result * quesma_api.Result
263266 result , err = handlersPipe .Handler (ctx , quesmaRequest )
264267
@@ -338,22 +341,24 @@ func (r *RouterV2) sendHttpRequestToElastic(ctx context.Context, req *http.Reque
338341 }
339342
340343 go func () {
341- elkResponseChan <- recordRequestToElasticV2 (req .URL .Path , r .QuesmaManagementConsole , func () elasticResultV2 {
344+ elkResponseChan <- recordRequestToElasticV2 (req .URL .Path , r .diagnostic . DebugInfoCollector () , func () elasticResultV2 {
342345
343346 isWrite := elasticsearch .IsWriteRequest (req )
344347
345- var span telemetry.Span
348+ phoneHome := r .diagnostic .PhoneHomeAgent ()
349+
350+ var span diag.Span
346351 if isManagement {
347352 if isWrite {
348- span = r . PhoneHomeAgent .ElasticBypassedWriteRequestsDuration ().Begin ()
353+ span = phoneHome .ElasticBypassedWriteRequestsDuration ().Begin ()
349354 } else {
350- span = r . PhoneHomeAgent .ElasticBypassedReadRequestsDuration ().Begin ()
355+ span = phoneHome .ElasticBypassedReadRequestsDuration ().Begin ()
351356 }
352357 } else {
353358 if isWrite {
354- span = r . PhoneHomeAgent .ElasticWriteRequestsDuration ().Begin ()
359+ span = phoneHome .ElasticWriteRequestsDuration ().Begin ()
355360 } else {
356- span = r . PhoneHomeAgent .ElasticReadRequestsDuration ().Begin ()
361+ span = phoneHome .ElasticReadRequestsDuration ().Begin ()
357362 }
358363 }
359364
@@ -373,7 +378,7 @@ func isIngestV2(path string) bool {
373378 return strings .HasSuffix (path , routes .BulkPath ) // We may add more methods in future such as `_put` or `_create`
374379}
375380
376- func recordRequestToClickhouseV2 (path string , qmc * ui. QuesmaManagementConsole , requestFunc func () (* quesma_api.Result , error )) (* quesma_api.Result , error ) {
381+ func recordRequestToClickhouseV2 (path string , qmc diag. DebugInfoCollector , requestFunc func () (* quesma_api.Result , error )) (* quesma_api.Result , error ) {
377382 statName := ui .RequestStatisticKibana2Clickhouse
378383 if isIngestV2 (path ) {
379384 statName = ui .RequestStatisticIngest2Clickhouse
@@ -384,7 +389,7 @@ func recordRequestToClickhouseV2(path string, qmc *ui.QuesmaManagementConsole, r
384389 return response , err
385390}
386391
387- func recordRequestToElasticV2 (path string , qmc * ui. QuesmaManagementConsole , requestFunc func () elasticResultV2 ) elasticResultV2 {
392+ func recordRequestToElasticV2 (path string , qmc diag. DebugInfoCollector , requestFunc func () elasticResultV2 ) elasticResultV2 {
388393 statName := ui .RequestStatisticKibana2Elasticsearch
389394 if isIngestV2 (path ) {
390395 statName = ui .RequestStatisticIngest2Elasticsearch
0 commit comments