Add telemetry for continuous aggs

This adds a top-level telemetry entry for `num_continuous_aggs`.
2 designs were considered:
1) add entry to telemetry_metadata that's modified on add/drop
continuous aggs.
2) scan the catalogs for number of continuous aggs when making the
report.

After briefly trying (1), I switched to (2) for 2 reasons:
1) This avoids the dependency from continous_aggs on telemetry
and reverses that dependency. I think the other way is cleaner.
2) The code became simpler and more self-contained.
This commit is contained in:
Matvey Arye 2019-04-22 15:58:38 -04:00 committed by Matvey Arye
parent 58601cc3a0
commit c463d2634c
5 changed files with 81 additions and 1 deletions

View File

@ -595,3 +595,14 @@ ts_continuous_agg_rename_view(char *old_schema, char *name, char *new_schema, ch
}
return;
}
TSDLLEXPORT int32
ts_number_of_continuous_aggs()
{
int32 count = 0;
ScanIterator iterator =
ts_scan_iterator_create(CONTINUOUS_AGG, AccessShareLock, CurrentMemoryContext);
ts_scanner_foreach(&iterator) { count++; }
return count;
}

View File

@ -66,4 +66,6 @@ extern void ts_continuous_agg_rename_schema_name(char *old_schema, char *new_sch
extern void ts_continuous_agg_rename_view(char *old_schema, char *name, char *new_schema,
char *new_name);
extern TSDLLEXPORT int32 ts_number_of_continuous_aggs(void);
#endif /* TIMESCALEDB_TSL_CONTINUOUS_AGGS_CONTIGUOUS_AGG_H */

View File

@ -47,6 +47,7 @@
#define REQ_BUILD_OS_VERSION "build_os_version"
#define REQ_DATA_VOLUME "data_volume"
#define REQ_NUM_HYPERTABLES "num_hypertables"
#define REQ_NUM_CONTINUOUS_AGGS "num_continuous_aggs"
#define REQ_RELATED_EXTENSIONS "related_extensions"
#define REQ_TELEMETRY_METADATA "db_metadata"
#define REQ_LICENSE_INFO "license"
@ -163,6 +164,15 @@ get_num_hypertables()
return buf->data;
}
static char *
get_num_continuous_aggs()
{
StringInfo buf = makeStringInfo();
appendStringInfo(buf, "%d", ts_number_of_continuous_aggs());
return buf->data;
}
static char *
get_database_size()
{
@ -252,6 +262,7 @@ build_version_body(void)
ts_jsonb_add_str(parseState, REQ_BUILD_OS_VERSION, BUILD_OS_VERSION);
ts_jsonb_add_str(parseState, REQ_DATA_VOLUME, get_database_size());
ts_jsonb_add_str(parseState, REQ_NUM_HYPERTABLES, get_num_hypertables());
ts_jsonb_add_str(parseState, REQ_NUM_CONTINUOUS_AGGS, get_num_continuous_aggs());
/* Add related extensions, which is a nested JSON */
ext_key.type = jbvString;

View File

@ -305,8 +305,15 @@ WHERE key != 'os_name_pretty';
last_tuned_version
postgresql_version
related_extensions
num_continuous_aggs
timescaledb_version
(19 rows)
(20 rows)
SELECT json_object_field(get_telemetry_report()::json,'num_continuous_aggs');
json_object_field
-------------------
"0"
(1 row)
-- check telemetry picks up content from telemetry_metadata
SELECT json_object_field(get_telemetry_report()::json,'db_metadata');
@ -322,3 +329,34 @@ SELECT json_object_field(get_telemetry_report()::json,'instance_metadata');
{"cloud": "ci"}
(1 row)
--create a continuous agg
CREATE TABLE device_readings (
observation_time TIMESTAMPTZ NOT NULL
);
SELECT table_name FROM create_hypertable('device_readings', 'observation_time');
table_name
-----------------
device_readings
(1 row)
CREATE VIEW device_summary
WITH (timescaledb.continuous) AS
SELECT
time_bucket('1 hour', observation_time) as bucket,
min(observation_time)
FROM
device_readings
GROUP BY bucket;
NOTICE: adding not-null constraint to column "time_partition_col"
SELECT json_object_field(get_telemetry_report()::json,'num_continuous_aggs');
json_object_field
-------------------
"1"
(1 row)
SELECT json_object_field(get_telemetry_report()::json,'num_hypertables');
json_object_field
-------------------
"2"
(1 row)

View File

@ -126,6 +126,8 @@ SET timescaledb.telemetry_level=off;
SELECT * FROM json_object_keys(get_telemetry_report()::json) AS key
WHERE key != 'os_name_pretty';
SELECT json_object_field(get_telemetry_report()::json,'num_continuous_aggs');
-- check telemetry picks up content from telemetry_metadata
SELECT json_object_field(get_telemetry_report()::json,'db_metadata');
@ -133,3 +135,19 @@ SELECT json_object_field(get_telemetry_report()::json,'db_metadata');
SELECT json_object_field(get_telemetry_report()::json,'instance_metadata');
--create a continuous agg
CREATE TABLE device_readings (
observation_time TIMESTAMPTZ NOT NULL
);
SELECT table_name FROM create_hypertable('device_readings', 'observation_time');
CREATE VIEW device_summary
WITH (timescaledb.continuous) AS
SELECT
time_bucket('1 hour', observation_time) as bucket,
min(observation_time)
FROM
device_readings
GROUP BY bucket;
SELECT json_object_field(get_telemetry_report()::json,'num_continuous_aggs');
SELECT json_object_field(get_telemetry_report()::json,'num_hypertables');