Group-level Productivity Analytics do not show metrics for nested projects in subgroups

Summary

When viewing productivity analytics for a group, you cannot view metrics for projects that are not direct children of the group. Specifically, if you are viewing analytics for a group that contains subgroups, data for projects within those subgroups does not load.

All descendent projects are selectable from the dropdown, but when selected, show the message There is no data available. Please change your selection. Data from nested descendant projects is included at the group level, just not when looking at the projects themselves.

This was reported by a customer here: https://gitlab.zendesk.com/agent/tickets/163688 (internal only)

Steps to reproduce

I've created an example group with the following group structure:

Prod Analytics Bug Repro (This is the root group)
| - Top Level Project
| - Subgroup A
    | - Project A
    | - Subgroup B
        | - Project B

In each project, I've created 2 merge requests, one has been merged and one has not.

To see this in action, go to the example group Prod Analytics Bug Repro and view the Productivity Analytics page.

The first view will correctly show metrics for the group and all its descendants - there should be 3 MRs, which are shown as expected. You can also select the direct child project, Top Level Project, and its metrics will show correctly as well.

When you try to view Project A or Project B, the graph shows up empty and displays the message There is no data available. Please change your selection.

I've included screenshots further down.

Example Project

https://gitlab.com/gitlab-gold/prod-analytics-bug-repro

What is the current bug behavior?

Projects nested in subgroups do not properly return data when viewed from productivity analytics at the group level.

What is the expected correct behavior?

Projects nested in subgroups should properly return data when viewed from productivity analytics at the group level.

Relevant logs and/or screenshots

Group level productivity analytics

Screen_Shot_2020-07-16_at_5.08.34_PM

Group level productivity analytics - direct child project

Screen_Shot_2020-07-16_at_5.08.47_PM

Group level productivity analytics - nested descendant projects

Screen_Shot_2020-07-16_at_5.08.59_PM Screen_Shot_2020-07-16_at_5.09.11_PM

Output of checks

This bug happens on GitLab.com

Possible fixes

I haven't looked too deeply into the code responsible, but this is probably the root of the problem: when selecting one of these nested projects, I see several requests return 404 in the network tab. They have query parameters like this:

Screen_Shot_2020-07-16_at_5.20.37_PM

Based on group_id: "gitlab-gold/prod-analytics-bug-repro" it seems there's a disconnect between the request the frontend sends and the way Rails finds the project by its group path.

The group path is passed in here: https://gitlab.com/gitlab-org/gitlab/-/blob/429080b319d9e67cf832d32c4219f6f3f8d0b82e/ee/app/views/groups/analytics/productivity_analytics/show.html.haml#L14

Instead of providing a static group path (which I believe is what's used in the query parameters that return not found), each dropdown item should provide its own group ID to be used in the API request when it's selected.