Skip to content

API for team deployment frequency trends #45

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

Merged
merged 2 commits into from
Apr 10, 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
45 changes: 44 additions & 1 deletion apiserver/dora/api/deployment_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def get_prs_included_in_deployment(deployment_id: str):
}
),
)
def get_cockpit_lead_time_trends(
def get_team_deployment_frequency(
team_id: str,
from_time: datetime,
to_time: datetime,
Expand All @@ -173,3 +173,46 @@ def get_cockpit_lead_time_trends(
)

return adapt_deployment_frequency_metrics(team_deployment_frequency_metrics)


@app.route("/team/<team_id>/deployment_frequency/trends", methods={"GET"})
@queryschema(
Schema(
{
Required("from_time"): All(str, Coerce(datetime.fromisoformat)),
Required("to_time"): All(str, Coerce(datetime.fromisoformat)),
Optional("pr_filter"): All(str, Coerce(json.loads)),
Optional("workflow_filter"): All(str, Coerce(coerce_workflow_filter)),
}
),
)
def get_team_deployment_frequency_trends(
team_id: str,
from_time: datetime,
to_time: datetime,
pr_filter: Dict = None,
workflow_filter: WorkflowFilter = None,
):

query_validator = get_query_validator()
interval = query_validator.interval_validator(from_time, to_time)
query_validator.team_validator(team_id)

pr_filter: PRFilter = apply_pr_filter(
pr_filter, EntityType.TEAM, team_id, [SettingType.EXCLUDED_PRS_SETTING]
)

deployments_analytics_service = get_deployment_analytics_service()

week_to_deployments_count_map: Dict[
datetime, int
] = deployments_analytics_service.get_weekly_deployment_frequency_trends(
team_id, interval, pr_filter, workflow_filter
)

return {
"deployment_frequency_trends": {
week.isoformat(): {"count": deployment_count}
for week, deployment_count in week_to_deployments_count_map.items()
}
}
4 changes: 2 additions & 2 deletions apiserver/dora/api/pull_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_lead_time_prs(
}
),
)
def get_cockpit_lead_time(
def get_team_lead_time(
team_id: str,
from_time: datetime,
to_time: datetime,
Expand Down Expand Up @@ -141,7 +141,7 @@ def get_cockpit_lead_time(
}
),
)
def get_cockpit_lead_time_trends(
def get_team_lead_time_trends(
team_id: str,
from_time: datetime,
to_time: datetime,
Expand Down
20 changes: 20 additions & 0 deletions apiserver/dora/service/deployments/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ def get_team_deployment_frequency_metrics(
monthly_deployment_frequency,
)

def get_weekly_deployment_frequency_trends(
self,
team_id: str,
interval: Interval,
pr_filter: PRFilter,
workflow_filter: WorkflowFilter,
) -> Dict[datetime, int]:

team_successful_deployments = (
self.deployments_service.get_team_successful_deployments_in_interval(
team_id, interval, pr_filter, workflow_filter
)
)

team_weekly_deployments = generate_expanded_buckets(
team_successful_deployments, interval, "conducted_at", "weekly"
)

return get_key_to_count_map_from_key_to_list_map(team_weekly_deployments)

def _map_prs_to_repo_id_and_base_branch(
self, pull_requests: List[PullRequest]
) -> Dict[Tuple[str, str], List[PullRequest]]:
Expand Down