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

[snapshots] record snapshot creation time #3125

Merged
merged 7 commits into from
Jun 28, 2023

Conversation

sharder996
Copy link
Contributor

Debated the use of QDateTime vs std::chrono::time_point, but some functions that would be useful for serializing the object to a string and vice versa are only available in C++20. You can still make it work with the C++17 STL, but you will be forced to use std::time_t in places. Depending on the platform, std::time_t can be only 32 bits, meaning that its maximmum date is sometime in 2038.

@sharder996 sharder996 requested a review from ricab June 13, 2023 21:25
@codecov
Copy link

codecov bot commented Jun 13, 2023

Codecov Report

Merging #3125 (976eb07) into snapshots (92ab1f3) will decrease coverage by 0.08%.
The diff coverage is 0.00%.

@@              Coverage Diff              @@
##           snapshots    #3125      +/-   ##
=============================================
- Coverage      84.21%   84.13%   -0.08%     
=============================================
  Files            246      246              
  Lines          13152    13164      +12     
=============================================
  Hits           11076    11076              
- Misses          2076     2088      +12     
Impacted Files Coverage Δ
include/multipass/snapshot.h 100.00% <ø> (ø)
src/daemon/daemon.cpp 64.41% <0.00%> (-0.11%) ⬇️
src/platform/backends/shared/base_snapshot.cpp 0.00% <0.00%> (ø)
src/platform/backends/shared/base_snapshot.h 0.00% <0.00%> (ø)

Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Good stuff @sharder996, thanks!

include/multipass/snapshot.h Show resolved Hide resolved
src/platform/backends/qemu/qemu_snapshot.cpp Outdated Show resolved Hide resolved
src/platform/backends/shared/base_snapshot.cpp Outdated Show resolved Hide resolved
: BaseSnapshot{json["name"].toString().toStdString(), // name
json["comment"].toString().toStdString(), // comment
QDateTime::fromString(json["creation_timestamp"].toString(),
"yyyy-MM-ddTHH:mm:ss.zzzZ"), // creation_timestamp
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this pretty much the same as Qt::ISODate? In any case, can you extract a constant please?

src/platform/backends/shared/base_snapshot.cpp Outdated Show resolved Hide resolved
src/platform/backends/shared/base_snapshot.h Show resolved Hide resolved
src/platform/backends/shared/base_snapshot.h Outdated Show resolved Hide resolved
src/daemon/daemon.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Almost.


private:
std::string name;
std::string comment;
const QDateTime creation_timestamp;
Copy link
Collaborator

Choose a reason for hiding this comment

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

All other const fields are below, after a comment explaining them. Is there a reason why you need this order? Otherwise, could you move the timestamp there?

@sharder996 sharder996 force-pushed the record-snapshot-creation-time branch from e65404d to d5037b4 Compare June 28, 2023 06:37
Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Hey @sharder996, one final detail that I missed before. And this needs a rebase now.

@@ -134,6 +145,7 @@ QJsonObject multipass::BaseSnapshot::serialize() const

snapshot.insert("name", QString::fromStdString(name));
snapshot.insert("comment", QString::fromStdString(comment));
snapshot.insert("creation_timestamp", creation_timestamp.toString(Qt::ISODate));
Copy link
Collaborator

@ricab ricab Jun 28, 2023

Choose a reason for hiding this comment

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

I just realized this was dropping milliseconds. There is a Qt::ISODateWithMs which is closer (same?) to what you had initially.

Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW, I believe this explains the wrong order after loading snapshots that were taken in quick succession:

$ mp snapshot b -n foo && mp snapshot a -n bar && mp snapshot b -n bar && mp snapshot b -n baz && mp snapshot a -n baz && mp snapshot a -n foo
Snapshot taken: b.foo
Snapshot taken: a.bar
Snapshot taken: b.bar
Snapshot taken: b.baz
Snapshot taken: a.baz
Snapshot taken: a.foo
$ multipass info --snapshot-overview --all                                                 Instance   Snapshot   Parent   Comment
a          bar        --       --
a          baz        bar      --
a          foo        baz      --
b          foo        --       --
b          bar        foo      --
b          baz        bar      --
$ snap stop multipass.multipassd
2023-06-28T12:43:29+01:00 INFO Waiting for "snap.multipass.multipassd.service" to stop.
Stopped.
$ snap start multipass.multipassd
Started.
$ multipass info --snapshot-overview --all
Instance   Snapshot   Parent   Comment
a          bar        --       --
a          foo        baz      --
a          baz        bar      --
b          foo        --       --
b          baz        bar      --
b          bar        foo      --

@sharder996 sharder996 force-pushed the record-snapshot-creation-time branch from d5037b4 to 976eb07 Compare June 28, 2023 16:57
Copy link
Collaborator

@ricab ricab left a comment

Choose a reason for hiding this comment

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

Yup, that's it!

@ricab ricab merged commit a30ab9b into snapshots Jun 28, 2023
10 of 14 checks passed
@bors bors bot deleted the record-snapshot-creation-time branch June 28, 2023 17:55
ricab added a commit that referenced this pull request Aug 29, 2023
[snapshots] record snapshot creation time
@ricab ricab mentioned this pull request Oct 24, 2023
ricab added a commit that referenced this pull request Oct 25, 2023
[snapshots] record snapshot creation time
ricab added a commit that referenced this pull request Oct 30, 2023
[snapshots] record snapshot creation time
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.

2 participants