make fn logger more reasonable

something still feels off with this, but i tinkered with it for a day-ish and
didn't come up with anything a whole lot better. doing a lot of the
maneuvering in the caller seemed better but it was just bloating up GetCall so
went back to having it basically like it was, but returning the limited
underlying buffer to read from so we can ship to the db.

some small changes to the LogStore interface, swapped it to take an
io.Reader instead of a string for more flexibility in the future while
essentially maintaining the same level of performance that we have now.
i'm guessing in the not so distant future we'll ship these to some s3 like
service and it would be better to stream them in than carry around a giant
string anyway. also, carrying around up to 1MB buffers in memory isn't great,
we may want to switch to file backed logs for calls, too. using io.Reader for
logs should make #279 more reasonable if/once we move to some s3-like thing,
we can stream from the log storage service direct to clients.

this fixes the span being out of whack and allows the 'right' context to be
used to upload logs (next to inserting the call). deletes the dbWriter we had,
and we just do this in call.End now (which makes sense to me at least).
removes the dupe code for making an stderr for hot / cold and simplifies the
way to get a func logger (no more 7 param methods yay).

closes #298
This commit is contained in:
Reed Allman
2017-09-06 12:52:40 -07:00
parent 0280df0cdf
commit 1811b4e230
9 changed files with 126 additions and 111 deletions

View File

@@ -1,7 +1,10 @@
package logs
import (
"bytes"
"context"
"io"
"github.com/fnproject/fn/api/models"
"github.com/pkg/errors"
)
@@ -27,8 +30,10 @@ func (m *mock) SetDatastore(ctx context.Context, ds models.Datastore) {
m.ds = ds
}
func (m *mock) InsertLog(ctx context.Context, appName, callID, callLog string) error {
m.Logs[callID] = &models.CallLog{CallID: callID, Log: callLog}
func (m *mock) InsertLog(ctx context.Context, appName, callID string, callLog io.Reader) error {
var b bytes.Buffer
io.Copy(&b, callLog)
m.Logs[callID] = &models.CallLog{CallID: callID, Log: b.String()}
return nil
}