-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Let users move
GrpcLifecycleObserver
in the filter chain (#2171)
Motivation: gRPC users can not use `HttpLifecycleObserverServiceFilter` to install `GrpcLifecycleObserver` because `onGrpcStatus` won't be invoked. Sometimes, it's necessary to see the state of other filters from inside the observer. Modifications: - Make `HttpLifecycleObserverServiceFilter` extensible as a class, but keep all its methods `final`; - Add `GrpcLifecycleObserverServiceFilter`; Result: Users can install `GrpcLifecycleObserver` anywhere in a filter chain.
- Loading branch information
1 parent
3ae63a5
commit c8d0139
Showing
4 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...rpc-netty/src/main/java/io/servicetalk/grpc/netty/GrpcLifecycleObserverServiceFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright © 2022 Apple Inc. and the ServiceTalk project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.servicetalk.grpc.netty; | ||
|
||
import io.servicetalk.grpc.api.GrpcLifecycleObserver; | ||
import io.servicetalk.grpc.api.GrpcServerBuilder; | ||
import io.servicetalk.http.api.HttpServerBuilder; | ||
import io.servicetalk.http.api.StreamingHttpServiceFilterFactory; | ||
import io.servicetalk.http.netty.HttpLifecycleObserverServiceFilter; | ||
|
||
/** | ||
* An HTTP service filter that tracks events during gRPC request/response lifecycle. | ||
* <p> | ||
* The recommended approach is to use {@link GrpcServerBuilder#lifecycleObserver(GrpcLifecycleObserver)} to configure | ||
* an observer that captures entire state of the request processing. In cases when an observer should be moved down in | ||
* a filter chain or applied conditionally, this filter can be used. | ||
* <p> | ||
* This filter is recommended to be appended as the first filter at the | ||
* {@link HttpServerBuilder#appendNonOffloadingServiceFilter(StreamingHttpServiceFilterFactory)} | ||
* or {@link HttpServerBuilder#appendServiceFilter(StreamingHttpServiceFilterFactory)} | ||
* (which can be configured using {@link GrpcServerBuilder#initializeHttp(GrpcServerBuilder.HttpInitializer)}) | ||
* to account for all work done by other filters. If it's preferred to get visibility to information populated by other | ||
* filters (like tracing keys), it can be appended after those filters. | ||
*/ | ||
public final class GrpcLifecycleObserverServiceFilter extends HttpLifecycleObserverServiceFilter { | ||
|
||
/** | ||
* Create a new instance. | ||
* | ||
* @param observer The {@link GrpcLifecycleObserver observer} implementation that consumes gRPC lifecycle events. | ||
*/ | ||
public GrpcLifecycleObserverServiceFilter(final GrpcLifecycleObserver observer) { | ||
super(new GrpcToHttpLifecycleObserverBridge(observer)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters