From b195917a77aa572c6ed47e3029bf01fbd9ca4fd1 Mon Sep 17 00:00:00 2001 From: Dave Tisza Date: Wed, 20 Dec 2023 09:24:35 -0500 Subject: [PATCH] Remove update_athena_metric_tables lambda --- .../update_athena_metric_tables/README.md | 649 ----- ...lter_table_schema_for_new_metrics_added.py | 206 -- .../lambda_function.py | 139 - ...plate_generate_metrics_for_report_date.sql | 1314 ---------- ...nerate_per_app_metrics_for_report_date.sql | 2273 ----------------- .../test_lambda_function_local.py | 126 - .../test_run_sql_template_on_athena.py | 181 -- .../utils/__init__.py | 0 .../utils/utils.py | 416 --- 9 files changed, 5304 deletions(-) delete mode 100644 insights/lambdas/update_athena_metric_tables/README.md delete mode 100644 insights/lambdas/update_athena_metric_tables/alter_table_schema_for_new_metrics_added.py delete mode 100644 insights/lambdas/update_athena_metric_tables/lambda_function.py delete mode 100644 insights/lambdas/update_athena_metric_tables/sql_templates/template_generate_metrics_for_report_date.sql delete mode 100644 insights/lambdas/update_athena_metric_tables/sql_templates/template_generate_per_app_metrics_for_report_date.sql delete mode 100644 insights/lambdas/update_athena_metric_tables/test_lambda_function_local.py delete mode 100644 insights/lambdas/update_athena_metric_tables/test_run_sql_template_on_athena.py delete mode 100644 insights/lambdas/update_athena_metric_tables/utils/__init__.py delete mode 100644 insights/lambdas/update_athena_metric_tables/utils/utils.py diff --git a/insights/lambdas/update_athena_metric_tables/README.md b/insights/lambdas/update_athena_metric_tables/README.md deleted file mode 100644 index bfbd65b3a..000000000 --- a/insights/lambdas/update_athena_metric_tables/README.md +++ /dev/null @@ -1,649 +0,0 @@ -# Table of Contents - -- [BB2 BFD-Insights Athena Tables for QuickSight Summary](#summary) - - [Per Application Metrics Table](#per-app-table) - - [Top Level Metrics Table](#top-level-table) - - [Weekly Update of the Metric Tables](#weekly-update-tables) -- [HOW-TO: Testing SQL Templates Individually](#how-to-test-sql-templates) -- [Lambda Function to Update Metrics Tables](#lambda-function) -- [HOW-TO: Update QuickSight DataSets](#how-to-update-qs-datasets) -- [HOW-TO: A Walk-Through Example of Adding New Metrics](#how-to-new-metrics) - - [Adding a New Per Application Metric](#how-to-add-per-app-metric) - - [Adding a New Top Level Metric](#how-to-add-top-level-metric) - - [Testing the New SQL Templates with the Lambda Function](#testing-templates-lambda) - -# BB2 BFD-Insights Athena Tables for QuickSight Summary - -In between the Kinesis Firehose log streams and QuickSights there are Athena tables setup for mapping the reporting data. The reporting data is used to build dashboards and analysis in QuickSight. - -This document contains information about the tables, templates with Athena SQL used to generate metrics, the Lambda function that is scheduled to run weekly and how to develop & add new metrics. - -## Per Application Metrics Table - -This table contains one row per BB2 application for each of the report dates (`report_date` column). It contains metrics related to each application. - -| | | -| ---------- | ------------------------------------------------------------------- | -| TABLE NAME | \_global_state_per_app | -| TEMPLATE | `sql_templates/template_generate_per_app_metrics_for_report_date.sql` | - -NOTE: There is a separate table for each BB2 ENV enviornment (prod, impl). - -### Summary: - -* This is a JOIN of top level BB2 stats from the `bb2.events__perf_mon` table with type="global_state_metrics_per_app" and per application stats from the same table with type="global_state_metrics". - -* This returns sets of data grouped by `vpc`, and `report_date`. - -* This excludes our internal use applications from the per application results. - -* To test or view results via the Athena SQL editor use the following for the target ENV: - ```sql - /* Show all records */ - SELECT * FROM "bb2"."_global_state_per_app" - ``` - ```sql - /* Show distinct report dates */ - SELECT DISTINCT report_date FROM "bb2"."_global_state_per_app" - ``` - -## Top Level Metrics Table - -This table contains one row per report dates (`report_date` column). It contains metrics related to the entire API system as a whole. A `sum()` of metrics from the per application table is also included. - -| | | -| ---------- | ------------------------------------------------------------------- | -| TABLE NAME | \_global_state | -| TEMPLATE | `sql_templates/template_generate_metrics_for_report_date.sql` | - -Summary: - -* This utilizes the previously run `_global_state_per_app` table results to provide counts of apps and bene data grouped by `vpc` and `report_date`. - -* To test or view results via the Athena SQL editor use the following for the target ENV: - ```sql - /* Show all records */ - SELECT * FROM "bb2"."_global_state" - ``` - ```sql - /* Show distinct report dates */ - SELECT DISTINCT report_date FROM "bb2"."_global_state" - ``` - -# Weekly Update of the Metric Tables - -A scheduled AWS Lambda function is used to update the tables used for dashboards and anylysis in AWS QuickSight. - -The lambda function, templates and development tools are included in the `insights/lambdas/update_athena_metric_tables` directory. - -The files in this directory are: - -- `lambda_function.py`: - - Python Lambda function setup on a schedule in the BFD AWS account. - - It takes parameters for the target enviornment (prod/impl) and metrics reporting table basenames used. - - There is one scheduled call per environment and is run weekly. - - This can be tested in local development. See [Lambda Function to Update Metrics Tables](#lambda-function) for more info. -- `sql_templates/template_generate_per_app_metrics_for_report_date.sql`: - - Used to generate the per application metrics. - - One row per application is produced. - - These can be linked together using the `vpc` and `report_date` fields. -- `sql_templates/template_generate_metrics_for_report_date.sql`: - - Used to generate the top-level metrics for the report week. - - One row is produced with the week's metrics. -- `test_run_sql_template_on_athena.py`: - - Used from the command line to run and test Athena SQL queries using a template. With this you can preview the SQL template results with out updating the reporting tables. - - This is a tool useful when developing and adding new metrics to the template files. -- `alter_table_schema_for_new_metrics_added.py`: - - Utility to ALTER a TARGET table with schema changes from a SOURCE table (using -the column differences). - - After developing new metrics, this utility is used to alter (add new columns) to the main tables used by QuickSight. -- `test_lambda_function_local.py`: - - Utility to test the `lambda_handler()` in `lambda_function.py` in local development. - - -# HOW-TO: Testing SQL Templates Individually - -This command line tool can be used to test out the templates individually with out updating the reporting tables. - -The Python program is: `test_run_sql_template_on_athena.py` - -The command's help (via `-h` option) has info about the parameters that can be used. - -The following is an example of usage for testing out the per application template using `report_date = "2023-01-09"` and `vpc = "prod"`: - -``` -clear;rm out.csv; python test_run_sql_template_on_athena.py -t 2023-01-09 -e prod -i sql_templates/template_generate_per_app_metrics_for_report_date_testing1.sql -o out.csv -``` - -NOTE: When using the `-o` option, the results are also written to a CSV file for your review. You can also view the query results and run time information via the AWS console Athena Query Editor. - -NOTE: When working on the main top level SQL template, it is expecting an entry to already exist in the related per application metric table. The `-b` option can be used to specifiy the table you are working with. For example: `-b global_state_per_app_testing1`. - -``` -clear;rm out.csv; python test_run_sql_template_on_athena.py -t 2023-01-09 -e prod -i sql_templates/template_generate_per_app_metrics_for_report_date.sql -o out.csv -b global_state_per_app -``` - -Another useful command line option is the `-a` for appending SQL at the end of the rendered template. When testing you can use this to add a WHERE clause to select only the results of interest. The following are some examples: -- To see results for the `TEST_APP` application only add this to the command: -``` --a "WHERE t0.name = 'TEST_APP'" -``` -- To see results for the `app_sdk_requests_python_count` metric that have a result greater than zero: - ``` - -a "WHERE app_sdk_requests_python_count > 0" - ``` -The per-application table is used by the top-level template. When you are finished adding new metrics to the per-application template and ready to update the top-level template, use the following command line option to create or update the table: -- Add the `--update-per-app-table` to the command line options. -- This is OFF by default. - -# Lambda Function to Update Metrics Tables - -The Python Lambda program is: `lambda_function.py` - -## Summary: - -- The Lambda function is installed in the BFD AWS account w/ BB2 permissions. -- On a weekly schedule, the function is called via an EventBridge schedule with parameters for the target VPC (impl/prod). -- Runs a query to check if the per application table exists. -- Runs a query to check if entries exist for the `report_date`. - - Skips updating the table, if entries exist. -- Updates or creates the per application table with results using the per application SQL template. - - Retries this up to 3 times, in case there are time-out issues. Note that these occasionally occur for unknown reasons. Re-running the same query is usually successful. -- Runs a query to check if the top-level table exists. -- Runs a query to check if an entry exists for the `report_date`. - - Skips updating the table, if an entry exists. -- Updates or creates the top-level table with results using the SQL template. - - Retries this up to 3 times if there are time-out issues. - -## Lambda Parameters: - -A dictionary of parameters is passed in to the Lambda function. - -These parameters are: - -- REGION: AWS region. Ex. "us-east-1" -- WORKGROUP: The Athena workgroup. Ex. "bb2" -- DATABASE: The database. Ex. "bb2", -- ENV: The target BB2 environment (prod/impl). Ex. "prod" -- BASENAME_MAIN: The basename for the top-level table. Ex. "global_state", -- BASENAME_PER_APP: The basename for the per-application table. Ex. "global_state_per_app" -- TARGET_DATE: Target report week to generate metrics for. Ex. "2023-01-09" - - If this is blank (""), the report week will be selected based on the current date. - -### The following is an example dictionary: - -```python -event = { - "REGION": "us-east-1", - "WORKGROUP": "bb2", - "DATABASE": "bb2", - "ENV": "prod", - "BASENAME_MAIN": "global_state_new1", - "BASENAME_PER_APP": "global_state_per_app_new1", - "TARGET_DATE": "2023-01-09" -} -``` -- NOTE: If TARGET_DATE = "", today's date will be used to determine the current report_date. - - - -- The Lambda program can be run locally for development testing. See [Testing the New SQL Templates with the Lambda Function](#testing-templates-lambda). -- The main part of the code has an area where the `event` parameters can be setup and tested via a call to the `lambda_handler(event, context)`. Be sure to backup the main tables and update the table basenames used when running locally for development. For an example, see: [HOW-TO: A Walk-Through Example of Adding New Metrics](#how-to-new-metrics). - - -# HOW-TO: Update QuickSight DataSets - -The following is a general procedure for updating QuickSight datasets. After the tables are updated in Athena, they must be refreshed (manually or scheduled) to be used in QuickSight. - -1. Login to AWS Quicksight. - -2. Go to the `Datasets` section. - -3. Select the data set related to the view that was modified. You can also create a new view in a similar way. - -4. Click on the `Refresh now` button. This start a refresh for the dataset. - -5. If there are changes to field names, you will be prompted to map the old fields to the new ones. - -6. Edit your existing Analyses that are utlizing the dataset related to the changes. Use the SHARE and PUBLISH to update the related dashboard. - - -# HOW-TO: A Walk-Through Example of Adding New Metrics - -In the following example, we are wanting to add a count metric related to our Python SDK usage. - -We will be using a `report_date` of `2023-02-13` that contains metrics for the week of `2023-02-06` thru `2023-02-12`. - -The BB2 API application log events will contain a field `req_header_bluebutton_sdk` that has a value of: "python", "node" or empty. This shows requests that were made using one of our SDKs. This is a link to the related [code](https://github.com/CMSgov/bluebutton-web-server/blob/efdc585c87f787575c2c4f292401e95976cf0d7f/hhs_oauth_server/request_logging.py#L236) - -We are wanting to get counts of usage at both the per application and top level (system wide). - -Our new metric fields will be: - -- Per application: - - `app_sdk_requests_python_count` -- Top level: - - `sdk_requests_python_count` - -Use Splunk to identify and find entries in the logs for the report_date period used: `2023-02-13`. We will use this Splunk search as an example for building our Athena SQL query. The following shows a count of `python` SDK requests: - -``` -index=bluebutton source="/var/log/pyapps/perf_mon.log*" env=impl message.type="request_response_middleware" message.req_header_bluebutton_sdk="python" | stats count -``` - -To begin, change your working directory via: -``` -cd insights/lambdas/update_athena_metric_tables -``` - -## Adding a New Per Application Metric - -1. Identify a similar existing metric in the `sql_templates/template_generate_per_app_metrics_for_report_date.sql` template. - - For example, we will use the metric `app_fhir_v1_call_synthetic_count`. - - In the `enabled_metrics_list` list, comment out the other metrics besides this one or a few. A smaller list will make the query run faster. - - Test that you are able to run the SQL using the following command line. For more info see: [HOW-TO: Testing SQL Templates Individually](#how-to-test-sql-templates). - ``` - clear;rm out.csv; python test_run_sql_template_on_athena.py -t 2023-02-13 -e impl -i sql_templates/template_generate_per_app_metrics_for_report_date.sql -o out.csv - ``` - - Review the results via the Athena console or out.csv file. - - You should see values for this metric and 0 values for the ones disabled. - -2. Add the new metric name to the `enabled_metrics_list`: - - Add the following at the bottom while commenting out the other metrics. - ```SQL - /* - ... other metrics listed .... - ... - 'app_approval_view_post_fail_count', - */ - 'app_sdk_requests_python_count' - ``` -3. Add a COALESCE entry for the new metric. - - Search on `app_approval_view_post_fail_count` to find an example that is currently at the end of the list. - - Add the new entry after the last one: - ```sql - COALESCE(t227.app_approval_view_post_fail_count, 0) - app_approval_view_post_fail_count, - COALESCE(t228.app_sdk_requests_python_count, 0) - app_sdk_requests_python_count - ``` - -4. Add a section with the SQL that counts the events in the middleware event logs. Use the example metric and Splunk search as a guide. - - Add the following `LEFT JOIN` section at the end of the file for the `python` metric: - ```sql - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_sdk_requests_python_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_sdk_requests_python_count') - - AND req_header_bluebutton_sdk = 'python' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t228 ON t228.app_name = t0.name - ``` - - Test the results using the command line from #1. - - To help with testing, you can append a WHERE clause that will only show results that are non-zero. Add the `-a APPEND_SQL` command line option to do this: - ``` - clear;rm out.csv; python test_run_sql_template_on_athena.py -t 2023-02-13 -e impl -i sql_templates/template_generate_per_app_metrics_for_report_date.sql -o out.csv -a "WHERE app_sdk_requests_python_count > 0" - ``` -5. Verify the results vs. the results in Splunk. If successful, we are ready to continue working on the top-level metric. - -6. Add the full list of metrics back to the `enabled_metrics_list`. - - This is by removing the comments around the disabled metrics from #2. - -7. Create or Update the per application table you are using for testing. - - This table is utilized in the top level template we will be updating in the next section. - - NOTE: This SQL will take longer to run with the full metrics list enabled. - - For our example, we will be using the following setting for our Lambda function testing later: - ```python - "BASENAME_PER_APP": "global_state_per_app_testing1", - ``` - - Run the command line to create or update the per applications table in Athena. - - Add the `--update-per-app-table` option to the command line: - ``` - clear; python test_run_sql_template_on_athena.py -t 2023-02-13 -e impl -i sql_templates/template_generate_per_app_metrics_for_report_date.sql --update-per-app-table - ``` - - This will create or update the table. - - The default table is `global_state_per_app_testing1`. Use `-b BASENAME_PER_APP` option, if you want to use a different basename. - - Use the folowing SQL in the Athena query editor to verify the update was successful: - ```SQL - SELECT * FROM bb2.impl_global_state_per_app_testing1 - ``` - - If you have a need to remove/drop the table and re-create it, use the following command: - ```SQL - DROP TABLE bb2.impl_global_state_per_app_testing1 - ``` - -8. Adding a new metric to the PER APPLICATION SQL template is COMPLETE! - - We are ready to add the related top-level metrics in the next section. - - -## Adding a New Top Level Metric - -1. Identify that similar existing metric from #1 in the previous section in the top-level template. - - This in the `sql_templates/template_generate_metrics_for_report_date.sql` template. - - For example, we will use the metric `fhir_v1_call_synthetic_count`. - - In the `enabled_metrics_list` list, comment out the other metrics besides this one or a few. A smaller list will make the query run faster. - - Test that you are able to run the SQL using the following command line. See previous details in this README for more info about this command. - ``` - clear;rm out.csv; python test_run_sql_template_on_athena.py -t 2023-02-13 -e impl -i sql_templates/template_generate_metrics_for_report_date.sql -o out.csv - ``` - - Add the `-b BASENAME_PER_APP` option to the command, if not using the `global_state_per_app_testing1` default value. - - Review the results via the Athena console or out.csv file. - -2. Add the new metric name to the `enabled_metrics_list`: - - Add the following at the bottom while commenting out the other metrics. - ```SQL - /* - ... other metrics listed .... - ... - - 'auth_demoscope_not_required_deny_synthetic_bene_count', - */ - 'sdk_requests_python_count' - ``` - -3. Add a section with the SQL that counts the events in the middleware event logs. Use the example metric and Splunk search as a guide. - - Add the following section at the end of the related SELECT block. - - This is a [link](https://github.com/CMSgov/bluebutton-web-server/blob/329056cf4027ae29e22e75a33659fd84a501547e/insights/lambdas/update_athena_metric_tables/sql_templates/template_generate_metrics_for_report_date.sql#L1314) to the location of the the current `auth_demoscope_not_required_deny_synthetic_bene_count` last metric. - - We will add our new SQL after this line. This last line will be shown below before the new SQL code to help with syntax. - ```sql - ) as auth_demoscope_not_required_deny_synthetic_bene_count, - ( - select - count(*) - from - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'sdk_requests_python_count') - AND req_header_bluebutton_sdk = 'python' - ) - ) as sdk_requests_python_count - ``` - - Test the results using the command line from #1. - -4. Add a SUM() of of the per-application metrics to the `global_state_metrics_per_app_for_max_group_timestamp` sub-select section. - - This performs a SUM() on the values in the per-application table. It should match or closely match the `sdk_requests_python_count` top-level metrics---minus counts for internal applications. - - Currently the last SUM() metric is `app_all_approval_view_post_fail_count` located [here](https://github.com/CMSgov/bluebutton-web-server/blob/329056cf4027ae29e22e75a33659fd84a501547e/insights/lambdas/update_athena_metric_tables/sql_templates/template_generate_metrics_for_report_date.sql#L608). - - The SUM() type metrics are prefixed with "`app_all_`". - - We will add our new SQL after this line. This last line will be shown below before the new SQL code to help with syntax. - ```sql - ) app_all_approval_view_post_fail_count, - "sum"( - app_sdk_requests_python_count - ) app_all_sdk_requests_python_count - ``` - - Test the results using the command line from #1. - -5. Verify the results vs. the results in Splunk. If successful, we are ready to test the new templates using the Lambda function. - -6. Add the full list of metrics back to the `enabled_metrics_list`. - - This is by removing the comments around the disabled metrics from #2. - -7. Adding a new metric to the TOP LEVEL SQL template is COMPLETE! - - We are ready to test the templates with the Lambda function! - -## Testing the New SQL Templates with the Lambda Function - -The Python Lambda program is: `lambda_function.py` - -There is a command line utility that can be used to test the `lambda_handler()` function. - -This utility is: `test_lambda_function_local.py` - - -1. Determine the parameters to match those you have been using so far. - - The following is the `event` we are wanting to test and pass to the `lambda_hanlder()`. - ```python - event = { - "REGION": "us-east-1", - "WORKGROUP": "bb2", - "DATABASE": "bb2", - "ENV": "impl", - "BASENAME_MAIN": "global_state_testing1", - "BASENAME_PER_APP": "global_state_per_app_testing1", - "TARGET_DATE": "2023-02-13", - } - ``` -2. Run and test the Lambda locally. - - Run the following command line: - ``` - clear; python test_lambda_function_local.py -e impl -t 2023-02-13 -m global_state_testing1 -p global_state_per_app_testing1 - ``` - - NOTE: From your previous testing, the per-application table may already be updated and skipped. The top-level table will be updated or created. - - Use the folowing SQL in the Athena query editor to verify the update was successful: - ```SQL - SELECT * FROM bb2.impl_global_state_testing1 - ``` - ```SQL - SELECT * FROM bb2.impl_global_state_per_app_testing1 - ``` -3. Test the Lambda using other `ENV` settings. In this example, we used `impl` for Sandbox. For production use `"ENV": "prod"`. - -4. Verify the results! If successful, we are ready to add the new fields to the production tables and optionally regenerate metrics for previous report dates---if desired. - - -## Adding New Fields to the Tables Used for QuickSight - -The metrics tables used for QuickSight will need to be altered to support inserting entries with the new fields we created. - -### Athena Tables Used by QuickSight: - - | ENV | TableName | - |------|---------------------------| - | impl | impl_global_state_per_app | - | impl | impl_global_state | - | prod | prod_global_state_per_app | - | prod | prod_global_state | - - -The following is a summary of the procedure: - - Backup the current tables for `impl`, and `prod` enviornments. - - Create a working copy of the tables. - - The report date entries that we wish to recreate can be excluded from the copy, if desired. - - We announced our SDKs on 12/21/2022, so we will recreate our metrics for the report dates from 2022-12-26 thru 2023-02-13 (current). - - We will copy entries with a `report_date` before 2022-12-26. - - -1. BACKUP the current metrics tables using the AWS Athena Query Editor. - - **Repeat for the prod enviornment too.** - - Replace "2023_02_17" with your date. - - This is to create a backup of tables, just in case! - - These backups can be used to restore metrics history in case something went wrong. - - ```sql - /* Main (top-level) metrics table backup. */ - CREATE TABLE bb2.impl_global_state_bak_2023_02_17 AS - SELECT * FROM bb2.impl_global_state - ``` - ```sql - /* Show report_date entries */ - SELECT DISTINCT report_date FROM bb2.impl_global_state_bak_2023_02_17 - ``` - - ```sql - /* PER_APP metrics table backup. */ - CREATE TABLE bb2.impl_global_state_per_app_bak_2023_02_17 AS - SELECT * FROM bb2.impl_global_state_per_app - ``` - ```sql - /* Show report_date entries */ - SELECT DISTINCT report_date FROM bb2.impl_global_state_per_app_bak_2023_02_17 - ``` - -2. Copy the current metrics tables to the following. - - Table names: - - bb2.impl_global_state_copy1 - - bb2.impl_global_state_per_app_copy1 - - **Repeat for the prod enviornment too.** - - These will have the schema BEFORE you added the new metrics. - - We will copy entries with a `report_date` before 2022-12-26, so that we can recreate the desired entries since our SDK announcement. - - Drop the `_copy1` tables, if they already exist. - ```sql - DROP TABLE bb2.impl_global_state_copy1 - ``` - ```sql - DROP TABLE bb2.impl_global_state_per_app_copy1 - ``` - - Use the following SQL commands to copy the tables. Repeat for `prod`! - ```sql - CREATE TABLE bb2.impl_global_state_copy1 AS - SELECT * FROM bb2.impl_global_state - WHERE report_date < CAST('2022-12-26' as Date) - ``` - ```sql - /* Show report_date entries */ - SELECT DISTINCT report_date FROM bb2.impl_global_state_copy1 - ``` - ```sql - CREATE TABLE bb2.impl_global_state_per_app_copy1 AS - SELECT * FROM bb2.impl_global_state_per_app - WHERE report_date < CAST('2022-12-26' as Date) - ``` - ```sql - /* Show report_date entries */ - SELECT DISTINCT report_date FROM bb2.impl_global_state_per_app_copy1 - ``` - -3. Review the SCHEMA for the `_testing1` tables with the new metric fields. - - The following command is useful for comparing the schemas with the new metric field: - ```sql - SHOW COLUMNS FROM bb2.impl_global_state_testing1 - ``` - ```sql - SHOW COLUMNS FROM bb2.impl_global_state_per_app_testing1 - ``` - -4. Use the `alter_table_schema_for_new_metrics_added.py` tool to ALTER the table. - -This command line tool can be used to ALTER a TARGET table with the schema changes of a SOURCE table. Note that this tool only works for additions and not removing columns. - -In our example, we want to alter the `_copy1` table with the additinal columns we added to the `_testing1` table. - -Repeat the following for the `prod` environment. - - - Review the per application table with the following command: - ``` - clear; python alter_table_schema_for_new_metrics_added.py -s "impl_global_state_per_app_testing1" -t "impl_global_state_per_app_copy1" - ``` - - Verify that the expected column changes are OK. - - There should be one column to add: `app_sdk_requests_python_count`. - - If OK, ALTER the table by adding the `--alter-table` command line option. - ``` - clear; python alter_table_schema_for_new_metrics_added.py -s "impl_global_state_per_app_testing1" -t "impl_global_state_per_app_copy1" --alter-table - ``` - - - Review the top-level table with the following command: - ``` - clear; python alter_table_schema_for_new_metrics_added.py -s "impl_global_state_testing1" -t "impl_global_state_copy1" - ``` - - Verify that the expected column changes are OK. - - There should be two columns to add: `app_sdk_requests_python_count` and `app_all_sdk_requests_python_count`. - - If OK, ALTER the table by adding the `--alter-table` command line option. - ``` - clear; python alter_table_schema_for_new_metrics_added.py -s "impl_global_state_testing1" -t "impl_global_state_copy1" --alter-table - ``` - -5. Determine the parameters to match those you have been using so far. - -In this step we will be verifying that the lambda can update our `_copy1` tables that will be replacing the main ones, after re-running metrics for report dates since 2022-12-26. - - - Determine the parameters to match those you have been using so far: - - ```python - event = { - "REGION": "us-east-1", - "WORKGROUP": "bb2", - "DATABASE": "bb2", - "ENV": "impl", - "BASENAME_MAIN": "global_state_copy1", - "BASENAME_PER_APP": "global_state_per_app_copy1", - "TARGET_DATE": "2022-12-26" - } - ``` - - Run the lambda function to test locally with the `test_lambda_function_local.py` utility program: - ``` - clear; python test_lambda_function_local.py -e impl -t 2022-12-26 -m global_state_copy1 -p global_state_per_app_copy1 - ``` - -6. Verify the rows were added to the `_copy1` tables. - - - Verify per application rows. - ``` - SELECT * FROM bb2.impl_global_state_per_app_copy1 - WHERE report_date = CAST('2022-12-26' as Date) - ``` - - Verify top-level rows. - ``` - SELECT * FROM bb2.impl_global_state_copy1 - WHERE report_date = CAST('2022-12-26' as Date) - ``` - -7. Run for additional report dates after 2022-12-26 up until the current. - - - NOTE: Multiple target dates can be added to the list. This is useful when regenerating the metrics entries for desired report dates, after new metrics are developed and added. - - - Use the `-t / --target-report-dates` option with the `test_lambda_function_local.py` utility to use the lambda program locally to update the `_copy1` table with entries. - - For example, we can update a batch of 4 report_dates with entries from 2022-12-26 thru 2023-01-16 with the following command line: - ``` - clear; python test_lambda_function_local.py -e impl -t 2022-12-26,2023-01-02,2023-01-09,2023-01-16 -m global_state_copy1 -p global_state_per_app_copy1 - ``` - -8. Verify the new rows were added to the `_copy1` tables since 2022-12-26. - - - Verify per application rows. - ``` - SELECT * FROM bb2.impl_global_state_per_app_copy1 - WHERE report_date > CAST('2022-12-26' as Date) - ``` - - Verify top-level rows. - ``` - SELECT * FROM bb2.impl_global_state_copy1 - WHERE report_date > CAST('2022-12-26' as Date) - ``` - -9. Review if there are any missing `report_date` entries. - - - Verify per application: - ```sql - SELECT DISTINCT report_date FROM bb2.impl_global_state_per_app_copy1 - ``` - - Verify top-level rows: - ```sql - SELECT DISTINCT report_date FROM bb2.impl_global_state_copy1 - ``` - - If there are missing entries, follow the instruction in #7 to update them. - -10. Copy the `_copy1` tables in to place for use in QuickSight. - - - Verify that report date entries are complete per #9 for each table for `impl` and `prod` enviornments. - - Verify that the related tables have been backed up per #1. - - Remove the main tables using the following Athena SQL example: - ```sql - DROP TABLE bb2.impl_global_state - ``` - - Copy the `_copy1` version of the table in to place: - ```sql - CREATE TABLE bb2.impl_global_state AS - SELECT * FROM bb2.impl_global_state_copy1 - ``` - - Repeat this for each table that was updated. - -11. View the changes in QuickSight dashboards - - - Follow [HOW-TO: Update QuickSight DataSets](#how-to-update-qs-datasets). - - Refresh the datasets for each of the tables. - - In QuickSight, view the `BB2 DASG Metrics` and `PROD-APPLICATIONS` dashboards to verify that the new metrics are showing. diff --git a/insights/lambdas/update_athena_metric_tables/alter_table_schema_for_new_metrics_added.py b/insights/lambdas/update_athena_metric_tables/alter_table_schema_for_new_metrics_added.py deleted file mode 100644 index 7fe10f69b..000000000 --- a/insights/lambdas/update_athena_metric_tables/alter_table_schema_for_new_metrics_added.py +++ /dev/null @@ -1,206 +0,0 @@ -import argparse -import boto3 -import re - -from utils.utils import ( - run_athena_query_result_to_s3, - download_content_from_s3, -) -""" -Summary: - -Utility to ALTER a TARGET table with schema changes -from a SOURCE table (using the column differences). - -This can be used when adding new metric columns/fields. - -It will compare a SOURCE and TARGET table schema, then ALTER -the DESTINATION table with the new columns (difference). - -See README.md for usage examples. -""" - - -def get_table_columns(session, params, table_name): - """ - Returns COLUMNS list for given full table name. - - Returns a list of [column-name, type] pairs. - """ - params["query"] = "DESCRIBE " + params["database"] + "." + table_name - - output_s3_path = run_athena_query_result_to_s3(session, params, 1000) - result_list = download_content_from_s3(output_s3_path) - - # Get the first keyname from the very first list item. - keyname = [a for a, b in result_list[0].items()][0] - - split_regex = re.compile(r"(\w+)\s*(date\s|int\s|bigint\s|string\s)\s+$") - - columns_list = [] - - # Add [column_name, type] pairs to list - for d in result_list: - m = split_regex.match(d[keyname]) - if m: - column_type_pair = [] - column_type_pair.append([m.group(1).strip(), m.group(2).strip()]) - columns_list.append(column_type_pair) - - return columns_list - - -def lists_diff(list1, list2): - # Return list of items in list1 but not in list2 - diff_list = [] - for i1 in list1: - found = False - for i2 in list2: - if i1 == i2: - found = True - break - if not found: - diff_list.append(i1) - - return diff_list - - -def alter_table_add_columns(session, params, table_name, alter_list): - """ - ALTER the table to add columns from alter_list - """ - if len(alter_list) == 0: - print("---") - print("--- ERROR: alter_list is empty!") - print("---") - return False - - alter_sql = ( - "ALTER TABLE " + params["database"] + "." + table_name + " ADD COLUMNS (" - ) - - cnt = 0 - for i in alter_list: - if cnt != 0: - alter_sql += ", " - alter_sql += i[0][0] + " " + i[0][1] - cnt += 1 - alter_sql += ")" - - params["query"] = alter_sql - - run_athena_query_result_to_s3(session, params, 1000) - - return True - - -parser = argparse.ArgumentParser( - description="Utility to ALTER a TARGET table with schema changes from a SOURCE table (using the column differences)." -) -parser.add_argument( - "--region", - "-r", - help="The Athena AWS region.", - default="us-east-1", - type=str, -) -parser.add_argument( - "--workgroup", - "-w", - help="The AWS Glue table workgroup.", - default="bb2", - type=str, -) -parser.add_argument( - "--database", - "-d", - help="The AWS Glue table database.", - default="bb2", - type=str, -) -parser.add_argument( - "--source-table-name", - "-s", - help="The SOURCE table that has new columns/metrics.", - required=True, - type=str, -) -parser.add_argument( - "--target-table-name", - "-t", - help="The TARGET table to be updated that is missing SOURCE table columns.", - required=True, - type=str, -) -parser.add_argument( - "--alter-table", - default=False, - action='store_true', - help="ALTER the destination table with schema differences.", -) - -args = parser.parse_args() - -REGION = args.region if args.region else None -WORKGROUP = args.workgroup if args.workgroup else None -DATABASE = args.database if args.database else None -ALTER_TABLE = args.alter_table if args.alter_table else None -SOURCE_TABLE = args.source_table_name if args.source_table_name else None -TARGET_TABLE = args.target_table_name if args.target_table_name else None - -params = { - "region": REGION, - "workgroup": WORKGROUP, - "database": DATABASE, -} - -print("---") -print("---Using the following paramters:") -print("---") -print("--- AWS REGION: ", REGION) -print("--- WORKGROUP: ", WORKGROUP) -print("--- DATABASE: ", DATABASE) -print("---") -print("--- ALTER_TABLE: ", ALTER_TABLE) -print("--- (If False, just show changes to be made)") -print("---") -print("--- SOURCE_TABLE: ", SOURCE_TABLE) -print("--- TARGET_TABLE: ", TARGET_TABLE) -print("---") - -session = boto3.Session() - -source_columns_list = get_table_columns(session, params, SOURCE_TABLE) -target_columns_list = get_table_columns(session, params, TARGET_TABLE) - -source_columns_count = len(source_columns_list) -target_columns_count = len(target_columns_list) - -diff_columns_list = lists_diff(source_columns_list, target_columns_list) -print("---") -print("--- SOURCE TABLE HAS TOTAL COLUMNS = ", len(source_columns_list) + 1) -print("---") -print("--- TARGET TABLE HAS TOTAL COLUMNS = ", len(target_columns_list) + 1) -print("---") -print( - "--- SOURCE has ", - (source_columns_count - target_columns_count), - " additional columns to add.", -) -print("---") -print("--- COLUMNS TO BE ADDED TO THE TARGET TABLE:") -print("---") -for i in diff_columns_list: - print(" ADDING: ", i[0]) -print("---") -print("--- Verify columns to be add and use the --alter-table option to apply!") - -if ALTER_TABLE: - if alter_table_add_columns(session, params, TARGET_TABLE, diff_columns_list): - print("---") - print("--- ALTER was successful!!!") - print("---") - else: - print("---") - print("--- ALTER failed!!!!") - print("---") diff --git a/insights/lambdas/update_athena_metric_tables/lambda_function.py b/insights/lambdas/update_athena_metric_tables/lambda_function.py deleted file mode 100644 index fe69d81e4..000000000 --- a/insights/lambdas/update_athena_metric_tables/lambda_function.py +++ /dev/null @@ -1,139 +0,0 @@ -import boto3 -import datetime - -from utils.utils import ( - get_report_dates_from_target_date, - update_or_create_metrics_table, -) - - -""" -Summary: - -This lambda supports the updating (or creation) of metric -tables via Athena used for BB2 Insights dashboards in QuickSight. - -It does the following: - -- Accepts a lambda parameters dictionary in the following format: - { - "REGION": "", - "WORKGROUP": "bb2", - "DATABASE": "bb2", - "ENV": "" - "BASENAME_MAIN": "" Ex: "global_state" - "BASENAME_PER_APP": "" Ex: "global_state_per_app" - "TARGET_DATE": EX: "2022-09-19", - "RETRY_SLEEP_SECONDS": "30", Default is 60, if ommitted. - } - -- Computes the report_date, start_date, and end_date based on the TARGET_DATE param. - - - If the TARGET_DATE is blank, the current date will be used for the TARGET_DATE. - -- Updates (or creates) the per-applications table for the target report_date, - ENV and BASENAME_PER_APP params. - -- Updates (or creates) the main (top-level) table for the target report_date, - ENV and BASENAME_MAIN params. - -For each of the tables, it does the following: - -- Check if the table already exists. Setup to create it, if not. - -- Check if an entry for the report_date already exists to prevent duplicate - entries. - -- Execute the relatate SQL from the corresponding template file and - update (or create) the table with the results. - -- Retry running the SQL if there is a time-out up to 3-times. - Will sleep between retries. - -""" - - -TEMPLATE_FILE_PER_APP = ( - "./sql_templates/template_generate_per_app_metrics_for_report_date.sql" -) - -TEMPLATE_FILE_MAIN = "./sql_templates/template_generate_metrics_for_report_date.sql" - - -def lambda_handler(event, context): - session = boto3.Session() - - target_week_date = event["TARGET_DATE"] - report_dates = get_report_dates_from_target_date(target_week_date) - print("##") - print("## -------------------------") - print("## UPDATING FOR TARGET_DATE (if blank, today): ", target_week_date) - print("##") - print("## report_dates DICT: ", report_dates) - print("##") - - params = { - "region": event["REGION"], - "workgroup": event["WORKGROUP"], - "database": event["DATABASE"], - "env": event["ENV"], - "basename_main": event["BASENAME_MAIN"], - "basename_per_app": event["BASENAME_PER_APP"], - "report_dates": report_dates, - "retry_sleep_seconds": event.get("RETRY_SLEEP_SECONDS", "300") - } - - lambda_start_time = datetime.datetime.now() - print("##") - print("## EVENT: " + str(event)) - print("##") - print("## Lambda Start Time: ", lambda_start_time) - print("##") - - # Update/create PER_APP table - query_start_time = datetime.datetime.now() - success_flag = update_or_create_metrics_table( - session, params, params["basename_per_app"], TEMPLATE_FILE_PER_APP - ) - query_end_time = datetime.datetime.now() - query_duration_time = query_end_time - query_start_time - print("## Query Duration Time: ", query_duration_time) - - if success_flag: - print("## SUCCESS: PER_APP TABLE was updated/created!") - else: - print("## FAIL: PER_APP TABLE update/create un-successful after retries!") - return { - "STATUS": "FAIL", - "DETAIL": "PER_APP table create/update was un-successful after retries!", - } - - # Update/create MAIN table - query_start_time = datetime.datetime.now() - success_flag = update_or_create_metrics_table( - session, params, params["basename_main"], TEMPLATE_FILE_MAIN - ) - query_end_time = datetime.datetime.now() - query_duration_time = query_end_time - query_start_time - print("## Query Duration Time: ", query_duration_time) - - if success_flag: - print("## SUCCESS: MAIN TABLE was updated/created!") - - lambda_end_time = datetime.datetime.now() - lambda_duration_time = lambda_end_time - lambda_start_time - print("##") - print("## Lambda End Time: ", lambda_end_time) - print("## Lambda Duration Time: ", lambda_duration_time) - print("##") - else: - print("## FAIL: MAIN TABLE update/create un-successful after retries!") - return { - "STATUS": "FAIL", - "DETAIL": "MAIN table create/update was un-successful after retries!", - } - - return { - "STATUS": "SUCCESS", - "DETAIL": "Metric tables are ready for refresh in QuickSight!", - } diff --git a/insights/lambdas/update_athena_metric_tables/sql_templates/template_generate_metrics_for_report_date.sql b/insights/lambdas/update_athena_metric_tables/sql_templates/template_generate_metrics_for_report_date.sql deleted file mode 100644 index 174b0d99f..000000000 --- a/insights/lambdas/update_athena_metric_tables/sql_templates/template_generate_metrics_for_report_date.sql +++ /dev/null @@ -1,1314 +0,0 @@ -/* Report metrics to main table entry for Quicksight Dashboard use */ -WITH report_params AS ( - /* Report parameters - Generates metrics between start/end dates */ - SELECT - '${ENV}' as vpc, - CAST('${START_DATE}' as Date) as start_date, - CAST('${END_DATE}' as Date) as end_date, - CAST('${REPORT_DATE}' as Date) as report_date, - /* List of metrics to enable. - NOTE: To greatly speed up development and testing of new metrics, - this list can be used to select only metrics - being worked on. - */ - ARRAY [ - 'fhir_v1_call_real_count', - 'fhir_v1_call_synthetic_count', - 'fhir_v1_eob_call_real_count', - 'fhir_v1_eob_call_synthetic_count', - 'fhir_v1_coverage_call_real_count', - 'fhir_v1_coverage_call_synthetic_count', - 'fhir_v1_patient_call_real_count', - 'fhir_v1_patient_call_synthetic_count', - 'fhir_v1_metadata_call_count', - 'fhir_v1_eob_since_call_real_count', - 'fhir_v1_eob_since_call_synthetic_count', - 'fhir_v1_coverage_since_call_real_count', - 'fhir_v1_coverage_since_call_synthetic_count', - 'fhir_v2_call_real_count', - 'fhir_v2_call_synthetic_count', - 'fhir_v2_eob_call_real_count', - 'fhir_v2_eob_call_synthetic_count', - 'fhir_v2_coverage_call_real_count', - 'fhir_v2_coverage_call_synthetic_count', - 'fhir_v2_patient_call_real_count', - 'fhir_v2_patient_call_synthetic_count', - 'fhir_v2_metadata_call_count', - 'fhir_v2_eob_since_call_real_count', - 'fhir_v2_eob_since_call_synthetic_count', - 'fhir_v2_coverage_since_call_real_count', - 'fhir_v2_coverage_since_call_synthetic_count', - 'auth_ok_real_bene_count', - 'auth_ok_synthetic_bene_count', - 'auth_fail_or_deny_real_bene_count', - 'auth_fail_or_deny_synthetic_bene_count', - 'auth_demoscope_required_choice_sharing_real_bene_count', - 'auth_demoscope_required_choice_sharing_synthetic_bene_count', - 'auth_demoscope_required_choice_not_sharing_real_bene_count', - 'auth_demoscope_required_choice_not_sharing_synthetic_bene_count', - 'auth_demoscope_required_choice_deny_real_bene_count', - 'auth_demoscope_required_choice_deny_synthetic_bene_count', - 'auth_demoscope_not_required_not_sharing_real_bene_count', - 'auth_demoscope_not_required_not_sharing_synthetic_bene_count', - 'auth_demoscope_not_required_deny_real_bene_count', - 'auth_demoscope_not_required_deny_synthetic_bene_count', - 'sdk_requests_python_count', - 'sdk_requests_node_count' - ] as enabled_metrics_list -), - -/* All perf_mon application log events. Is a base for other sub-queries - NOTE: This includes the report_date for getting at the max(group_timestamp) */ -perf_mon_events_all AS ( - select - * - from - "bb2"."events_${ENV}_perf_mon" - WHERE - ( - vpc = ( - select - vpc - FROM - report_params - ) - and cast("from_iso8601_timestamp"(time_of_event) AS date) >= ( - select - start_date - FROM - report_params - ) - and cast("from_iso8601_timestamp"(time_of_event) AS date) <= ( - select - report_date - FROM - report_params - ) - /* - Restricting select by partitions. - NOTE: This significantly speeds up the SQL! - */ - AND ${PARTITION_LIMIT_SQL} - ) -), - -/* Find the max(group_timestamp) from - nightly global state events - NOTE: We are wanting the entries that get logged - on the actual report_date vs. other metrics to - just include <= end_date. -*/ -max_group_timestamp AS ( - SELECT - max(group_timestamp) as max_group_timestamp - FROM - perf_mon_events_all - WHERE - type = 'global_state_metrics' -), -perf_mon_events AS ( - select - * - from - perf_mon_events_all - WHERE - cast("from_iso8601_timestamp"(time_of_event) AS date) <= ( - select - end_date - FROM - report_params - ) -), - -request_response_middleware_events AS ( - select - *, - json_extract(user, '$$.crosswalk.fhir_id') as crosswalk_fhir_id - from - perf_mon_events - WHERE - ( - type = 'request_response_middleware' - AND - ( path LIKE '/v%/o/authorize%' - OR path = '/mymedicare/login' - OR path = '/mymedicare/sls-callback' - OR path LIKE '/v1/fhir%' - OR path LIKE '/v2/fhir%' - OR path LIKE '/v%/o/token%/' - ) - ) -), - -api_audit_events AS ( - select - *, - json_extract(user, '$$.crosswalk.fhir_id') as crosswalk_fhir_id - from - perf_mon_events - WHERE - ( - type = 'Authentication:start' - OR type = 'Authentication:success' - OR type = 'Authorization' - OR type = 'AccessToken' - ) -), - -/* Select all application names and metrics from - nightly global state per application events -*/ -applications_state_metrics AS ( - SELECT - * - /* - DISTINCT name app_name, - group_timestamp max_group_timestamp, - */ - FROM - perf_mon_events_all - WHERE - type = 'global_state_metrics_per_app' - AND - group_timestamp = ( - select - max_group_timestamp - FROM - max_group_timestamp - ) - AND - name NOT IN ('TestApp', 'BlueButton Client (Test - Internal Use Only)', - 'MyMedicare PROD', 'new-relic') -), -/* Select all top level global state metrics from - nightly global state event -*/ -global_state_metrics_for_max_group_timestamp AS ( - SELECT - '${ENV}' as vpc, - CAST('${START_DATE}' as Date) as start_date, - CAST('${END_DATE}' as Date) as end_date, - CAST('${REPORT_DATE}' as Date) as report_date, - group_timestamp max_group_timestamp, - real_bene_cnt max_real_bene_cnt, - synth_bene_cnt max_synth_bene_cnt, - crosswalk_real_bene_count max_crosswalk_real_bene_count, - crosswalk_synthetic_bene_count max_crosswalk_synthetic_bene_count, - crosswalk_table_count max_crosswalk_table_count, - crosswalk_archived_table_count max_crosswalk_archived_table_count, - grant_real_bene_count max_grant_real_bene_count, - grant_synthetic_bene_count max_grant_synthetic_bene_count, - grant_table_count max_grant_table_count, - grant_archived_table_count max_grant_archived_table_count, - grant_real_bene_deduped_count max_grant_real_bene_deduped_count, - grant_synthetic_bene_deduped_count max_grant_synthetic_bene_deduped_count, - grantarchived_real_bene_deduped_count max_grantarchived_real_bene_deduped_count, - grantarchived_synthetic_bene_deduped_count max_grantarchived_synthetic_bene_deduped_count, - grant_and_archived_real_bene_deduped_count max_grant_and_archived_real_bene_deduped_count, - grant_and_archived_synthetic_bene_deduped_count max_grant_and_archived_synthetic_bene_deduped_count, - token_real_bene_deduped_count max_token_real_bene_deduped_count, - token_synthetic_bene_deduped_count max_token_synthetic_bene_deduped_count, - token_table_count max_token_table_count, - token_archived_table_count max_token_archived_table_count, - global_apps_active_cnt max_global_apps_active_cnt, - global_apps_inactive_cnt max_global_apps_inactive_cnt, - global_apps_require_demographic_scopes_cnt max_global_apps_require_demographic_scopes_cnt, - global_developer_count max_global_developer_count, - global_developer_distinct_organization_name_count max_global_developer_distinct_organization_name_count, - global_developer_with_first_api_call_count max_global_developer_with_first_api_call_count, - global_developer_with_registered_app_count max_global_developer_with_registered_app_count - FROM - perf_mon_events_all - WHERE - type = 'global_state_metrics' - AND - group_timestamp = ( - select - max_group_timestamp - FROM - max_group_timestamp - ) -), - -/* Select metrics already generated for report_date group_timestamp - from PER_APP table: ENV_global_state_per_app -*/ -global_state_metrics_per_app_for_max_group_timestamp AS ( - SELECT - vpc, - start_date, - end_date, - report_date, - max_group_timestamp, - /* - NOTE: Metrics in this section prefixed by "total_" come from the - type = "global_state_metrics", - where counts are performed at time of logging. - */ - max_crosswalk_real_bene_count total_crosswalk_real_bene, - max_crosswalk_synthetic_bene_count total_crosswalk_synthetic_bene, - max_crosswalk_table_count total_crosswalk_table_count, - max_crosswalk_archived_table_count total_crosswalk_archived_table_count, - max_grant_real_bene_count total_grant_real_bene_count, - max_grant_synthetic_bene_count total_grant_synthetic_bene_count, - max_grant_table_count total_grant_table_count, - max_grant_archived_table_count total_grant_archived_table_count, - max_grant_real_bene_deduped_count total_grant_real_bene_deduped_count, - max_grant_synthetic_bene_deduped_count total_grant_synthetic_bene_deduped_count, - max_grantarchived_real_bene_deduped_count total_grantarchived_real_bene_deduped_count, - max_grantarchived_synthetic_bene_deduped_count total_grantarchived_synthetic_bene_deduped_count, - max_grant_and_archived_real_bene_deduped_count total_grant_and_archived_real_bene_deduped_count, - max_grant_and_archived_synthetic_bene_deduped_count total_grant_and_archived_synthetic_bene_deduped_count, - max_token_real_bene_deduped_count total_token_real_bene_deduped_count, - max_token_synthetic_bene_deduped_count total_token_synthetic_bene_deduped_count, - max_token_table_count total_token_table_count, - max_token_archived_table_count total_token_archived_table_count, - max_global_apps_active_cnt total_apps_in_system, - max_global_apps_inactive_cnt total_inactive_apps_in_system, - max_global_apps_require_demographic_scopes_cnt total_apps_require_demo_scopes_cnt, - max_global_developer_count total_developer_count, - max_global_developer_distinct_organization_name_count total_developer_distinct_organization_name_count, - max_global_developer_with_first_api_call_count total_developer_with_first_api_call_count, - max_global_developer_with_registered_app_count total_developer_with_registered_app_count, - /* - NOTE: Metrics in this section prefixed by "app_" come from the - type = "global_state_metrics_per_app", - per the vw_${ENV}_global_state_per_app view - where the counts/sums are performed in SQL below. - */ - "count"( - ( - CASE - WHEN (app_active = true) THEN 1 - END - ) - ) app_total_active, - "count"( - ( - CASE - WHEN ( - (app_real_bene_cnt > 25) - AND (app_active = true) - ) THEN 1 - END - ) - ) app_active_bene_cnt_gt25, - "count"( - ( - CASE - WHEN ( - (app_real_bene_cnt <= 25) - AND (app_active = true) - ) THEN 1 - END - ) - ) app_active_bene_cnt_le25, - "count"( - ( - CASE - WHEN ( - (app_created IS NOT NULL) - AND (app_active = true) - ) THEN 1 - END - ) - ) app_active_registered, - "count"( - ( - CASE - WHEN ( - (app_first_active IS NOT NULL) - AND (app_active = true) - ) THEN 1 - END - ) - ) app_active_first_api, - "count"( - ( - CASE - WHEN ( - ( - app_require_demographic_scopes = true - ) - AND (app_active = true) - ) THEN 1 - END - ) - ) app_active_require_demographic, - "sum"( - ( - CASE - WHEN (app_active = true) THEN app_real_bene_cnt - END - ) - ) app_grant_active_real_bene, - "sum"( - ( - CASE - WHEN (app_active = true) THEN app_synth_bene_cnt - END - ) - ) app_grant_active_synthetic_bene, - "count"(*) app_all, - "count"( - ( - CASE - WHEN (app_real_bene_cnt > 25) THEN 1 - END - ) - ) app_all_real_bene_gt25, - "count"( - ( - CASE - WHEN (app_real_bene_cnt <= 25) THEN 1 - END - ) - ) app_all_real_bene_le25, - "count"( - ( - CASE - WHEN (app_created IS NOT NULL) THEN 1 - END - ) - ) app_all_registered, - "count"( - ( - CASE - WHEN (app_first_active IS NOT NULL) THEN 1 - END - ) - ) app_all_first_api, - "count"( - ( - CASE - WHEN ( - app_require_demographic_scopes = true - ) THEN 1 - END - ) - ) app_all_require_demographic, - "sum"(app_grant_and_archived_real_bene_deduped_count) app_all_grant_real_bene, - "sum"( - app_grant_and_archived_synthetic_bene_deduped_count - ) app_all_grant_synthetic_bene, - "sum"( - app_fhir_v1_call_real_count - ) app_all_fhir_v1_call_real_count, - "sum"( - app_fhir_v1_call_synthetic_count - ) app_all_fhir_v1_call_synthetic_count, - "sum"( - app_fhir_v1_eob_call_real_count - ) app_all_fhir_v1_eob_call_real_count, - "sum"( - app_fhir_v1_eob_call_synthetic_count - ) app_all_fhir_v1_eob_call_synthetic_count, - "sum"( - app_fhir_v1_coverage_call_real_count - ) app_all_fhir_v1_coverage_call_real_count, - "sum"( - app_fhir_v1_coverage_call_synthetic_count - ) app_all_fhir_v1_coverage_call_synthetic_count, - "sum"( - app_fhir_v1_patient_call_real_count - ) app_all_fhir_v1_patient_call_real_count, - "sum"( - app_fhir_v1_patient_call_synthetic_count - ) app_all_fhir_v1_patient_call_synthetic_count, - "sum"( - app_fhir_v1_metadata_call_count - ) app_all_fhir_v1_metadata_call_count, - "sum"( - app_fhir_v1_eob_since_call_real_count - ) app_all_fhir_v1_eob_since_call_real_count, - "sum"( - app_fhir_v1_eob_since_call_synthetic_count - ) app_all_fhir_v1_eob_since_call_synthetic_count, - "sum"( - app_fhir_v1_coverage_since_call_real_count - ) app_all_fhir_v1_coverage_since_call_real_count, - "sum"( - app_fhir_v1_coverage_since_call_synthetic_count - ) app_all_fhir_v1_coverage_since_call_synthetic_count, - "sum"( - app_fhir_v2_call_real_count - ) app_all_fhir_v2_call_real_count, - "sum"( - app_fhir_v2_call_synthetic_count - ) app_all_fhir_v2_call_synthetic_count, - "sum"( - app_fhir_v2_eob_call_real_count - ) app_all_fhir_v2_eob_call_real_count, - "sum"( - app_fhir_v2_eob_call_synthetic_count - ) app_all_fhir_v2_eob_call_synthetic_count, - "sum"( - app_fhir_v2_coverage_call_real_count - ) app_all_fhir_v2_coverage_call_real_count, - "sum"( - app_fhir_v2_coverage_call_synthetic_count - ) app_all_fhir_v2_coverage_call_synthetic_count, - "sum"( - app_fhir_v2_patient_call_real_count - ) app_all_fhir_v2_patient_call_real_count, - "sum"( - app_fhir_v2_patient_call_synthetic_count - ) app_all_fhir_v2_patient_call_synthetic_count, - "sum"( - app_fhir_v2_metadata_call_count - ) app_all_fhir_v2_metadata_call_count, - "sum"( - app_fhir_v2_eob_since_call_real_count - ) app_all_fhir_v2_eob_since_call_real_count, - "sum"( - app_fhir_v2_eob_since_call_synthetic_count - ) app_all_fhir_v2_eob_since_call_synthetic_count, - "sum"( - app_fhir_v2_coverage_since_call_real_count - ) app_all_fhir_v2_coverage_since_call_real_count, - "sum"( - app_fhir_v2_coverage_since_call_synthetic_count - ) app_all_fhir_v2_coverage_since_call_synthetic_count, - "sum"( - app_auth_ok_real_bene_count - ) app_all_auth_ok_real_bene_count, - "sum"( - app_auth_ok_synthetic_bene_count - ) app_all_auth_ok_synthetic_bene_count, - "sum"( - app_auth_fail_or_deny_real_bene_count - ) app_all_auth_fail_or_deny_real_bene_count, - "sum"( - app_auth_fail_or_deny_synthetic_bene_count - ) app_all_auth_fail_or_deny_synthetic_bene_count, - "sum"( - app_auth_demoscope_required_choice_sharing_real_bene_count - ) app_all_auth_demoscope_required_choice_sharing_real_bene_count, - "sum"( - app_auth_demoscope_required_choice_sharing_synthetic_bene_count - ) app_all_auth_demoscope_required_choice_sharing_synthetic_bene_count, - "sum"( - app_auth_demoscope_required_choice_not_sharing_real_bene_count - ) app_all_auth_demoscope_required_choice_not_sharing_real_bene_count, - "sum"( - app_auth_demoscope_required_choice_not_sharing_synthetic_bene_count - ) app_all_auth_demoscope_required_choice_not_sharing_synthetic_bene_count, - "sum"( - app_auth_demoscope_required_choice_deny_real_bene_count - ) app_all_auth_demoscope_required_choice_deny_real_bene_count, - "sum"( - app_auth_demoscope_required_choice_deny_synthetic_bene_count - ) app_all_auth_demoscope_required_choice_deny_synthetic_bene_count, - "sum"( - app_auth_demoscope_not_required_not_sharing_real_bene_count - ) app_all_auth_demoscope_not_required_not_sharing_real_bene_count, - "sum"( - app_auth_demoscope_not_required_not_sharing_synthetic_bene_count - ) app_all_auth_demoscope_not_required_not_sharing_synthetic_bene_count, - "sum"( - app_auth_demoscope_not_required_deny_real_bene_count - ) app_all_auth_demoscope_not_required_deny_real_bene_count, - "sum"( - app_auth_demoscope_not_required_deny_synthetic_bene_count - ) app_all_auth_demoscope_not_required_deny_synthetic_bene_count, - "sum"( - app_token_authorization_code_2xx_count - ) app_all_token_authorization_code_2xx_count, - "sum"( - app_token_authorization_code_4xx_count - ) app_all_token_authorization_code_4xx_count, - "sum"( - app_token_authorization_code_5xx_count - ) app_all_token_authorization_code_5xx_count, - "sum"( - app_token_authorization_code_for_real_bene_count - ) app_all_token_authorization_code_for_real_bene_count, - "sum"( - app_token_authorization_code_for_synthetic_bene_count - ) app_all_token_authorization_code_for_synthetic_bene_count, - "sum"( - app_token_refresh_for_real_bene_count - ) app_all_token_refresh_for_real_bene_count, - "sum"( - app_token_refresh_for_synthetic_bene_count - ) app_all_token_refresh_for_synthetic_bene_count, - "sum"( - app_token_refresh_response_2xx_count - ) app_all_token_refresh_response_2xx_count, - "sum"( - app_token_refresh_response_4xx_count - ) app_all_token_refresh_response_4xx_count, - "sum"( - app_token_refresh_response_5xx_count - ) app_all_token_refresh_response_5xx_count, - "sum"( - app_authorize_initial_count - ) app_all_authorize_initial_count, - "sum"( - app_medicare_login_redirect_OK_count - ) app_all_medicare_login_redirect_OK_count, - "sum"( - app_medicare_login_redirect_FAIL_count - ) app_all_medicare_login_redirect_FAIL_count, - "sum"( - app_authentication_start_ok_count - ) app_all_authentication_start_ok_count, - "sum"( - app_authentication_start_fail_count - ) app_all_authentication_start_fail_count, - "sum"( - app_authentication_matched_new_bene_real_count - ) app_all_authentication_matched_new_bene_real_count, - "sum"( - app_authentication_matched_new_bene_synthetic_count - ) app_all_authentication_matched_new_bene_synthetic_count, - "sum"( - app_authentication_matched_returning_bene_real_count - ) app_all_authentication_matched_returning_bene_real_count, - "sum"( - app_authentication_matched_returning_bene_synthetic_count - ) app_all_authentication_matched_returning_bene_synthetic_count, - "sum"( - app_sls_callback_ok_real_count - ) app_all_sls_callback_ok_real_count, - "sum"( - app_sls_callback_ok_synthetic_count - ) app_all_sls_callback_ok_synthetic_count, - "sum"( - app_sls_callback_fail_count - ) app_all_sls_callback_fail_count, - "sum"( - app_approval_view_get_ok_real_count - ) app_all_approval_view_get_ok_real_count, - "sum"( - app_approval_view_get_ok_synthetic_count - ) app_all_approval_view_get_ok_synthetic_count, - "sum"( - app_approval_view_get_fail_count - ) app_all_approval_view_get_fail_count, - "sum"( - app_approval_view_post_ok_real_count - ) app_all_approval_view_post_ok_real_count, - "sum"( - app_approval_view_post_ok_synthetic_count - ) app_all_approval_view_post_ok_synthetic_count, - "sum"( - app_approval_view_post_fail_count - ) app_all_approval_view_post_fail_count, - "sum"( - app_sdk_requests_python_count - ) app_all_sdk_requests_python_count, - "sum"( - app_sdk_requests_node_count - ) app_all_sdk_requests_node_count - FROM - ${ENV}_${BASENAME_PER_APP} - WHERE - cast(report_date AS date) = ( - select - report_date - FROM - report_params - ) - GROUP BY - vpc, - start_date, - end_date, - report_date, - max_group_timestamp, - max_real_bene_cnt, - max_synth_bene_cnt, - max_crosswalk_real_bene_count, - max_crosswalk_synthetic_bene_count, - max_crosswalk_table_count, - max_crosswalk_archived_table_count, - max_grant_real_bene_count, - max_grant_synthetic_bene_count, - max_grant_table_count, - max_grant_archived_table_count, - max_grant_real_bene_deduped_count, - max_grant_synthetic_bene_deduped_count, - max_grantarchived_real_bene_deduped_count, - max_grantarchived_synthetic_bene_deduped_count, - max_grant_and_archived_real_bene_deduped_count, - max_grant_and_archived_synthetic_bene_deduped_count, - max_token_real_bene_deduped_count, - max_token_synthetic_bene_deduped_count, - max_token_table_count, - max_token_archived_table_count, - max_global_apps_active_cnt, - max_global_apps_inactive_cnt, - max_global_apps_require_demographic_scopes_cnt, - max_global_developer_count, - max_global_developer_distinct_organization_name_count, - max_global_developer_with_first_api_call_count, - max_global_developer_with_registered_app_count - ORDER BY - start_date ASC -), - -v1_fhir_events AS ( - select - time_of_event, - path, - fhir_id, - req_qparam_lastupdated - from - perf_mon_events - WHERE - ( - type = 'request_response_middleware' - and vpc = '${ENV}' - and request_method = 'GET' - and path LIKE '/v1/fhir%' - and response_code = 200 - AND - app_name NOT IN ('TestApp', 'BlueButton Client (Test - Internal Use Only)', - 'MyMedicare PROD', 'new-relic') - ) -), - -v2_fhir_events AS ( - select - time_of_event, - path, - fhir_id, - req_qparam_lastupdated - from - perf_mon_events - WHERE - ( - type = 'request_response_middleware' - and vpc = '${ENV}' - and request_method = 'GET' - and path LIKE '/v2/fhir%' - and response_code = 200 - AND - app_name NOT IN ('TestApp', 'BlueButton Client (Test - Internal Use Only)', - 'MyMedicare PROD', 'new-relic') - ) -), - -auth_events AS ( - select - time_of_event, - auth_require_demographic_scopes, - auth_crosswalk_action, - auth_share_demographic_scopes, - auth_status, - share_demographic_scopes, - allow, - json_extract(user, '$$.crosswalk.fhir_id') as fhir_id - from - perf_mon_events - WHERE - ( - type = 'Authorization' - and vpc = '${ENV}' - AND - auth_app_name NOT IN ('TestApp', 'BlueButton Client (Test - Internal Use Only)', - 'MyMedicare PROD', 'new-relic') - ) -) - - -SELECT - t0.*, - ( - total_crosswalk_real_bene - app_all_grant_real_bene - ) diff_total_crosswalk_vs_grant_and_archived_real_bene, - ( - total_crosswalk_synthetic_bene - app_all_grant_synthetic_bene - ) diff_total_crosswalk_vs_grant_and_archived_synthetic_bene, - - /* V1 FHIR resource stats top level */ - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_call_real_count') - AND - try_cast(fhir_id as BIGINT) > 0 - ) - ) as fhir_v1_call_real_count, - - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_call_synthetic_count') - and try_cast(fhir_id as BIGINT) < 0 - ) - ) as fhir_v1_call_synthetic_count, - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_eob_call_real_count') - and path LIKE '/v1/fhir/ExplanationOfBenefit%' - and try_cast(fhir_id as BIGINT) > 0 - ) - ) as fhir_v1_eob_call_real_count, - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_eob_call_synthetic_count') - and path LIKE '/v1/fhir/ExplanationOfBenefit%' - and try_cast(fhir_id as BIGINT) < 0 - ) - ) as fhir_v1_eob_call_synthetic_count, - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_coverage_call_real_count') - and path LIKE '/v1/fhir/Coverage%' - and try_cast(fhir_id as BIGINT) > 0 - ) - ) as fhir_v1_coverage_call_real_count, - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_coverage_call_synthetic_count') - and path LIKE '/v1/fhir/Coverage%' - and try_cast(fhir_id as BIGINT) < 0 - ) - ) as fhir_v1_coverage_call_synthetic_count, - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_patient_call_real_count') - and path LIKE '/v1/fhir/Patient%' - and try_cast(fhir_id as BIGINT) > 0 - ) - ) as fhir_v1_patient_call_real_count, - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_patient_call_synthetic_count') - and path LIKE '/v1/fhir/Patient%' - and try_cast(fhir_id as BIGINT) < 0 - ) - ) as fhir_v1_patient_call_synthetic_count, - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_metadata_call_count') - and path LIKE '/v1/fhir/metadata%' - ) - ) as fhir_v1_metadata_call_count, - /* V1 since (lastUpdated) stats top level */ - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_eob_since_call_real_count') - and path LIKE '/v1/fhir/ExplanationOfBenefit%' - and try_cast(fhir_id as BIGINT) > 0 - and req_qparam_lastupdated != '' - ) - ) as fhir_v1_eob_since_call_real_count, - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_eob_since_call_synthetic_count') - and path LIKE '/v1/fhir/ExplanationOfBenefit%' - and try_cast(fhir_id as BIGINT) < 0 - and req_qparam_lastupdated != '' - ) - ) as fhir_v1_eob_since_call_synthetic_count, - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_coverage_since_call_real_count') - and path LIKE '/v1/fhir/Coverage%' - and try_cast(fhir_id as BIGINT) > 0 - and req_qparam_lastupdated != '' - ) - ) as fhir_v1_coverage_since_call_real_count, - ( - select - count(*) - from - v1_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v1_coverage_since_call_synthetic_count') - and path LIKE '/v1/fhir/Coverage%' - and try_cast(fhir_id as BIGINT) < 0 - and req_qparam_lastupdated != '' - ) - ) as fhir_v1_coverage_since_call_synthetic_count, - /* V2 FHIR resource stats top level */ - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_call_real_count') - and try_cast(fhir_id as BIGINT) > 0 - ) - ) as fhir_v2_call_real_count, - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_call_synthetic_count') - and try_cast(fhir_id as BIGINT) < 0 - ) - ) as fhir_v2_call_synthetic_count, - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_eob_call_real_count') - and path LIKE '/v2/fhir/ExplanationOfBenefit%' - and try_cast(fhir_id as BIGINT) > 0 - ) - ) as fhir_v2_eob_call_real_count, - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_eob_call_synthetic_count') - and path LIKE '/v2/fhir/ExplanationOfBenefit%' - and try_cast(fhir_id as BIGINT) < 0 - ) - ) as fhir_v2_eob_call_synthetic_count, - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_coverage_call_real_count') - and path LIKE '/v2/fhir/Coverage%' - and try_cast(fhir_id as BIGINT) > 0 - ) - ) as fhir_v2_coverage_call_real_count, - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_coverage_call_synthetic_count') - and path LIKE '/v2/fhir/Coverage%' - and try_cast(fhir_id as BIGINT) < 0 - ) - ) as fhir_v2_coverage_call_synthetic_count, - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_patient_call_real_count') - and path LIKE '/v2/fhir/Patient%' - and try_cast(fhir_id as BIGINT) > 0 - ) - ) as fhir_v2_patient_call_real_count, - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_patient_call_synthetic_count') - and path LIKE '/v2/fhir/Patient%' - and try_cast(fhir_id as BIGINT) < 0 - ) - ) as fhir_v2_patient_call_synthetic_count, - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_metadata_call_count') - and path LIKE '/v2/fhir/metadata%' - ) - ) as fhir_v2_metadata_call_count, - /* V2 since (lastUpdated) stats top level */ - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_eob_since_call_real_count') - and path LIKE '/v2/fhir/ExplanationOfBenefit%' - and try_cast(fhir_id as BIGINT) > 0 - and req_qparam_lastupdated != '' - ) - ) as fhir_v2_eob_since_call_real_count, - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_eob_since_call_synthetic_count') - and path LIKE '/v2/fhir/ExplanationOfBenefit%' - and try_cast(fhir_id as BIGINT) < 0 - and req_qparam_lastupdated != '' - ) - ) as fhir_v2_eob_since_call_synthetic_count, - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_coverage_since_call_real_count') - and path LIKE '/v2/fhir/Coverage%' - and try_cast(fhir_id as BIGINT) > 0 - and req_qparam_lastupdated != '' - ) - ) as fhir_v2_coverage_since_call_real_count, - ( - select - count(*) - from - v2_fhir_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'fhir_v2_coverage_since_call_synthetic_count') - and path LIKE '/v2/fhir/Coverage%' - and try_cast(fhir_id as BIGINT) < 0 - and req_qparam_lastupdated != '' - ) - ) as fhir_v2_coverage_since_call_synthetic_count, - /* AUTH and demographic scopes stats top level */ - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_ok_real_bene_count') - and try_cast(fhir_id as BIGINT) > 0 - and auth_status = 'OK' - and allow = True - ) - ) as auth_ok_real_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_ok_synthetic_bene_count') - and try_cast(fhir_id as BIGINT) < 0 - and auth_status = 'OK' - and allow = True - ) - ) as auth_ok_synthetic_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_fail_or_deny_real_bene_count') - and try_cast(fhir_id as BIGINT) > 0 - and auth_status = 'FAIL' - ) - ) as auth_fail_or_deny_real_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_fail_or_deny_synthetic_bene_count') - and try_cast(fhir_id as BIGINT) < 0 - and auth_status = 'FAIL' - ) - ) as auth_fail_or_deny_synthetic_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_demoscope_required_choice_sharing_real_bene_count') - and try_cast(fhir_id as BIGINT) > 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'True' - and share_demographic_scopes = 'True' - ) - ) as auth_demoscope_required_choice_sharing_real_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_demoscope_required_choice_sharing_synthetic_bene_count') - and try_cast(fhir_id as BIGINT) < 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'True' - and share_demographic_scopes = 'True' - ) - ) as auth_demoscope_required_choice_sharing_synthetic_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_demoscope_required_choice_not_sharing_real_bene_count') - and try_cast(fhir_id as BIGINT) > 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'True' - and share_demographic_scopes = 'False' - ) - ) as auth_demoscope_required_choice_not_sharing_real_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_demoscope_required_choice_not_sharing_synthetic_bene_count') - and try_cast(fhir_id as BIGINT) < 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'True' - and share_demographic_scopes = 'False' - ) - ) as auth_demoscope_required_choice_not_sharing_synthetic_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_demoscope_required_choice_deny_real_bene_count') - and try_cast(fhir_id as BIGINT) > 0 - and allow = False - and auth_require_demographic_scopes = 'True' - ) - ) as auth_demoscope_required_choice_deny_real_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_demoscope_required_choice_deny_synthetic_bene_count') - and try_cast(fhir_id as BIGINT) < 0 - and allow = False - and auth_require_demographic_scopes = 'True' - ) - ) as auth_demoscope_required_choice_deny_synthetic_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_demoscope_not_required_not_sharing_real_bene_count') - and try_cast(fhir_id as BIGINT) > 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'False' - ) - ) as auth_demoscope_not_required_not_sharing_real_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_demoscope_not_required_not_sharing_synthetic_bene_count') - and try_cast(fhir_id as BIGINT) < 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'False' - ) - ) as auth_demoscope_not_required_not_sharing_synthetic_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_demoscope_not_required_deny_real_bene_count') - and try_cast(fhir_id as BIGINT) > 0 - and allow = False - and auth_require_demographic_scopes = 'False' - ) - ) as auth_demoscope_not_required_deny_real_bene_count, - ( - select - count(*) - from - auth_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'auth_demoscope_not_required_deny_synthetic_bene_count') - and try_cast(fhir_id as BIGINT) < 0 - and allow = False - and auth_require_demographic_scopes = 'False' - ) - ) as auth_demoscope_not_required_deny_synthetic_bene_count, - ( - select - count(*) - from - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'sdk_requests_python_count') - AND req_header_bluebutton_sdk = 'python' - ) - ) as sdk_requests_python_count, - ( - select - count(*) - from - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'sdk_requests_node_count') - AND req_header_bluebutton_sdk = 'python' - ) - ) as sdk_requests_node_count - -FROM - ( - SELECT - * - FROM global_state_metrics_per_app_for_max_group_timestamp - ) t0 - - LEFT JOIN - ( - SELECT - * - FROM global_state_metrics_for_max_group_timestamp - ) t1 - ON t1.max_group_timestamp = t0.max_group_timestamp diff --git a/insights/lambdas/update_athena_metric_tables/sql_templates/template_generate_per_app_metrics_for_report_date.sql b/insights/lambdas/update_athena_metric_tables/sql_templates/template_generate_per_app_metrics_for_report_date.sql deleted file mode 100644 index d979bb4c1..000000000 --- a/insights/lambdas/update_athena_metric_tables/sql_templates/template_generate_per_app_metrics_for_report_date.sql +++ /dev/null @@ -1,2273 +0,0 @@ -/* Report metrics to applications table entry for Quicksight Dashboard use */ -WITH report_params AS ( - /* Report parameters - Generates metrics between start/end dates */ - SELECT - '${ENV}' as vpc, - CAST('${START_DATE}' as Date) as start_date, - CAST('${END_DATE}' as Date) as end_date, - CAST('${REPORT_DATE}' as Date) as report_date, - /* List of metrics to enable. - NOTE: To greatly speed up development and testing of new metrics, - this list can be used to select only metrics - being worked on. - */ - ARRAY [ - 'app_fhir_v1_call_real_count', - 'app_fhir_v1_call_synthetic_count', - 'app_fhir_v1_eob_call_real_count', - 'app_fhir_v1_eob_call_synthetic_count', - 'app_fhir_v1_coverage_call_real_count', - 'app_fhir_v1_coverage_call_synthetic_count', - 'app_fhir_v1_patient_call_real_count', - 'app_fhir_v1_patient_call_synthetic_count', - 'app_fhir_v1_metadata_call_count', - 'app_fhir_v1_eob_since_call_real_count', - 'app_fhir_v1_eob_since_call_synthetic_count', - 'app_fhir_v1_coverage_since_call_real_count', - 'app_fhir_v1_coverage_since_call_synthetic_count', - 'app_fhir_v2_call_real_count', - 'app_fhir_v2_call_synthetic_count', - 'app_fhir_v2_eob_call_real_count', - 'app_fhir_v2_eob_call_synthetic_count', - 'app_fhir_v2_coverage_call_real_count', - 'app_fhir_v2_coverage_call_synthetic_count', - 'app_fhir_v2_patient_call_real_count', - 'app_fhir_v2_patient_call_synthetic_count', - 'app_fhir_v2_metadata_call_count', - 'app_fhir_v2_eob_since_call_real_count', - 'app_fhir_v2_eob_since_call_synthetic_count', - 'app_fhir_v2_coverage_since_call_real_count', - 'app_fhir_v2_coverage_since_call_synthetic_count', - 'app_auth_ok_real_bene_count', - 'app_auth_ok_synthetic_bene_count', - 'app_auth_ok_real_bene_distinct_count', - 'app_auth_ok_synthetic_bene_distinct_count', - 'app_auth_fail_or_deny_real_bene_count', - 'app_auth_fail_or_deny_synthetic_bene_count', - 'app_auth_fail_or_deny_real_bene_distinct_count', - 'app_auth_fail_or_deny_synthetic_bene_distinct_count', - 'app_auth_demoscope_required_choice_sharing_real_bene_count', - 'app_auth_demoscope_required_choice_sharing_synthetic_bene_count', - 'app_auth_demoscope_required_choice_not_sharing_real_bene_count', - 'app_auth_demoscope_required_choice_not_sharing_synthetic_bene_count', - 'app_auth_demoscope_required_choice_deny_real_bene_count', - 'app_auth_demoscope_required_choice_deny_synthetic_bene_count', - 'app_auth_demoscope_not_required_not_sharing_real_bene_count', - 'app_auth_demoscope_not_required_not_sharing_synthetic_bene_count', - 'app_auth_demoscope_not_required_deny_real_bene_count', - 'app_auth_demoscope_not_required_deny_synthetic_bene_count', - 'app_token_refresh_for_real_bene_count', - 'app_token_refresh_for_synthetic_bene_count', - 'app_token_authorization_code_for_real_bene_count', - 'app_token_authorization_code_for_synthetic_bene_count', - 'app_token_refresh_response_2xx_count', - 'app_token_refresh_response_4xx_count', - 'app_token_refresh_response_5xx_count', - 'app_token_authorization_code_2xx_count', - 'app_token_authorization_code_4xx_count', - 'app_token_authorization_code_5xx_count', - 'app_authorize_initial_count', - 'app_medicare_login_redirect_ok_count', - 'app_medicare_login_redirect_fail_count', - 'app_authentication_start_ok_count', - 'app_authentication_start_fail_count', - 'app_authentication_matched_new_bene_real_count', - 'app_authentication_matched_new_bene_synthetic_count', - 'app_authentication_matched_returning_bene_real_count', - 'app_authentication_matched_returning_bene_synthetic_count', - 'app_sls_callback_ok_real_count', - 'app_sls_callback_ok_synthetic_count', - 'app_sls_callback_fail_count', - 'app_approval_view_get_ok_real_count', - 'app_approval_view_get_ok_synthetic_count', - 'app_approval_view_get_fail_count', - 'app_approval_view_post_ok_real_count', - 'app_approval_view_post_ok_synthetic_count', - 'app_approval_view_post_fail_count', - 'app_sdk_requests_python_count', - 'app_sdk_requests_node_count' - ] as enabled_metrics_list -), - -/* All perf_mon application log events. Is a base for other sub-queries - NOTE: This includes the report_date for getting at the max(group_timestamp) */ -perf_mon_events_all AS ( - select - * - from - "bb2"."events_${ENV}_perf_mon" - WHERE - ( - vpc = ( - select - vpc - FROM - report_params - ) - and cast("from_iso8601_timestamp"(time_of_event) AS date) >= ( - select - start_date - FROM - report_params - ) - and cast("from_iso8601_timestamp"(time_of_event) AS date) <= ( - select - report_date - FROM - report_params - ) - /* - Restricting select by partitions. - NOTE: This significantly speeds up the SQL! - */ - AND ${PARTITION_LIMIT_SQL} - ) -), - -/* Find the max(group_timestamp) from - nightly global state per application events - - NOTE: We are wanting the entries that get logged - on the actual report_date vs. other metrics to - just include <= end_date. -*/ -max_group_timestamp AS ( - SELECT - max(group_timestamp) as max_group_timestamp - FROM - perf_mon_events_all - WHERE - type = 'global_state_metrics_per_app' -), -perf_mon_events AS ( - select - * - from - perf_mon_events_all - WHERE - cast("from_iso8601_timestamp"(time_of_event) AS date) <= ( - select - end_date - FROM - report_params - ) -), - -request_response_middleware_events AS ( - select - *, - json_extract(user, '$$.crosswalk.fhir_id') as crosswalk_fhir_id - from - perf_mon_events - WHERE - ( - type = 'request_response_middleware' - AND - ( path LIKE '/v%/o/authorize%' - OR path = '/mymedicare/login' - OR path = '/mymedicare/sls-callback' - OR path LIKE '/v1/fhir%' - OR path LIKE '/v2/fhir%' - OR path LIKE '/v%/o/token%/' - ) - ) -), - -api_audit_events AS ( - select - *, - json_extract(user, '$$.crosswalk.fhir_id') as crosswalk_fhir_id - from - perf_mon_events - WHERE - ( - type = 'Authentication:start' - OR type = 'Authentication:success' - OR type = 'Authorization' - OR type = 'AccessToken' - ) -), - -/* Select all application names and metrics from - nightly global state per application events -*/ -applications_state_metrics AS ( - SELECT - * - /* - DISTINCT name app_name, - group_timestamp max_group_timestamp, - */ - FROM - perf_mon_events_all - WHERE - type = 'global_state_metrics_per_app' - AND - group_timestamp = ( - select - max_group_timestamp - FROM - max_group_timestamp - ) - AND - name NOT IN ('TestApp', 'BlueButton Client (Test - Internal Use Only)', - 'MyMedicare PROD', 'new-relic') -), -/* Select all top level global state metrics from - nightly global state event -*/ -global_state_metrics_for_max_group_timestamp AS ( - SELECT - group_timestamp max_group_timestamp, - real_bene_cnt max_real_bene_cnt, - synth_bene_cnt max_synth_bene_cnt, - crosswalk_real_bene_count max_crosswalk_real_bene_count, - crosswalk_synthetic_bene_count max_crosswalk_synthetic_bene_count, - crosswalk_table_count max_crosswalk_table_count, - crosswalk_archived_table_count max_crosswalk_archived_table_count, - grant_real_bene_count max_grant_real_bene_count, - grant_synthetic_bene_count max_grant_synthetic_bene_count, - grant_table_count max_grant_table_count, - grant_archived_table_count max_grant_archived_table_count, - grant_real_bene_deduped_count max_grant_real_bene_deduped_count, - grant_synthetic_bene_deduped_count max_grant_synthetic_bene_deduped_count, - grantarchived_real_bene_deduped_count max_grantarchived_real_bene_deduped_count, - grantarchived_synthetic_bene_deduped_count max_grantarchived_synthetic_bene_deduped_count, - grant_and_archived_real_bene_deduped_count max_grant_and_archived_real_bene_deduped_count, - grant_and_archived_synthetic_bene_deduped_count max_grant_and_archived_synthetic_bene_deduped_count, - token_real_bene_deduped_count max_token_real_bene_deduped_count, - token_synthetic_bene_deduped_count max_token_synthetic_bene_deduped_count, - token_table_count max_token_table_count, - token_archived_table_count max_token_archived_table_count, - global_apps_active_cnt max_global_apps_active_cnt, - global_apps_inactive_cnt max_global_apps_inactive_cnt, - global_apps_require_demographic_scopes_cnt max_global_apps_require_demographic_scopes_cnt, - global_developer_count max_global_developer_count, - global_developer_distinct_organization_name_count max_global_developer_distinct_organization_name_count, - global_developer_with_first_api_call_count max_global_developer_with_first_api_call_count, - global_developer_with_registered_app_count max_global_developer_with_registered_app_count - FROM - perf_mon_events_all - WHERE - type = 'global_state_metrics' - AND - group_timestamp = ( - select - max_group_timestamp - FROM - max_group_timestamp - ) -) - -SELECT - '${ENV}' as vpc, - CAST('${START_DATE}' as Date) as start_date, - CAST('${END_DATE}' as Date) as end_date, - CAST('${REPORT_DATE}' as Date) as report_date, - t0.group_timestamp max_group_timestamp, - - t9999.max_real_bene_cnt, - t9999.max_synth_bene_cnt, - t9999.max_crosswalk_real_bene_count, - t9999.max_crosswalk_synthetic_bene_count, - t9999.max_crosswalk_table_count, - t9999.max_crosswalk_archived_table_count, - t9999.max_grant_real_bene_count, - t9999.max_grant_synthetic_bene_count, - t9999.max_grant_table_count, - t9999.max_grant_archived_table_count, - t9999.max_grant_real_bene_deduped_count, - t9999.max_grant_synthetic_bene_deduped_count, - t9999.max_grantarchived_real_bene_deduped_count, - t9999.max_grantarchived_synthetic_bene_deduped_count, - t9999.max_grant_and_archived_real_bene_deduped_count, - t9999.max_grant_and_archived_synthetic_bene_deduped_count, - t9999.max_token_real_bene_deduped_count, - t9999.max_token_synthetic_bene_deduped_count, - t9999.max_token_table_count, - t9999.max_token_archived_table_count, - t9999.max_global_apps_active_cnt, - t9999.max_global_apps_inactive_cnt, - t9999.max_global_apps_require_demographic_scopes_cnt, - t9999.max_global_developer_count, - t9999.max_global_developer_distinct_organization_name_count, - t9999.max_global_developer_with_first_api_call_count, - t9999.max_global_developer_with_registered_app_count, - - t0.name app_name, - t0.id app_id, - t0.created app_created, - t0.updated app_updated, - t0.active app_active, - t0.first_active app_first_active, - t0.last_active app_last_active, - t0.require_demographic_scopes app_require_demographic_scopes, - t0.user_organization app_user_organization, - t0.user_id app_user_id, - t0.user_username app_user_username, - t0.user_date_joined app_user_date_joined, - t0.user_last_login app_user_last_login, - t0.real_bene_cnt app_real_bene_cnt, - t0.synth_bene_cnt app_synth_bene_cnt, - t0.grant_real_bene_count app_grant_real_bene_count, - t0.grant_synthetic_bene_count app_grant_synthetic_bene_count, - t0.grant_table_count app_grant_table_count, - t0.grant_archived_table_count app_grant_archived_table_count, - t0.grantarchived_real_bene_deduped_count app_grantarchived_real_bene_deduped_count, - t0.grantarchived_synthetic_bene_deduped_count app_grantarchived_synthetic_bene_deduped_count, - t0.grant_and_archived_real_bene_deduped_count app_grant_and_archived_real_bene_deduped_count, - t0.grant_and_archived_synthetic_bene_deduped_count app_grant_and_archived_synthetic_bene_deduped_count, - t0.token_real_bene_count app_token_real_bene_count, - t0.token_synthetic_bene_count app_token_synthetic_bene_count, - t0.token_table_count app_token_table_count, - t0.token_archived_table_count app_token_archived_table_count, - - /* FHIR V1 per application */ - COALESCE(t1.app_fhir_v1_call_real_count, 0) - app_fhir_v1_call_real_count, - COALESCE(t2.app_fhir_v1_call_synthetic_count, 0) - app_fhir_v1_call_synthetic_count, - COALESCE(t3.app_fhir_v1_eob_call_real_count, 0) - app_fhir_v1_eob_call_real_count, - COALESCE(t4.app_fhir_v1_eob_call_synthetic_count, 0) - app_fhir_v1_eob_call_synthetic_count, - COALESCE(t5.app_fhir_v1_coverage_call_real_count, 0) - app_fhir_v1_coverage_call_real_count, - COALESCE(t6.app_fhir_v1_coverage_call_synthetic_count, 0) - app_fhir_v1_coverage_call_synthetic_count, - COALESCE(t7.app_fhir_v1_patient_call_real_count, 0) - app_fhir_v1_patient_call_real_count, - COALESCE(t8.app_fhir_v1_patient_call_synthetic_count, 0) - app_fhir_v1_patient_call_synthetic_count, - COALESCE(t9.app_fhir_v1_metadata_call_count, 0) - app_fhir_v1_metadata_call_count, - COALESCE(t10.app_fhir_v1_eob_since_call_real_count, 0) - app_fhir_v1_eob_since_call_real_count, - COALESCE(t11.app_fhir_v1_eob_since_call_synthetic_count, 0) - app_fhir_v1_eob_since_call_synthetic_count, - COALESCE(t12.app_fhir_v1_coverage_since_call_real_count, 0) - app_fhir_v1_coverage_since_call_real_count, - COALESCE(t13.app_fhir_v1_coverage_since_call_synthetic_count, 0) - app_fhir_v1_coverage_since_call_synthetic_count, - - /* FHIR V2 per application */ - COALESCE(t21.app_fhir_v2_call_real_count, 0) - app_fhir_v2_call_real_count, - COALESCE(t22.app_fhir_v2_call_synthetic_count, 0) - app_fhir_v2_call_synthetic_count, - COALESCE(t23.app_fhir_v2_eob_call_real_count, 0) - app_fhir_v2_eob_call_real_count, - COALESCE(t24.app_fhir_v2_eob_call_synthetic_count, 0) - app_fhir_v2_eob_call_synthetic_count, - COALESCE(t25.app_fhir_v2_coverage_call_real_count, 0) - app_fhir_v2_coverage_call_real_count, - COALESCE(t26.app_fhir_v2_coverage_call_synthetic_count, 0) - app_fhir_v2_coverage_call_synthetic_count, - COALESCE(t27.app_fhir_v2_patient_call_real_count, 0) - app_fhir_v2_patient_call_real_count, - COALESCE(t28.app_fhir_v2_patient_call_synthetic_count, 0) - app_fhir_v2_patient_call_synthetic_count, - COALESCE(t29.app_fhir_v2_metadata_call_count, 0) - app_fhir_v2_metadata_call_count, - COALESCE(t30.app_fhir_v2_eob_since_call_real_count, 0) - app_fhir_v2_eob_since_call_real_count, - COALESCE(t31.app_fhir_v2_eob_since_call_synthetic_count, 0) - app_fhir_v2_eob_since_call_synthetic_count, - COALESCE(t32.app_fhir_v2_coverage_since_call_real_count, 0) - app_fhir_v2_coverage_since_call_real_count, - COALESCE(t33.app_fhir_v2_coverage_since_call_synthetic_count, 0) - app_fhir_v2_coverage_since_call_synthetic_count, - - /* AUTH per applicaiton */ - COALESCE(t101.app_auth_ok_real_bene_count, 0) - app_auth_ok_real_bene_count, - COALESCE(t102.app_auth_ok_synthetic_bene_count, 0) - app_auth_ok_synthetic_bene_count, - COALESCE(t103.app_auth_ok_real_bene_distinct_count, 0) - app_auth_ok_real_bene_distinct_count, - COALESCE(t104.app_auth_ok_synthetic_bene_distinct_count, 0) - app_auth_ok_synthetic_bene_distinct_count, - - COALESCE(t105.app_auth_fail_or_deny_real_bene_count, 0) - app_auth_fail_or_deny_real_bene_count, - COALESCE(t106.app_auth_fail_or_deny_synthetic_bene_count, 0) - app_auth_fail_or_deny_synthetic_bene_count, - COALESCE(t107.app_auth_fail_or_deny_real_bene_distinct_count, 0) - app_auth_fail_or_deny_real_bene_distinct_count, - COALESCE(t108.app_auth_fail_or_deny_synthetic_bene_distinct_count, 0) - app_auth_fail_or_deny_synthetic_bene_distinct_count, - - COALESCE(t109.app_auth_demoscope_required_choice_sharing_real_bene_count, 0) - app_auth_demoscope_required_choice_sharing_real_bene_count, - COALESCE(t110.app_auth_demoscope_required_choice_sharing_synthetic_bene_count, 0) - app_auth_demoscope_required_choice_sharing_synthetic_bene_count, - COALESCE(t111.app_auth_demoscope_required_choice_not_sharing_real_bene_count, 0) - app_auth_demoscope_required_choice_not_sharing_real_bene_count, - COALESCE(t112.app_auth_demoscope_required_choice_not_sharing_synthetic_bene_count, 0) - app_auth_demoscope_required_choice_not_sharing_synthetic_bene_count, - COALESCE(t113.app_auth_demoscope_required_choice_deny_real_bene_count, 0) - app_auth_demoscope_required_choice_deny_real_bene_count, - COALESCE(t114.app_auth_demoscope_required_choice_deny_synthetic_bene_count, 0) - app_auth_demoscope_required_choice_deny_synthetic_bene_count, - COALESCE(t115.app_auth_demoscope_not_required_not_sharing_real_bene_count, 0) - app_auth_demoscope_not_required_not_sharing_real_bene_count, - COALESCE(t116.app_auth_demoscope_not_required_not_sharing_synthetic_bene_count, 0) - app_auth_demoscope_not_required_not_sharing_synthetic_bene_count, - COALESCE(t117.app_auth_demoscope_not_required_deny_real_bene_count, 0) - app_auth_demoscope_not_required_deny_real_bene_count, - COALESCE(t118.app_auth_demoscope_not_required_deny_synthetic_bene_count, 0) - app_auth_demoscope_not_required_deny_synthetic_bene_count, - - - COALESCE(t200.app_token_refresh_for_real_bene_count, 0) - app_token_refresh_for_real_bene_count, - COALESCE(t201.app_token_refresh_for_synthetic_bene_count, 0) - app_token_refresh_for_synthetic_bene_count, - COALESCE(t202.app_token_authorization_code_for_real_bene_count, 0) - app_token_authorization_code_for_real_bene_count, - COALESCE(t203.app_token_authorization_code_for_synthetic_bene_count, 0) - app_token_authorization_code_for_synthetic_bene_count, - COALESCE(t204.app_token_refresh_response_2xx_count, 0) - app_token_refresh_response_2xx_count, - COALESCE(t205.app_token_refresh_response_4xx_count, 0) - app_token_refresh_response_4xx_count, - COALESCE(t206.app_token_refresh_response_5xx_count, 0) - app_token_refresh_response_5xx_count, - COALESCE(t207.app_token_authorization_code_2xx_count, 0) - app_token_authorization_code_2xx_count, - COALESCE(t208.app_token_authorization_code_4xx_count, 0) - app_token_authorization_code_4xx_count, - COALESCE(t209.app_token_authorization_code_5xx_count, 0) - app_token_authorization_code_5xx_count, - COALESCE(t210.app_authorize_initial_count, 0) - app_authorize_initial_count, - COALESCE(t211.app_medicare_login_redirect_ok_count, 0) - app_medicare_login_redirect_ok_count, - COALESCE(t212.app_medicare_login_redirect_fail_count, 0) - app_medicare_login_redirect_fail_count, - COALESCE(t213.app_authentication_start_ok_count, 0) - app_authentication_start_ok_count, - COALESCE(t214.app_authentication_start_fail_count, 0) - app_authentication_start_fail_count, - COALESCE(t215.app_authentication_matched_new_bene_real_count, 0) - app_authentication_matched_new_bene_real_count, - COALESCE(t216.app_authentication_matched_new_bene_synthetic_count, 0) - app_authentication_matched_new_bene_synthetic_count, - COALESCE(t217.app_authentication_matched_returning_bene_real_count, 0) - app_authentication_matched_returning_bene_real_count, - COALESCE(t218.app_authentication_matched_returning_bene_synthetic_count, 0) - app_authentication_matched_returning_bene_synthetic_count, - COALESCE(t219.app_sls_callback_ok_real_count, 0) - app_sls_callback_ok_real_count, - COALESCE(t220.app_sls_callback_ok_synthetic_count, 0) - app_sls_callback_ok_synthetic_count, - COALESCE(t221.app_sls_callback_fail_count, 0) - app_sls_callback_fail_count, - COALESCE(t222.app_approval_view_get_ok_real_count, 0) - app_approval_view_get_ok_real_count, - COALESCE(t223.app_approval_view_get_ok_synthetic_count, 0) - app_approval_view_get_ok_synthetic_count, - COALESCE(t224.app_approval_view_get_fail_count, 0) - app_approval_view_get_fail_count, - COALESCE(t225.app_approval_view_post_ok_real_count, 0) - app_approval_view_post_ok_real_count, - COALESCE(t226.app_approval_view_post_ok_synthetic_count, 0) - app_approval_view_post_ok_synthetic_count, - COALESCE(t227.app_approval_view_post_fail_count, 0) - app_approval_view_post_fail_count, - COALESCE(t228.app_sdk_requests_python_count, 0) - app_sdk_requests_python_count, - COALESCE(t229.app_sdk_requests_node_count, 0) - app_sdk_requests_node_count - -FROM - ( - SELECT - * - FROM applications_state_metrics - ) t0 - - LEFT JOIN - ( - SELECT - * - FROM global_state_metrics_for_max_group_timestamp - ) t9999 ON t9999.max_group_timestamp = t0.group_timestamp - - /* V1 FHIR resource stats per application */ - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_call_real_count') - - AND path LIKE '/v1/fhir%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t1 ON t1.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_call_synthetic_count') - - AND path LIKE '/v1/fhir%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t2 ON t2.app_name = t0.name - - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_eob_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_eob_call_real_count') - - AND path LIKE '/v1/fhir/ExplanationOfBenefit%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t3 ON t3.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_eob_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_eob_call_synthetic_count') - - AND path LIKE '/v1/fhir/ExplanationOfBenefit%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t4 ON t4.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_coverage_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_coverage_call_real_count') - - AND path LIKE '/v1/fhir/Coverage%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t5 ON t5.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_coverage_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_coverage_call_synthetic_count') - - AND path LIKE '/v1/fhir/Coverage%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t6 ON t6.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_patient_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_patient_call_real_count') - - AND path LIKE '/v1/fhir/Patient%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t7 ON t7.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_patient_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_patient_call_synthetic_count') - - AND path LIKE '/v1/fhir/Patient%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t8 ON t8.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_metadata_call_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_metadata_call_count') - - AND path LIKE '/v1/fhir/metadata%' - AND request_method = 'GET' - AND response_code = 200 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t9 ON t9.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_eob_since_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_eob_since_call_real_count') - - AND path LIKE '/v1/fhir/ExplanationOfBenefit%' - AND req_qparam_lastupdated != '' - - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t10 ON t10.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_eob_since_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_eob_since_call_synthetic_count') - - AND path LIKE '/v1/fhir/ExplanationOfBenefit%' - AND req_qparam_lastupdated != '' - - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t11 ON t11.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_coverage_since_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_coverage_since_call_real_count') - - AND path LIKE '/v1/fhir/Coverage%' - AND req_qparam_lastupdated != '' - - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t12 ON t12.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v1_coverage_since_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v1_coverage_since_call_synthetic_count') - - AND path LIKE '/v1/fhir/Coverage%' - AND req_qparam_lastupdated != '' - - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t13 ON t13.app_name = t0.name - - - /* V2 FHIR resource stats per application */ - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_call_real_count') - - AND path LIKE '/v2/fhir%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t21 ON t21.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_call_synthetic_count') - - AND path LIKE '/v2/fhir%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t22 ON t22.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_eob_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_eob_call_real_count') - - AND path LIKE '/v2/fhir/ExplanationOfBenefit%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t23 ON t23.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_eob_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_eob_call_synthetic_count') - - AND path LIKE '/v2/fhir/ExplanationOfBenefit%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t24 ON t24.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_coverage_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_coverage_call_real_count') - - AND path LIKE '/v2/fhir/Coverage%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t25 ON t25.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_coverage_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_coverage_call_synthetic_count') - - AND path LIKE '/v2/fhir/Coverage%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t26 ON t26.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_patient_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_patient_call_real_count') - - AND path LIKE '/v2/fhir/Patient%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t27 ON t27.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_patient_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_patient_call_synthetic_count') - - AND path LIKE '/v2/fhir/Patient%' - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t28 ON t28.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_metadata_call_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_metadata_call_count') - - AND path LIKE '/v2/fhir/metadata%' - AND request_method = 'GET' - AND response_code = 200 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t29 ON t29.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_eob_since_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_eob_since_call_real_count') - - AND path LIKE '/v2/fhir/ExplanationOfBenefit%' - AND req_qparam_lastupdated != '' - - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t30 ON t30.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_eob_since_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_eob_since_call_synthetic_count') - - AND path LIKE '/v2/fhir/ExplanationOfBenefit%' - AND req_qparam_lastupdated != '' - - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t31 ON t31.app_name = t0.name - - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_coverage_since_call_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_coverage_since_call_real_count') - - AND path LIKE '/v2/fhir/Coverage%' - AND req_qparam_lastupdated != '' - - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t32 ON t32.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_fhir_v2_coverage_since_call_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_fhir_v2_coverage_since_call_synthetic_count') - - AND path LIKE '/v2/fhir/Coverage%' - AND req_qparam_lastupdated != '' - - AND request_method = 'GET' - AND response_code = 200 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t33 ON t33.app_name = t0.name - - /* AUTH per application */ - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_ok_real_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_ok_real_bene_count') - AND type = 'Authorization' - AND try_cast(crosswalk_fhir_id as BIGINT) > 0 - and auth_status = 'OK' - and allow = True - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t101 ON t101.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_ok_synthetic_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_ok_synthetic_bene_count') - AND type = 'Authorization' - AND try_cast(crosswalk_fhir_id as BIGINT) < 0 - and auth_status = 'OK' - and allow = True - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t102 ON t102.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(DISTINCT auth_uuid) as app_auth_ok_real_bene_distinct_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_ok_real_bene_distinct_count') - AND type = 'Authorization' - AND try_cast(crosswalk_fhir_id as BIGINT) > 0 - and auth_status = 'OK' - and allow = True - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t103 ON t103.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(DISTINCT auth_uuid) as app_auth_ok_synthetic_bene_distinct_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_ok_synthetic_bene_distinct_count') - AND type = 'Authorization' - AND try_cast(crosswalk_fhir_id as BIGINT) < 0 - and auth_status = 'OK' - and allow = True - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t104 ON t104.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_fail_or_deny_real_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_fail_or_deny_real_bene_count') - AND type = 'Authorization' - AND try_cast(crosswalk_fhir_id as BIGINT) > 0 - and auth_status = 'FAIL' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t105 ON t105.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_fail_or_deny_synthetic_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_fail_or_deny_synthetic_bene_count') - AND type = 'Authorization' - AND try_cast(crosswalk_fhir_id as BIGINT) < 0 - and auth_status = 'FAIL' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t106 ON t106.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(DISTINCT auth_uuid) as app_auth_fail_or_deny_real_bene_distinct_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_fail_or_deny_real_bene_distinct_count') - AND type = 'Authorization' - AND try_cast(crosswalk_fhir_id as BIGINT) > 0 - and auth_status = 'FAIL' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t107 ON t107.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(DISTINCT auth_uuid) as app_auth_fail_or_deny_synthetic_bene_distinct_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_fail_or_deny_synthetic_bene_distinct_count') - AND type = 'Authorization' - AND try_cast(crosswalk_fhir_id as BIGINT) < 0 - and auth_status = 'FAIL' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t108 ON t108.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_demoscope_required_choice_sharing_real_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_demoscope_required_choice_sharing_real_bene_count') - AND type = 'Authorization' - - AND try_cast(crosswalk_fhir_id as BIGINT) > 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'True' - and share_demographic_scopes = 'True' - - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t109 ON t109.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_demoscope_required_choice_sharing_synthetic_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_demoscope_required_choice_sharing_synthetic_bene_count') - AND type = 'Authorization' - - AND try_cast(crosswalk_fhir_id as BIGINT) < 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'True' - and share_demographic_scopes = 'True' - - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t110 ON t110.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_demoscope_required_choice_not_sharing_real_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_demoscope_required_choice_not_sharing_real_bene_count') - AND type = 'Authorization' - - AND try_cast(crosswalk_fhir_id as BIGINT) > 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'True' - and share_demographic_scopes = 'False' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t111 ON t111.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_demoscope_required_choice_not_sharing_synthetic_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_demoscope_required_choice_not_sharing_synthetic_bene_count') - AND type = 'Authorization' - - AND try_cast(crosswalk_fhir_id as BIGINT) < 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'True' - and share_demographic_scopes = 'False' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t112 ON t112.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_demoscope_required_choice_deny_real_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_demoscope_required_choice_deny_real_bene_count') - AND type = 'Authorization' - - AND try_cast(crosswalk_fhir_id as BIGINT) > 0 - and allow = False - and auth_require_demographic_scopes = 'True' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t113 ON t113.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_demoscope_required_choice_deny_synthetic_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_demoscope_required_choice_deny_synthetic_bene_count') - AND type = 'Authorization' - - AND try_cast(crosswalk_fhir_id as BIGINT) < 0 - and allow = False - and auth_require_demographic_scopes = 'True' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t114 ON t114.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_demoscope_not_required_not_sharing_real_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_demoscope_not_required_not_sharing_real_bene_count') - AND type = 'Authorization' - - AND try_cast(crosswalk_fhir_id as BIGINT) > 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'False' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t115 ON t115.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_demoscope_not_required_not_sharing_synthetic_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_demoscope_not_required_not_sharing_synthetic_bene_count') - AND type = 'Authorization' - - AND try_cast(crosswalk_fhir_id as BIGINT) < 0 - and auth_status = 'OK' - and allow = True - and auth_require_demographic_scopes = 'False' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t116 ON t116.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_demoscope_not_required_deny_real_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_demoscope_not_required_deny_real_bene_count') - AND type = 'Authorization' - - AND try_cast(crosswalk_fhir_id as BIGINT) > 0 - and allow = False - and auth_require_demographic_scopes = 'False' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t117 ON t117.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_auth_demoscope_not_required_deny_synthetic_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_auth_demoscope_not_required_deny_synthetic_bene_count') - AND type = 'Authorization' - - AND try_cast(crosswalk_fhir_id as BIGINT) < 0 - and allow = False - and auth_require_demographic_scopes = 'False' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t118 ON t118.app_name = t0.name - - /* Token stats per application */ - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_token_refresh_for_real_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_token_refresh_for_real_bene_count') - - AND type = 'AccessToken' - AND action = 'authorized' - AND auth_grant_type = 'refresh_token' - AND try_cast(crosswalk.fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t200 ON t200.app_name = t0.name - - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_token_refresh_for_synthetic_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_token_refresh_for_synthetic_bene_count') - - AND type = 'AccessToken' - AND action = 'authorized' - AND auth_grant_type = 'refresh_token' - AND try_cast(crosswalk.fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t201 ON t201.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_token_authorization_code_for_real_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_token_authorization_code_for_real_bene_count') - - AND type = 'AccessToken' - AND auth_grant_type = 'authorization_code' - AND try_cast(crosswalk.fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t202 ON t202.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_token_authorization_code_for_synthetic_bene_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_token_authorization_code_for_synthetic_bene_count') - - AND type = 'AccessToken' - AND auth_grant_type = 'authorization_code' - AND try_cast(crosswalk.fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t203 ON t203.app_name = t0.name - - /* Token request stats per application */ - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_token_refresh_response_2xx_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_token_refresh_response_2xx_count') - - AND request_method = 'POST' - AND path LIKE '/v%/o/token%/' - AND auth_grant_type = 'refresh_token' - AND response_code >= 200 - AND response_code < 300 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t204 ON t204.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_token_refresh_response_4xx_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_token_refresh_response_4xx_count') - - AND request_method = 'POST' - AND path LIKE '/v%/o/token%/' - AND auth_grant_type = 'refresh_token' - AND response_code >= 400 - AND response_code < 500 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t205 ON t205.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_token_refresh_response_5xx_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_token_refresh_response_5xx_count') - - AND request_method = 'POST' - AND path LIKE '/v%/o/token%/' - AND auth_grant_type = 'refresh_token' - AND response_code >= 500 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t206 ON t206.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_token_authorization_code_2xx_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_token_authorization_code_2xx_count') - - AND request_method = 'POST' - AND path LIKE '/v%/o/token%/' - AND auth_grant_type = 'authorization_code' - AND response_code >= 200 - AND response_code < 300 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t207 ON t207.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_token_authorization_code_4xx_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_token_authorization_code_4xx_count') - - AND request_method = 'POST' - AND path LIKE '/v%/o/token%/' - AND auth_grant_type = 'authorization_code' - AND response_code >= 400 - AND response_code < 500 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t208 ON t208.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_token_authorization_code_5xx_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_token_authorization_code_5xx_count') - - AND request_method = 'POST' - AND path LIKE '/v%/o/token%/' - AND auth_grant_type = 'authorization_code' - AND response_code >= 500 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t209 ON t209.app_name = t0.name - - /* Auth flow stats per application */ - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_authorize_initial_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_authorize_initial_count') - - AND path LIKE '/v%/o/authorize/' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t210 ON t210.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_medicare_login_redirect_ok_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_medicare_login_redirect_ok_count') - - AND path = '/mymedicare/login' - AND response_code = 302 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t211 ON t211.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_medicare_login_redirect_fail_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_medicare_login_redirect_fail_count') - - AND path = '/mymedicare/login' - AND response_code != 302 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t212 ON t212.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_authentication_start_ok_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_authentication_start_ok_count') - - AND type = 'Authentication:start' - AND sls_userinfo_status_code = 200 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t213 ON t213.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_authentication_start_fail_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_authentication_start_fail_count') - - AND type = 'Authentication:start' - AND sls_userinfo_status_code != 200 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t214 ON t214.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_authentication_matched_new_bene_real_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_authentication_matched_new_bene_real_count') - - AND type = 'Authentication:success' - AND try_cast(crosswalk_fhir_id as BIGINT) > 0 - AND auth_crosswalk_action = 'C' - - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t215 ON t215.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_authentication_matched_new_bene_synthetic_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_authentication_matched_new_bene_synthetic_count') - - AND type = 'Authentication:success' - and try_cast(crosswalk_fhir_id as BIGINT) < 0 - AND auth_crosswalk_action = 'C' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t216 ON t216.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_authentication_matched_returning_bene_real_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_authentication_matched_returning_bene_real_count') - - AND type = 'Authentication:success' - AND try_cast(crosswalk_fhir_id as BIGINT) > 0 - AND auth_crosswalk_action = 'R' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t217 ON t217.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_authentication_matched_returning_bene_synthetic_count - FROM - api_audit_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_authentication_matched_returning_bene_synthetic_count') - - AND type = 'Authentication:success' - and try_cast(crosswalk_fhir_id as BIGINT) < 0 - AND auth_crosswalk_action = 'R' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t218 ON t218.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_sls_callback_ok_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_sls_callback_ok_real_count') - - AND path = '/mymedicare/sls-callback' - AND response_code = 302 - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t219 ON t219.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_sls_callback_ok_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_sls_callback_ok_synthetic_count') - - AND path = '/mymedicare/sls-callback' - AND response_code = 302 - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t220 ON t220.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_sls_callback_fail_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_sls_callback_fail_count') - - AND path = '/mymedicare/sls-callback' - AND response_code != 302 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t221 ON t221.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_approval_view_get_ok_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_approval_view_get_ok_real_count') - - AND path LIKE '/v%/o/authorize/%/' - AND request_method = 'GET' - AND response_code IN (200, 302) - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t222 ON t222.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_approval_view_get_ok_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_approval_view_get_ok_synthetic_count') - - AND path LIKE '/v%/o/authorize/%/' - AND request_method = 'GET' - AND response_code IN (200, 302) - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t223 ON t223.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_approval_view_get_fail_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_approval_view_get_fail_count') - - AND path LIKE '/v%/o/authorize/%/' - AND request_method = 'GET' - AND response_code NOT IN (200, 302) - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t224 ON t224.app_name = t0.name - - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_approval_view_post_ok_real_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_approval_view_post_ok_real_count') - - AND path LIKE '/v%/o/authorize/%/' - AND request_method = 'POST' - AND response_code IN (200, 302) - AND try_cast(fhir_id as BIGINT) > 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t225 ON t225.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_approval_view_post_ok_synthetic_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_approval_view_post_ok_synthetic_count') - - AND path LIKE '/v%/o/authorize/%/' - AND request_method = 'POST' - AND response_code IN (200, 302) - AND try_cast(fhir_id as BIGINT) < 0 - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t226 ON t226.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_approval_view_post_fail_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_approval_view_post_fail_count') - - AND path LIKE '/v%/o/authorize/%/' - AND request_method = 'POST' - AND response_code NOT IN (200, 302) - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t227 ON t227.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_sdk_requests_python_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_sdk_requests_python_count') - - AND req_header_bluebutton_sdk = 'python' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t228 ON t228.app_name = t0.name - - LEFT JOIN - ( - SELECT - COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) as app_name, - count(*) as app_sdk_requests_node_count - FROM - request_response_middleware_events - WHERE - ( - CONTAINS((SELECT enabled_metrics_list FROM report_params), - 'app_sdk_requests_node_count') - - AND req_header_bluebutton_sdk = 'node' - ) - GROUP BY COALESCE(NULLIF(app_name,''), NULLIF(application.name,''), - NULLIF(auth_app_name,''), NULLIF(req_app_name,''), - NULLIF(resp_app_name,'')) - ) t229 ON t229.app_name = t0.name \ No newline at end of file diff --git a/insights/lambdas/update_athena_metric_tables/test_lambda_function_local.py b/insights/lambdas/update_athena_metric_tables/test_lambda_function_local.py deleted file mode 100644 index eac58d3a1..000000000 --- a/insights/lambdas/update_athena_metric_tables/test_lambda_function_local.py +++ /dev/null @@ -1,126 +0,0 @@ -import argparse -from lambda_function import lambda_handler - -""" -Call / Test lambda handler with params for local development. - -Edit and use the following params when testing and developing locally. - -NOTE: These params are not used when launched via AWS Lambda. - -When launching via AWS Lambda you must pass the parameters dictionary -via the "event". This can be included with the Lambda TEST parameters or -via the EventBridge caller. -""" -parser = argparse.ArgumentParser( - description="Utility to test the lambda_function() locally for development." -) -parser.add_argument( - "--region", - "-r", - help="The Athena AWS region.", - default="us-east-1", - type=str, -) -parser.add_argument( - "--workgroup", - "-w", - help="The AWS Glue table workgroup.", - default="bb2", - type=str, -) -parser.add_argument( - "--database", - "-d", - help="The AWS Glue table database.", - default="bb2", - type=str, -) -parser.add_argument( - "--env", - "-e", - help="The BB2 environment (prod/impl/test).", - required=True, - type=str, -) -parser.add_argument( - "--target-report-dates", - "-t", - help="The target report dates. EX: 2023-02-27, 2023-03-06", - default="", - type=str, -) - -parser.add_argument( - "--basename-main", - "-m", - help="The basename for the top-level/main metric table. EX: global_state_copy1", - default="global_state_copy1", - type=str, -) - -parser.add_argument( - "--basename-per-app", - "-p", - help="The basename for the per-application metric table. EX: global_state_per_app_copy1", - default="global_state_per_app_copy1", - type=str, -) -parser.add_argument( - "--retry-sleep-seconds", - "-s", - help="The time in seconds between query retries. EX: 30", - default="60", - type=str, -) - -args = parser.parse_args() - -REGION = args.region if args.region else None -WORKGROUP = args.workgroup if args.workgroup else None -DATABASE = args.database if args.database else None -ENV = args.env if args.env else None -TARGET_DATES = args.target_report_dates if args.target_report_dates else "" -BASENAME_MAIN = args.basename_main if args.basename_main else None -BASENAME_PER_APP = args.basename_per_app if args.basename_per_app else None -RETRY_SLEEP_SECONDS = args.retry_sleep_seconds if args.retry_sleep_seconds else None - -target_date_list = TARGET_DATES.split(",") - -print("--- Testing lambda_function.py") -print("---") -print("--- Using the following parameters:") -print("---") -print("--- TARGET_DATE_LIST: ", str(target_date_list)) -print("--- REGION: ", REGION) -print("--- WORKGROUP: ", WORKGROUP) -print("--- DATABASE: ", DATABASE) -print("--- ENV: ", ENV) -print("--- BASENAME_MAIN: ", BASENAME_MAIN) -print("--- BASENAME_PER_APP: ", BASENAME_PER_APP) -print("--- RETRY_SLEEP_SECONDS: ", RETRY_SLEEP_SECONDS) -print("---") - - -event = { - "REGION": REGION, - "WORKGROUP": WORKGROUP, - "DATABASE": DATABASE, - "ENV": ENV, - "BASENAME_MAIN": BASENAME_MAIN, - "BASENAME_PER_APP": BASENAME_PER_APP, - "RETRY_SLEEP_SECONDS": RETRY_SLEEP_SECONDS -} - - -for target_date in target_date_list: - event["TARGET_DATE"] = target_date - context = None - status = lambda_handler(event, context) - print("##") - print("## STATUS: ", status) - print("##") - print("##") - print("## -------------------------------") - print("##") - print("##") diff --git a/insights/lambdas/update_athena_metric_tables/test_run_sql_template_on_athena.py b/insights/lambdas/update_athena_metric_tables/test_run_sql_template_on_athena.py deleted file mode 100644 index 852e40ac7..000000000 --- a/insights/lambdas/update_athena_metric_tables/test_run_sql_template_on_athena.py +++ /dev/null @@ -1,181 +0,0 @@ -import argparse -import boto3 - -from utils.utils import ( - get_report_dates_from_target_date, - run_athena_query_using_template, - output_results_list_to_csv_file, - update_or_create_metrics_table, -) - - -""" -Summary: - -Program to test out Athena SQL template for development. - -This can be used when adding new metrics. It runs the SQL given the -template parameters on the command line and DOES NOT updated the related -reporting table. See README.md for usage examples. - -""" -parser = argparse.ArgumentParser( - description="Utility script to test out Athena SQL template for development." -) -parser.add_argument( - "--input-template-file", - "-i", - help="The name of the input template file.", - required=True, - type=str, -) -parser.add_argument( - "--region", - "-r", - help="The Athena AWS region.", - default="us-east-1", - type=str, -) -parser.add_argument( - "--workgroup", - "-w", - help="The AWS Glue table workgroup.", - default="bb2", - type=str, -) -parser.add_argument( - "--database", - "-d", - help="The AWS Glue table database.", - default="bb2", - type=str, -) -parser.add_argument( - "--env", - "-e", - help="The BB2 environment (prod/impl/test).", - required=True, - type=str, -) -parser.add_argument( - "--target-report-date", - "-t", - help="The target report date/week. EX: 2023-01-23", - required=True, - type=str, -) -parser.add_argument( - "--results-output-file", - "-o", - help="The output file to write Athena SQL query results to.", - default="", - type=str, -) -parser.add_argument( - "--basename_per_app", - "-b", - help="The per-app table basename, if used in query tested.", - default="global_state_per_app_testing1", - type=str, -) -parser.add_argument( - "--append-sql", - "-a", - help="SQL to be appended. For example, a where clause can be added to only show results of interest while testing.", - default="", - type=str, -) -parser.add_argument( - "--update-per-app-table", - default=False, - action='store_true', - help="Update or create table for per-app table basename.", -) - -# args = parser.parse_args(["--no-update-per-app-table"]) -args = parser.parse_args() - -INPUT_TEMPLATE_FILE = args.input_template_file if args.input_template_file else None -REGION = args.region if args.region else None -WORKGROUP = args.workgroup if args.workgroup else None -DATABASE = args.database if args.database else None -ENV = args.env if args.env else None -TARGET_DATE = args.target_report_date if args.target_report_date else None -OUTPUT_FILE = args.results_output_file if args.results_output_file else None -BASENAME_PER_APP = args.basename_per_app if args.basename_per_app else None -APPEND_SQL = args.append_sql if args.append_sql else None -UPDATE_PER_APP_TABLE = args.update_per_app_table if args.update_per_app_table else None - -print("--- Running SQL from template in Athena...") -print("---") -print("---Check recent-queries in the AWS console Athena Query Editor for results.") -print("---Or use the -o option to output to a file locally.") -print("---") -print("---Using the following parameters:") -print("---") -print("--- INPUT_TEMPLATE_FILE: ", INPUT_TEMPLATE_FILE) -print("--- REGION: ", REGION) -print("--- WORKGROUP: ", WORKGROUP) -print("--- DATABASE: ", DATABASE) -print("--- ENV: ", ENV) -print("--- TARGET_DATE: ", TARGET_DATE) -print("--- BASENAME_PER_APP: ", BASENAME_PER_APP) -print("--- UPDATE_PER_APP_TABLE: ", UPDATE_PER_APP_TABLE) -print("--- APPEND_SQL: ", APPEND_SQL) -print("--- OUTPUT_FILE: ", OUTPUT_FILE) -print("---") - -session = boto3.Session() - -target_week_date = TARGET_DATE -report_dates = get_report_dates_from_target_date(target_week_date) - -params = { - "region": REGION, - "workgroup": WORKGROUP, - "database": DATABASE, - "env": ENV, - "basename_main": None, - "basename_per_app": BASENAME_PER_APP, - "append_sql": APPEND_SQL, - "report_dates": report_dates, -} - -print("---") -print("---") -print("--- params: ", params) -print("---") -print("---") - -# Update/create table -if UPDATE_PER_APP_TABLE: - success_flag = update_or_create_metrics_table( - session, params, params["basename_per_app"], INPUT_TEMPLATE_FILE - ) - - if success_flag: - print("---") - print("--- SUCCESS: PER_APP TABLE was updated/created!") - print("---") - print( - "--- NOTE: You can DROP the table via the console if wanting to re-created it" - ) - print("--- or use a different report_date to add new entries.") - print("---") - else: - print("---") - print("--- FAIL: PER_APP TABLE update/create un-successful after retries!") - print("---") -else: - # Run SQL query - result_list = run_athena_query_using_template(session, params, INPUT_TEMPLATE_FILE) - - print("---") - print("--- Results list items returned: ", len(result_list)) - print("---") - - if OUTPUT_FILE: - print("---") - print("--- Writing results to: ", OUTPUT_FILE) - output_results_list_to_csv_file(result_list, OUTPUT_FILE) - print("---") diff --git a/insights/lambdas/update_athena_metric_tables/utils/__init__.py b/insights/lambdas/update_athena_metric_tables/utils/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/insights/lambdas/update_athena_metric_tables/utils/utils.py b/insights/lambdas/update_athena_metric_tables/utils/utils.py deleted file mode 100644 index dc2ca270b..000000000 --- a/insights/lambdas/update_athena_metric_tables/utils/utils.py +++ /dev/null @@ -1,416 +0,0 @@ -import boto3 -import csv -import re -import time - -from datetime import datetime, timezone -from dateutil.relativedelta import relativedelta, MO -from io import StringIO -from string import Template - -""" -Summary: - -Utility functions shared by: - - lambda_update_athena_metric_tables.py - - test_run_sql_template_on_athena.py -""" - - -def athena_query(client, params): - # NOTE: Output files will show up in the location configured for the workgroup. - response = client.start_query_execution( - QueryString=params["query"], - QueryExecutionContext={"Database": params["database"]}, - WorkGroup=params["workgroup"], - ) - return response - - -def run_athena_query_result_to_s3(session, params, max_execution=60): - client = session.client("athena", region_name=params["region"]) - execution = athena_query(client, params) - execution_id = execution["QueryExecutionId"] - state = "RUNNING" - print("## QueryExecutionId = ", execution_id) - - while max_execution > 0 and state in ["RUNNING", "QUEUED"]: - max_execution = max_execution - 5 - response = client.get_query_execution(QueryExecutionId=execution_id) - - if ( - "QueryExecution" in response - and "Status" in response["QueryExecution"] - and "State" in response["QueryExecution"]["Status"] - ): - state = response["QueryExecution"]["Status"]["State"] - if state == "FAILED": - return False - elif state == "SUCCEEDED": - s3_path = response["QueryExecution"]["ResultConfiguration"][ - "OutputLocation" - ] - return s3_path - - time.sleep(5) - - return False - - -def download_content_from_s3(s3_path, csv_format=True): - """ - Returns results as a list of dict items if csv_format=True - else return output value. - """ - s3 = boto3.resource("s3") - bucket_name = re.findall(r"^s3://([^/]+)", s3_path)[0] - key = re.findall(r"^s3://[^/]+[/](.+)", s3_path)[0] - try: - response = s3.Object(bucket_name, key).get() - except s3.meta.client.exceptions.NoSuchKey: - return None - - f = StringIO(response["Body"].read().decode("utf-8")) - if csv_format: - # Load csv in to dictionary - result_list = [] - for line in csv.DictReader(f): - result_list.append(line) - return result_list - else: - return f.getvalue() - - -def check_table_exists(session, params, table_basename): - """ - Returns True if table for table_basename exists, else False. - """ - params["query"] = ( - "SELECT count(*) FROM information_schema.tables " - + "WHERE table_schema = '" - + params["database"] - + "' AND table_name = '" - + params["env"] - + "_" - + table_basename - + "'" - ) - - output_s3_path = run_athena_query_result_to_s3(session, params, 1000) - result_list = download_content_from_s3(output_s3_path) - count = result_list[0].get("_col0") - - if count == "0": - return False - else: - return True - - -def check_table_for_report_date_entry(session, params, table_basename): - """ - Returns True/False for check of an existing - entry in the table for the report_date. - """ - # Setup SQL - params["query"] = ( - "SELECT count(*) " - + "FROM " - + params["database"] - + "." - + params["env"] - + "_" - + table_basename - + " " - + "WHERE report_date = CAST('" - + params["report_dates"]["report_date"] - + "' AS Date)" - ) - - output_s3_path = run_athena_query_result_to_s3(session, params, 1000) - if output_s3_path: - result_list = download_content_from_s3(output_s3_path) - else: - return False - - count = result_list[0].get("_col0") - - if count == "0": - return False - else: - return True - - -def get_sql_from_template_file(filepath, params): - f = open(filepath, "rt") - # read file contents to template obj - template = Template(f.read()) - f.close() - - ret = template.substitute( - ENV=params["env"], - BASENAME_PER_APP=params["basename_per_app"], - START_DATE=params["report_dates"]["start_date"], - END_DATE=params["report_dates"]["end_date"], - REPORT_DATE=params["report_dates"]["report_date"], - PARTITION_LIMIT_SQL=params["report_dates"]["partition_limit_sql"], - ) - - if params.get("append_sql", None): - ret = ret + "\n" + params["append_sql"] - - return ret - - -def get_table_columns_select_list(session, params, table_basename): - """ - Returns string with select list of columns for a given table. - Ex: "vpc, start_date, end_date, ..." - """ - params["query"] = ( - "SHOW COLUMNS FROM " - + params["database"] - + "." - + params["env"] - + "_" - + table_basename - ) - - output_s3_path = run_athena_query_result_to_s3(session, params, 1000) - result_list = download_content_from_s3(output_s3_path, csv_format=False) - - items_list = result_list.split() - return ",".join(items_list) - - -def run_athena_query_using_template(session, params, template_file): - """ - Run the athena query using template for the report_date. - """ - params["query"] = get_sql_from_template_file(template_file, params) - - output_s3_path = run_athena_query_result_to_s3(session, params, 1000) - result_list = download_content_from_s3(output_s3_path) - - return result_list - - -def update_or_create_table_for_report_date( - session, params, table_basename, template_file, table_exists -): - """ - Update the table with metrics for the report_date. - """ - if table_exists: - select_list = get_table_columns_select_list(session, params, table_basename) - - params["query"] = ( - "INSERT INTO " - + params["database"] - + "." - + params["env"] - + "_" - + table_basename - + "\n SELECT " - + select_list - + " FROM \n(" - + get_sql_from_template_file(template_file, params) - + "\n)" - ) - else: - params["query"] = ( - "CREATE TABLE " - + params["database"] - + "." - + params["env"] - + "_" - + table_basename - + " AS " - + get_sql_from_template_file(template_file, params) - ) - - output_s3_path = run_athena_query_result_to_s3(session, params, 1000) - - if output_s3_path: - result_list = download_content_from_s3(output_s3_path) - else: - result_list = None - - return result_list - - -def update_or_create_metrics_table(session, params, table_basename, template_file): - - print("##") - print( - "## --- UPDATE/CREATE TABLE: " - + params["database"] - + "." - + params["env"] - + "_" - + table_basename - ) - print("##") - - # Check if per_app table already exists - table_exists = check_table_exists(session, params, table_basename) - print("## table_exists: ", table_exists) - - # Update the per_app table if an entry does not already exist. - success_flag = False - for attempt_count in range(3): - # NOTE: Retry SQL run 3x for random Athena time-out issue. - print("## SQL RUN ATTEMPT: ", attempt_count + 1) - if table_exists: - if check_table_for_report_date_entry(session, params, table_basename): - print("## TABLE already has entry for report_date. Skipping...") - success_flag = True - break - else: - print("## Updating TABLE...") - # Update table - update_or_create_table_for_report_date( - session, params, table_basename, template_file, table_exists - ) - else: - # Create table - print("## Creating new TABLE...") - update_or_create_table_for_report_date( - session, params, table_basename, template_file, table_exists - ) - - # Checking if table was updated with SQL results - if check_table_for_report_date_entry(session, params, table_basename): - success_flag = True - break - - # Sleep between retries. - if not success_flag: - retry_seconds = params.get("retry_sleep_seconds", "60") - print("## RETRY SLEEPING FOR: ", retry_seconds) - time.sleep(int(retry_seconds)) - - return success_flag - - -def get_report_dates_from_target_date(target_date_str=""): - """ - Given a target date string return dates for the - report week to be used in queries. - - Use today's date if empty str. - - Returns: - report_date - start_date - end_date - dt - partition_1 - """ - if target_date_str == "": - target_date = datetime.now(timezone.utc) - else: - target_date = datetime.strptime(target_date_str, "%Y-%m-%d").astimezone( - timezone.utc - ) - - # Get report_date (Monday) from target date - report_date = target_date + relativedelta(weekday=MO(-1)) - - # Get start date for report week - start_date = report_date + relativedelta(weekday=MO(-2)) - - # Get end date for report week - end_date = report_date + relativedelta(days=-1) - - # Get Athena partition values from start/end dates - partition_min_year = start_date.strftime("%Y") - partition_max_year = report_date.strftime("%Y") - partition_min_day = start_date.strftime("%d") - partition_max_day = report_date.strftime("%d") - - if partition_max_year > partition_min_year: - """ - TODO: Improve this with the Glue table partitioning. - - The partitioning should be setup using a format that can - cross end of year dates. For example, dt = "2022-12-31". - - The current partitioning is split a dt = year, partition_1 = month, - so this causes performance issues in the current setup and EOY. - - The current performance is acceptable, but should revisit - for future needs. - """ - partition_min_month = "01" - partition_max_month = "12" - partition_limit_sql = ( - "( (dt = '" - + partition_min_year - + "' AND partition_1 = '12' AND partition_2 >= '" - + partition_min_day - + "') OR (dt = '" - + partition_max_year - + "' AND partition_1 = '01' AND partition_2 <= '" - + partition_max_day - + "') )" - ) - else: - # Set min/max month for partition search.Speeds up query! - partition_min_month = start_date.strftime("%m") - partition_max_month = report_date.strftime("%m") - if partition_max_month > partition_min_month: - partition_limit_sql = ( - "(dt = '" - + partition_min_year - + "' AND partition_1 = '" - + partition_min_month - + "' AND partition_2 >= '" - + partition_min_day - + "') OR (dt = '" - + partition_max_year - + "' AND partition_1 = '" - + partition_max_month - + "' AND partition_2 <= '" - + partition_max_day - + "')" - ) - else: - partition_limit_sql = ( - "(dt = '" - + partition_min_year - + "' AND partition_1 = '" - + partition_min_month - + "' AND partition_2 >= '" - + partition_min_day - + "') AND (dt = '" - + partition_max_year - + "' AND partition_1 = '" - + partition_max_month - + "' AND partition_2 <= '" - + partition_max_day - + "')" - ) - - report_dates = { - "report_date": report_date.strftime("%Y-%m-%d"), - "start_date": start_date.strftime("%Y-%m-%d"), - "end_date": end_date.strftime("%Y-%m-%d"), - "partition_min_year": partition_min_year, - "partition_min_month": partition_min_month, - "partition_min_day": partition_min_day, - "partition_max_year": partition_max_year, - "partition_max_month": partition_max_month, - "partition_max_day": partition_max_day, - "partition_limit_sql": partition_limit_sql, - } - return report_dates - - -def output_results_list_to_csv_file(result_list, output_file, include_header=True): - keys = result_list[0].keys() - - with open(output_file, "w", encoding="utf8", newline="") as f: - dw = csv.DictWriter(f, keys) - if include_header: - dw.writeheader() - dw.writerows(result_list)