Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@ GRANT USAGE ON SCHEMA sub_views TO GROUP readonly_group;

DROP MATERIALIZED VIEW IF EXISTS sub_views.mv_00_client_tenant_authserver_ips__latest_ts CASCADE;

CREATE MATERIALIZED VIEW sub_views.mv_00_client_tenant_authserver_ips__latest_ts AUTO REFRESH NO as
select gta.client_id, bra.requester_ip_address ips, max(bra.timestamp) as latest_ts from application.begin_request_audit bra
inner join jwt.generated_token_audit gta on bra.correlation_id = gta.correlation_id
where bra.service = 'authorization-server'
group by gta.client_id, bra.requester_ip_address
-- REMOVED: unnecessary after refactoring
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ GRANT USAGE ON SCHEMA sub_views TO GROUP readonly_group;
DROP MATERIALIZED VIEW IF EXISTS sub_views.mv_00_client_tenant_authserver_ips__main CASCADE;

CREATE MATERIALIZED VIEW sub_views.mv_00_client_tenant_authserver_ips__main AUTO REFRESH NO as
select t."name" tenant_name , gta.client_id client_id, c."name" client_name , bra.requester_ip_address ips
from application.begin_request_audit bra
inner join jwt.generated_token_audit gta on bra.correlation_id = gta.correlation_id
inner join domains.client c on c.id = gta.client_id
inner join domains.client_purpose cp on cp.client_id = c.id
inner join domains.purpose p on p.id = cp.purpose_id
inner join domains.tenant t on t.id = p.consumer_id
where bra.service = 'authorization-server'
group by t."name" , gta.client_id, c."name" , bra.requester_ip_address
select
gta.client_id,
bra.requester_ip_address ips,
max(bra.timestamp) as latest_ts,
min(bra.timestamp) as oldest_ts
from
application.begin_request_audit bra
inner join jwt.generated_token_audit gta
on bra.correlation_id = gta.correlation_id
where
bra.service = 'authorization-server'
group by
gta.client_id, bra.requester_ip_address
;
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@ GRANT USAGE ON SCHEMA sub_views TO GROUP readonly_group;

DROP MATERIALIZED VIEW IF EXISTS sub_views.mv_00_client_tenant_authserver_ips__oldest_ts CASCADE;

CREATE MATERIALIZED VIEW sub_views.mv_00_client_tenant_authserver_ips__oldest_ts AUTO REFRESH NO as
select gta.client_id, bra.requester_ip_address ips, min(bra.timestamp) as oldest_ts from application.begin_request_audit bra
inner join jwt.generated_token_audit gta on bra.correlation_id = gta.correlation_id
where bra.service = 'authorization-server'
group by gta.client_id, bra.requester_ip_address
-- REMOVED: unnecessary after refactoring
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ GRANT USAGE ON SCHEMA views TO ${NAMESPACE}_quicksight_user;
DROP MATERIALIZED VIEW IF EXISTS views.mv_01_client_tenant_authserver_ips CASCADE;

CREATE MATERIALIZED VIEW views.mv_01_client_tenant_authserver_ips AS
select main.tenant_name, main.client_name, main.ips, latest_ts.latest_ts, oldest_ts.oldest_ts from sub_views.mv_00_client_tenant_authserver_ips__main main
inner join sub_views.mv_00_client_tenant_authserver_ips__latest_ts latest_ts
on main.client_id = latest_ts.client_id and main.ips = latest_ts.ips
inner join sub_views.mv_00_client_tenant_authserver_ips__oldest_ts oldest_ts
on main.client_id = oldest_ts.client_id and main.ips = oldest_ts.ips;
select
t."name" tenant_name,
c."name" client_name,
main.client_id,
main.ips,
main.latest_ts,
main.oldest_ts
from
sub_views.mv_00_client_tenant_authserver_ips__main main
inner join domains.client c on c.id = main.client_id
inner join domains.tenant t on t.id = c.consumer_id
;

GRANT SELECT ON TABLE views.mv_01_client_tenant_authserver_ips TO ${NAMESPACE}_quicksight_user;
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ GRANT USAGE ON SCHEMA views TO ${NAMESPACE}_quicksight_user;
DROP MATERIALIZED VIEW IF EXISTS views.mv_01_auth_usage__data__last_calls CASCADE;

-- Repeat the same query with three time different time period
-- Last 5 entire minutes. At 14:05:06 this interval is [ 14:00:00, 14:05:00 [
-- Last 15 entire minutes. At 14:05:06 this interval is [ 13:50:00, 14:05:00 [
-- Last 30 entire minutes. At 14:05:06 this interval is [ 13:35:00, 14:05:00 [
-- N.B.: this view in not an "incremental refresh one" it will be recomputed at
-- Last 45 entire minutes. At 14:05:06 this interval is [ 13:20:00, 14:05:00 [
-- N.B.: this view is not an "incremental refresh one" it will be recomputed at
-- every "refresh lambda" execution
CREATE MATERIALIZED VIEW views.mv_01_auth_usage__data__last_calls as
select
Expand All @@ -22,13 +22,14 @@ CREATE MATERIALIZED VIEW views.mv_01_auth_usage__data__last_calls as
sum( quantity_4xx ) as quantity_4xx,
sum( total_4xx_execution_time ) as total_4xx_execution_time,
sum( quantity_5xx ) as quantity_5xx,
date_add('minute', -1 * 5, date_trunc( 'minute', getdate() ) ) as from_ts,
date_add('minute', -1 * 15, date_trunc( 'minute', getdate() ) ) as from_ts,
date_trunc( 'minute', getdate() ) as to_ts,
5 as period_length_minutes
15 as period_length_minutes,
max(minute_slot) as last_minute_with_requests
from
views.mv_00_auth_usage__data__calls
where
minute_slot between date_add('minute', -1 * 5, date_trunc( 'minute', getdate() ) )
minute_slot between date_add('minute', -1 * 15, date_trunc( 'minute', getdate() ) )
and date_trunc( 'minute', getdate() )
group by
consumer_name,
Expand All @@ -44,13 +45,14 @@ UNION ALL
sum( quantity_4xx ) as quantity_4xx,
sum( total_4xx_execution_time ) as total_4xx_execution_time,
sum( quantity_5xx ) as quantity_5xx,
date_add('minute', -1 * 15, date_trunc( 'minute', getdate() ) ) as from_ts,
date_add('minute', -1 * 30, date_trunc( 'minute', getdate() ) ) as from_ts,
date_trunc( 'minute', getdate() ) as to_ts,
15 as period_length_minutes
30 as period_length_minutes,
max(minute_slot) as last_minute_with_requests
from
views.mv_00_auth_usage__data__calls
where
minute_slot between date_add('minute', -1 * 15, date_trunc( 'minute', getdate() ) )
minute_slot between date_add('minute', -1 * 30, date_trunc( 'minute', getdate() ) )
and date_trunc( 'minute', getdate() )
group by
consumer_name,
Expand All @@ -66,13 +68,14 @@ UNION ALL
sum( quantity_4xx ) as quantity_4xx,
sum( total_4xx_execution_time ) as total_4xx_execution_time,
sum( quantity_5xx ) as quantity_5xx,
date_add('minute', -1 * 30, date_trunc( 'minute', getdate() ) ) as from_ts,
date_add('minute', -1 * 45, date_trunc( 'minute', getdate() ) ) as from_ts,
date_trunc( 'minute', getdate() ) as to_ts,
30 as period_length_minutes
45 as period_length_minutes,
max(minute_slot) as last_minute_with_requests
from
views.mv_00_auth_usage__data__calls
where
minute_slot between date_add('minute', -1 * 30, date_trunc( 'minute', getdate() ) )
minute_slot between date_add('minute', -1 * 45, date_trunc( 'minute', getdate() ) )
and date_trunc( 'minute', getdate() )
group by
consumer_name,
Expand Down