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

feat: Add graphql coverage analytics - flags, components #842

Merged
merged 6 commits into from
Oct 4, 2024

Conversation

suejung-sentry
Copy link
Contributor

@suejung-sentry suejung-sentry commented Sep 30, 2024

Description

This is another batch of fields to move over for the GraphQL restructure project.
It takes flags and components which are coverage related concepts and nests them within the new repository.coverageAnalytics type.

Closes codecov/engineering-team#2284

Tested by confirming the unit tests when moved over pass as expected.
Also tested in staging that the apis return the expected data.
The duplicated behavior will get cleaned up with this ticket after frontend cutover done.

Summary of Changes

These were the updates to the schema:

BEFORE

type Repository {
  name: String!
  <... other stuff>
  ### see below fields that are currently at repository.<field>
  flags(
    filters: FlagSetFilters
    orderingDirection: OrderingDirection
    first: Int
    after: String
    last: Int
    before: String
  ): FlagConnection! @cost(complexity: 3, multipliers: ["first", "last"])
  flagsCount: Int!
  flagsMeasurementsActive: Boolean!
  flagsMeasurementsBackfilled: Boolean!
  componentsMeasurementsActive: Boolean!
  componentsMeasurementsBackfilled: Boolean!
  componentsCount: Int!
  components(
    interval: MeasurementInterval!
    before: DateTime!
    after: DateTime!
    branch: String
    filters: ComponentMeasurementsSetFilters
    orderingDirection: OrderingDirection
  ): [ComponentMeasurements!]!
  componentsYaml(termId: String): [ComponentsYaml]!
  <... other stuff>
 }

AFTER

type Repository {
  name: String!
  <... other stuff>
  coverageAnalytics: CoverageAnalytics
 }

type CoverageAnalytics {
  <... other stuff>
  flags(    ### see these fields that got moved to be nested within repository.coverageAnalytics.<field>
    filters: FlagSetFilters
    orderingDirection: OrderingDirection
    first: Int
    after: String
    last: Int
    before: String
  ): FlagConnection! @cost(complexity: 3, multipliers: ["first", "last"])
  flagsCount: Int!
  flagsMeasurementsActive: Boolean!
  flagsMeasurementsBackfilled: Boolean!

  components(
    interval: MeasurementInterval!
    before: DateTime!
    after: DateTime!
    branch: String
    filters: ComponentMeasurementsSetFilters
    orderingDirection: OrderingDirection
  ): [ComponentMeasurements!]!
  componentsCount: Int!
  componentsMeasurementsActive: Boolean!
  componentsMeasurementsBackfilled: Boolean!
  componentsYaml(termId: String): [ComponentsYaml]!
}

This is the GraphQL Query

query CoverageAnalyticsBatch2(
  $owner: String!,
  $repo: String!,

  # flags
  $filters: FlagSetFilters,
  $orderingDirection: OrderingDirection!,
  $interval: MeasurementInterval!,
  $afterDate: DateTime!,
  $beforeDate: DateTime!,
  # $after: String!, # pagination cursor value

  # components
  $filtersComponents: ComponentMeasurementsSetFilters,
  $orderingDirectionComponents: OrderingDirection!,
  $intervalComponents: MeasurementInterval!,
  $beforeComponents: DateTime!,
  $afterComponents: DateTime!,
  $branch: String
) {
  owner(username: $owner) {
    plan {
      tierName
    }
    repository(name: $repo) {
      __typename
      ... on Repository {
       coverageAnalytics {
        # Flags-related fields and query
        flagsCount
        flagsMeasurementsActive
        flagsMeasurementsBackfilled

        flags(
          filters: $filters,
          orderingDirection: $orderingDirection,
          # after: $after,
          first: 15
        ) {
          pageInfo {
            hasNextPage
            endCursor
          }
          edges {
            node {
              name
              percentCovered
              percentChange
              measurements(
                interval: $interval,
                after: $afterDate,
                before: $beforeDate
              ) {
                avg
              }
            }
          }
        }

        # Components-related fields and query
        componentsCount
        componentsMeasurementsActive
        componentsMeasurementsBackfilled

        components(
          filters: $filtersComponents,
          orderingDirection: $orderingDirectionComponents,
          after: $afterComponents,
          interval: $intervalComponents,
          before: $beforeComponents,
          branch: $branch
        ) {
          componentId
          name
          percentCovered
          percentChange
          lastUploaded
          measurements {
            avg
          }
        }
      }
    }
    }
  }
}

example query variables

{
  "owner": "codecov",
  "repo": "worker",
  "filters": {
    "flagsNames": "asdf"
  },
  "orderingDirection": "DESC",
  "interval": "INTERVAL_1_DAY",
  "afterDate": "2023-09-01T00:00:00Z",
  "beforeDate": "2023-09-30T23:59:59Z",
  "filtersComponents": {
    "components": "asdfasdf"
  },
  "orderingDirectionComponents": "ASC",
  "intervalComponents": "INTERVAL_1_DAY",
  "beforeComponents": "2023-09-30T23:59:59Z",
  "afterComponents": "2023-09-01T00:00:00Z",
  "branch": "main"
}

Screenshots from testing in staging that the same data is returned when querying with and without the new nesting level
Screenshot 2024-10-04 at 8 50 38 AM
Screenshot 2024-10-04 at 8 50 22 AM
Screenshot 2024-10-04 at 8 49 57 AM
Screenshot 2024-10-04 at 8 49 45 AM

Copy link

codecov bot commented Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.29%. Comparing base (acf749e) to head (62bba62).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #842      +/-   ##
==========================================
+ Coverage   96.28%   96.29%   +0.01%     
==========================================
  Files         818      818              
  Lines       18818    18909      +91     
==========================================
+ Hits        18118    18209      +91     
  Misses        700      700              
Flag Coverage Δ
unit 92.60% <100.00%> (+0.03%) ⬆️
unit-latest-uploader 92.60% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-notifications
Copy link

codecov-notifications bot commented Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@@ -0,0 +1,784 @@
# TODO - delete this file with #2290 - tests have been ported over to new schema in test_flags.py
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed the existing file to _legacy.py and we can delete this file once ready

edges {
node {
...FlagFragment
coverageAnalytics {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file reflects the new flags related tests (existing tests are in the test_flags_legacy.py file that will get deleted once ready)

@@ -0,0 +1,1389 @@
from unittest.mock import PropertyMock, patch
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file will get cleaned up with #2290

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a copy of the existing graphql_api/tests/test_components.py original file

@suejung-sentry suejung-sentry marked this pull request as ready for review October 2, 2024 21:56
@suejung-sentry suejung-sentry requested a review from a team as a code owner October 2, 2024 21:56
@codecov codecov deleted a comment from codecov-public-qa bot Oct 2, 2024
@codecov codecov deleted a comment from codecov-qa bot Oct 2, 2024
Copy link
Contributor

@calvin-codecov calvin-codecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

My 2.1 PR also touches test_components.py but I think it should be separate enough that it doesn't think there are conflicts.

Copy link
Contributor

@ajay-sentry ajay-sentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@suejung-sentry
Copy link
Contributor Author

LGTM.

My 2.1 PR also touches test_components.py but I think it should be separate enough that it doesn't think there are conflicts.

Thanks! I'll ping you to coordinate, if you want to go first!

@suejung-sentry suejung-sentry added this pull request to the merge queue Oct 4, 2024
Merged via the queue into main with commit 812ec4a Oct 4, 2024
18 of 19 checks passed
@suejung-sentry suejung-sentry deleted the sshin/2284-new branch October 4, 2024 16:08
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.1] Update Schema Definition and API Implementation
3 participants