Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ BB2-897 ] Nightly global state metrics additional counts (#988)
* Create format_timestamp() utility function * Create grant counts functions - Create get_grant_counts() function with related top level grant counts and elapsed timings. The functions return a DICT with the mentric items. Located in apps/authorization/models.py - Create get_grant_by_app_counts(application) function with related per application grant counts and elapsed timings. The functions return a DICT with the mentric items. Located in apps/authorization/models.py * Create access_token count functions - Create get_access_token_counts() function with related top level token counts and elapsed timings. The functions return a DICT with the metric items. Located in apps/dot_ext/models.py - Create get_access_token_by_app_counts(application) function with related single application token counts and elapsed timings. The functions return a DICT with the metric items. Located in apps/dot_ext/models.py * Add elapsed time to check_crosswalks() function * Add new global state metrics counts to logging - Add new count and elapsed time metric items to logging that are returned by check_crosswalks(), get_grant_counts(), get_grant_by_app_counts(), get_grant_counts(), get_access_token_counts(), get_access_token_by_app_counts(), get_application_counts() functions. These are for "global_state_metrics" and "global_state_metrics_per_app" type log events in apps/logging/loggers.py - Update group_timestamp to use the format_timestamp() utility function in apps/logging/management/commands/log_global_state_metrics.py * Create global state metrics logging unit tests - Update JSON SCHEMA for GLOBAL_STATE_METRICS_LOG_SCHEMA and GLOBAL_STATE_METRICS_PER_APP_LOG_SCHEMA in apps/logging/tests/audit_logger_schemas.py - Create a helper method _create_range_users_app_token_grant(self, start_fhir_id, count, app_name) hat creates a RANGE of users connected to an application with Crosswalk, Access Token, and Grant for use in tests. Returns a DICT of users granted by fhir_id. For the BaseApiTest class in apps/test.py - Create tests to validate log metrics items after creating/removing a variety of real/synth users, apps and grants using BaseApiTest helper function. This updates the test_management_command_logging() test method in apps/logging/tests/test_loggers_management_command.py * Remove print debugging statements * Update check_crosswalks() test * Remove redundant comments * Update code formatting * Update queries to handle NULL/empty crosswalks - Update queries to exclude NULL crosswalk records in get_grant_counts() and get_grant_by_app_counts(application) functions in apps/authorization/models.py - Update queries to exclude NULL crosswalk records in get_access_token_counts() and get_access_token_by_app_counts(application) functions in apps/dot_ext/models.py - Add test #5 for "Test that crosswalk record with fhir_id = "" is not counted." in TestLoggersGlobalMetricsManagementCommand.test_management_command_logging method in apps/logging/tests/test_loggers_management_command.py - Add test #6 for "Test that missing/NULL crosswalk record is not counted" in TestLoggersGlobalMetricsManagementCommand.test_management_command_logging method in apps/logging/tests/test_loggers_management_command.py * Refactor namings See confluence doc for details * Add table total record counts - Add items crosswalk_table_count & crosswalk_archived_table_count - Add items grant_table_count & grant_archived_table_count - Add items token_table_count & token_archived_table_count - Update log schema for new logging items in apps/logging/tests/audit_logger_schemas.py - Add tests for new logging items in apps/logging/tests/test_loggers_management_command.py - Refactor validate methods to be simpler by iterating over a fields list for _validate_global_state_metrics_log() and _validate_global_state_per_app_metrics_log() in apps/logging/tests/test_loggers_management_command.py * Fix value from testing
- Loading branch information