Skip to content

Conversation

aaron-steinfeld
Copy link
Contributor

Description

This change adds support for registering global filter rules which will be applied to all graphql handlers. This allows rules to be managed independently of the various handlers, a more extensible design.

Testing

Added and updated unit tests

Checklist:

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@aaron-steinfeld aaron-steinfeld requested a review from a team as a code owner January 29, 2021 17:31
@codecov
Copy link

codecov bot commented Jan 29, 2021

Codecov Report

Merging #546 (0395ea2) into main (c795786) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #546      +/-   ##
==========================================
+ Coverage   85.57%   85.59%   +0.01%     
==========================================
  Files         759      760       +1     
  Lines       15560    15581      +21     
  Branches     1987     1988       +1     
==========================================
+ Hits        13316    13337      +21     
  Misses       2211     2211              
  Partials       33       33              
Impacted Files Coverage Δ
projects/distributed-tracing/src/public-api.ts 100.00% <100.00%> (ø)
...del/schema/filter/global-graphql-filter.service.ts 100.00% <100.00%> (ø)
...dlers/spans/spans-graphql-query-handler.service.ts 100.00% <100.00%> (ø)
...lers/traces/trace-graphql-query-handler.service.ts 97.10% <100.00%> (+0.08%) ⬆️
...ers/traces/traces-graphql-query-handler.service.ts 100.00% <100.00%> (ø)
...es/query/entities-graphql-query-builder.service.ts 100.00% <100.00%> (ø)
...y/entity-topology-graphql-query-handler.service.ts 95.50% <100.00%> (+0.05%) ⬆️
...s/explore/explore-graphql-query-handler.service.ts 97.50% <100.00%> (+0.06%) ⬆️

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 c795786...0395ea2. Read the comment docs.

@github-actions

This comment has been minimized.

...this.argBuilder.forOrderBy(request.sort),
...this.argBuilder.forFilters(request.filters)
...this.argBuilder.forFilters(
this.globalGraphQlFilterService.mergeGlobalFilters(resolveTraceType(request.traceType), request.filters)
Copy link
Contributor

Choose a reason for hiding this comment

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

Putting this everywhere doesn't seem too scalable and may be error prone. Can we add it in idk GraphQlQueryEventService may be so that the inherited filters already have the desired filter?

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 don't love it, but it seems like the best place we have right now. There's no place with central knowledge of all queries, by design - and filters aren't a concept that applies to every request in the same way. QueryEventService for example pushes filters down to the data sources to apply, which is even more decentralized (and only works in the dashboard code) - the service itself doesn't know the request shapes to provide them.

Open to other ideas, but I think the handlers are the narrowest (and most stable point) that still has the context on how to apply the filters without a larger redesign.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then can we do it using an abstract method which the concrete handler has to provide? I could see people easily missing to apply the right global filters in new handlers.

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 wouldn't work very well as an abstract method. The transformation depends on the shape of the request, the logic of the handler and the shape of the constructed query. We could make a util, but at that point we're basically wrapping this.globalGraphQlFilterService.mergeGlobalFilters with another function, so no real purpose. Also, there's no base class for the handlers (and if there were, we wouldn't want to add an injection dependency to it for something that's only applicable to certain handlers).

Copy link
Contributor

Choose a reason for hiding this comment

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

okay. I was thinking we could just define a function below. While it doesn't do much, it would just force the dev to consider the case of global filter application. Otherwise it is easy to miss. It is still a hack.

export interface GraphQlHandler<TRequest, TResponse> {
  readonly type: GraphQlHandlerType;

  matchesRequest(request: unknown): request is TRequest;
  /**
   * Converts the provided request into a single selection, or a map of selections with arbitrary keys.
   * If a map is provided, the response provided to the converter will use the same keys to disambiguate
   * the response for each selection.
   */
  convertRequest(request: TRequest): GraphQlSelection | Map<unknown, GraphQlSelection>;
  /**
   * Converts the provided response, or map of responses (if a map of selections were provided in the request
   * conversion), to a response object.
   */
  convertResponse(response: unknown | Map<unknown, unknown>, request: TRequest): TResponse | Observable<TResponse>;

  getRequestOptions?(request: TRequest): GraphQlRequestOptions;
}

We do need a better solution for this.

@github-actions

This comment has been minimized.

@aaron-steinfeld aaron-steinfeld merged commit 6e35969 into main Jan 30, 2021
@aaron-steinfeld aaron-steinfeld deleted the global-filtering branch January 30, 2021 17:53
@github-actions
Copy link

Unit Test Results

    4 files  ±0  233 suites  +1   13m 15s ⏱️ -25s
828 tests +4  828 ✔️ +4  0 💤 ±0  0 ❌ ±0 
832 runs  +4  832 ✔️ +4  0 💤 ±0  0 ❌ ±0 

Results for commit 6e35969. ± Comparison against base commit c795786.

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 participants