Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dashboard notification count dataset #1553

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

whabanks
Copy link
Contributor

Summary | Résumé

This dataset combines the notification, notification_history, and fact_notification_status tables so we can track and identify any discrepancies.

Related Issues | Cartes liées

Before merging this PR

Read code suggestions left by the
cds-ai-codereviewer bot. Address
valid suggestions and shortly write down reasons to not address others. To help
with the classification of the comments, please use these reactions on each of the
comments made by the AI review:

Classification Reaction Emoticon
Useful +1 👍
Noisy eyes 👀
Hallucination confused 😕
Wrong but teachable rocket 🚀
Wrong and incorrect -1 👎

The classifications will be extracted and summarized into an analysis of how helpful
or not the AI code review really is.

Test instructions | Instructions pour tester la modification

TODO: Fill in test instructions for the reviewer.

Release Instructions | Instructions pour le déploiement

None.

Reviewer checklist | Liste de vérification du réviseur

  • This PR does not break existing functionality.
  • This PR does not violate GCNotify's privacy policies.
  • This PR does not raise new security concerns. Refer to our GC Notify Risk Register document on our Google drive.
  • This PR does not significantly alter performance.
  • Additional required documentation resulting of these changes is covered (such as the README, setup instructions, a related ADR or the technical documentation).

⚠ If boxes cannot be checked off before merging the PR, they should be moved to the "Release Instructions" section with appropriate steps required to verify before release. For example, changes to celery code may require tests on staging to verify that performance has not been affected.

- The dataset combines the notification, notification_history, and fact_notification_status tables so we can track and identify any discrepancies
Copy link

Staging: quicksight

✅   Terraform Init: success
✅   Terraform Validate: success
✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

Plan: 2 to add, 1 to change, 0 to destroy
Show summary
CHANGE NAME
add aws_quicksight_data_set.dashboard-notification-counts
aws_quicksight_refresh_schedule.dashboard-notification-counts
update aws_s3_object.manifest_file
Show plan
Resource actions are indicated with the following symbols:
  + create
  ~ update in-place

Terraform will perform the following actions:

  # aws_quicksight_data_set.dashboard-notification-counts will be created
  + resource "aws_quicksight_data_set" "dashboard-notification-counts" {
      + arn            = (known after apply)
      + aws_account_id = (known after apply)
      + data_set_id    = "dashboard-notification-counts"
      + id             = (known after apply)
      + import_mode    = "SPICE"
      + name           = "Dashboard notification counts"
      + output_columns = (known after apply)
      + tags_all       = (known after apply)

      + permissions {
          + actions   = [
              + "quicksight:CancelIngestion",
              + "quicksight:CreateIngestion",
              + "quicksight:DeleteDataSet",
              + "quicksight:DescribeDataSet",
              + "quicksight:DescribeDataSetPermissions",
              + "quicksight:DescribeIngestion",
              + "quicksight:ListIngestions",
              + "quicksight:PassDataSet",
              + "quicksight:UpdateDataSet",
              + "quicksight:UpdateDataSetPermissions",
            ]
          + principal = "arn:aws:quicksight:ca-central-1:239043911459:group/default/quicksight-dataset-owners"
        }
      + permissions {
          + actions   = [
              + "quicksight:DescribeDataSet",
              + "quicksight:DescribeDataSetPermissions",
              + "quicksight:DescribeIngestion",
              + "quicksight:ListIngestions",
              + "quicksight:PassDataSet",
            ]
          + principal = "arn:aws:quicksight:ca-central-1:239043911459:group/default/quicksight-dataset-viewers"
        }

      + physical_table_map {
          + physical_table_map_id = "notification-counts"

          + custom_sql {
              + data_source_arn = "arn:aws:quicksight:ca-central-1:239043911459:datasource/NotificationCanadaCastaging"
              + name            = "dashboard-notification-counts"
              + sql_query       = <<-EOT
                    WITH n AS (
                              SELECT
                                service_id,
                                COUNT(id) AS n_count,
                                DATE_PART('day', created_at) AS day
                              FROM notifications
                              WHERE
                                created_at >= DATE_TRUNC('day', NOW()) - interval '14 days'
                                AND created_at <= (DATE_TRUNC('day', NOW()) + interval '1 day' - interval '1 second')
                                AND key_type <> 'test'
                              GROUP BY
                                DATE_PART('day', created_at),
                                service_id
                              ORDER BY day
                            ),
                            nh AS (
                              SELECT
                                service_id,
                                COUNT(id) AS nh_count,
                                DATE_PART('day', created_at) AS day
                              FROM notification_history
                              WHERE
                                created_at >= DATE_TRUNC('day', NOW()) - interval '14 days'
                                AND created_at <= (DATE_TRUNC('day', NOW()) + interval '1 day' - interval '1 second')
                                AND key_type <> 'test'
                              GROUP BY
                                DATE_PART('day', created_at),
                                service_id
                              ORDER BY day, service_id
                            ),
                            ft AS (
                              SELECT
                                service_id,
                                SUM(notification_count) AS ft_count,
                                DATE_PART('day', bst_date) AS day
                              FROM ft_notification_status
                              WHERE
                                bst_date >= DATE_TRUNC('day', NOW()) - interval '14 days'
                                AND bst_date <= (DATE_TRUNC('day', NOW()) + interval '1 day' - interval '1 second')
                                AND key_type <> 'test'
                              GROUP BY
                                DATE_PART('day', bst_date),
                                service_id
                              ORDER BY day
                            )
                            SELECT
                              COALESCE(n.service_id, nh.service_id, ft.service_id) AS service_id,
                              COALESCE(n.day, nh.day, ft.day) AS day,
                              n.n_count,
                              nh.nh_count,
                              ft.ft_count,
                              CASE
                                WHEN nh.nh_count IS NOT NULL AND ft.ft_count IS NOT NULL AND nh.nh_count <> ft.ft_count THEN '❌'
                                ELSE '✅'
                              END AS count_comparison
                            FROM n
                            FULL OUTER JOIN nh
                              ON n.day = nh.day AND n.service_id = nh.service_id
                            FULL OUTER JOIN ft
                              ON COALESCE(n.day, nh.day) = ft.day
                              AND COALESCE(n.service_id, nh.service_id) = ft.service_id
                            ORDER BY day, service_id
                EOT

              + columns {
                  + name = "service_id"
                  + type = "STRING"
                }
              + columns {
                  + name = "day"
                  + type = "INTEGER"
                }
              + columns {
                  + name = "n_count"
                  + type = "INTEGER"
                }
              + columns {
                  + name = "nh_count"
                  + type = "INTEGER"
                }
              + columns {
                  + name = "ft_count"
                  + type = "INTEGER"
                }
              + columns {
                  + name = "count_comparison"
                  + type = "STRING"
                }
            }
        }
    }

  # aws_quicksight_refresh_schedule.dashboard-notification-counts will be created
  + resource "aws_quicksight_refresh_schedule" "dashboard-notification-counts" {
      + arn            = (known after apply)
      + aws_account_id = (known after apply)
      + data_set_id    = "dashboard-notification-counts"
      + id             = (known after apply)
      + schedule_id    = "schedule-dashboard-notification-counts"

      + schedule {
          + refresh_type          = "FULL_REFRESH"
          + start_after_date_time = (known after apply)

          + schedule_frequency {
              + interval        = "DAILY"
              + time_of_the_day = "01:00"
              + timezone        = (known after apply)
            }
        }
    }

  # aws_s3_object.manifest_file will be updated in-place
  ~ resource "aws_s3_object" "manifest_file" {
      ~ etag                   = "4f558e8d8cdbbf914a95755cbda61968" -> "221f592f333f2fc284626cfdb8c4bc80"
        id                     = "quicksight/s3-manifest-sms-usage.json"
        tags                   = {}
      + version_id             = (known after apply)
        # (12 unchanged attributes hidden)
    }

Plan: 2 to add, 1 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Show Conftest results
WARN - plan.json - main - Missing Common Tags: ["aws_cloudformation_stack.sms-usage-notifications"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.quicksight-rds"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.quicksight-s3-usage"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.quicksight_vpc_connection_ec2"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.quicksight_vpc_connection_iam"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_role.quicksight"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_role.vpc_connection_role"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.dashboard-notification-counts"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.jobs"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.login_events"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.notifications"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.organisation"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.services"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.sms_usage"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.template-category-history"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.templates"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.users"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_source.rds"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_source.s3_sms_usage"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_vpc_connection.rds"]
WARN - plan.json - main - Missing Common Tags: ["aws_s3_object.manifest_file"]

40 tests, 19 passed, 21 warnings, 0 failures, 0 exceptions

Copy link

staging: quicksight

✅   Terraform Init: success
✅   Terraform Validate: success
✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

Plan: 2 to add, 1 to change, 0 to destroy
Show summary
CHANGE NAME
add aws_quicksight_data_set.dashboard-notification-counts
aws_quicksight_refresh_schedule.dashboard-notification-counts
update aws_s3_object.manifest_file
Show plan
Resource actions are indicated with the following symbols:
  + create
  ~ update in-place

Terraform will perform the following actions:

  # aws_quicksight_data_set.dashboard-notification-counts will be created
  + resource "aws_quicksight_data_set" "dashboard-notification-counts" {
      + arn            = (known after apply)
      + aws_account_id = (known after apply)
      + data_set_id    = "dashboard-notification-counts"
      + id             = (known after apply)
      + import_mode    = "SPICE"
      + name           = "Dashboard notification counts"
      + output_columns = (known after apply)
      + tags_all       = (known after apply)

      + data_set_usage_configuration (known after apply)

      + logical_table_map (known after apply)

      + permissions {
          + actions   = [
              + "quicksight:CancelIngestion",
              + "quicksight:CreateIngestion",
              + "quicksight:DeleteDataSet",
              + "quicksight:DescribeDataSet",
              + "quicksight:DescribeDataSetPermissions",
              + "quicksight:DescribeIngestion",
              + "quicksight:ListIngestions",
              + "quicksight:PassDataSet",
              + "quicksight:UpdateDataSet",
              + "quicksight:UpdateDataSetPermissions",
            ]
          + principal = "arn:aws:quicksight:ca-central-1:239043911459:group/default/quicksight-dataset-owners"
        }
      + permissions {
          + actions   = [
              + "quicksight:DescribeDataSet",
              + "quicksight:DescribeDataSetPermissions",
              + "quicksight:DescribeIngestion",
              + "quicksight:ListIngestions",
              + "quicksight:PassDataSet",
            ]
          + principal = "arn:aws:quicksight:ca-central-1:239043911459:group/default/quicksight-dataset-viewers"
        }

      + physical_table_map {
          + physical_table_map_id = "notification-counts"

          + custom_sql {
              + data_source_arn = "arn:aws:quicksight:ca-central-1:239043911459:datasource/NotificationCanadaCastaging"
              + name            = "dashboard-notification-counts"
              + sql_query       = <<-EOT
                    WITH n AS (
                              SELECT
                                service_id,
                                COUNT(id) AS n_count,
                                DATE_PART('day', created_at) AS day
                              FROM notifications
                              WHERE
                                created_at >= DATE_TRUNC('day', NOW()) - interval '14 days'
                                AND created_at <= (DATE_TRUNC('day', NOW()) + interval '1 day' - interval '1 second')
                                AND key_type <> 'test'
                              GROUP BY
                                DATE_PART('day', created_at),
                                service_id
                              ORDER BY day
                            ),
                            nh AS (
                              SELECT
                                service_id,
                                COUNT(id) AS nh_count,
                                DATE_PART('day', created_at) AS day
                              FROM notification_history
                              WHERE
                                created_at >= DATE_TRUNC('day', NOW()) - interval '14 days'
                                AND created_at <= (DATE_TRUNC('day', NOW()) + interval '1 day' - interval '1 second')
                                AND key_type <> 'test'
                              GROUP BY
                                DATE_PART('day', created_at),
                                service_id
                              ORDER BY day, service_id
                            ),
                            ft AS (
                              SELECT
                                service_id,
                                SUM(notification_count) AS ft_count,
                                DATE_PART('day', bst_date) AS day
                              FROM ft_notification_status
                              WHERE
                                bst_date >= DATE_TRUNC('day', NOW()) - interval '14 days'
                                AND bst_date <= (DATE_TRUNC('day', NOW()) + interval '1 day' - interval '1 second')
                                AND key_type <> 'test'
                              GROUP BY
                                DATE_PART('day', bst_date),
                                service_id
                              ORDER BY day
                            )
                            SELECT
                              COALESCE(n.service_id, nh.service_id, ft.service_id) AS service_id,
                              COALESCE(n.day, nh.day, ft.day) AS day,
                              n.n_count,
                              nh.nh_count,
                              ft.ft_count,
                              CASE
                                WHEN nh.nh_count IS NOT NULL AND ft.ft_count IS NOT NULL AND nh.nh_count <> ft.ft_count THEN '❌'
                                ELSE '✅'
                              END AS count_comparison
                            FROM n
                            FULL OUTER JOIN nh
                              ON n.day = nh.day AND n.service_id = nh.service_id
                            FULL OUTER JOIN ft
                              ON COALESCE(n.day, nh.day) = ft.day
                              AND COALESCE(n.service_id, nh.service_id) = ft.service_id
                            ORDER BY day, service_id
                EOT

              + columns {
                  + name = "service_id"
                  + type = "STRING"
                }
              + columns {
                  + name = "day"
                  + type = "INTEGER"
                }
              + columns {
                  + name = "n_count"
                  + type = "INTEGER"
                }
              + columns {
                  + name = "nh_count"
                  + type = "INTEGER"
                }
              + columns {
                  + name = "ft_count"
                  + type = "INTEGER"
                }
              + columns {
                  + name = "count_comparison"
                  + type = "STRING"
                }
            }

          + s3_source (known after apply)
        }
    }

  # aws_quicksight_refresh_schedule.dashboard-notification-counts will be created
  + resource "aws_quicksight_refresh_schedule" "dashboard-notification-counts" {
      + arn            = (known after apply)
      + aws_account_id = (known after apply)
      + data_set_id    = "dashboard-notification-counts"
      + id             = (known after apply)
      + schedule_id    = "schedule-dashboard-notification-counts"

      + schedule {
          + refresh_type          = "FULL_REFRESH"
          + start_after_date_time = (known after apply)

          + schedule_frequency {
              + interval        = "DAILY"
              + time_of_the_day = "01:00"
              + timezone        = (known after apply)
            }
        }
    }

  # aws_s3_object.manifest_file will be updated in-place
  ~ resource "aws_s3_object" "manifest_file" {
      ~ etag                          = "4f558e8d8cdbbf914a95755cbda61968" -> "221f592f333f2fc284626cfdb8c4bc80"
        id                            = "quicksight/s3-manifest-sms-usage.json"
        tags                          = {}
      + version_id                    = (known after apply)
        # (24 unchanged attributes hidden)
    }

Plan: 2 to add, 1 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Show Conftest results
WARN - plan.json - main - Missing Common Tags: ["aws_cloudformation_stack.sms-usage-notifications"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.quicksight-rds"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.quicksight-s3-usage"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.quicksight_vpc_connection_ec2"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.quicksight_vpc_connection_iam"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_role.quicksight"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_role.vpc_connection_role"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.dashboard-notification-counts"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.jobs"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.login_events"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.notifications"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.organisation"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.services"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.sms_usage"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.template-category-history"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.templates"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_set.users"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_source.rds"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_data_source.s3_sms_usage"]
WARN - plan.json - main - Missing Common Tags: ["aws_quicksight_vpc_connection.rds"]
WARN - plan.json - main - Missing Common Tags: ["aws_s3_object.manifest_file"]

40 tests, 19 passed, 21 warnings, 0 failures, 0 exceptions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants