Skip to content

Commit

Permalink
Fix telemetry installed_time format
Browse files Browse the repository at this point in the history
This patch changes the telemetry code to always send the installed_time
timestamp AS ISO8601. Previously it was depending on local settings
leading to timestamps not processable by the telemetry receiver.
  • Loading branch information
svenklemm committed Aug 7, 2020
1 parent 56b4c10 commit 8efad01
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/telemetry/telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ get_pgversion_string()
return buf->data;
}

#define ISO8601_FORMAT "YYYY-MM-DD\"T\"HH24:MI:SSOF"

static char *
format_iso8601(Datum value)
{
return TextDatumGetCString(
DirectFunctionCall2(timestamptz_to_char, value, CStringGetTextDatum(ISO8601_FORMAT)));
}

static StringInfo
build_version_body(void)
{
Expand All @@ -319,9 +328,7 @@ build_version_body(void)
DirectFunctionCall1(uuid_out, ts_telemetry_metadata_get_exported_uuid())));
ts_jsonb_add_str(parse_state,
REQ_INSTALL_TIME,
DatumGetCString(
DirectFunctionCall1(timestamptz_out,
ts_telemetry_metadata_get_install_timestamp())));
format_iso8601(ts_telemetry_metadata_get_install_timestamp()));

ts_jsonb_add_str(parse_state, REQ_INSTALL_METHOD, TIMESCALEDB_INSTALL_METHOD);

Expand Down
14 changes: 14 additions & 0 deletions test/expected/telemetry.out
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,17 @@ SELECT json_object_field(get_telemetry_report()::json,'num_hypertables');
"1"
(1 row)

set datestyle to iso;
-- check that installed_time formatting in telemetry report does not depend on local date settings
SELECT json_object_field_text(get_telemetry_report()::json,'installed_time') as installed_time
\gset
set datestyle to sql;
SELECT json_object_field_text(get_telemetry_report()::json,'installed_time') as installed_time2
\gset
SELECT :'installed_time' = :'installed_time2' AS equal, length(:'installed_time'), length(:'installed_time2');
equal | length | length
-------+--------+--------
t | 22 | 22
(1 row)

RESET datestyle;
13 changes: 13 additions & 0 deletions test/sql/telemetry.sql
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,16 @@ CREATE TABLE device_readings (
SELECT table_name FROM create_hypertable('device_readings', 'observation_time');

SELECT json_object_field(get_telemetry_report()::json,'num_hypertables');

set datestyle to iso;
-- check that installed_time formatting in telemetry report does not depend on local date settings
SELECT json_object_field_text(get_telemetry_report()::json,'installed_time') as installed_time
\gset
set datestyle to sql;
SELECT json_object_field_text(get_telemetry_report()::json,'installed_time') as installed_time2
\gset

SELECT :'installed_time' = :'installed_time2' AS equal, length(:'installed_time'), length(:'installed_time2');

RESET datestyle;

0 comments on commit 8efad01

Please sign in to comment.