|
|
|
|
|
by cdoxsey
2678 days ago
|
|
This algorithm is great. I was working on a new metric alert evaluation system and built an expression parser for things like: system.disk.free{*} / 1024 by {host}
The naive approach to parsing will result in the wrong order of operations, since they'll just be done in the order they appear: x + y * z => (x + y) * z
Rather than: x + (y * z)
As it should be. The shunting yard algorithm will rearrange the expressions.After implementing it I noticed my results were different than the reference system... and that's when I discovered we did arithmetic wrong in the main app and had for years. So I had to hard code a toggle for whether to do math properly :(. It's a sort of Hippocratic oath when it comes to these things... first do no harm, and even if it was wrong, people were relying on the existing functionality, and changing it would likely result in sudden alerts for folks. In the end we did fix it in the main app, but you always feel kind of dirty writing code like that. |
|