Skip to content

Backend: Implement individual component sorting by usage count OR clean up related code/columns

Summary

In #452545 (closed) we implemented usage data aggregation for each catalog resource, for a rolling 30-day window. Then in #452620 (closed), we introduced the USAGE_COUNT_* sort options on the GraphQl ciCatalogResources endpoint. These tasks support the feature to allow users to sort catalog resources (aka "catalog projects") by usage in the UI (i.e. on the CI/CD Catalog index page).

We had originally planned in #440382 (closed) to also aggregate the usage data by individual components, but then decided this was not yet necessary.

In this issue, depending on our future use case, we may either proceed with: (1) supporting the ability to sort the individual components by usage, or (2) removing any code/table columns related to tracking individual component usage.

Proposal

Option 1: Proceed to support sorting by individual component usages

We need to:

  1. Add batch data aggregation for each individual component, following the same approach in #452545 (closed). It should use a separate worker than the one for aggregation by catalog resource.
  2. Add the option to sort components by usage in GraphQl, so we can query them like so:
query getSortedComponents {
  ciCatalogResource(fullPath: "path/to/resource") {
    id
    versions(name: "1.0.0") {
      nodes {
        components(sort: USAGE_COUNT_ASC) {
          nodes {
            id
            last30DayUsageCount
          }
        }
      }
    }
  }
}

Option 2: Remove code/columns related to individual component usage

  1. Remove the columns last_30_day_usage_count and last_30_day_usage_count_updated_at from catalog_resource_components table. (It was introduced in !147293 (merged).)
  2. Consider removing the component_id column from p_catalog_resource_component_usages. If we no longer need to track each individual component, then there would be no need to record such granular data. This would improve the storage and query efficiency of the database table. We would also need to update the service Ci::Components::Usages::CreateService and where it's used.

Implementation Table

Group Issue Link
backend Spike: Evaluate how to calculate number of time... (#438409 - closed)
backend Backend: Component usage instrumentation (#440382 - closed)
backend Backend: Implement daily worker to aggregate la... (#452545 - closed)
backend Backend: Add option to sort CI catalog resource... (#452620 - closed)
frontend Frontend: Show usage statistics and sort option... (#434333 - closed)
frontend Frontend: Present the number of times a single ... (#443632 - closed)
backend Backend: Reduce data retention period and store... (#443681 - closed)
backend 👈 You are here
Edited by Leaminn Ma