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
Use grpc-dotnet instead of grpc #9149
Changes from 8 commits
a0dacd5
f3a1e9f
9485b58
40bfd60
09ea3fa
fc59747
7b460d6
a17c3f5
d426b2a
579de0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,42 @@ | ||
// Copyright 2016-2020, Pulumi Corporation | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Grpc.Core; | ||
using Grpc.Net.Client; | ||
using Pulumirpc; | ||
|
||
namespace Pulumi | ||
{ | ||
internal class GrpcEngine : IEngine | ||
{ | ||
private readonly Engine.EngineClient _engine; | ||
// Using a static dictionary to keep track of and re-use gRPC channels | ||
// According to the docs, creating GrpcChannels is expensive so we keep track of a bunch of them here | ||
private static ConcurrentDictionary<string, GrpcChannel> _engineChannels = new ConcurrentDictionary<string, GrpcChannel>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: |
||
|
||
public GrpcEngine(string engine) | ||
{ | ||
// maxRpcMessageSize raises the gRPC Max Message size from `4194304` (4mb) to `419430400` (400mb) | ||
var maxRpcMessageSize = 400 * 1024 * 1024; | ||
var grpcChannelOptions = new List<ChannelOption> { new ChannelOption(ChannelOptions.MaxReceiveMessageLength, maxRpcMessageSize)}; | ||
this._engine = new Engine.EngineClient(new Channel(engine, ChannelCredentials.Insecure, grpcChannelOptions)); | ||
|
||
if (!_engineChannels.ContainsKey(engine)) | ||
{ | ||
// Allow for insecure HTTP/2 transport (only needed for netcoreapp3.1) | ||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); | ||
// Inititialize the engine channel once for this address | ||
_engineChannels[engine] = GrpcChannel.ForAddress(new Uri($"http://{engine}"), new GrpcChannelOptions | ||
{ | ||
MaxReceiveMessageSize = maxRpcMessageSize, | ||
MaxSendMessageSize = maxRpcMessageSize, | ||
Credentials = Grpc.Core.ChannelCredentials.Insecure, | ||
}); | ||
} | ||
|
||
this._engine = new Engine.EngineClient(_engineChannels[engine]); | ||
} | ||
|
||
public async Task LogAsync(LogRequest request) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,37 @@ | ||
// Copyright 2016-2020, Pulumi Corporation | ||
|
||
using System.Collections.Generic; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Grpc.Core; | ||
using Grpc.Net.Client; | ||
using Pulumirpc; | ||
using Grpc.Core; | ||
using System.Collections.Generic; | ||
using System.Collections.Concurrent; | ||
|
||
namespace Pulumi | ||
{ | ||
internal class GrpcMonitor : IMonitor | ||
{ | ||
private readonly ResourceMonitor.ResourceMonitorClient _client; | ||
|
||
private static ConcurrentDictionary<string, GrpcChannel> _monitorChannels = new ConcurrentDictionary<string, GrpcChannel>(); | ||
public GrpcMonitor(string monitor) | ||
{ | ||
// maxRpcMessageSize raises the gRPC Max Message size from `4194304` (4mb) to `419430400` (400mb) | ||
var maxRpcMessageSize = 400 * 1024 * 1024; | ||
var grpcChannelOptions = new List<ChannelOption> { new ChannelOption(ChannelOptions.MaxReceiveMessageLength, maxRpcMessageSize)}; | ||
this._client = new ResourceMonitor.ResourceMonitorClient(new Channel(monitor, ChannelCredentials.Insecure, grpcChannelOptions)); | ||
if (!_monitorChannels.ContainsKey(monitor)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder if we should have a "GrpcPool" class to share between GrpcEngine and GrpcMonitor. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think for this use case it is simple enough to keep it as imo |
||
{ | ||
// Allow for insecure HTTP/2 transport (only needed for netcoreapp3.x) | ||
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); | ||
// Inititialize the monitor channel once for this monitor address | ||
_monitorChannels[monitor] = GrpcChannel.ForAddress(new Uri($"http://{monitor}"), new GrpcChannelOptions | ||
{ | ||
MaxReceiveMessageSize = maxRpcMessageSize, | ||
MaxSendMessageSize = maxRpcMessageSize, | ||
Credentials = ChannelCredentials.Insecure | ||
}); | ||
} | ||
|
||
this._client = new ResourceMonitor.ResourceMonitorClient(_monitorChannels[monitor]); | ||
} | ||
|
||
public async Task<SupportsFeatureResponse> SupportsFeatureAsync(SupportsFeatureRequest request) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added links to the docs, thanks!