private static ServiceLoad StartLoadReportingService() { var loadReportingServiceImpl = new LoadReportingGrpcImpl(); var server = new Server { Services = { LoadReportingGrpc.BindService(loadReportingServiceImpl) }, Ports = { new ServerPort(Host, Port, ServerCredentials.Insecure) } }; ServiceLoad serviceLoad = new ServiceLoad(); loadReportingServiceImpl.AllowMonitoring(ServiceName, serviceLoad); server.Start(); return(serviceLoad); }
static async Task Main(string[] args) { if (!TryGetArguments(args, out int port, out int secondsUntilUnhealthy, out int currentRequests)) { return; } // The health service every serious grpc server has: var healthService = new HealthServiceImpl(); healthService.SetStatus(_serviceName, HealthCheckResponse.Types.ServingStatus.Serving); // The load reporting service required for Quaestor load-balancer: LoadReportingGrpcImpl loadReporter = new LoadReportingGrpcImpl(); // Use Load.StartRequest(); at the beginning // and Load.StartRequest(); at the end of a request // or assign a known load rate using Load.KnownLoadRate Load = new ServiceLoad { ProcessCapacity = 1, CurrentProcessCount = currentRequests, ServerUtilization = 0.12345 }; loadReporter.AllowMonitoring("Worker", Load); var server = new Server { Services = { // YourGrpc.BindService(yourActualServiceImpl), Health.BindService(healthService), LoadReportingGrpc.BindService(loadReporter) }, Ports = { new ServerPort("localhost", port, ServerCredentials.Insecure) } }; server.Start(); if (secondsUntilUnhealthy > 0) { await SetUnhealthyAfter(secondsUntilUnhealthy, healthService); } Console.WriteLine("Press any key to finish."); Console.ReadKey(true); }
private static void AssertCorrectReport(LoadReportingGrpc.LoadReportingGrpcClient client, ServiceLoad actualLoad) { var loadResponse = client.ReportLoad(new LoadReportRequest { ServiceName = ServiceName }); Assert.NotNull(loadResponse.ServerStats); ServerStats serverStats = loadResponse.ServerStats; Assert.AreEqual(actualLoad.ProcessCapacity, serverStats.RequestCapacity); Assert.AreEqual(actualLoad.CurrentProcessCount, serverStats.CurrentRequests); Assert.AreEqual(actualLoad.ServerUtilization, serverStats.ServerUtilization); }
/// <summary> /// Starts the grpc server, binds the <see cref="QualityVerificationGrpcImpl"/> together /// with the <see cref="IServiceHealth"/> implementation and returns a handle for both. /// </summary> /// <param name="arguments">The microserver command line / config arguments.</param> /// <param name="inputsFactory">The factory method that creates the /// <see cref="IBackgroundVerificationInputs"/> instance. If no factory is proveded, only /// stand-alone verification (such as XML) can be used.</param> /// <param name="markUnhealthyOnExceptions"></param> /// <returns></returns> public static StartedGrpcServer <QualityVerificationGrpcImpl> StartVerificationServer( [NotNull] MicroserverArguments arguments, [CanBeNull] Func <VerificationRequest, IBackgroundVerificationInputs> inputsFactory, bool markUnhealthyOnExceptions) { var healthService = new HealthServiceImpl(); IServiceHealth health = new ServiceHealth(healthService); LoadReportingGrpcImpl loadReporting = new LoadReportingGrpcImpl(); ServiceLoad serviceLoad = new ServiceLoad(arguments.MaxParallel); loadReporting.AllowMonitoring(nameof(QualityVerificationGrpc), serviceLoad); var verificationServiceImpl = new QualityVerificationGrpcImpl(inputsFactory, arguments.MaxParallel) { CurrentLoad = serviceLoad }; if (markUnhealthyOnExceptions) { verificationServiceImpl.Health = health; } health.SetStatus(verificationServiceImpl.GetType(), true); Grpc.Core.Server server = StartGrpcServer(arguments, verificationServiceImpl, healthService, loadReporting); _msg.InfoFormat("Service is listening on host {0}, port {1}.", arguments.HostName, arguments.Port); return(new StartedGrpcServer <QualityVerificationGrpcImpl>( server, verificationServiceImpl, health)); }
private void StartAndRegisterServices(string hostName, int startPort) { for (int port = startPort; port < startPort + _serviceCount; port++) { var healthService = new HealthServiceImpl(); healthService.SetStatus(_serviceName, HealthCheckResponse.Types.ServingStatus.Serving); var loadReportingService = new LoadReportingGrpcImpl(); ServiceLoad serviceLoad = new ServiceLoad(3); loadReportingService.AllowMonitoring(_serviceName, serviceLoad); var server = new Server { Services = { Health.BindService(healthService), LoadReportingGrpc.BindService(loadReportingService) }, Ports = { new ServerPort(hostName, port, ServerCredentials.Insecure) } }; server.Start(); _serviceLoadByLocation.Add(new ServiceLocation(_serviceName, hostName, port, false), serviceLoad); _serviceRegistry.Ensure(_serviceName, hostName, port, false); } }
public void SetupFixture() { _actualLoad = StartLoadReportingService(); }