-
Notifications
You must be signed in to change notification settings - Fork 877
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
Feature: Add support for multiple lua scripts evaluation #704
Feature: Add support for multiple lua scripts evaluation #704
Conversation
First impression: this looks good! Let me know when you're ready for a review and I'd be happy to help with moving this along. |
No breaking changes, the same option and env var supports now multiple Lua scripts separated by comma Closes #699
Pull Request Test Coverage Report for Build 1737
💛 - Coveralls |
Codecov Report
@@ Coverage Diff @@
## master #704 +/- ##
=======================================
Coverage 88.26% 88.27%
=======================================
Files 16 16
Lines 1960 1961 +1
=======================================
+ Hits 1730 1731 +1
Misses 154 154
Partials 76 76
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Morning, I tested quickly new version with redis manually, no issues noticed. |
exporter/exporter.go
Outdated
if err := e.extractLuaScriptMetrics(ch, c); err != nil { | ||
return err | ||
for _, script := range e.options.LuaScript { | ||
if err := e.extractLuaScriptMetrics(ch, c, script); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies, I should have caught this during the initial, cursory review but missed it.
I think you should continue here when an error occurs and 1) log the error to the console and b) record a gauge metric with success==1/error==0 with the script name as a label.
To do that you'll need to have the label so change LuaScript in the exporter struct to be an array of Filename string & Script []byte so you have the filename available.
You should probably also record that filename label with the lua script results in lua.go:30 to avoid collisions of two scripts using the same variable name when returning results and for added info where a value is coming from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Thank you for review. I will try to update it this week.
But are you sure that we want to start exporter even if file is not found?
- log the error to the console
It's already doing it failing on first not accessible file FATA[0000] Error loading script file test1.lua err: open test1.lua: no such file or directory
You should probably also record that filename label with the lua script results in lua.go:30 to avoid collisions of two scripts using the same variable name when returning results and for added info where a value is coming from.
Yep, this sounds reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, this should fail fast on startup if a file is not present and the metric can record if executing the lua script succeeded or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @oliver006
Merry Christmas and a happy new year!🎄
I managed to check my PR during holidays and I think I implemented all we discussed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all your effort here!
I'll merge this as soon as the CI server runs (it sometimes gets backed up)
Any merry Christmas and a happy, healthy new year to you too!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @oliver006
It seems CI has some issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the CI has issues, it's pretty annoying. Let me find time the next few days and migrate it to a new CI instance. In the meantime, I'll merge the PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally got around to fixing the CI, your feature is released now as https://github.com/oliver006/redis_exporter/releases/tag/v1.46.0
Quick ping here to see if you're still working on this, would love to see this land. |
Hi, |
No worries, I get it, end of the year is hectic, I just wanted to check in. Take your time and ping me when you're ready for review. |
To monitor lua script evaluation: 0-error 1-ok 2-no results
@@ -374,7 +374,8 @@ func NewRedisExporter(redisURI string, opts Options) (*Exporter, error) { | |||
"master_link_up": {txt: "Master link status on Redis slave", lbls: []string{"master_host", "master_port"}}, | |||
"master_sync_in_progress": {txt: "Master sync in progress", lbls: []string{"master_host", "master_port"}}, | |||
"number_of_distinct_key_groups": {txt: `Number of distinct key groups`, lbls: []string{"db"}}, | |||
"script_values": {txt: "Values returned by the collect script", lbls: []string{"key"}}, | |||
"script_result": {txt: "Result of the collect script evaluation", lbls: []string{"filename"}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed, I added new metric script_result
, which will indicate if evaluation of Lua failed.
So far I set 0 - fail, 1 - ok, 2 - empty results.
ExpectedKeys: 3, | ||
Wants: []string{`test_exporter_last_scrape_error{err=""} 0`, `test_script_values{key="a"} 11`, `test_script_values{key="b"} 12`}, | ||
ExpectedKeys: 4, | ||
Wants: []string{`test_exporter_last_scrape_error{err=""} 0`, `test_script_values{filename="test.lua",key="a"} 11`, `test_script_values{filename="test.lua",key="b"} 12`, `test_script_values{filename="test.lua",key="c"} 13`, `test_script_result{filename="test.lua"} 1`}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that tests were missing one result, so I added it
`test_script_values{filename="test.lua",key="c"} 13`,
ExpectedError: true, | ||
Wants: []string{`test_exporter_last_scrape_error{err="ERR Error compiling script`}, | ||
Wants: []string{`test_exporter_last_scrape_error{err="ERR Error compiling script`, `test_script_result{filename="test.lua"} 0`}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added check of new metric script_result
to borked1, borked2 tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, thanks for finishing this!
LuaScript: []byte(`return {"a", "11", "b", "12", "c", "13"}`), | ||
Registry: prometheus.NewRegistry(), | ||
LuaScript: map[string][]byte{ | ||
"test.lua": []byte(`return {"a", "11", "b", "12", "c", "13"}`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
No breaking changes, the same option and env var supports now multiple Lua scripts separated by comma
Closes #699