From fc58be13f62e691645dd75d56ce26d2e121b13e0 Mon Sep 17 00:00:00 2001 From: Julien Desfossez Date: Thu, 11 Jan 2018 13:44:56 -0500 Subject: [PATCH] Add the GMT offset in the rotated chunk path MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The path of a rotated chunk is composed of the start and end timestamp of the trace inside that chunk. In order to support distributed environments, we now specify the GMT offset in this path as well. The date is now formatted in ISO 8601. Here is an example: ~/lttng-traces//20180118T144610-0500-20180118T144611-0500-1 Chunk start: 2018-01-18 14:46:10 Chunk end: 2018-01-18 14:46:11 GMT offset: GMT-5 on both timestamps Chunk ID: 1 (number of rotations that occured in this session so far) Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/cmd.c | 4 ++-- src/bin/lttng-sessiond/rotate.c | 12 +++++++----- tests/regression/tools/rotation/rotate_utils.sh | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 924ac9231..375324aec 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -4377,7 +4377,7 @@ int cmd_rotate_session(struct ltt_session *session, int ret; size_t strf_ret; struct tm *timeinfo; - char datetime[16]; + char datetime[21]; time_t now; bool ust_active = false; @@ -4479,7 +4479,7 @@ int cmd_rotate_session(struct ltt_session *session, ret = -LTTNG_ERR_UNK; goto end; } - strf_ret = strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", + strf_ret = strftime(datetime, sizeof(datetime), "%Y%m%dT%H%M%S%z", timeinfo); if (!strf_ret) { ERR("Failed to format local time timestamp in rotate session command"); diff --git a/src/bin/lttng-sessiond/rotate.c b/src/bin/lttng-sessiond/rotate.c index 237723d3d..4264cd4bd 100644 --- a/src/bin/lttng-sessiond/rotate.c +++ b/src/bin/lttng-sessiond/rotate.c @@ -209,8 +209,8 @@ error: int rename_complete_chunk(struct ltt_session *session, time_t ts) { struct tm *timeinfo; - char datetime[16], start_datetime[16]; char new_path[LTTNG_PATH_MAX]; + char datetime[21], start_datetime[21]; int ret; size_t strf_ret; @@ -221,7 +221,8 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) ret = -1; goto end; } - strf_ret = strftime(datetime, sizeof(datetime), "%Y%m%d-%H%M%S", + + strf_ret = strftime(datetime, sizeof(datetime), "%Y%m%dT%H%M%S%z", timeinfo); if (strf_ret == 0) { ERR("Failed to format timestamp while renaming completed session chunk"); @@ -230,7 +231,7 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) } if (session->rotate_count == 1) { - char start_time[16]; + char start_time[21]; timeinfo = localtime(&session->last_chunk_start_ts); if (!timeinfo) { @@ -240,7 +241,7 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) } strf_ret = strftime(start_time, sizeof(start_time), - "%Y%m%d-%H%M%S", timeinfo); + "%Y%m%dT%H%M%S%z", timeinfo); if (strf_ret == 0) { ERR("Failed to format timestamp while renaming completed session chunk"); ret = -1; @@ -302,7 +303,8 @@ int rename_complete_chunk(struct ltt_session *session, time_t ts) ret = -1; goto end; } - strf_ret = strftime(start_datetime, sizeof(start_datetime), "%Y%m%d-%H%M%S", timeinfo); + strf_ret = strftime(start_datetime, sizeof(start_datetime), + "%Y%m%dT%H%M%S%z", timeinfo); if (!strf_ret) { ERR("Failed to format timestamp while renaming completed session chunk"); ret = -1; diff --git a/tests/regression/tools/rotation/rotate_utils.sh b/tests/regression/tools/rotation/rotate_utils.sh index 1a78c174b..37ada9486 100644 --- a/tests/regression/tools/rotation/rotate_utils.sh +++ b/tests/regression/tools/rotation/rotate_utils.sh @@ -2,8 +2,8 @@ function set_chunk_pattern () { # Need to call this function after $today has been set. - # YYYYMMDD-HHMMSS-YYYYMMDD-HHMMSS - export chunk_pattern="${today}-[0-9][0-9][0-9][0-9][0-9][0-9]-${today}-[0-9][0-9][0-9][0-9][0-9][0-9]" + # YYYYMMDDTHHMMSS[+-]HHMM-YYYYMMDDTHHMMSS[+-]HHMM + export chunk_pattern="${today}T[0-9][0-9][0-9][0-9][0-9][0-9][+-][0-9][0-9][0-9][0-9]-${today}T[0-9][0-9][0-9][0-9][0-9][0-9][+-][0-9][0-9][0-9][0-9]" } function validate_test_chunks () -- 2.34.1