flagr icon indicating copy to clipboard operation
flagr copied to clipboard

Using ISO dates with greater/less than constraints

Open Aidurber opened this issue 4 years ago • 0 comments

Expected Behavior

When adding an ISO Date string as a constraint. I should be able to use >, >=, <=, < operators in the constraints. This is useful for adding users who signed up before or after a given date into an experiment.

Current Behavior

In the debug logs there is an error:

{
  "segmentDebugLogs": [
    {
      "msg": "Literal is not a number: \"2021-09-29T00:00:00.000Z\"",
      "segmentID": 22
    }
  ]
}

Possible Solution

There is a work around and that's to convert the date string into a unix timestamp in both the entity context and the constraint. However, this makes it hard to setup and debug tests. Reading signup_date >= "2021-09-29T00:00:00.000Z" is easier to understand what the constraint is trying to do instead of signup_date >= 1632873600. Especially since non-technical users can operate the Flagr UI.

I think the solution would just be to remove the validation from the constraints. Allow users to use greater/less than operators on strings.

Another possible solution would be to add new greater/less operators such as:

  • isAfter
  • isOnOrAfter
  • isBefore
  • isOnOrBefore That works exclusively with dates.

Steps to Reproduce (for bugs)

  1. Create an experiment
  2. Add control and variant variants
  3. Create a new segment with a rollout of 100%
  4. Add a constraint: signup_date >= "2021-09-29T00:00:00.000Z"
  5. Set the distribution to 50/50 for control and variant
  6. Save segment
  7. Open the evaluation debugger
  8. In the entityContext object add "signup_date": "2021-09-29T00:00:00.000Z"
  9. POST the evaluation
  10. Observe the response
{
  "evalContext": {
    "enableDebug": true,
    "entityContext": {
      "hello": "world",
      "signup_date": "2021-09-29T00:00:00.000Z"
    },
    "entityID": "a1234",
    "entityType": "report",
    "flagID": 18,
    "flagKey": "ktehf28ej911otjcb"
  },
  "evalDebugLog": {
    "segmentDebugLogs": [
      {
        "msg": "Literal is not a number: \"2021-09-29T00:00:00.000Z\"",
        "segmentID": 22
      }
    ]
  },
  "flagID": 18,
  "flagKey": "signup-constraint-test",
  "flagSnapshotID": 359,
  "segmentID": 22,
  "timestamp": "2021-09-28T07:14:19Z"
}

Context

I'm trying to add an experiment that only includes users that have signed up before or after a given date. The Flagr UI is operated by non-technical team members and asking them to parse a date into a UNIX timestamp is a nonstarter.

Your Environment

  • Version used (flagr version): 1.1.2
  • Server type and version: Unknown
  • Operating System and version (uname -a): Unknown
  • Link to your project: N/A

Aidurber avatar Sep 28 '21 07:09 Aidurber