Skip to content
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
2 changes: 1 addition & 1 deletion src/config/guc.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void PschInitGuc(void) {
"pg_stat_ch.extra_attributes",
"Key-value pairs appended to exported Arrow batches.",
"Semicolon-separated k:v pairs for resource columns: "
"'instance_ubid:abc;server_role:primary;region:us-east-1'.",
"'instance_ubid:abc;server_role:primary;read_replica_type:regional;region:us-east-1'.",
&psch_extra_attributes,
"",
PGC_SIGHUP,
Expand Down
19 changes: 13 additions & 6 deletions src/export/arrow_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ struct ArrowBatchBuilder::Impl {
arrow::StringBuilder instance_ubid_builder;
arrow::StringBuilder server_ubid_builder;
DictBuilder server_role_builder;
DictBuilder read_replica_type_builder;
DictBuilder region_builder;
DictBuilder cell_builder;
DictBuilder service_version_builder;
Expand Down Expand Up @@ -260,6 +261,7 @@ struct ArrowBatchBuilder::Impl {
arrow::field("instance_ubid", arrow::utf8()),
arrow::field("server_ubid", arrow::utf8()),
arrow::field("server_role", DictionaryUtf8Type()),
arrow::field("read_replica_type", DictionaryUtf8Type()),
arrow::field("region", DictionaryUtf8Type()),
Comment on lines 261 to 265
arrow::field("cell", DictionaryUtf8Type()),
arrow::field("service_version", DictionaryUtf8Type()),
Expand Down Expand Up @@ -424,6 +426,8 @@ struct ArrowBatchBuilder::Impl {
"Arrow instance_ubid append") ||
!AppendString(&server_ubid_builder, ExtraAttr("server_ubid"), "Arrow server_ubid append") ||
!AppendString(&server_role_builder, ExtraAttr("server_role"), "Arrow server_role append") ||
!AppendString(&read_replica_type_builder, ExtraAttr("read_replica_type"),
"Arrow read_replica_type append") ||
!AppendString(&region_builder, ExtraAttr("region"), "Arrow region append") ||
!AppendString(&cell_builder, ExtraAttr("cell"), "Arrow cell append") ||
!AppendString(&service_version_builder, service_version, "Arrow service_version append") ||
Expand All @@ -432,12 +436,13 @@ struct ArrowBatchBuilder::Impl {
return false;
}

estimated_bytes +=
kFixedBytesPerRow + db_name.size() + db_user.size() + app.size() + client_addr.size() +
query_text.size() + err_message.size() + err_sqlstate.size() + service_version.size() +
ExtraAttr("instance_ubid").size() + ExtraAttr("server_ubid").size() +
ExtraAttr("server_role").size() + ExtraAttr("region").size() + ExtraAttr("cell").size() +
ExtraAttr("host_id").size() + ExtraAttr("pod_name").size();
estimated_bytes += kFixedBytesPerRow + db_name.size() + db_user.size() + app.size() +
client_addr.size() + query_text.size() + err_message.size() +
err_sqlstate.size() + service_version.size() +
ExtraAttr("instance_ubid").size() + ExtraAttr("server_ubid").size() +
ExtraAttr("server_role").size() + ExtraAttr("read_replica_type").size() +
ExtraAttr("region").size() + ExtraAttr("cell").size() +
ExtraAttr("host_id").size() + ExtraAttr("pod_name").size();
++num_rows;
return true;
}
Expand Down Expand Up @@ -519,6 +524,7 @@ struct ArrowBatchBuilder::Impl {
!add_array(&instance_ubid_builder, "Arrow instance_ubid finish") ||
!add_array(&server_ubid_builder, "Arrow server_ubid finish") ||
!add_dict_array(&server_role_builder, "Arrow server_role finish") ||
!add_dict_array(&read_replica_type_builder, "Arrow read_replica_type finish") ||
!add_dict_array(&region_builder, "Arrow region finish") ||
!add_dict_array(&cell_builder, "Arrow cell finish") ||
!add_dict_array(&service_version_builder, "Arrow service_version finish") ||
Expand Down Expand Up @@ -625,6 +631,7 @@ struct ArrowBatchBuilder::Impl {
instance_ubid_builder.Reset();
server_ubid_builder.Reset();
server_role_builder.ResetFull();
read_replica_type_builder.ResetFull();
region_builder.ResetFull();
cell_builder.ResetFull();
service_version_builder.ResetFull();
Expand Down
7 changes: 6 additions & 1 deletion t/026_arrow_dump.pl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
'duration_us', 'rows', 'pid', 'query_id',
'shared_blks_hit', 'shared_blks_read',
'wal_records', 'wal_bytes',
'service_version', 'region',
'service_version', 'region', 'read_replica_type',
]
missing = [c for c in expected if schema.get_field_index(c) == -1]
if missing:
Expand All @@ -203,6 +203,11 @@
rows_field = schema.field('rows')
assert rows_field.type == pa.uint64(), f"rows type wrong: {rows_field.type}"

# read_replica_type is a dictionary-encoded column (like server_role/region), not plain utf8.
rr_field = schema.field('read_replica_type')
assert pa.types.is_dictionary(rr_field.type), f"read_replica_type not dict-encoded: {rr_field.type}"
assert rr_field.type.value_type == pa.utf8(), f"read_replica_type dict value type wrong: {rr_field.type.value_type}"

print(f"OK:fields={len(schema)},rows={total_rows}")
PYEOF

Expand Down
Loading