-
Notifications
You must be signed in to change notification settings - Fork 256
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
timestamps: use ISO 8601 format #1536
base: master
Are you sure you want to change the base?
Conversation
a0ff4d2
to
5e1bdf6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bareos-check-sources doesn't agree with your changes, please fix them.
We should decide what we want to achieve with the TimeStampFormat and LogTimeStampFormat.
Do we want to adapt in btime.cc bstrftimes to also take care of the format, our code is calling both of them, maybe one function would be better?
docs/manuals/source/include/autogenerated/bareos-sd-config-schema.json
Outdated
Show resolved
Hide resolved
docs/manuals/source/include/autogenerated/bareos-fd-config-schema.json
Outdated
Show resolved
Hide resolved
docs/manuals/source/include/autogenerated/bareos-dir-config-schema.json
Outdated
Show resolved
Hide resolved
0ab35c2
to
6faa586
Compare
The job report still contain wrong date (at least for backup) see result of bareos-basic tests. |
7ee54a5
to
d34bd16
Compare
6d3f2b2
to
6970f56
Compare
5f3a2e7
to
89b5e9f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Besides my other comments, we should pick up the whole repository and not just one file if we want to have it in third-party.
Also, we should probably discuss the usage of some package manager instead of shipping all dependencies.
core/src/cats/sql_find.cc
Outdated
"EXTRACT('EPOCH' FROM FirstWritten)," | ||
"EXTRACT('EPOCH' FROM LastWritten)," | ||
"EXTRACT('EPOCH' FROM LabelDate)," | ||
"EXTRACT('EPOCH' FROM InitialWrite) " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is good practice to name these fields, even if we just access them via index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
core/src/cats/sql_find.cc
Outdated
"EXTRACT('EPOCH' FROM FirstWritten)," | ||
"EXTRACT('EPOCH' FROM LastWritten)," | ||
"EXTRACT('EPOCH' FROM LabelDate)," | ||
"EXTRACT('EPOCH' FROM InitialWrite) " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is good practice to name these fields, even if we just access them via index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, as the text-variants of these fields are not needed anymore it may be a good idea to replace FirstWritten
with EXTRACT('EPOCH' FROM FirstWritten) AS FirstWritten
in place and keep the original offset-index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
core/src/cats/sql_find.cc
Outdated
bstrncpy(mr->cFirstWritten, (row[20] != NULL) ? row[20] : "", | ||
sizeof(mr->cFirstWritten)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cFirstWritten is never used (and can be removed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
core/src/cats/sql_find.cc
Outdated
bstrncpy(mr->cLastWritten, (row[21] != NULL) ? row[21] : "", | ||
sizeof(mr->cLastWritten)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cLastWritten is never used (and can be removed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
core/src/cats/sql_find.cc
Outdated
bstrncpy(mr->cLabelDate, (row[26] != NULL) ? row[26] : "", | ||
sizeof(mr->cLabelDate)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cLabelDate is never used (and can be removed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
core/src/include/baconfig.h
Outdated
@@ -56,6 +56,22 @@ | |||
# define ioctl_req_t int | |||
#endif | |||
|
|||
#if defined(HAVE_WIN32) | |||
static constexpr char* kBareosDefaultTimestampFormat | |||
= (char*)"%Y-%m-%dT%H:%M:%S"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This casts away the const
ness of the constant, which will lead to undefined behaviour.
The safe approach is to change the interface of the receiving function to accept a const char*
core/src/include/baconfig.h
Outdated
#if defined(HAVE_WIN32) | ||
static constexpr char* kBareosDefaultTimestampFormat | ||
= (char*)"%Y-%m-%dT%H:%M:%S"; | ||
// %z is missing because it is not correctly implemented in windows :( | ||
#else | ||
static constexpr char* kBareosDefaultTimestampFormat = (char*)"%Y-%m-%dT%T%z"; | ||
#endif | ||
|
||
// for use in TO_CHAR database queries | ||
static constexpr char* kBareosDatabaseDefaultTimestampFormat | ||
= (char*)"YYYY-MM-DD\"T\"HH24:MI:SSTZH:TZM"; | ||
|
||
// to create filenames, so only what is allowed in filenames also on windows | ||
static constexpr char* kBareosFilenameTimestampFormat | ||
= (char*)"%Y-%m-%dT%H.%M.%S"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it probably makes sense to group these into a class or namespace, so we end up with TimestampFormat::Default
, TimestampFormat::Database
and TimestampFormat::Filename
.
Also I'm not 100% sure that this is the right place for these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
core/src/include/baconfig.h
Outdated
# ifndef NO_UNDERSCORE_MACRO | ||
# ifndef _ | ||
# define _(s) (s) | ||
# endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That workaround is not going to cut it.
We need some solution to completely get rid of that _()
macro. It currently breaks things and it will continue to produce weird issues if we don't remove it somehow.
core/src/lib/btime.cc
Outdated
#include "include/bareos.h" | ||
#include "lib/btime.h" | ||
#include <math.h> | ||
#include "../../../third-party/date/include/date/date.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should be #include <date/date.h>
. include-path setup should be done by CMake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
core/src/lib/btime.h
Outdated
char* bstrftime(char* dt, int maxlen, utime_t tim); | ||
char* bstrftime_filename(char* dt, int maxlen, utime_t tim); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these interfaces still feel like they belong to the 90's.
I guess we should have overloads that just return a std::string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
I've two remarks, what about if I don't want to use the hardcoded timestamp format ? if log_format_timestamp is deprecated and not used how can I change it. |
3080ea4
to
075f3ea
Compare
Open question, what about the format of
We have also the case in query module with choice 4 the returned array show TZ in 2 digits while it is 4 elsewhere and the date is formatted without the
|
pr-tool still has some issues to be fixed
|
When bareos asks for a date, the format is still the same as before. Internally, the current timezone offset will be appended to the input and used to calculate the correct timestamp.
The string displayed here is the way that postgresql formats I have only changed the format string for queries where the database string is used as input into our date parsing functions. All queries have been adapted, so that the timestamps are correctly formatted by the database. |
4cb56f4
to
0168331
Compare
Generic comments after rough testing
similar for storage
In restore preview the When is shown with actual timestamp+timezone, but the input can't have the timezone ...
|
- fix OP#5573 Signed-off-by: Bruno Friedmann <bruno.friedmann@bareos.com>
* replace #define MAX_TIME_LENGTH with constexpr kMaxTimeLength * reimplement bstrftime() functions * better handling of daylight saving times * improved unit-test
when no parameter is supplied the current time is used.
64d3cbd
to
2161063
Compare
change most uses of std::string's data() to use c_str() where a const char* is sufficient.
So uses of _ will not be broken by the preprocessor.
2161063
to
9efbeb0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I found out today we have a few outstanding issues with this PR left:
- requires at least PostgreSQL 11 due to TO_CHAR()
- at least one query getting Job.StartTime passes it unconverted to
StrToUtime()
which may lead to miscalculated since time, there may be more occurences of that though
Previously this was done with strings, so we passed the raw timestamp from the database around and parsed it where needed. Now the database returns a utime_t and we can format it if desired.
This PR introduces the usage of ISO8601 format to format timestamps and adds
timezone support both in formatting and for storing in the Database.
2023-08-24T17:49:24+0200
Thu 05-Oct-2023 02:05+0200
2023-10-01T17.16.25+0200
2023-10-01T17:16:53.123456+0200
2023-10-05T08:57:39+0200
Breaking changes:
log_timestamp_format
have been deprecated and are not used anymore.Other changes:
_()
intoT_()
Translate to avoid problems.third-party/date
Important
During the catalog database upgrade, the
TIMESTAMP WITHOUT TIME ZONE
columns will be updated toTIMESTAMP WITH TIME ZONE
. It is mandatory that the Postgresql has the correct TIMEZONE setting before the update, so that Postgresql can update the values correctly.Please check
If you have any questions or problems, please give a comment in the PR.
Helpful documentation and best practices
Checklist for the reviewer of the PR (will be processed by the Bareos team)
Make sure you check/merge the PR using
devtools/pr-tool
to have some simple automated checks run and a proper changelog record added.General
Source code quality
Tests