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

Fix telemetry installed_time format #2164

Merged
merged 2 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/linux-build-and-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ jobs:
steps:
- name: Install Dependencies
if: runner.os == 'Linux'
run: sudo apt install flex bison lcov systemd-coredump gdb ${{ matrix.extra_packages }}
run: |
sudo apt-get update
sudo apt-get install flex bison lcov systemd-coredump gdb ${{ matrix.extra_packages }}

# on macOS the path used is depending on the runner version leading to cache failure
# when the runner version changes so we extract runner version from path and add it
Expand Down
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;