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

Starlark processor: Allow to manage errors that occur in the apply function #8354

Closed
essobedo opened this issue Nov 2, 2020 · 10 comments
Closed
Assignees

Comments

@essobedo
Copy link
Contributor

essobedo commented Nov 2, 2020

Thanks to the Starlark processor, it is now possible to execute code written in Starlark language which is very cool. The problem is how to deal with errors that occur within the apply function. Indeed, for example if we want to parse a JSON content, and the JSON content is invalid. Up to now, we get an error in the logger of Telegraf while we would like to somehow catch the exception (which is not supported by the Starlark language) to add a field in my metric with an error message.

@ssoroka
Copy link
Contributor

ssoroka commented Nov 2, 2020

This is a good idea. I think we could add some extra functions to help with this. Let me test out some ideas and get back to you

@ssoroka ssoroka self-assigned this Nov 2, 2020
@srebhan
Copy link
Member

srebhan commented Nov 3, 2020

How about we add an extra error() API that you can fill just like the apply() function? It could have the exact same API returning some metrics and additionally get the error message?
@essobedo: What do you think about this? For example it could look something like:

def on_error(metric, error):
    metric.fields["ok"] = False
    metric.fields["error"] = error.message

    return metric

Would that work for you?

@essobedo
Copy link
Contributor Author

essobedo commented Nov 3, 2020

@srebhan

Would that work for you?

Yes, clearly, It would be good enough

@srebhan
Copy link
Member

srebhan commented Nov 3, 2020

@ssoroka: What do you think about my proposal? How should the function be called? Do you want to or should I? :-)

@essobedo
Copy link
Contributor Author

essobedo commented Nov 9, 2020

@ssoroka Hi, were you able to test something? do you want me to provide a PR based on what @srebhan proposed or something else? More generally, can I help in any way?

@srebhan
Copy link
Member

srebhan commented Nov 13, 2020

@essobedo: If you are up to putting together a PR that would be cool. I'm willing to review it if you don't mind.
Otherwise let me know and I'll see if I can do something...

@essobedo essobedo changed the title Starlark processor: How to manage errors in an apply function? Starlark processor: Allow to manage errors thrown in the apply function Nov 13, 2020
@essobedo essobedo changed the title Starlark processor: Allow to manage errors thrown in the apply function Starlark processor: Allow to manage errors that occur in the apply function Nov 13, 2020
@essobedo
Copy link
Contributor Author

@srebhan @ssoroka here is my PR proposal #8401

@ssoroka
Copy link
Contributor

ssoroka commented Nov 13, 2020

merged! I think we could do a little bit more in this area, I've added a couple more issues under the starlark label.

I'm going to close this out as the original issue is resolved.

@ssoroka ssoroka closed this as completed Nov 13, 2020
@srebhan
Copy link
Member

srebhan commented Nov 14, 2020

@essobedo: I think catch should belong to the Starlark language. Maybe you can also try to get it into the upstream repository at https://github.com/google/starlark-go!?

@essobedo
Copy link
Contributor Author

@srebhan AFAIK It is not supported intentionally to keep it simple so I don't think they will accept it anyway google/skylark#125

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

No branches or pull requests

3 participants