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

Created on 2 Nov 2020  路  10Comments  路  Source: influxdata/telegraf

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.

arestarlark

Most helpful comment

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.

All 10 comments

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

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?

@srebhan

Would that work for you?

Yes, clearly, It would be good enough

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

@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?

@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...

@srebhan @ssoroka here is my PR proposal https://github.com/influxdata/telegraf/pull/8401

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.

@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!?

@srebhan AFAIK It is not supported intentionally to keep it simple so I don't think they will accept it anyway https://github.com/google/skylark/issues/125

Was this page helpful?
0 / 5 - 0 ratings