Skip to content

Commit d5e5994

Browse files
committed
reasonable compromise with config
1 parent b15c388 commit d5e5994

File tree

5 files changed

+22
-26
lines changed

5 files changed

+22
-26
lines changed

api/agent/agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,10 +1192,10 @@ func newHotContainer(ctx context.Context, evictor Evictor, call *call, cfg *Conf
11921192
// fix is to make a new one each swap, it's cheap enough to be doable.
11931193
// TODO(reed): we should only do this if they configure to log stderr, not if they use WithLogger(),
11941194
// for now use explicit disable with DisableDebugUserLogs
1195-
sec := &nopCloser{newLogWriter(
1195+
sec := newLogWriter(
11961196
logrus.WithFields(logrus.Fields{"tag": "stderr", "app_id": call.AppID, "fn_id": call.FnID, "image": call.Image, "container_id": id}),
11971197
cfg.UserLogLevel,
1198-
)}
1198+
)
11991199
gw.Swap(newLineWriterWithBuffer(buf1, sec))
12001200
stderr = gw
12011201
bufs = append(bufs, buf1)

api/agent/call.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ type CallOverrider func(*http.Request, *models.Call, map[string]string) (map[str
4545
// CallOpt allows configuring a call before execution
4646
// TODO(reed): consider the interface here, all options must be defined in agent and flexible
4747
// enough for usage by extenders of fn, this straddling is painful. consider models.Call?
48-
type CallOpt func(c *call) error
48+
type CallOpt func(Config, *call) error
4949

5050
// FromHTTPFnRequest Sets up a call from an http trigger request
5151
func FromHTTPFnRequest(app *models.App, fn *models.Fn, req *http.Request) CallOpt {
52-
return func(c *call) error {
52+
return func(cfg Config, c *call) error {
5353
id := id.New().String()
5454

5555
var syslogURL string
@@ -121,7 +121,7 @@ func reqURL(req *http.Request) string {
121121

122122
// FromModel creates a call object from an existing stored call model object, reading the body from the stored call payload
123123
func FromModel(mCall *models.Call) CallOpt {
124-
return func(c *call) error {
124+
return func(cfg Config, c *call) error {
125125
c.Call = mCall
126126

127127
req, err := http.NewRequest(c.Method, c.URL, strings.NewReader(c.Payload))
@@ -138,7 +138,7 @@ func FromModel(mCall *models.Call) CallOpt {
138138

139139
// FromModelAndInput creates a call object from an existing stored call model object , reading the body from a provided stream
140140
func FromModelAndInput(mCall *models.Call, in io.ReadCloser) CallOpt {
141-
return func(c *call) error {
141+
return func(cfg Config, c *call) error {
142142
c.Call = mCall
143143

144144
req, err := http.NewRequest(c.Method, c.URL, in)
@@ -156,7 +156,7 @@ func FromModelAndInput(mCall *models.Call, in io.ReadCloser) CallOpt {
156156
// WithTrigger adds trigger specific bits to a call.
157157
// TODO consider removal, this is from a shuffle
158158
func WithTrigger(t *models.Trigger) CallOpt {
159-
return func(c *call) error {
159+
return func(cfg Config, c *call) error {
160160
// right now just set the trigger id
161161
c.TriggerID = t.ID
162162
return nil
@@ -166,31 +166,31 @@ func WithTrigger(t *models.Trigger) CallOpt {
166166
// WithWriter sets the writer that the call uses to send its output message to
167167
// TODO this should be required
168168
func WithWriter(w io.Writer) CallOpt {
169-
return func(c *call) error {
169+
return func(cfg Config, c *call) error {
170170
c.respWriter = w
171171
return nil
172172
}
173173
}
174174

175175
// WithLogger sets stderr to the provided one
176176
func WithLogger(w io.ReadWriteCloser) CallOpt {
177-
return func(c *call) error {
177+
return func(cfg Config, c *call) error {
178178
c.stderr = w
179179
return nil
180180
}
181181
}
182182

183183
// InvokeDetached mark a call to be a detached call
184184
func InvokeDetached() CallOpt {
185-
return func(c *call) error {
185+
return func(cfg Config, c *call) error {
186186
c.Model().Type = models.TypeDetached
187187
return nil
188188
}
189189
}
190190

191191
// WithContext overrides the context on the call
192192
func WithContext(ctx context.Context) CallOpt {
193-
return func(c *call) error {
193+
return func(cfg Config, c *call) error {
194194
c.req = c.req.WithContext(ctx)
195195
return nil
196196
}
@@ -199,15 +199,15 @@ func WithContext(ctx context.Context) CallOpt {
199199
// WithExtensions adds internal attributes to the call that can be interpreted by extensions in the agent
200200
// Pure runner can use this to pass an extension to the call
201201
func WithExtensions(extensions map[string]string) CallOpt {
202-
return func(c *call) error {
202+
return func(cfg Config, c *call) error {
203203
c.extensions = extensions
204204
return nil
205205
}
206206
}
207207

208208
// WithDockerAuth configures a call to retrieve credentials for an image pull
209209
func WithDockerAuth(auth docker.Auther) CallOpt {
210-
return func(c *call) error {
210+
return func(cfg Config, c *call) error {
211211
c.dockerAuth = auth
212212
return nil
213213
}
@@ -217,13 +217,12 @@ func WithDockerAuth(auth docker.Auther) CallOpt {
217217
// Configure UserLogLevel or DisableDebugUserLogs on agent to change behavior.
218218
func WithStderrLogger() CallOpt {
219219
// TODO(reed): we could take a context here which would allow request level logging vars on ctx to be used here too
220-
return func(c *call) error {
221-
// TODO(reed): fucking hell this is a pain to configure
222-
if a.cfg.DisableDebugUserLogs {
220+
return func(cfg Config, c *call) error {
221+
if cfg.DisableDebugUserLogs {
223222
return nil
224223
}
225224

226-
c.stderr = setupLogger(a.cfg.UserLogLevel, c.Call)
225+
c.stderr = setupLogger(c.Call, cfg.UserLogLevel)
227226
return nil
228227
}
229228
}
@@ -238,7 +237,7 @@ func (a *agent) GetCall(opts ...CallOpt) (Call, error) {
238237
opts = append(opts, a.callOpts...)
239238

240239
for _, o := range opts {
241-
err := o(&c)
240+
err := o(a.cfg, &c)
242241
if err != nil {
243242
return nil, err
244243
}

api/agent/func_logger.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ var (
1414
bufPool = &sync.Pool{New: func() interface{} { return new(bytes.Buffer) }}
1515
)
1616

17-
// * [always] writes bytes per line to stderr as DEBUG
18-
func setupLogger(level string, c *models.Call) io.WriteCloser {
17+
// the returned writer writes bytes per line to stderr
18+
func setupLogger(c *models.Call, level string) io.WriteCloser {
1919
lbuf := bufPool.Get().(*bytes.Buffer)
2020

2121
close := func() {
@@ -27,14 +27,14 @@ func setupLogger(level string, c *models.Call) io.WriteCloser {
2727
stderrLogger := logrus.WithFields(logrus.Fields{"user_log": true, "app_id": c.AppID, "fn_id": c.FnID, "image": c.Image, "call_id": c.ID})
2828
loggo := newLogWriter(stderrLogger, level)
2929
linew := newLineWriterWithBuffer(lbuf, loggo)
30-
linew = &fCloser{
30+
return &fCloser{
31+
Writer: linew,
3132
close: func() error {
3233
err := linew.Close()
3334
close()
3435
return err
3536
},
3637
}
37-
return linew
3838
}
3939

4040
// implements passthrough WriteCloser with overwritable Close

api/agent/lb_agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (a *lbAgent) GetCall(opts ...CallOpt) (Call, error) {
149149
opts = append(opts, a.callOpts...)
150150

151151
for _, o := range opts {
152-
err := o(&c)
152+
err := o(a.cfg, &c)
153153
if err != nil {
154154
return nil, err
155155
}

api/server/runner_fninvoke.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,3 @@ func (s *Server) fnInvoke(resp http.ResponseWriter, req *http.Request, app *mode
144144
bufPool.Put(buf) // at this point, submit returned without timing out, so we can re-use this one
145145
return nil
146146
}
147-
148-
func getCallOptions(req *http.Request, app *models.App, fn *models.Fn, trig *models.Trigger, rw http.ResponseWriter) []agent.CallOpt {
149-
}

0 commit comments

Comments
 (0)