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

Dataloader integration #21

Closed

Conversation

lytedev
Copy link

@lytedev lytedev commented Jun 24, 2019

Resolves #18

Note that at this point in time, mostly due to my unfamiliarity as of yet with the code and the data structures at play, this mostly provides very bland spans. If somebody could inform me how to extract the current field for a given blueprint execution, that would get me 90% there I think

@codecov-io
Copy link

codecov-io commented Jun 24, 2019

Codecov Report

Merging #21 into master will decrease coverage by 7.4%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #21      +/-   ##
==========================================
- Coverage   22.22%   14.81%   -7.41%     
==========================================
  Files           6        8       +2     
  Lines          36       54      +18     
==========================================
  Hits            8        8              
- Misses         28       46      +18
Impacted Files Coverage Δ
lib/opencensus/absinthe/phase/schema_push.ex 0% <0%> (ø)
lib/opencensus/absinthe.ex 0% <0%> (ø) ⬆️
lib/opencensus/absinthe/phase/push.ex 0% <0%> (ø) ⬆️
lib/opencensus/absinthe/acc.ex 0% <0%> (ø) ⬆️
lib/opencensus/absinthe/middleware/dataloader.ex 0% <0%> (ø)
lib/opencensus/absinthe/middleware.ex 38.09% <0%> (ø) ⬆️

Continue to review full report at Codecov.

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

@garthk
Copy link
Collaborator

garthk commented Jun 27, 2019

bland spans

That'll do. I'm not hurting in production from not having any attributes on the blueprint span. Knowing which resolver is slow is most of the battle.

I won't be able to review any of these changes this week, I'm afraid.

@garthk
Copy link
Collaborator

garthk commented Jul 9, 2019

I swear, it'll end up there'll be some way to process the middleware chain to wrap the arguments to the async and batch middleware before they invoke Task.async/1… but I can't nut it out.

Copy link
Collaborator

@garthk garthk left a comment

Choose a reason for hiding this comment

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

I'm sorry this took so long. I needed to get my head around Dataloader first.

This'll be a lot easier to get landed if I get #17 done, first.

README.md Outdated
@@ -82,6 +82,14 @@ end

[c:middleware/3]: https://hexdocs.pm/absinthe/Absinthe.Schema.html#c:middleware/3

If you're using [`Dataloader`][dataloader], you will want to use the provided
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I'm just too much of an [RFC 2119 fan, but can we get the word SHOULD in here?

@@ -41,6 +41,14 @@ defmodule Opencensus.Absinthe do

Worst case, you'll need to copy the code from the current `pipeline` target and add a call to
`Opencensus.Absinthe.add_phases/1` as above.

If you're using [`Dataloader`][dataloader], you will want to use the provided
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is in a @moduledoc or @doc, you can refer directly to the Dataloader and Opencensus.Absinthe.Middleware.Dataloader documentation by the module name. You don't need to construct your own links.

lib/opencensus/absinthe/acc.ex Show resolved Hide resolved
@@ -12,15 +12,20 @@ defmodule Opencensus.Absinthe.Middleware do
@impl true
@spec call(Resolution.t(), term()) :: Resolution.t()
def call(%Resolution{state: :unresolved} = resolution, field: field) do
acc = Acc.get(resolution)
case Acc.get(resolution) do
# nil ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to guard against this with some unit tests rather than commented out warnings. :)

Copy link
Author

Choose a reason for hiding this comment

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

I've added better comments and removed the commented-out warning 👍

end
end)

span_ctx = :oc_trace.start_span("resolution_#{counter || 0}", acc.span_ctx, span_options)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I love the counter! Can we make that part of the main accumulator so we can track how many times we looped the loop regardless of the mechanism? I'm OK with an extra span per overall resolution named "resolution 0" etc.

Let's also put the counter to the resolution span attributes as "absinthe.blueprint.resolution", and the blueprint span attributes as "absinthe.blueprint.resolution_count". I'm pretty sure:ocp.put_span_attribute/2 and :oc_trace.put_span_attribute/3 won't mind it being put more than once.

Copy link
Author

Choose a reason for hiding this comment

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

Ok - I think I got this working - if not, please be detailed on what I'm doing wrong. Again, I'm not too familiar with Absinthe. ='(

Thank you very much!

exec
|> Acc.set(new_acc)
|> DefaultDataloader.before_resolution()
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

I recently automated insertion of Opencensus.Absinthe.Middleware on literally every field with a resolver in our code base, simulating what'll happen with Absinthe 1.5 by default.

Turns out, it's a mess when tracing every field meets Absinthe.Resolution.Helpers.dataloader/3. For every item in the output, we get a span starting just before the call to Dataloader.load and ending just after the call to the last on_load in the chain. We need to know how long Dataloader.run/1 took and what it was doing, but the trace can't tell us.

Strikes me if you finish your span right here, we'll know!

Read also, #26, which is all about this.


acc
|> Map.get(@span_key)
|> :oc_trace.finish_span()
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we wait until after_resolution/1 to finish the span, it'll include a lot of time spent waiting for other middleware and plugins.

@garthk
Copy link
Collaborator

garthk commented Jul 31, 2019

If somebody could inform me how to extract the current field for a given blueprint execution

Your middleware/3 callback can insert {ModuleName, term}; see our middleware/3 arranging to get Opencensus.Absinthe.Middleware.call/2 called. You can derive arguments from field and object in middleware/3, or pull the same data out of res in your call/2. See the private Opencensus.Absinthe.Middleware.extract_metadata/1 for details. See also, #27, which might help.

@lytedev
Copy link
Author

lytedev commented Aug 1, 2019

Thanks for the feedback! I'll go over it and try and get something back to you shortly. 👍

@lytedev lytedev closed this Dec 2, 2020
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.

Add functionality to easily integrate with Dataloaders
3 participants