Skip to content

Commit

Permalink
PG-946 fix telemetry filenames (#13)
Browse files Browse the repository at this point in the history
* PG-946 Fix telemetry filenames

* PG-946 Update tests
  • Loading branch information
artemgavrilov authored Aug 5, 2024
1 parent 4d06aa3 commit 8a13c5b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
6 changes: 3 additions & 3 deletions expected/basic.out
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ SELECT percona_pg_telemetry_version();
SELECT regexp_replace(regexp_replace(latest_output_filename, '\d{11,}', '<INSTANCE ID>', 'g'), '\d{6,}', '<TIMESTAMP>', 'g') AS latest_output_filename
, pt_enabled
FROM percona_pg_telemetry_status();
latest_output_filename | pt_enabled
-------------------------------------------------------+------------
./percona_pg_telemetry-<INSTANCE ID>-<TIMESTAMP>.json | t
latest_output_filename | pt_enabled
----------------------------------+------------
./<TIMESTAMP>-<INSTANCE ID>.json | t
(1 row)

DROP EXTENSION percona_pg_telemetry;
6 changes: 3 additions & 3 deletions expected/basic_1.out
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ SELECT percona_pg_telemetry_version();
SELECT regexp_replace(regexp_replace(latest_output_filename, '\d{11,}', '<INSTANCE ID>', 'g'), '\d{6,}', '<TIMESTAMP>', 'g') AS latest_output_filename
, pt_enabled
FROM percona_pg_telemetry_status();
latest_output_filename | pt_enabled
-------------------------------------------------------------------------------------+------------
/usr/local/percona/telemetry/pg/percona_pg_telemetry-<INSTANCE ID>-<TIMESTAMP>.json | t
latest_output_filename | pt_enabled
----------------------------------------------------------------+------------
/usr/local/percona/telemetry/pg/<TIMESTAMP>-<INSTANCE ID>.json | t
(1 row)

DROP EXTENSION percona_pg_telemetry;
14 changes: 5 additions & 9 deletions percona_pg_telemetry.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ PG_MODULE_MAGIC;

/* General defines */
#define PT_BUILD_VERSION "1.0"
#define PT_FILENAME_BASE "percona_pg_telemetry"
#define PT_FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)

/* Init and exported functions */
Expand Down Expand Up @@ -167,7 +166,7 @@ generate_filename(char *filename)
time_t currentTime;

time(&currentTime);
pg_snprintf(f_name, MAXPGPATH, "%s-%lu-%ld.json", PT_FILENAME_BASE, system_id, currentTime);
pg_snprintf(f_name, MAXPGPATH, "%ld-%lu.json", currentTime, system_id);

join_path_components(filename, ptss->telemetry_path, f_name);

Expand Down Expand Up @@ -240,11 +239,10 @@ load_telemery_files(void)
DIR *d;
struct dirent *de;
uint64 system_id = GetSystemIdentifier();
char json_file_id[MAXPGPATH];
char filename_tail[MAXPGPATH];
char full_path[MAXPGPATH];
List *files_list = NIL;
ListCell *lc = NULL;
int file_id_len;

validate_dir(ptss->telemetry_path);

Expand All @@ -258,12 +256,10 @@ load_telemery_files(void)
ptss->telemetry_path)));
}

pg_snprintf(json_file_id, sizeof(json_file_id), "%s-%lu", PT_FILENAME_BASE, system_id);
file_id_len = strlen(json_file_id);

pg_snprintf(filename_tail, sizeof(filename_tail), "%lu.json", system_id);
while ((de = ReadDir(d, ptss->telemetry_path)) != NULL)
{
if (strncmp(json_file_id, de->d_name, file_id_len) == 0)
if (strstr(de->d_name, filename_tail) != NULL)
{
/* Construct the file full path */
snprintf(full_path, sizeof(full_path), "%s/%s", ptss->telemetry_path, de->d_name);
Expand Down Expand Up @@ -413,7 +409,7 @@ pt_shmem_init(void)

/* Set paths */
strncpy(ptss->telemetry_path, t_folder, MAXPGPATH);
pg_snprintf(ptss->dbtemp_filepath, MAXPGPATH, "%s/%s-%lu.temp", ptss->telemetry_path, PT_FILENAME_BASE, system_id);
pg_snprintf(ptss->dbtemp_filepath, MAXPGPATH, "%s/%lu.temp", ptss->telemetry_path, system_id);

/* Let's be optimistic here. No error code and no file currently being written. */
ptss->error_code = PT_SUCCESS;
Expand Down

0 comments on commit 8a13c5b

Please sign in to comment.