@@ -14,22 +14,14 @@ import (
1414 "github.com/go-kit/log"
1515 "github.com/go-kit/log/level"
1616 "github.com/grafana/loki/v3/tools/querytee/goldfish"
17+ "github.com/grafana/loki/v3/tools/querytee/responsecomparator"
1718)
1819
19- type ResponsesComparator interface {
20- Compare (expected , actual []byte , queryEvaluationTime time.Time ) (* ComparisonSummary , error )
21- }
22-
23- type ComparisonSummary struct {
24- skipped bool
25- missingMetrics int
26- }
27-
2820type ProxyEndpoint struct {
2921 backends []* ProxyBackend
3022 metrics * ProxyMetrics
3123 logger log.Logger
32- comparator ResponsesComparator
24+ comparator responsecomparator. ResponsesComparator
3325
3426 instrumentCompares bool
3527
@@ -43,7 +35,7 @@ type ProxyEndpoint struct {
4335 goldfishManager * goldfish.Manager
4436}
4537
46- func NewProxyEndpoint (backends []* ProxyBackend , routeName string , metrics * ProxyMetrics , logger log.Logger , comparator ResponsesComparator , instrumentCompares bool ) * ProxyEndpoint {
38+ func NewProxyEndpoint (backends []* ProxyBackend , routeName string , metrics * ProxyMetrics , logger log.Logger , comparator responsecomparator. ResponsesComparator , instrumentCompares bool ) * ProxyEndpoint {
4739 hasPreferredBackend := false
4840 for _ , backend := range backends {
4941 if backend .preferred {
@@ -195,12 +187,12 @@ func (p *ProxyEndpoint) executeBackendRequests(r *http.Request, resCh chan *Back
195187 "route-name" , p .routeName ,
196188 "query" , r .URL .RawQuery , "err" , err )
197189 result = comparisonFailed
198- } else if summary != nil && summary .skipped {
190+ } else if summary != nil && summary .Skipped {
199191 result = comparisonSkipped
200192 }
201193
202194 if p .instrumentCompares && summary != nil {
203- p .metrics .missingMetrics .WithLabelValues (p .backends [i ].name , p .routeName , result , issuer ).Observe (float64 (summary .missingMetrics ))
195+ p .metrics .missingMetrics .WithLabelValues (p .backends [i ].name , p .routeName , result , issuer ).Observe (float64 (summary .MissingMetrics ))
204196 }
205197 p .metrics .responsesComparedTotal .WithLabelValues (p .backends [i ].name , p .routeName , result , issuer ).Inc ()
206198 }
@@ -275,9 +267,9 @@ func (p *ProxyEndpoint) waitBackendResponseForDownstream(resCh chan *BackendResp
275267 return responses [0 ]
276268}
277269
278- func (p * ProxyEndpoint ) compareResponses (expectedResponse , actualResponse * BackendResponse , queryEvalTime time.Time ) (* ComparisonSummary , error ) {
270+ func (p * ProxyEndpoint ) compareResponses (expectedResponse , actualResponse * BackendResponse , queryEvalTime time.Time ) (* responsecomparator. ComparisonSummary , error ) {
279271 if expectedResponse .err != nil {
280- return & ComparisonSummary {skipped : true }, nil
272+ return & responsecomparator. ComparisonSummary {Skipped : true }, nil
281273 }
282274
283275 if actualResponse .err != nil {
@@ -286,7 +278,7 @@ func (p *ProxyEndpoint) compareResponses(expectedResponse, actualResponse *Backe
286278
287279 // compare response body only if we get a 200
288280 if expectedResponse .status != 200 {
289- return & ComparisonSummary {skipped : true }, nil
281+ return & responsecomparator. ComparisonSummary {Skipped : true }, nil
290282 }
291283
292284 if actualResponse .status != 200 {
0 commit comments