Copy logs up to v2 endpoints (#1207)

Copies the log endpoints up to the V2 endpoints, in a similar way to
the call endpoints.

The main change is to when logs are inserted into S3. The signature of
the function has been changed to take the whole call object, rather
than just the app and call id's. This allows the function to switch
between calls for Routes and those for Fns. Obviously this switching
can be removed when v1 is removed.

In the sql implementation it inserts with both appID and fnID, this
allows the two get's to work, and the down grade of the
migration. When the v1 logs are removed, the appId can be dropped.

The log fetch test and error messages have been changed to be FnID specific.
This commit is contained in:
Tom Coupland
2018-09-13 10:30:10 +01:00
committed by GitHub
parent ac11d42e56
commit a0ccc4d7c4
15 changed files with 186 additions and 58 deletions

View File

@@ -95,7 +95,8 @@ var tables = [...]string{`CREATE TABLE IF NOT EXISTS routes (
`CREATE TABLE IF NOT EXISTS logs (
id varchar(256) NOT NULL PRIMARY KEY,
app_id varchar(256) NOT NULL,
app_id varchar(256),
fn_id varchar(256),
log text NOT NULL
);`,
@@ -1059,7 +1060,7 @@ func (ds *SQLStore) GetCalls1(ctx context.Context, filter *models.CallFilter) ([
return res, nil
}
func (ds *SQLStore) InsertLog(ctx context.Context, appID, callID string, logR io.Reader) error {
func (ds *SQLStore) InsertLog(ctx context.Context, call *models.Call, logR io.Reader) error {
// coerce this into a string for sql
var log string
if stringer, ok := logR.(fmt.Stringer); ok {
@@ -1072,13 +1073,12 @@ func (ds *SQLStore) InsertLog(ctx context.Context, appID, callID string, logR io
log = b.String()
}
query := ds.db.Rebind(`INSERT INTO logs (id, app_id, log) VALUES (?, ?, ?);`)
_, err := ds.db.ExecContext(ctx, query, callID, appID, log)
query := ds.db.Rebind(`INSERT INTO logs (id, app_id, fn_id, log) VALUES (?, ?, ?, ?);`)
_, err := ds.db.ExecContext(ctx, query, call.ID, call.AppID, call.FnID, log)
return err
}
func (ds *SQLStore) GetLog(ctx context.Context, appID, callID string) (io.Reader, error) {
func (ds *SQLStore) GetLog1(ctx context.Context, appID, callID string) (io.Reader, error) {
query := ds.db.Rebind(`SELECT log FROM logs WHERE id=? AND app_id=?`)
row := ds.db.QueryRowContext(ctx, query, callID, appID)
@@ -1094,6 +1094,22 @@ func (ds *SQLStore) GetLog(ctx context.Context, appID, callID string) (io.Reader
return strings.NewReader(log), nil
}
func (ds *SQLStore) GetLog(ctx context.Context, fnID, callID string) (io.Reader, error) {
query := ds.db.Rebind(`SELECT log FROM logs WHERE id=? AND fn_id=?`)
row := ds.db.QueryRowContext(ctx, query, callID, fnID)
var log string
err := row.Scan(&log)
if err != nil {
if err == sql.ErrNoRows {
return nil, models.ErrCallLogNotFound
}
return nil, err
}
return strings.NewReader(log), nil
}
func buildFilterRouteQuery(filter *models.RouteFilter) (string, []interface{}) {
if filter == nil {
return "", nil