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

count persisted cache hits #1117

Merged
merged 6 commits into from
May 23, 2022
Merged

count persisted cache hits #1117

merged 6 commits into from
May 23, 2022

Conversation

Geal
Copy link
Contributor

@Geal Geal commented May 20, 2022

Fix #1014

This counts properly persisted_cache_hits, but not persisted_cache_misses. Apparently, in that case we do not even get into the update_apollo_metrics function, so I suspect the error returned by APQ skips the reporting phase. I also do not know yet under which stats_report_key I should record APQ cache misses, because if we get a cache miss, we do not know which query it was linked to.

Looking at this code it's not clear to me which stats report key I should use: https://github.com/apollographql/apollo-server/blob/main/packages/apollo-server-core/src/plugin/usageReporting/plugin.ts#L644-L682

@netlify
Copy link

netlify bot commented May 20, 2022

Deploy Preview for apollo-router-docs ready!

Name Link
🔨 Latest commit a40abdd
🔍 Latest deploy log https://app.netlify.com/sites/apollo-router-docs/deploys/628b6ab63402a900083b7d7b
😎 Deploy Preview https://deploy-preview-1117--apollo-router-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions

This comment has been minimized.

@Geal
Copy link
Contributor Author

Geal commented May 20, 2022

@glasser could you provide some context on how persisted_query_misses should be handled? If I understand correctly, in case of APQ cache miss, we cannot know the expected query, so there's no associated stats report key?

In the protobuf schema, I also see the Trace message has these fields:

  // Was this query specified successfully as a persisted query hash?
  bool persisted_query_hit = 21;
  // Did this query contain both a full query string and a persisted query hash?
  // (This typically means that a previous request was rejected as an unknown
  // persisted query.)
  bool persisted_query_register = 22;

Is it counted separately from the QueryLatencyStats message?

@glasser
Copy link
Member

glasser commented May 20, 2022

@Geal persisted_query_register in Trace matches persisted_query_misses in aggregated stats and is a better name for the same thing. Perhaps we should rename the aggregated field to match the trace field.

Looks from monorepo log -S persisted_query_register etc that the history was:

  • When we first implemented APQs (in engineproxy!) we added stats about it with the persisted_query_misses misnomer, and we didn't actually mention persisted query-ness in traces at all. Back then Traces and Stats were sent to our servers completely separately and there was no concept of taking a trace and aggregating it to stats.
  • When we implemented the reporting protocol for "direct reporting from Apollo Server" it initially was implemented as "only send traces, never send stats, all aggregation happens inside Apollo's servers". (This was intended as a short-term plan to last a month or two before we went back to reporting-agent-style aggregation and accidentally lasted a couple years oops.) So now we had the concept of turning traces into stats, which meant all data that go into stats had to be represented in traces. So I added a relevant field in https://github.com/mdg-private/monorepo/pull/940 and named it persisted_query_register instead of persisted_query_miss because it's more accurate. And wrote the comment you quoted above. However I never went back and renamed the stats field.

So yeah, don't actually count "misses", count "registers" since those typically come right after a miss.

Does that make sense?

Note that Apollo Server doesn't have a way of reporting persisted query not-found or not-supported errors (or like "no query provided"); it has a comment suggesting that that might be a good idea, but for now they just aren't reported at all.

@glasser
Copy link
Member

glasser commented May 20, 2022

(FWIW, while implementing this is a good idea for feature-parity's sake, I don't believe Studio actually shows this data anywhere. In fact I don't think it writes the aggregated data anywhere and it probably does save the Trace flags along with the Trace but doesn't expose it via the API, let alone show it in the UI.)

@Geal
Copy link
Contributor Author

Geal commented May 23, 2022

ok, so then I'll record query registers in persisted_cache_misses, thank you for the explanation!

Geoffroy Couprie added 2 commits May 23, 2022 11:19
@Geal Geal requested review from BrynCooke and garypen May 23, 2022 09:49
@Geal Geal marked this pull request as ready for review May 23, 2022 09:49
Copy link
Contributor

@BrynCooke BrynCooke left a comment

Choose a reason for hiding this comment

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

LGTM. Needs a changelog entry.

@Geal Geal merged commit 8091d59 into main May 23, 2022
@Geal Geal deleted the geal/report-apq-usage branch May 23, 2022 15:05
@garypen garypen mentioned this pull request May 31, 2022
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.

reporting: need to fill in persisted_query_misses
4 participants