Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invocation Filters #980

Closed
mathewc opened this issue Jan 20, 2017 · 14 comments
Closed

Invocation Filters #980

mathewc opened this issue Jan 20, 2017 · 14 comments
Assignees
Labels
Milestone

Comments

@mathewc
Copy link
Member

mathewc commented Jan 20, 2017

We should consider adding an Invoke Filter concept. This is very similar to WebAPI ActionFilters (the problem domain is basically the same). We've already had some related asks (see #734, #895). The idea is to provide a declarative programming model that allows people to attach filters to their job methods, classes, etc. similar to the way filters are specified in WebAPI. The invoke filter will receive a context object that contains everything needed to perform validations, do logging, etc. before any input/output bindings occur and before the function executes. In addition to invocation filters, we'll also enable different filter types mapping to different stages in the execution pipeline (e.g. exception/error filters). Here’s an sketch:

[ErrorHandler]
public static class Functions
{
    [ValidateOrder]
    public static void ProcessOrder([QueueTrigger(orders)] Order order) {}
}

public class ValidateOrdeAttribute : InvokeFilterAttribute
{
    public override void OnExecuting(FunctionExecutingContext context) 
    {
        // perform validations, etc.
    }

    public override void OnExecuted(FunctionExecutedContext context) 
    {
        // perform validations, etc.
    }
}

This attribute could be applied at the function or class level. We could also support host level as well (e.g. add to JobHostConfiguration service collection). Just like WebAPI ActionFilters, where they can be specified declaratively, as well as at the service config level.

@abatishchev
Copy link

+1. Please. Otherwise extendability and traceability are actually very limited.

@jamesbascle
Copy link

I'd like to make a note that, IMO, this should support async WebJobs as first class citizens - it was actually a rather complicated and touchy thing to get working with my interception strategy. Having to add ContinuesWith, manually setting cancel/exception/result, and more, is a lot to ask when the entire point behind WebJobs is to keep things as simple as possible.

@mathewc
Copy link
Member Author

mathewc commented Jan 20, 2017

@jamesbascle Of course we'd support async filters. Basically we'll be doing something like WebAPI ActionFilters. As you can see, that model supports sync/async. If you're asking for something more, please share details.

I realize my sketch code above didn't make that clear :)

@VenkateshSrini
Copy link

VenkateshSrini commented Jan 20, 2017

My two cents worth modification to your code


public static class Functions
{
    [MyInvokeFilter]
    public static void ProcessMessage([QueueTrigger(“test”)] string message) { … }
}

public class MyInvokeFilterAttribute : InvokeFilterAttribute
{
    public override Task OnExecuting(FunctionExecutingContext context) 
    {
        // perform validations, etc.
    }


    public override Task OnExecuted(FunctionExecutedContext context) 
    {
        // perform validations, etc.
    }
}

Can we also combine a sort of rules engine to these function context Out of the Box. This will actually provide the rules that needs be executed before the functions is executed. Otherwise it will exit without executing the rule. This is similar to rules of openWhisk. To start with we can leverage the WF4 rules engine.

Question how we will instantiate the rule engine in performance/cost efficient way. If we get this trick right then we are home

@dfaivre
Copy link

dfaivre commented Mar 21, 2017

I assume like WebAPI, we could apply a filter globally?

@VenkateshSrini
Copy link

Applying only in function level right? Because each job in an isolated entity. Multiple jobs (dissimilar) could be packaged at runtime in a job host. So I think applying filter globally will not make that much sense

@jamesbascle
Copy link

jamesbascle commented Mar 23, 2017 via email

@will-beta
Copy link

Looking forward to it!

@VenkateshSrini
Copy link

Is it closed because another PR has been opened or is it implemented. Please clarify

@jamesbascle
Copy link

jamesbascle commented Aug 4, 2017

@VenkateshSrini check the case and commits. It's merged into master dev.

@mathewc
Copy link
Member Author

mathewc commented Aug 16, 2017

FYI - this feature is now available in the nightly builds on myget with version 2.1.0-beta1-10998. There is also a wiki page describing the feature here: https://github.com/Azure/azure-webjobs-sdk/wiki/Function-Filters

@sonic1981
Copy link

Despite this thread being from 2017 the link to that wiki still has

This features is still in preview. Please be cautious using this in production applications.

Is this true? Is it in preview or has it been accepted permanently now?

@sonic1981
Copy link

sonic1981 commented Oct 19, 2020

Looks like this is getting helb up by #1284

Specifically #1284 (comment)

@sonic1981
Copy link

Looking like this approach is going to get abandoned:

I can see some interest in this and so going to give the answer that may help folks plan the best, but things can always change. We don't have any plans to bring functions filters as currently implemented as this preview feature forward. That said, the scenario that many people are interested in using function filters for, namely to add some logic and middleware before an execution triggers, is something we do want to solve for. We have recently prototyped some features as part of the upcoming out of process .NET work that allows users to add some middleware to execute before a function triggers for something like token validation or whatnot. If you were to ask me today that's what I would say is the future of this scenario, and not function filters as implemented.

I'm happy to keep this issue open to continue discussion around it, but don't want folks to hold out thinking we are holding out and waiting to move this from preview to GA. There were always some tradeoffs with the approach we took with filters and we feel we may be able to provide the benefits in a more flexible way with something like middleware.

#1284 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants