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

fix: move API usage files to API folders #131

Conversation

Chloe070196
Copy link

@Chloe070196 Chloe070196 commented Oct 1, 2024

BUG (in 24.10.00): In #126, for Aspen Administration > System Reports > API Usage Dashboards, only the 'runPendingDatabaseUpdates' data could be successfully exported as a CSV due to a hard-coded bit of control flow in services/Admin/AJAX.php.


Keeping the dashboard and usage graph service files for APIs in the Admin folder would have created the need for additional parameters and control flow logic in the exportUsageData method which both Admin usage data CSV export and API usage data CSV export relied on. Additionally, their class names did not follow the same naming conventions (_Dashboard and_UsageGraphs) as the other usage dashboards and graphs classes now tend to do in Aspen.

This refactor provides some additional separation of concerns by replacing services/Admin/APIUsageDashboard.php and services/Admin/APIUsageGraphs.php with services/API/Dashboard.php and services/API/UsageGraphs, thereby fixing the csv export issue.

Expected behaviour post-patch:

  • the CSV export now works for any usage graph (not only 'runPendingDatabaseUpdates'), so that the dowloaded CSV contains data, and that data matches the selected usage stat.
  • the title of the link to the usage graph pages now also include the name of the method (stat).
  • the urls for the API Usage Dashboard and API Usage graphs change from /Admin/APIUsageDashboard to /API/UsageDashboard and /Admin/APIUsageGraphs to /API/UsageGraphs

Test plan:

  1. ensure that api_usage is populated by more than one module and more than one method. Out of the box adb only tends to show 'runPendingDatabaseUpdates' for the 'SystemAPI' module. If not, insert additional mock data (e.g INSERT INTO api_usage values (2,2024,8,'2024-8','UserAPI', 'updateNotificationOnboardingStatus', 12);)

  2. Log in to Aspen as an Admin

  3. In Aspen Administration > System Reports, open API Usage Dashboard. Notice the title of the links match their section and header.

  4. For each API and for each of their stats, open their usage graph page. Notice that the data matches the data on the dashboard, both in the raw data table and on the graph. Also notice that the title of the graph match its section and header in the dashboard.

  5. Click 'Export to CSV' (bottom left of the page) to check that the downloaded file's contents match
    those of the raw data table and that its name includes the stat name.

To replicate the bug, follow this test plan on a 24.10.00-based branch without applying the patch. After applying, navigate back to the Aspen Administration menu page and access the API Usage Dashboard from the link there (notice the change in url).

@Chloe070196 Chloe070196 changed the base branch from 24.10.00_additional_usage_graphs to refactor_API_usagegraphs October 1, 2024 08:24
@Chloe070196
Copy link
Author

Awaiting opportunity to test fully - unsure how to get other API than SystemAPI to show on the API Usage Dashboard under System Reports

Keeping the dashboard and usage graph service
files for APIs in the Admin folder would have
created the need for additional parameters and
control flow logic in the exportUsageData method
which both Admin usage data CSV export and API
usage data CSV export relied on. Additionally,
the resulting class names do not follow the same
naming conventions (<serviceName>_Dashboard and
<serviceName>_UsageGraphs) as the rest of Aspen.

This refactor provides a separation of concerns by
replacing services/Admin/APIUsageDashboard.php and
services/Admin/APIUsageGraphs.php with
services/API/Dashboard.php and
services/API/UsageGraphs.

In doing so, it also fixes an issue where only the
csv file for 'runPendingDatabaseUpdates' could be
downloaded.

Test plan:

1) Log in to Aspen as an Admin
2) In Aspen Administration > System Reports, open
API Usage Dashboard. Notice the title of the links
match their section and header.
3) For each API and for each of their stats, open
their usage graph page. Notice that the data
matches the data on the dashboard, both in the raw
data table and on the graph. Also notice that the
tilte of the graph match its section and header in
the dashboard.
4) Click 'Export to CSV' (bottom left of the page)
to check that the downloaded file's contents match
those of the raw data table and that its name
includes the stat name.

Run through this plan before applying the patch,
and notice that the CSV export only works for
'runPendingDatabaseUpdates'. After the patch, it
is expected to work for any usage graph.
@Chloe070196 Chloe070196 force-pushed the refactor_API_usagegraphs branch from 5ae8dbe to 1d4edb6 Compare October 9, 2024 08:27
@Chloe070196 Chloe070196 changed the base branch from refactor_API_usagegraphs to where_is_it_button_renders_consistently October 9, 2024 08:28
@Chloe070196 Chloe070196 changed the base branch from where_is_it_button_renders_consistently to 24.10.00_refactor_API_usagegraphs October 9, 2024 08:32
@ammopt ammopt merged commit 37c0949 into PTFS-Europe:24.10.00_refactor_API_usagegraphs Oct 9, 2024
3 checks passed
@ammopt
Copy link
Member

ammopt commented Oct 9, 2024

Good fix. Test plan works as advertised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants