Skip to content

refactor(dup): use DateTime internally#1142

Draft
noaccOS wants to merge 5 commits intoastarte-platform:release-1.2from
noaccOS:refactor/dup-datetime
Draft

refactor(dup): use DateTime internally#1142
noaccOS wants to merge 5 commits intoastarte-platform:release-1.2from
noaccOS:refactor/dup-datetime

Conversation

@noaccOS
Copy link
Copy Markdown
Collaborator

@noaccOS noaccOS commented Mar 12, 2025

depends on #1134 to avoid a rebase

depends on astarte-platform/astarte_core#119 and astarte-platform/astarte_data_access#100

see #1129 for context

timestamps are preserved in telemetry.

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?
  • Yes
  • No

Additional documentation e.g. usage docs, diagrams, etc.:


@noaccOS noaccOS force-pushed the refactor/dup-datetime branch from 9e49bbe to a948e58 Compare March 12, 2025 16:41
@noaccOS noaccOS requested review from Annopaolo, davidebriani, eddbbt, lusergit and shinnokdisengir and removed request for Annopaolo and davidebriani March 12, 2025 16:44
@noaccOS noaccOS force-pushed the refactor/dup-datetime branch from a948e58 to df1f304 Compare March 13, 2025 13:26
@noaccOS noaccOS force-pushed the refactor/dup-datetime branch 2 times, most recently from c1b32f0 to 522c3b5 Compare March 13, 2025 16:09
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.96%. Comparing base (754277a) to head (3dce23f).

Additional details and impacted files
@@               Coverage Diff               @@
##           release-1.2    #1142      +/-   ##
===============================================
+ Coverage        63.88%   63.96%   +0.07%     
===============================================
  Files               30       30              
  Lines             1944     1948       +4     
===============================================
+ Hits              1242     1246       +4     
  Misses             702      702              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@noaccOS noaccOS force-pushed the refactor/dup-datetime branch from 522c3b5 to 5446dba Compare March 13, 2025 16:18
Copy link
Copy Markdown
Collaborator

@Annopaolo Annopaolo left a comment

Choose a reason for hiding this comment

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

I'm not sure there's a need for using the DecimicrosecondDateTime struct instead of a well-defined separation between integer timestamps and DateTimes, but if it works...

@groups_lifespan_decimicroseconds 60 * 10 * 1000 * 10000
@deletion_refresh_lifespan_decimicroseconds 60 * 10 * 1000 * 10000
@datastream_maximum_retention_refresh_lifespan_decimicroseconds 60 * 10 * 1000 * 10000
@interface_lifespan minute: 10
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This seems rather ad hoc, I'd suggest using the standard :timer.minutes(10) and update DecimicrosecondDateTime.shift consequently.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It mimics DateTime.shift. Although the duration type is not yet available, we can mimic its functionality if we're just compiling a constant minute: 10 value

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If you don't like, I'd argue for having two variables for each lifespan, as in

@interface_lifespan_amount 10
@interface_lifespan_unit :minute

# usage
DecimicrosecondDateTime.add(datetime, @interface_lifespan_amount, @interface_lifespan_unit)

DateTime.add expects a unit anyway, IMO it's easier to understand if we give it in minutes ourselves

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I was not familiar with DateTime.shift's game, now I see why. Looks ok

@noaccOS
Copy link
Copy Markdown
Collaborator Author

noaccOS commented Mar 17, 2025

I'm not sure there's a need for using the DecimicrosecondDateTime struct instead of a well-defined separation between integer timestamps and DateTimes, but if it works...

I started out using a tuple, but ended up using a struct because it allows easier matches here

@eddbbt
Copy link
Copy Markdown
Contributor

eddbbt commented Mar 18, 2025

This has been moved to DataAccess imho it shall not be merged as it is

noaccOS added a commit to noaccOS/astarte_core that referenced this pull request Mar 18, 2025
import decimicrosecond datetime from
astarte-platform/astarte#1142

this way it can be used in data_access's datetime for cast and
split_submillis

Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
@davidebriani
Copy link
Copy Markdown
Collaborator

To be honest, I am not sure what is the problem that the PR is trying to solve.
Maybe some more context could be added in the PR's description?

@noaccOS noaccOS force-pushed the refactor/dup-datetime branch from 5446dba to ee888e8 Compare March 18, 2025 15:09
@noaccOS noaccOS marked this pull request as draft March 18, 2025 15:09
@noaccOS
Copy link
Copy Markdown
Collaborator Author

noaccOS commented Mar 18, 2025

This has been moved to DataAccess imho it shall not be merged as it is

marking as draft as this was made dependent on prs in data_access and core

noaccOS added 3 commits March 19, 2025 10:29
use DateTime.add directly instead of converting to and from timestamps,
which makes it harder to understand what's happening

Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
@noaccOS noaccOS force-pushed the refactor/dup-datetime branch from 8bb2a29 to ffbda9f Compare March 19, 2025 09:33
defp execute_time_based_actions(state, timestamp) do
if state.connected && state.last_seen_message > 0 do
if state.connected && DecimicrosecondDateTime.after?(state.last_seen_message, @epoch) do
# timestamps are handled as microseconds*10, so we need to divide by 10 when saving as a metric for a coherent data
Copy link
Copy Markdown
Contributor

@eddbbt eddbbt Mar 19, 2025

Choose a reason for hiding this comment

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

leftover (comment)

alias Astarte.Core.Device, as: CoreDevice
alias Astarte.Core.InterfaceDescriptor
alias Astarte.Core.Mapping
alias Astarte.DataAccess.DateTime, as: MsDateTime
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can remove the alias now

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

why?

Comment on lines +71 to +72
{:astarte_core, github: "noaccOS/astarte_core", branch: "chore/decimicro"},
{:astarte_data_access, github: "noaccOS/astarte_data_access", branch: "chore/decimicro"},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

those are not merged yet?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

check PR description

implement a new type, DecimicrosecondDateTime to allow using DateTimes
with one extra precision digit compared to std DateTimes.
Functions from the original DateTime are implemented as they're needed.

timestamps are preserved in telemetry.

Signed-off-by: Francesco Noacco <francesco.noacco@secomind.com>
@noaccOS noaccOS force-pushed the refactor/dup-datetime branch from ffbda9f to 3dce23f Compare March 19, 2025 10:03
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.

4 participants