Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fixes deployment frequency Calculation #382

Merged
merged 4 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/analytics_server/mhq/api/deployment_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
31 changes: 22 additions & 9 deletions backend/analytics_server/mhq/service/deployments/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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,
)
)
Expand Down Expand Up @@ -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,
Expand All @@ -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,
)
)
Expand All @@ -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())
2 changes: 0 additions & 2 deletions backend/analytics_server/mhq/service/sync_data.py
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion setup_utils/init_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Expand Down
Loading