-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(query): change logging bridge to be a service instead
It is no longer necessary for the query logging to be a bridge as the stats are available for consumption from the ProxyQueryService. This change changes the logging bridge to directly implement the proxy query service instead of implementing a bridge.
- Loading branch information
1 parent
9a5126d
commit f37e65f
Showing
5 changed files
with
131 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package query_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"io" | ||
"testing" | ||
"time" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/google/go-cmp/cmp/cmpopts" | ||
"github.com/influxdata/flux" | ||
platform "github.com/influxdata/influxdb" | ||
"github.com/influxdata/influxdb/query" | ||
"github.com/influxdata/influxdb/query/mock" | ||
) | ||
|
||
var orgID = MustIDBase16("ba55ba55ba55ba55") | ||
|
||
// MustIDBase16 is an helper to ensure a correct ID is built during testing. | ||
func MustIDBase16(s string) platform.ID { | ||
id, err := platform.IDFromString(s) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return *id | ||
} | ||
|
||
var opts = []cmp.Option{ | ||
cmpopts.IgnoreUnexported(query.ProxyRequest{}), | ||
cmpopts.IgnoreUnexported(query.Request{}), | ||
} | ||
|
||
func TestLoggingProxyQueryService(t *testing.T) { | ||
wantStats := flux.Statistics{ | ||
TotalDuration: time.Second, | ||
CompileDuration: time.Second, | ||
QueueDuration: time.Second, | ||
PlanDuration: time.Second, | ||
RequeueDuration: time.Second, | ||
ExecuteDuration: time.Second, | ||
Concurrency: 2, | ||
MaxAllocated: 2048, | ||
} | ||
wantBytes := 10 | ||
pqs := &mock.ProxyQueryService{ | ||
QueryF: func(ctx context.Context, w io.Writer, req *query.ProxyRequest) (flux.Statistics, error) { | ||
w.Write(make([]byte, wantBytes)) | ||
return wantStats, nil | ||
}, | ||
} | ||
var logs []query.Log | ||
logger := &mock.QueryLogger{ | ||
LogFn: func(l query.Log) error { | ||
logs = append(logs, l) | ||
return nil | ||
}, | ||
} | ||
|
||
wantTime := time.Now() | ||
lpqs := query.LoggingProxyQueryService{ | ||
ProxyQueryService: pqs, | ||
QueryLogger: logger, | ||
NowFunction: func() time.Time { | ||
return wantTime | ||
}, | ||
} | ||
|
||
var buf bytes.Buffer | ||
req := &query.ProxyRequest{ | ||
Request: query.Request{ | ||
Authorization: nil, | ||
OrganizationID: orgID, | ||
Compiler: nil, | ||
}, | ||
Dialect: nil, | ||
} | ||
stats, err := lpqs.Query(context.Background(), &buf, req) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !cmp.Equal(wantStats, stats, opts...) { | ||
t.Errorf("unexpected query stats: -want/+got\n%s", cmp.Diff(wantStats, stats, opts...)) | ||
} | ||
wantLogs := []query.Log{{ | ||
Time: wantTime, | ||
OrganizationID: orgID, | ||
Error: nil, | ||
ProxyRequest: req, | ||
ResponseSize: int64(wantBytes), | ||
Statistics: wantStats, | ||
}} | ||
if !cmp.Equal(wantLogs, logs, opts...) { | ||
t.Errorf("unexpected query logs: -want/+got\n%s", cmp.Diff(wantLogs, logs, opts...)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package mock | ||
|
||
import "github.com/influxdata/influxdb/query" | ||
|
||
var _ query.Logger = (*QueryLogger)(nil) | ||
|
||
type QueryLogger struct { | ||
LogFn func(query.Log) error | ||
} | ||
|
||
func (l *QueryLogger) Log(log query.Log) error { | ||
return l.LogFn(log) | ||
} |