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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

freat: add date_to_unix_ts/3 function to the rule engine #10392

Conversation

kjellwinblad
Copy link
Contributor

@kjellwinblad kjellwinblad commented Apr 13, 2023

Fixes https://emqx.atlassian.net/browse/EMQX-9245

Summary

馃 Generated by Copilot at 8435571

Add a new rule engine function date_to_unix_ts/3 to convert date strings to unix timestamps and a test case for it in emqx_rule_funcs_SUITE.erl.

PR Checklist

Please convert it to a draft if any of the following conditions are not met. Reviewers may skip over until all the items are checked:

  • Added tests for the changes
  • Changed lines covered in coverage report
  • Change log has been added to changes/{ce,ee}/(feat|perf|fix)-<PR-id>.en.md files
  • For internal contributor: there is a jira ticket to track this change
  • If there should be document changes, a PR to emqx-docs.git is sent, or a jira ticket is created to follow up
  • Schema changes are backward compatible

@kjellwinblad kjellwinblad requested a review from a team as a code owner April 13, 2023 14:08
@kjellwinblad kjellwinblad force-pushed the kjell/rule_engine/add_missing_datetime_function/EMQX-9245 branch from 8435571 to 695f86a Compare April 13, 2023 14:12
@kjellwinblad kjellwinblad force-pushed the kjell/rule_engine/add_missing_datetime_function/EMQX-9245 branch from 695f86a to d3ccd8a Compare April 13, 2023 14:14
@coveralls
Copy link
Collaborator

coveralls commented Apr 13, 2023

Pull Request Test Coverage Report for Build 4719918024

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • 431 unchanged lines in 43 files lost coverage.
  • Overall coverage increased (+0.08%) to 81.236%

Files with Coverage Reduction New Missed Lines %
apps/emqx_authn/src/enhanced_authn/emqx_enhanced_authn_scram_mnesia.erl 1 86.57%
apps/emqx_modules/src/emqx_delayed.erl 1 94.78%
apps/emqx_modules/src/emqx_modules_schema.erl 1 95.24%
apps/emqx_slow_subs/src/emqx_slow_subs_schema.erl 1 83.33%
apps/emqx/src/emqx_channel.erl 1 87.64%
apps/emqx/src/emqx_sys_mon.erl 1 90.63%
apps/emqx/src/emqx_cm.erl 2 91.89%
apps/emqx/src/emqx_limiter/src/emqx_limiter_bucket_ref.erl 2 88.24%
lib-ee/emqx_ee_bridge/src/emqx_ee_bridge.erl 2 95.74%
apps/emqx_resource/src/schema/emqx_resource_schema.erl 3 95.56%
Totals Coverage Status
Change from base Build 4687261328: 0.08%
Covered Lines: 25518
Relevant Lines: 31412

馃挍 - Coveralls

ArgsOffset = [<<"second">>, <<"+08:00">>, <<"%y-%m-%d-%H:%M:%S%Z">>],
?FORALL(
S,
erlang:system_time(second),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is called only once for all tests. I tried locally with nanosecond and printing the value, it's always the same.

To achieve the desired generation of values, I think one way is to do:

Suggested change
erlang:system_time(second),
?LAZY(erlang:system_time(second)),

Not sure if the most correct way to produce values, but does produce different values.

Also, note that the generation is very fast: it produces several values in a second. So, even with ?LAZY, this will basically always return the same value.

Perhaps we could instead define a range of epoch values? Like

Suggested change
erlang:system_time(second),
range(0, 4000000000),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think this problem existed in the other test cases in the same function as well. Will try to fix them too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thalesmg thanks for spotting this. I have updated the test case in the latest commit.

apps/emqx_rule_engine/src/emqx_rule_funcs.erl Outdated Show resolved Hide resolved
kjellwinblad and others added 2 commits April 14, 2023 12:48
Co-authored-by: Thales Macedo Garitezi <thalesmg@gmail.com>
@kjellwinblad kjellwinblad merged commit 0c727fc into emqx:master Apr 17, 2023
111 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants