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

Add type checking for codecov metrics #3148

Merged
merged 2 commits into from
Aug 28, 2024

Conversation

rohitvinnakota-codecov
Copy link
Contributor

Description

This closes https://github.com/orgs/codecov/projects/31/views/11?pane=issue&itemId=68552864.

We already have some validation server side. This PR adds some TS checking so that we can receive type safe messaging earlier.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. In 2022 this entity acquired Codecov and as result Sentry is going to need some rights from me in order to utilize my contributions in this PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@codecov-qa
Copy link

codecov-qa bot commented Aug 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.31%. Comparing base (703b34b) to head (0c3d5b6).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3148   +/-   ##
=======================================
  Coverage   98.31%   98.31%           
=======================================
  Files         923      923           
  Lines       14400    14401    +1     
  Branches     3910     3910           
=======================================
+ Hits        14157    14158    +1     
  Misses        238      238           
  Partials        5        5           
Files with missing lines Coverage Δ
...rc/pages/DefaultOrgSelector/DefaultOrgSelector.jsx 100.00% <ø> (ø)
...e/BundlesTab/BundleOnboarding/BundleOnboarding.tsx 95.23% <ø> (ø)
.../RepoPage/CoverageOnboarding/CircleCI/CircleCI.tsx 100.00% <ø> (ø)
...CoverageOnboarding/GitHubActions/GitHubActions.tsx 100.00% <ø> (ø)
...c/pages/RepoPage/CoverageOnboarding/NewRepoTab.tsx 100.00% <ø> (ø)
...codecovEventMetrics/useStoreCodecovEventMetric.tsx 100.00% <100.00%> (ø)
Components Coverage Δ
Assets 54.05% <ø> (ø)
Layouts 98.80% <ø> (ø)
Pages 99.03% <ø> (ø)
Services 99.51% <100.00%> (+<0.01%) ⬆️
Shared 99.71% <ø> (ø)
UI 94.51% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 703b34b...0c3d5b6. Read the comment docs.

Copy link

codecov-public-qa bot commented Aug 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.31%. Comparing base (703b34b) to head (0c3d5b6).

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3148   +/-   ##
=======================================
  Coverage   98.31%   98.31%           
=======================================
  Files         923      923           
  Lines       14400    14401    +1     
  Branches     3855     3855           
=======================================
+ Hits        14157    14158    +1     
  Misses        238      238           
  Partials        5        5           
Files Coverage Δ
...rc/pages/DefaultOrgSelector/DefaultOrgSelector.jsx 100.00% <ø> (ø)
...e/BundlesTab/BundleOnboarding/BundleOnboarding.tsx 95.23% <ø> (ø)
.../RepoPage/CoverageOnboarding/CircleCI/CircleCI.tsx 100.00% <ø> (ø)
...CoverageOnboarding/GitHubActions/GitHubActions.tsx 100.00% <ø> (ø)
...c/pages/RepoPage/CoverageOnboarding/NewRepoTab.tsx 100.00% <ø> (ø)
...codecovEventMetrics/useStoreCodecovEventMetric.tsx 100.00% <100.00%> (ø)
Components Coverage Δ
Assets 54.05% <ø> (ø)
Layouts 98.80% <ø> (ø)
Pages 99.03% <ø> (ø)
Services 99.51% <100.00%> (+<0.01%) ⬆️
Shared 99.71% <ø> (ø)
UI 94.51% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 703b34b...0c3d5b6. Read the comment docs.

@codecov-notifications
Copy link

codecov-notifications bot commented Aug 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3148   +/-   ##
=======================================
  Coverage   98.31%   98.31%           
=======================================
  Files         923      923           
  Lines       14400    14401    +1     
  Branches     3941     3936    -5     
=======================================
+ Hits        14157    14158    +1     
  Misses        238      238           
  Partials        5        5           
Files Coverage Δ
...rc/pages/DefaultOrgSelector/DefaultOrgSelector.jsx 100.00% <ø> (ø)
...e/BundlesTab/BundleOnboarding/BundleOnboarding.tsx 95.23% <ø> (ø)
.../RepoPage/CoverageOnboarding/CircleCI/CircleCI.tsx 100.00% <ø> (ø)
...CoverageOnboarding/GitHubActions/GitHubActions.tsx 100.00% <ø> (ø)
...c/pages/RepoPage/CoverageOnboarding/NewRepoTab.tsx 100.00% <ø> (ø)
...codecovEventMetrics/useStoreCodecovEventMetric.tsx 100.00% <100.00%> (ø)
Components Coverage Δ
Assets 54.05% <ø> (ø)
Layouts 98.80% <ø> (ø)
Pages 99.03% <ø> (ø)
Services 99.51% <100.00%> (+<0.01%) ⬆️
Shared 99.71% <ø> (ø)
UI 94.51% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 703b34b...0c3d5b6. Read the comment docs.

@codecov-staging
Copy link

Bundle Report

Changes will increase total bundle size by 510 bytes ⬆️

Bundle name Size Change
gazebo-staging-array-push 5.71MB 510 bytes ⬆️

@codecov-releaser
Copy link
Contributor

✅ Deploy preview for gazebo ready!

Previews expire after 1 month automatically.

Storybook

Commit Created Cloud Enterprise
0c3d5b6 Tue, 27 Aug 2024 16:35:59 GMT Cloud Enterprise

Copy link

codecov bot commented Aug 27, 2024

Bundle Report

Changes will increase total bundle size by 510 bytes ⬆️

Bundle name Size Change
gazebo-production-array-push 5.71MB 510 bytes ⬆️

Copy link

codecov bot commented Aug 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.31%. Comparing base (703b34b) to head (0c3d5b6).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##               main      #3148   +/-   ##
===========================================
  Coverage   98.31000   98.31000           
===========================================
  Files           923        923           
  Lines         14400      14401    +1     
  Branches       3910       3936   +26     
===========================================
+ Hits          14157      14158    +1     
  Misses          238        238           
  Partials          5          5           
Files with missing lines Coverage Δ
...rc/pages/DefaultOrgSelector/DefaultOrgSelector.jsx 100.00% <ø> (ø)
...e/BundlesTab/BundleOnboarding/BundleOnboarding.tsx 95.23% <ø> (ø)
.../RepoPage/CoverageOnboarding/CircleCI/CircleCI.tsx 100.00% <ø> (ø)
...CoverageOnboarding/GitHubActions/GitHubActions.tsx 100.00% <ø> (ø)
...c/pages/RepoPage/CoverageOnboarding/NewRepoTab.tsx 100.00% <ø> (ø)
...codecovEventMetrics/useStoreCodecovEventMetric.tsx 100.00% <100.00%> (ø)
Components Coverage Δ
Assets 54.05% <ø> (ø)
Layouts 98.80% <ø> (ø)
Pages 99.03% <ø> (ø)
Services 99.51% <100.00%> (+<0.01%) ⬆️
Shared 99.71% <ø> (ø)
UI 94.51% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 703b34b...0c3d5b6. Read the comment docs.

Copy link
Contributor

@nicholas-codecov nicholas-codecov left a comment

Choose a reason for hiding this comment

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

Just some optimizations we can make for the bundler.

Comment on lines +26 to +32
export const EVENT_METRICS = {
VISITED_PAGE: 'VISITED_PAGE',
CLICKED_BUTTON: 'CLICKED_BUTTON',
COPIED_TEXT: 'COPIED_TEXT',
COMPLETED_UPLOAD: 'COMPLETED_UPLOAD',
INSTALLED_APP: 'INSTALLED_APP',
} as const
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of creating an object here, can we just export the different metrics as const's? Using objects like this stop some minification optimizations from happening because you can't shorten names on field properties for objects, instead just exporting the const's directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can pre-face them with METRICS_ to better identify them.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a tradeoff, in Rohit's approach the optimization is being traded off for a better auto-complete experience in the IDE.

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 prefer to use a single object as a source of truth for all metrics as it is more structured that way. IMO the benefits from readability and accessibility of the structure outweigh any minification optimizations on a few lines, given just a small number of constants.

Happy to make the change if you think there are any practical performance concerns from not doing this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Giving this a bit more thought, I think we should take a slightly different approach then both the current implementation and my original suggestion, my original reasoning isn't all that great.

I think we should remove the object entirely because it's introduces a lot of duplicate code both the key and value are always the same, and using the object that way also introduces the possibility that only one side of the key or value is changed but not the other, making this code brittle.

The approach I think would solve all the concerns and be very ergonomic is to create a union type and just use string literals in place. Right now the typeahead will only work after you imported the object, whereas with a type union it works instantly after you open a leading quote.

Here's an example of what the union type would look like:

type EventMetric =  'VISITED_PAGE' | 'CLICKED_BUTTON' | 'COPIED_TEXT' | 'COMPLETED_UPLOAD' | 'INSTALLED_APP' 

Copy link
Contributor

@ajay-sentry ajay-sentry Aug 28, 2024

Choose a reason for hiding this comment

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

Similarly, we can utilize TS enums here if we want something similarly ergonomic.
https://www.typescriptlang.org/docs/handbook/enums.html#enums-at-compile-time

This example is somewhat of a middle ground between both of your approaches, just a little easier for me to read personally without all the '|' as we add more metrics but also not as verbose as setting the keys and values to the same thing

enum EVENT_METRICS {
  VISITED_PAGE,
  CLICKED_BUTTON,
  COPIED_TEXT,
  COMPLETED_UPLOAD,
  INSTALLED_APP
}

type EventMetrics = keyof typeof EVENT_METRICS

const mymetric:EventMetrics = 'lol' // This errors because it's looking for the union string type

Copy link
Contributor

@nicholas-codecov nicholas-codecov Aug 28, 2024

Choose a reason for hiding this comment

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

Can you add some comments around the enum, to inform people to not actually ever use the enum directly. There are quite a few gotcha's with enums, that we want to avoid at all costs so we don't want people to accidentally use it and cause larger issues.

You can read more about the issues with enums, and I personally think we should avoid them, "Why I Don't Like Enums", but I'm okay with using them as long as we don't export them and just use them to build out the string literal unions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are good points, but I think for a change a small as this, how we choose to implement it will have a negligible effect on performance or any other meaningful metric.

I will merge this change as is later today unless we think there is a strong practical reason to go with one approach over the other.

@rohitvinnakota-codecov rohitvinnakota-codecov added this pull request to the merge queue Aug 28, 2024
Merged via the queue into main with commit d2174d6 Aug 28, 2024
62 checks passed
@rohitvinnakota-codecov rohitvinnakota-codecov deleted the rvinnakota/update-types branch August 28, 2024 19:10
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.

4 participants