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 IBM cost analysis #7146

Merged
merged 13 commits into from
Jun 26, 2024
Merged

Add IBM cost analysis #7146

merged 13 commits into from
Jun 26, 2024

Conversation

glen-84
Copy link
Collaborator

@glen-84 glen-84 commented Jun 5, 2024

Summary of the changes (Less than 80 chars)

  • Adds IBM cost analysis.

❓ Questions

  • What am I doing wrong with the error handling in CostAnalysisMiddleware? It doesn't end the request. It's probably something silly. [@michaelstaib]

  • Is it important that a fragment definition is visited after it is spread? If you spread it twice, it is only visited once.

    • It seems logical that it would be visited from the root, not after it is first spread. This makes the path generation awkward, since you end up with paths like: query.examples.example1Field2[0].~fragment1~~fragment1.@example by default instead of just ~~fragment1.@example (the fragment definition starts at the root). Would changing this break things?
  • For unnamed operations, I've used o.Operation.ToString().ToLowerInvariant() for the path element – is that okay? ✅

    • f.e. query for an unnamed query, etc.
  • For fragment spreads with no TypeCondition, I've used context.OutputFields.Peek().Type.TypeName() – is that okay?

    • i.e. The name of the type of the field on which the spread is defined.
  • How do we avoid requiring the developer to add a @listSize directive to every single list in their project? Could we somehow attach this directive to connection types by default? [@michaelstaib]

    • RequireOneSlicingArgument would have to be set to false, otherwise the user would be forced to specify first or last.
  • Should we support introspectionOnly? (https://ibm.github.io/graphql-specs/cost-spec.html#sec-introspectionOnly) [@michaelstaib]

  • Should we support NoSchemaIntrospectionCustomRule? (https://ibm.github.io/graphql-specs/cost-spec.html#sec-NoSchemaIntrospectionCustomRule) - yes

  • For the CostMetrics cache, how much memory can we use, what should the default cache size be, etc.? - we deal with that in a later pr

  • I used the NonBacktracking option for the introspection regexes to reduce the chance of performance issues – should I keep this, or allow backtracking? - keep it!

  • Is there a better way to handle optional value-typed attribute arguments in ListSizeAttribute (for AssumedSize)? Currently using a nullable backing field. - looks good

  • Should we sort the fieldCostByLocation / typeCostByLocation by key (path)? - lets skip it and check if people have an issue with it

  • I've not yet done anything with @skip/@include. I wonder if supporting static true/false is worth it? lets revisit this for the december release

✅ To-do:

💡 Ideas

  • Should we exit early as the costs exceed the maximums?
    • Under which conditions? (only in production, etc.)
  • Should we log a warning when the default list size of 1 is used? (i.e. not configured with @listSize)

🛠️ FIXMEs: 6.

(search for FIXME in src/HotChocolate/CostAnalysis/)

Copy link

github-actions bot commented Jun 5, 2024

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@github-actions github-actions bot added 📚 documentation This issue is about working on our documentation. 🌶️ strawberry shake labels Jun 26, 2024
@michaelstaib michaelstaib marked this pull request as ready for review June 26, 2024 09:22
Copy link

codecov bot commented Jun 26, 2024

Codecov Report

Attention: Patch coverage is 79.23920% with 322 lines in your changes missing coverage. Please review.

Project coverage is 71.03%. Comparing base (ce8b5f7) to head (ab67695).

Files Patch % Lines
...nalysis/src/CostAnalysis/Utilities/ResultHelper.cs 31.40% 83 Missing ⚠️
...lysis/Properties/CostAnalysisResources.Designer.cs 0.00% 24 Missing ⚠️
...late/CostAnalysis/src/CostAnalysis/CostAnalyzer.cs 91.11% 20 Missing ⚠️
...olate/CostAnalysis/src/CostAnalysis/ErrorHelper.cs 20.00% 20 Missing ⚠️
...rc/CostAnalysis/Utilities/CostAnalyzerUtilities.cs 80.95% 20 Missing ⚠️
...nalysis/src/CostAnalysis/CostAnalyzerMiddleware.cs 82.52% 18 Missing ⚠️
...Extensions/CostAnalyzerRequestContextExtensions.cs 35.71% 18 Missing ⚠️
.../Core/src/Abstractions/Execution/ResponseStream.cs 61.53% 15 Missing ⚠️
...src/AspNetCore/Extensions/HttpContextExtensions.cs 29.41% 12 Missing ⚠️
...is/src/CostAnalysis/Types/ListSizeDirectiveType.cs 91.86% 10 Missing ⚠️
... and 22 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7146      +/-   ##
==========================================
- Coverage   78.72%   71.03%   -7.69%     
==========================================
  Files        2371     2688     +317     
  Lines      117420   134282   +16862     
==========================================
+ Hits        92443    95393    +2950     
- Misses      24977    38889   +13912     
Flag Coverage Δ
unittests 71.03% <79.23%> (-7.69%) ⬇️

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.

@michaelstaib michaelstaib merged commit 9be7cd6 into main Jun 26, 2024
8 checks passed
@michaelstaib michaelstaib deleted the gai/ibm-cost-spec branch June 26, 2024 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants