Using Caching in LUA transform #8134
-
I need to add fields to log_events by GET'ing info via a http call. I am planning to use LUA hooks.init to maintain the cache. Will something like this work ?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Also would love if I can rebuild the cache every N hours using the timers. @jszwedko |
Beta Was this translation helpful? Give feedback.
-
Hey @atibdialpad ! Yeah, the runtime will persist across events so you can do caching like that. I'd suggest rewriting this a bit to something like: [transforms.lua]
type = "lua"
inputs = []
version = "2"
hooks.process = "process"
source = '''
cache = {}
function get(key)
if not cache[key] then
cache[key] = <make a http call here to populate the cache>
end
return cache[key]
end
function process(event, emit)
if event.log.interface_name then
event.log.interface_description = get(interface_name)
end
end
''' You could also use the timer mechanism to clear the cache on an interval. |
Beta Was this translation helpful? Give feedback.
Hey @atibdialpad !
Yeah, the runtime will persist across events so you can do caching like that. I'd suggest rewriting this a bit to something like:
You could also use the timer mechanism to clear the cache on an interval.