cel-go icon indicating copy to clipboard operation
cel-go copied to clipboard

Support context propagation on overloads

Open nlachfr opened this issue 3 years ago • 3 comments

Feature request checklist

  • [x] There are no issues that match the desired change
  • [ ] The change is large enough it can't be addressed with a simple Pull Request
  • [ ] If this is a bug, please file a Bug Report.

Change

Currently, it is possible to use go contexts with the ContextEval(context.Context, interface{}) method. However, this context is not usable by function overloads.

Example

fn := &functions.ContextOverload{
    Operator: "longRunningOperation",
    Unary: func(ctx context.Context, value ref.Val) {
        if err := longRunningOperation(ctx, value.Value()); err != nil {
            return types.Bool(false)
        }
        return types.Bool(true)
    }
}

nlachfr avatar Jun 26 '22 14:06 nlachfr

This is similar to what's exposed in #368; however, in that PR the Context argument is not stored. Also, in Kubernetes it seems to be more common to store the callback channel.

There's been interest in reviving #368, so I'll take a look at what you're proposing and hopefully merge the approaches as best I can

TristonianJones avatar Jun 27 '22 01:06 TristonianJones

@TristonianJones Is this still on the agenda? We might be a bit out of line doing async calls as part of custom CEL functions, but this would simplify those use cases quite a bit (partly in terms of propagating request deadline, but also caller authentication for upstream RPCs!).

odsod avatar Nov 22 '22 00:11 odsod

@TristonianJones How can I help in adding this feature ? For now, #368 seems to be frozen and being able to use the execution Context in overloads will be useful for network related functions

nlachfr avatar Jan 12 '23 19:01 nlachfr