-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Citus stats tenants collector view (#6761)
Add a view that collects statistics from all nodes
- Loading branch information
1 parent
46e0089
commit 4b99fd0
Showing
11 changed files
with
183 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 47 additions & 8 deletions
55
src/backend/distributed/sql/udfs/citus_stats_tenants/11.3-1.sql
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
55 changes: 47 additions & 8 deletions
55
src/backend/distributed/sql/udfs/citus_stats_tenants/latest.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,66 @@ | ||
CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants( | ||
-- cts in the query is an abbreviation for citus_stats_tenants | ||
CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants ( | ||
return_all_tenants BOOLEAN DEFAULT FALSE, | ||
OUT nodeid INT, | ||
OUT colocation_id INT, | ||
OUT tenant_attribute TEXT, | ||
OUT read_count_in_this_period INT, | ||
OUT read_count_in_last_period INT, | ||
OUT query_count_in_this_period INT, | ||
OUT query_count_in_last_period INT, | ||
OUT score BIGINT) | ||
RETURNS SETOF RECORD | ||
LANGUAGE C | ||
AS 'citus', $$citus_stats_tenants$$; | ||
|
||
OUT score BIGINT | ||
) | ||
RETURNS SETOF record | ||
LANGUAGE plpgsql | ||
AS $function$ | ||
BEGIN | ||
RETURN QUERY | ||
SELECT * | ||
FROM jsonb_to_recordset(( | ||
SELECT | ||
jsonb_agg(all_cst_rows_as_jsonb.cst_row_as_jsonb)::jsonb | ||
FROM ( | ||
SELECT | ||
jsonb_array_elements(run_command_on_all_nodes.result::jsonb)::jsonb || | ||
('{"nodeid":' || run_command_on_all_nodes.nodeid || '}')::jsonb AS cst_row_as_jsonb | ||
FROM | ||
run_command_on_all_nodes ( | ||
$$ | ||
SELECT | ||
coalesce(to_jsonb (array_agg(cstl.*)), '[]'::jsonb) | ||
FROM citus_stats_tenants_local($$||return_all_tenants||$$) cstl; | ||
$$, | ||
parallel:= TRUE, | ||
give_warning_for_connection_errors:= TRUE) | ||
WHERE | ||
success = 't') | ||
AS all_cst_rows_as_jsonb)) | ||
AS ( | ||
nodeid INT, | ||
colocation_id INT, | ||
tenant_attribute TEXT, | ||
read_count_in_this_period INT, | ||
read_count_in_last_period INT, | ||
query_count_in_this_period INT, | ||
query_count_in_last_period INT, | ||
score BIGINT | ||
) | ||
ORDER BY score DESC | ||
LIMIT CASE WHEN NOT return_all_tenants THEN current_setting('citus.stats_tenants_limit')::BIGINT END; | ||
END; | ||
$function$; | ||
|
||
CREATE OR REPLACE VIEW citus.citus_stats_tenants AS | ||
SELECT | ||
nodeid, | ||
colocation_id, | ||
tenant_attribute, | ||
read_count_in_this_period, | ||
read_count_in_last_period, | ||
query_count_in_this_period, | ||
query_count_in_last_period | ||
FROM pg_catalog.citus_stats_tenants() | ||
ORDER BY score DESC; | ||
FROM pg_catalog.citus_stats_tenants(FALSE); | ||
|
||
ALTER VIEW citus.citus_stats_tenants SET SCHEMA pg_catalog; | ||
|
||
GRANT SELECT ON pg_catalog.citus_stats_tenants TO PUBLIC; |
27 changes: 27 additions & 0 deletions
27
src/backend/distributed/sql/udfs/citus_stats_tenants_local/11.3-1.sql
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/backend/distributed/sql/udfs/citus_stats_tenants_local/latest.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants_local( | ||
return_all_tenants BOOLEAN DEFAULT FALSE, | ||
OUT colocation_id INT, | ||
OUT tenant_attribute TEXT, | ||
OUT read_count_in_this_period INT, | ||
OUT read_count_in_last_period INT, | ||
OUT query_count_in_this_period INT, | ||
OUT query_count_in_last_period INT, | ||
OUT score BIGINT) | ||
RETURNS SETOF RECORD | ||
LANGUAGE C | ||
AS 'citus', $$citus_stats_tenants_local$$; | ||
|
||
|
||
CREATE OR REPLACE VIEW citus.citus_stats_tenants_local AS | ||
SELECT | ||
colocation_id, | ||
tenant_attribute, | ||
read_count_in_this_period, | ||
read_count_in_last_period, | ||
query_count_in_this_period, | ||
query_count_in_last_period | ||
FROM pg_catalog.citus_stats_tenants_local() | ||
ORDER BY score DESC; | ||
|
||
ALTER VIEW citus.citus_stats_tenants_local SET SCHEMA pg_catalog; | ||
GRANT SELECT ON pg_catalog.citus_stats_tenants_local TO PUBLIC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.