elastic-ipfs / metrics-collector

collect elastic-ipfs events into metrics
Other
2 stars 0 forks source link

IndexerCompleted events should express duration instead of startTime, endTime #33

Closed gobengo closed 2 years ago

gobengo commented 2 years ago

because JSON + ISO8601 can't express nanosecond durations https://nickb.dev/blog/iso8601-and-nanosecond-precision-across-languages/

And duration is 1) what we really care about in metrics-collector 2) what we actually have available at time of emitting IndexerCompleted 3) capable of expressing more precise measurement than previous startTime,endTime ISO8601 scheme

Plan

gobengo commented 2 years ago
alanshaw commented 2 years ago

Can we just get some reasons why we need nanosecond precision?

gobengo commented 2 years ago

@alanshaw we don't definitely need nanoseconds duration. happy to drop that. It still feels ideal to send an indexing duration instead of startTime/endTime pair. At the same time.... if we dont need to change it then we dont need to change it. i.e. maybe this isn't strictly needed for 'mvp'.

@alanshaw should I

I'm flexible either way.

One thing:

It makes calculating the duration complicated in javascript. ... Anyone receiving the event and dealing with it in javascript (like, wanting to do any calculations) has a harder time than if it's milliseconds.

Is it? const durationNs = BigInt(event.indexing.duration.value) vs const durationMs = Date.parse(event.indexing.endTime) - Date.parse(event.indexing.startTime))

alanshaw commented 2 years ago

One thing:

It makes calculating the duration complicated in javascript. ... Anyone receiving the event and dealing with it in javascript (like, wanting to do any calculations) has a harder time than if it's milliseconds.

Is it? const durationNs = BigInt(event.indexing.duration.value) vs const durationMs = Date.parse(event.indexing.endTime) - Date.parse(event.indexing.startTime))

* the latter is more characters/logic and less precision. neither is that hard to parse in JS

Not in that case I guess. I think I was angling for duration to be in ms. If it's nanoseconds it's just a bit more difficult to do time maths with because Date is all in ms. You have to convert to bigints and remember how many zeros in a nanosecond and how to convert between.

gobengo commented 2 years ago

@alanshaw and I discussed and we're going to just pause this issue for now and focus on some other priorities. The IndexerCompleted events in elastic-ipfs/indexer-lambda are event.indexing.duration nanoseconds in addition to event.indexing.{startTime,endTime} ISO8601 strings. More than enough info. It's not as important that metrics-collector uses duration ns instead of endTime - startTime ms