-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1418 from NASA-AMMOS/feat/hasura-events-view
Add Hasura Events Views
- Loading branch information
Showing
17 changed files
with
469 additions
and
19 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
30 changes: 30 additions & 0 deletions
30
deployment/hasura/metadata/databases/tables/hasura/refresh_activity_type_logs.yaml
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,30 @@ | ||
table: | ||
name: refresh_activity_type_logs | ||
schema: hasura | ||
configuration: | ||
custom_name: "refresh_activity_type_logs" | ||
object_relationships: | ||
- name: model | ||
using: | ||
manual_configuration: | ||
remote_table: | ||
name: mission_model | ||
schema: merlin | ||
column_mapping: | ||
model_id: id | ||
select_permissions: | ||
- role: aerie_admin | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
- role: user | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
- role: viewer | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true |
30 changes: 30 additions & 0 deletions
30
deployment/hasura/metadata/databases/tables/hasura/refresh_model_parameter_logs.yaml
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,30 @@ | ||
table: | ||
name: refresh_model_parameter_logs | ||
schema: hasura | ||
configuration: | ||
custom_name: "refresh_model_parameter_logs" | ||
object_relationships: | ||
- name: model | ||
using: | ||
manual_configuration: | ||
remote_table: | ||
name: mission_model | ||
schema: merlin | ||
column_mapping: | ||
model_id: id | ||
select_permissions: | ||
- role: aerie_admin | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
- role: user | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
- role: viewer | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true |
30 changes: 30 additions & 0 deletions
30
deployment/hasura/metadata/databases/tables/hasura/refresh_resource_types_logs.yaml
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,30 @@ | ||
table: | ||
name: refresh_resource_type_logs | ||
schema: hasura | ||
configuration: | ||
custom_name: "refresh_resource_type_logs" | ||
object_relationships: | ||
- name: model | ||
using: | ||
manual_configuration: | ||
remote_table: | ||
name: mission_model | ||
schema: merlin | ||
column_mapping: | ||
model_id: id | ||
select_permissions: | ||
- role: aerie_admin | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
- role: user | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true | ||
- role: viewer | ||
permission: | ||
columns: '*' | ||
filter: {} | ||
allow_aggregations: true |
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
7 changes: 7 additions & 0 deletions
7
deployment/hasura/migrations/Aerie/1_hasura_events_views/down.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,7 @@ | ||
drop view hasura.refresh_resource_type_logs; | ||
drop view hasura.refresh_model_parameter_logs; | ||
drop view hasura.refresh_activity_type_logs; | ||
|
||
drop function hasura.get_event_logs(_trigger_name text); | ||
|
||
call migrations.mark_migration_rolled_back('1'); |
59 changes: 59 additions & 0 deletions
59
deployment/hasura/migrations/Aerie/1_hasura_events_views/up.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,59 @@ | ||
create function hasura.get_event_logs(_trigger_name text) | ||
returns table ( | ||
model_id int, | ||
model_name text, | ||
model_version text, | ||
triggering_user text, | ||
delivered boolean, | ||
success boolean, | ||
tries int, | ||
created_at timestamp, | ||
next_retry_at timestamp, | ||
status int, | ||
error jsonb, | ||
error_message text, | ||
error_type text | ||
) | ||
stable | ||
security invoker | ||
language plpgsql as $$ | ||
begin | ||
return query ( | ||
select | ||
(el.payload->'data'->'new'->>'id')::int as model_id, | ||
el.payload->'data'->'new'->>'name' as model_name, | ||
el.payload->'data'->'new'->>'version' as model_version, | ||
el.payload->'session_variables'->>'x-hasura-user-id' as triggering_user, | ||
el.delivered, | ||
eil.status is not distinct from 200 as success, -- is not distinct from to catch `null` | ||
el.tries, | ||
el.created_at, | ||
el.next_retry_at, | ||
eil.status, | ||
(eil.response -> 'data'->> 'message')::jsonb as error, | ||
(eil.response -> 'data'->> 'message')::jsonb->>'message' as error_message, | ||
(eil.response -> 'data'->> 'message')::jsonb->>'type' as error_type | ||
from hdb_catalog.event_log el | ||
join hdb_catalog.event_invocation_logs eil on el.id = eil.event_id | ||
where trigger_name = _trigger_name); | ||
end; | ||
$$; | ||
comment on function hasura.get_event_logs(_trigger_name text) is e'' | ||
'Get the logs for every run of a Hasura event with the specified trigger name.'; | ||
|
||
create view hasura.refresh_activity_type_logs as | ||
select * from hasura.get_event_logs('refreshActivityTypes'); | ||
comment on view hasura.refresh_activity_type_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshActivityTypes`.'; | ||
|
||
create view hasura.refresh_model_parameter_logs as | ||
select * from hasura.get_event_logs('refreshModelParameters'); | ||
comment on view hasura.refresh_model_parameter_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshModelParameters`.'; | ||
|
||
create view hasura.refresh_resource_type_logs as | ||
select * from hasura.get_event_logs('refreshResourceTypes'); | ||
comment on view hasura.refresh_resource_type_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshResourceTypes`.'; | ||
|
||
call migrations.mark_migration_applied('1'); |
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
60 changes: 60 additions & 0 deletions
60
deployment/postgres-init-db/sql/views/hasura/hasura_event_logs.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,60 @@ | ||
create function hasura.get_event_logs(_trigger_name text) | ||
returns table ( | ||
model_id int, | ||
model_name text, | ||
model_version text, | ||
triggering_user text, | ||
delivered boolean, | ||
success boolean, | ||
tries int, | ||
created_at timestamp, | ||
next_retry_at timestamp, | ||
status int, | ||
error jsonb, | ||
error_message text, | ||
error_type text | ||
) | ||
stable | ||
security invoker | ||
language plpgsql as $$ | ||
begin | ||
return query ( | ||
select | ||
(el.payload->'data'->'new'->>'id')::int as model_id, | ||
el.payload->'data'->'new'->>'name' as model_name, | ||
el.payload->'data'->'new'->>'version' as model_version, | ||
el.payload->'session_variables'->>'x-hasura-user-id' as triggering_user, | ||
el.delivered, | ||
eil.status is not distinct from 200 as success, -- is not distinct from to catch `null` | ||
el.tries, | ||
el.created_at, | ||
el.next_retry_at, | ||
eil.status, | ||
(eil.response -> 'data'->> 'message')::jsonb as error, | ||
(eil.response -> 'data'->> 'message')::jsonb->>'message' as error_message, | ||
(eil.response -> 'data'->> 'message')::jsonb->>'type' as error_type | ||
from hdb_catalog.event_log el | ||
join hdb_catalog.event_invocation_logs eil on el.id = eil.event_id | ||
where trigger_name = _trigger_name); | ||
end; | ||
$$; | ||
comment on function hasura.get_event_logs(_trigger_name text) is e'' | ||
'Get the logs for every run of a Hasura event with the specified trigger name.'; | ||
|
||
create view hasura.refresh_activity_type_logs as | ||
select * from hasura.get_event_logs('refreshActivityTypes'); | ||
comment on view hasura.refresh_activity_type_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshActivityTypes`.'; | ||
|
||
create view hasura.refresh_model_parameter_logs as | ||
select * from hasura.get_event_logs('refreshModelParameters'); | ||
comment on view hasura.refresh_model_parameter_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshModelParameters`.'; | ||
|
||
create view hasura.refresh_resource_type_logs as | ||
select * from hasura.get_event_logs('refreshResourceTypes'); | ||
comment on view hasura.refresh_resource_type_logs is e'' | ||
'View containing logs for every run of the Hasura event `refreshResourceTypes`.'; | ||
|
||
|
||
|
Oops, something went wrong.