diff --git a/backend/analytics_server/mhq/api/deployment_analytics.py b/backend/analytics_server/mhq/api/deployment_analytics.py index 7d427d2ae..8f482173e 100644 --- a/backend/analytics_server/mhq/api/deployment_analytics.py +++ b/backend/analytics_server/mhq/api/deployment_analytics.py @@ -75,7 +75,7 @@ def get_team_deployment_analytics( repo_id_to_deployments_map_with_prs: Dict[ str, List[Dict[Deployment, List[PullRequest]]] - ] = deployments_analytics_service.get_team_successful_deployments_in_interval_with_related_prs( + ] = deployments_analytics_service.get_team_all_deployments_in_interval_with_related_prs( team_id, interval, pr_filter, workflow_filter ) diff --git a/backend/analytics_server/mhq/service/deployments/analytics.py b/backend/analytics_server/mhq/service/deployments/analytics.py index e725c6d96..8fe7c4e8a 100644 --- a/backend/analytics_server/mhq/service/deployments/analytics.py +++ b/backend/analytics_server/mhq/service/deployments/analytics.py @@ -30,21 +30,22 @@ def __init__( self.deployments_service = deployments_service self.code_repo_service = code_repo_service - def get_team_successful_deployments_in_interval_with_related_prs( + def get_team_all_deployments_in_interval_with_related_prs( self, team_id: str, interval: Interval, pr_filter: PRFilter, workflow_filter: WorkflowFilter, - ) -> Dict[str, List[Dict[Deployment, List[PullRequest]]]]: + ) -> Dict[str, Dict[Deployment, List[PullRequest]]]: """ - Retrieves successful deployments within the specified interval for a given team, - along with related pull requests. Returns A dictionary mapping repository IDs to lists of deployments along with related pull requests. Each deployment is associated with a list of pull requests that contributed to it. + Retrieves all deployments within the specified interval for a given team, + along with related pull requests. Returns A dictionary mapping repository IDs to lists of deployments along with + related pull requests. Each deployment is associated with a list of pull requests that contributed to it. """ deployments: List[ Deployment - ] = self.deployments_service.get_team_successful_deployments_in_interval( + ] = self.deployments_service.get_team_all_deployments_in_interval( team_id, interval, pr_filter, workflow_filter ) @@ -193,8 +194,7 @@ def _get_deployment_frequency_metrics( successful_deployments = list( filter( - lambda x: x.conducted_at >= interval.from_time - and x.conducted_at <= interval.to_time, + lambda x: interval.from_time <= x.conducted_at <= interval.to_time, successful_deployments, ) ) @@ -227,6 +227,13 @@ def _get_deployment_frequency_metrics( ) ) + weekly_deployment_frequency = self._adjust_frequency_for_granularity( + weekly_deployment_frequency, daily_deployment_frequency, 7 + ) + monthly_deployment_frequency = self._adjust_frequency_for_granularity( + monthly_deployment_frequency, daily_deployment_frequency, 30 + ) + return DeploymentFrequencyMetrics( len(successful_deployments), daily_deployment_frequency, @@ -240,8 +247,7 @@ def _get_weekly_deployment_frequency_trends( successful_deployments = list( filter( - lambda x: x.conducted_at >= interval.from_time - and x.conducted_at <= interval.to_time, + lambda x: interval.from_time <= x.conducted_at <= interval.to_time, successful_deployments, ) ) @@ -252,6 +258,13 @@ def _get_weekly_deployment_frequency_trends( return get_key_to_count_map_from_key_to_list_map(team_weekly_deployments) + def _adjust_frequency_for_granularity( + self, frequency: int, daily_frequency: int, days_in_granularity: int + ) -> int: + if frequency < daily_frequency * days_in_granularity: + frequency = daily_frequency * days_in_granularity + return frequency + def get_deployment_analytics_service() -> DeploymentAnalyticsService: return DeploymentAnalyticsService(get_deployments_service(), CodeRepoService()) diff --git a/backend/analytics_server/mhq/service/sync_data.py b/backend/analytics_server/mhq/service/sync_data.py index a2d0b44e5..35e9abdc4 100644 --- a/backend/analytics_server/mhq/service/sync_data.py +++ b/backend/analytics_server/mhq/service/sync_data.py @@ -1,9 +1,7 @@ from mhq.service.code import sync_code_repos from mhq.service.incidents import sync_org_incidents from mhq.service.merge_to_deploy_broker import process_merge_to_deploy_cache -from mhq.service.query_validator import get_query_validator from mhq.service.workflows import sync_org_workflows -from mhq.utils.lock import get_redis_lock_service from mhq.utils.log import LOG sync_sequence = [ diff --git a/setup_utils/init_db.sh b/setup_utils/init_db.sh index ce0c8c47d..cc7655c06 100755 --- a/setup_utils/init_db.sh +++ b/setup_utils/init_db.sh @@ -5,7 +5,7 @@ set -u POSTGRES_USER="${DB_USER:-postgres}" POSTGRES_PASSWORD="${DB_PASS:-postgres}" -POSTGRES_DB="${DB_NAME:-dora-oss}" +POSTGRES_DB="${DB_NAME:-mhq-oss}" POSTGRES_PORT="${DB_PORT:-5432}" POSTGRES_HOST="${DB_HOST:-127.0.0.1}"