-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NMS-17003: Add tenant id on grpc exporter (#7590)
* NMS-17003: Add tenant id as part of metadata * NMS-17003: Update docs * NMS-17003: Handle review comments
- Loading branch information
Showing
4 changed files
with
88 additions
and
22 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
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
63 changes: 63 additions & 0 deletions
63
...grpc/exporter/src/main/java/org/opennms/features/grpc/exporter/GrpcHeaderInterceptor.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,63 @@ | ||
/* | ||
* Licensed to The OpenNMS Group, Inc (TOG) under one or more | ||
* contributor license agreements. See the LICENSE.md file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. | ||
* | ||
* TOG licenses this file to You under the GNU Affero General | ||
* Public License Version 3 (the "License") or (at your option) | ||
* any later version. You may not use this file except in | ||
* compliance with the License. You may obtain a copy of the | ||
* License at: | ||
* | ||
* https://www.gnu.org/licenses/agpl-3.0.txt | ||
* | ||
* 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 org.opennms.features.grpc.exporter; | ||
|
||
import io.grpc.CallOptions; | ||
import io.grpc.Channel; | ||
import io.grpc.ClientCall; | ||
import io.grpc.ClientInterceptor; | ||
import io.grpc.ForwardingClientCall; | ||
import io.grpc.Metadata; | ||
import io.grpc.MethodDescriptor; | ||
|
||
public class GrpcHeaderInterceptor implements ClientInterceptor { | ||
|
||
private final Metadata metadata; | ||
|
||
public GrpcHeaderInterceptor(String tenantId) { | ||
metadata = new Metadata(); | ||
metadata.put(Metadata.Key.of("tenant-id", Metadata.ASCII_STRING_MARSHALLER), tenantId); | ||
} | ||
|
||
@Override | ||
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall( | ||
MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) { | ||
return new HeaderAttachingClientCall<>(next.newCall(method, callOptions), metadata); | ||
} | ||
|
||
private final static class HeaderAttachingClientCall<ReqT, RespT> | ||
extends ForwardingClientCall.SimpleForwardingClientCall<ReqT, RespT> { | ||
|
||
private final Metadata metadata; | ||
HeaderAttachingClientCall(ClientCall<ReqT, RespT> call, Metadata metadataToAttach) { | ||
super(call); | ||
this.metadata = metadataToAttach; | ||
} | ||
|
||
@Override | ||
public void start(Listener<RespT> responseListener, Metadata headers) { | ||
headers.merge(metadata); | ||
super.start(responseListener, headers); | ||
} | ||
} | ||
} |
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