Starlark: Error: unknown binary op: int - time.duration

My data coming into Telegraf:

{
  "fields": {
    "description": "desc goes here"
  },
  "name": "measurement name",
  "tags": {
    "host": "hostname",
    "name": "interface-name",
    "path": "",
    "source": "source-name"
  },
  "timestamp": 1628116374
}

I want to filter out metrics that have timestamps that are older than 24hrs. My starlark stanza looks like this:

[[processors.starlark]]
namepass = ["interfaces"]
  source = '''
load('time.star', 'time')
def apply(metric):
  curDate = time.now().unix
  metric_date = time.from_timestamp(int(metric.time / 1e9))
  if metric_date >= curDate - time.parse_duration("24h") :
      return metric

However, this is giving me the following errors:

2021-08-13T19:06:46Z E! [processors.starlark] Error: unknown binary op: int - time.duration
2021-08-13T19:06:46Z E! [processors.starlark] Error in plugin: unknown binary op: int - time.duration

I think time.from_timestamp() returns an int64, and I believe the curDate var might be an int type. Since those are two separate types Go isn’t allowing the math to happen?

Starlark is not Go. Telegraf is written in Go and runs a Starlark interpreter within this plugin.
Starlark is a heavily restricted Python dialect.


As the error message says, the two data types are not compatible for this mathematical operation.
So either adjust the datatype of curDate or of the duration.
I haven’t tried it, but here are two possible ways:

curDate = time.now()  # Option 1
int(time.parse_duration("24h"))  # Option 2