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

Consider adding a mod() function or similar to OTTL #37880

Open
bixu opened this issue Feb 12, 2025 · 11 comments · May be fixed by #38353
Open

Consider adding a mod() function or similar to OTTL #37880

bixu opened this issue Feb 12, 2025 · 11 comments · May be fixed by #38353
Assignees
Labels
enhancement New feature or request pkg/ottl priority:p2 Medium

Comments

@bixu
Copy link

bixu commented Feb 12, 2025

Component(s)

pkg/ottl

Is your feature request related to a problem? Please describe.

One common use-case for OTTL is making sensitive key values. For example, credit card numbers. Using Regexes alone can be difficult and prone to bugs.

Describe the solution you'd like

Some algorithm like the Luhn algorithm would make OTTL easier to use in the context of redaction or masking of values like credit card numbers.

Describe alternatives you've considered

Regex functions do exist in OTTL, but it's relatively easy to introduce bugs when using "pure" regex. An additional layer of checking using something like Luhn/mod 10 could increase correctness.

@bixu bixu added enhancement New feature or request needs triage New item requiring triage labels Feb 12, 2025
Copy link
Contributor

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@TylerHelmuth TylerHelmuth added priority:p2 Medium and removed needs triage New item requiring triage labels Feb 12, 2025
@TylerHelmuth
Copy link
Member

I wonder if we should build this into OTTL's arithmetic capabilities so you can do 9 % 2

@bixu
Copy link
Author

bixu commented Feb 17, 2025

I mentioned the Luhn algorithm specifically only because it's used as part of validation for almost all credit card schemes, but if we can reproduce the Luhn check with a math function, that would be fine. (It would be cool to have an example snippet in the docs, though.)

@edmocosta
Copy link
Contributor

Although adding the reminder operator capability to OTTL would be useful, I think that wouldn't be enough for calculating the Luhn algorithm. If I'm not mistaken, it requires extra steps, such as looping through the number digits, double values, etc. which isn't supported by OTTL. That said, I'd go with a specific function Luhn(), since Mod() might be misinterpreted as normal modulus operation.

@bacherfl
Copy link
Contributor

bacherfl commented Mar 4, 2025

I could look into implementing this

@bacherfl bacherfl linked a pull request Mar 4, 2025 that will close this issue
@bacherfl
Copy link
Contributor

bacherfl commented Mar 5, 2025

The PR should be ready for review now - I implemented it as a specific Luhn() function now to enable the credit card checksum validation use case, but if needed, I could also follow up with another PR for a Mod() function

@edmocosta
Copy link
Contributor

Hi @bixu, just to double check, do you need validating numbers using the Luhn algorithm or calculating/getting the check digit? I initially thought it was the second option, but I think I misunderstood it. If that's a validation function, I'd name it LuhnCheck, LuhnValidate or something like that.

@bixu
Copy link
Author

bixu commented Mar 9, 2025

@edmocosta, I think the most common use-case here is to check if a number is (probably) a valid CC number. So I think @bacherfl's PR will do the trick here. I agree that the function name should clearly indicate this is a bool. What about LuhnValid(<int>)?

@edmocosta
Copy link
Contributor

@edmocosta, I think the most common use-case here is to check if a number is (probably) a valid CC number. So I think @bacherfl's PR will do the trick here. I agree that the function name should clearly indicate this is a bool. What about LuhnValid(<int>)?

Thanks for confirming @bixu! I think LuhnValid(<int>) would also work here. My personal preference would be LuhnCheck, but that's only my opinion (naming is hard). WDYT @TylerHelmuth @evan-bradley?

@bixu
Copy link
Author

bixu commented Mar 11, 2025

I don't have a strong opinion about the name other than signaling that the return value is a boolean. It probably makes sense to follow the style of existing functions, so I'm happy to work with whatever the maintainers decide.

@TylerHelmuth
Copy link
Member

Most of our boolean function start with Is such as IsRootSpan, IsMatch, IsMap, extra. To be consistent I think it would be IsValidLuhn or IsLuhnValid, IDK anything about this algorithm so IDK which is more appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg/ottl priority:p2 Medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants