public async Task <NullableValue> RegisterServiceAsync(ServiceRequest serviceRequest, CancellationToken cancellationToken = default(CancellationToken)) { if (!_connectionManager.Ready) { return(NullableValue.Null); } var connection = _connectionManager.GetConnection(); return(await new Call(_logger, _connectionManager).Execute(async() => { var client = new Register.RegisterClient(connection); var services = new Services(); services.Services_.Add(new Service { ServiceName = serviceRequest.ServiceName }); var mapping = await client.doServiceRegisterAsync(services, _config.GetMeta(), _config.GetTimeout(), cancellationToken); foreach (var service in mapping.Services) { if (service.Key == serviceRequest.ServiceName) { return new NullableValue(service.Value); } } return NullableValue.Null; }, () => NullableValue.Null, () => ExceptionHelpers.RegisterServiceError)); }
public async Task <NullableValue> RegisterApplicationAsync(string applicationCode, CancellationToken cancellationToken = default(CancellationToken)) { if (!_connectionManager.Ready) { return(NullableValue.Null); } var connection = _connectionManager.GetConnection(); var client = new ApplicationRegisterService.ApplicationRegisterServiceClient(connection); return(await new Call(_logger, _connectionManager).Execute(async() => { var applicationMapping = await client.applicationCodeRegisterAsync( new Application { ApplicationCode = applicationCode }, _config.GetMeta(), _config.GetTimeout(), cancellationToken); return new NullableValue(applicationMapping?.Application?.Value ?? 0); }, () => NullableValue.Null, () => ExceptionHelpers.RegisterApplicationError)); }
public async Task ReportAsync(IReadOnlyCollection <SegmentRequest> segmentRequests, CancellationToken cancellationToken = default(CancellationToken)) { if (!_connectionManager.Ready) { return; } var connection = _connectionManager.GetConnection(); try { var stopwatch = Stopwatch.StartNew(); var client = new TraceSegmentReportService.TraceSegmentReportServiceClient(connection); using (var asyncClientStreamingCall = client.collect(_config.GetMeta(), _config.GetReportTimeout(), cancellationToken)) { foreach (var segment in segmentRequests) { await asyncClientStreamingCall.RequestStream.WriteAsync(SegmentV6Helpers.Map(segment)); } await asyncClientStreamingCall.RequestStream.CompleteAsync(); await asyncClientStreamingCall.ResponseAsync; } stopwatch.Stop(); _logger.LogInformation($"Report {segmentRequests.Count} trace segment. cost: {stopwatch.Elapsed}s"); } catch (Exception ex) { _logger.LogError("Report trace segment fail.", ex); _connectionManager.Failure(ex); } }
public async Task <bool> ReportInstancePropertiesAsync(ServiceInstancePropertiesRequest serviceInstancePropertiesRequest, CancellationToken cancellationToken = default) { if (!_connectionManager.Ready) { return(false); } var connection = _connectionManager.GetConnection(); return(await new Call(_logger, _connectionManager).Execute(async() => { var client = new ManagementService.ManagementServiceClient(connection); var instance = new InstanceProperties { Service = serviceInstancePropertiesRequest.ServiceId, ServiceInstance = serviceInstancePropertiesRequest.ServiceInstanceId, }; instance.Properties.Add(new KeyStringValuePair { Key = OS_NAME, Value = serviceInstancePropertiesRequest.Properties.OsName }); instance.Properties.Add(new KeyStringValuePair { Key = HOST_NAME, Value = serviceInstancePropertiesRequest.Properties.HostName }); instance.Properties.Add(new KeyStringValuePair { Key = PROCESS_NO, Value = serviceInstancePropertiesRequest.Properties.ProcessNo.ToString() }); instance.Properties.Add(new KeyStringValuePair { Key = LANGUAGE, Value = serviceInstancePropertiesRequest.Properties.Language }); foreach (var ip in serviceInstancePropertiesRequest.Properties.IpAddress) { instance.Properties.Add(new KeyStringValuePair { Key = IPV4, Value = ip }); } var mapping = await client.reportInstancePropertiesAsync(instance, _config.GetMeta(), _config.GetTimeout(), cancellationToken); //todo: should assert the result? return true; }, () => false, () => ExceptionHelpers.ReportServiceInstancePropertiesError)); }
public async Task ReportAsync(CLRStatsRequest statsRequest, CancellationToken cancellationToken = default(CancellationToken)) { if (!_connectionManager.Ready) { return; } var connection = _connectionManager.GetConnection(); try { var request = new CLRMetricCollection { Service = _instrumentConfig.ServiceName ?? _instrumentConfig.ApplicationCode, ServiceInstance = _instrumentConfig.ServiceInstanceName, }; var metric = new CLRMetric { Cpu = new CPU { UsagePercent = statsRequest.CPU.UsagePercent }, Gc = new ClrGC { Gen0CollectCount = statsRequest.GC.Gen0CollectCount, Gen1CollectCount = statsRequest.GC.Gen1CollectCount, Gen2CollectCount = statsRequest.GC.Gen2CollectCount, HeapMemory = statsRequest.GC.HeapMemory }, Thread = new ClrThread { AvailableWorkerThreads = statsRequest.Thread.MaxWorkerThreads, AvailableCompletionPortThreads = statsRequest.Thread.MaxCompletionPortThreads, MaxWorkerThreads = statsRequest.Thread.MaxWorkerThreads, MaxCompletionPortThreads = statsRequest.Thread.MaxCompletionPortThreads }, Time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }; request.Metrics.Add(metric); var client = new CLRMetricReportService.CLRMetricReportServiceClient(connection); await client.collectAsync(request, _config.GetMeta(), _config.GetTimeout(), cancellationToken); } catch (Exception e) { _logger.Warning("Report CLR Stats error. " + e); } }
public Task PingAsync(PingRequest request, CancellationToken cancellationToken = default(CancellationToken)) { if (!_connectionManager.Ready) { return(Task.CompletedTask); } var connection = _connectionManager.GetConnection(); return(new Call(_logger, _connectionManager).Execute(async() => { var client = new ManagementService.ManagementServiceClient(connection); await client.keepAliveAsync(new InstancePingPkg { Service = request.ServiceName, ServiceInstance = request.InstanceId, }, _config.GetMeta(), _config.GetTimeout(), cancellationToken); }, () => ExceptionHelpers.PingError)); }
public Task PingAsync(PingRequest request, CancellationToken cancellationToken = default(CancellationToken)) { if (!_connectionManager.Ready) { return(Task.CompletedTask); } var connection = _connectionManager.GetConnection(); return(new Call(_logger, _connectionManager).Execute(async() => { var client = new ServiceInstancePing.ServiceInstancePingClient(connection); await client.doPingAsync(new ServiceInstancePingPkg { ServiceInstanceId = request.ServiceInstanceId, ServiceInstanceUUID = request.InstanceId, Time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }, _config.GetMeta(), _config.GetTimeout(), cancellationToken); }, () => ExceptionHelpers.PingError)); }