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

UnmarshalJSON function on the Time class assumes no nanosecond portion in the incoming int64 value #109

Open
ra-aylubimov opened this issue Apr 22, 2022 · 4 comments

Comments

@ra-aylubimov
Copy link

ra-aylubimov commented Apr 22, 2022

In harness\time\time.go, the UnmarshalJSON function assumes that the incoming int64 value does not have the nanosecond portion, and creates the Time type as:

*(*time.Time)(t) = time.Unix(parsedInt, 0)

We observe that this assumption is not true, at least for the executions query, as in

query {
 executions(limit:10) {
   nodes {
    id
    startedAt
    endedAt
    status
  }
}

The startedAt and endedAt fields return values greater than "seconds from Unix epoch", causing the function to return an invalid Time object.

@ra-aylubimov
Copy link
Author

I am testing a custom time unmarshalling helper function; please see if it can be helpful:

var maxSecondsTime = int64(math.Pow10(10)) - 1 // 10,000,000,000 - 1 = 9,999,999,999
func UnmarshalTimeFromInt64(t int64) *time.Time {
  // downgrade the incoming time to seconds
  for t > maxSecondsTime {
    t /= 1000
  }
  timeVal := time.Unix(t, 0)
  return &timeVal
}

@micahlmartin
Copy link
Collaborator

@ra-aylubimov can you show me the output of what you're getting with your query? It seems to be fine on my end.

{
  executions(limit: 15) {
    nodes {
      id
      startedAt
      endedAt
      status
    }
  }
}
{
  "data": {
    "executions": {
      "nodes": [
        {
          "id": "z6ODuayBQN-vN5pGa2ilFA",
          "startedAt": 1650903412833,
          "endedAt": 1650903424879,
          "status": "FAILED"
        },
        {
          "id": "ty7FNYaTQI2i5JCZbK4rOw",
          "startedAt": 1650903412378,
          "endedAt": 1650903418847,
          "status": "FAILED"
        },
        {
          "id": "gGeAUrQgSdq7vr58DIKheQ",
          "startedAt": 1650903002092,
          "endedAt": 1650903022146,
          "status": "FAILED"
        },
        {
          "id": "9jomBmjoQ9utKS1b0hixGw",
          "startedAt": 1650903000028,
          "endedAt": 1650903016468,
          "status": "FAILED"
        },
        {
          "id": "HqRV7V4QRBe_chn_Wd257g",
          "startedAt": 1650491896397,
          "endedAt": 1650491909753,
          "status": "FAILED"
        }
      ]
    }
  }
}

@ra-aylubimov
Copy link
Author

@micahlmartin
I see the same output of the query.
The problem I experience is with unamarshaling the time values into time.Time structure.
The time resolution returned by the query is in milliseconds.
But the custom unmarshaler assumes the value is in seconds, and creates a time.Time instance way in the future.

@ra-aylubimov
Copy link
Author

For reference, this is what I get for a similar query (limit=5).

{
"data": {
"executions": {
"nodes": [
{
"id": "6hwuw2j5QUOjUYnKsZZhPQ",
"startedAt": 1652451939643,
"endedAt": null,
"status": "RUNNING"
},
{
"id": "AK1cO5YyTiOuMa76sDIz-Q",
"startedAt": 1652451317581,
"endedAt": 1652452261218,
"status": "SUCCESS"
},
{
"id": "SXuNxQ2fTtWl6xFk4ZCezQ",
"startedAt": 1652451299049,
"endedAt": 1652452324682,
"status": "SUCCESS"
},
{
"id": "lVjFZMGuQOWgy35EFR4ozg",
"startedAt": 1652451289151,
"endedAt": 1652452273912,
"status": "SUCCESS"
},
{
"id": "GkuQLbYyT4-lgeflF9mkjg",
"startedAt": 1652451288816,
"endedAt": null,
"status": "RUNNING"
}
]
}
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants