public async Task ReportHealthAsync( HealthScope scope, string propertyName, HealthState state, string unhealthyEvaluations, string source, CancellationToken cancellationToken, string serviceName = null, string instanceName = null) { var(clusterId, tenantId, clusterType) = await ClusterIdentificationUtility.TupleGetClusterIdAndTypeAsync(this.fabricClient, this.token).ConfigureAwait(true); string jsonPayload = JsonConvert.SerializeObject( new { id = $"FO_{Guid.NewGuid().ToString()}", datetime = DateTime.UtcNow, clusterId = clusterId ?? string.Empty, clusterType = clusterType ?? string.Empty, source = ObserverConstants.FabricObserverName, property = propertyName, healthScope = scope.ToString(), healthState = state.ToString(), healthEvaluation = unhealthyEvaluations, serviceName = serviceName ?? string.Empty, instanceName = instanceName ?? string.Empty, }); await this.SendTelemetryAsync(jsonPayload).ConfigureAwait(false); }
// This is the only function impl that really makes sense for ClusterObserver // with respect to ITelemetryProvider as CO does not monitor resources and generate data. // It just reports AggregatedClusterHealth and related details surfaced by other Fabric services // running in the cluster. public async Task ReportHealthAsync( HealthScope scope, string propertyName, HealthState state, string unhealthyEvaluations, string source, CancellationToken cancellationToken, string serviceName = null, string instanceName = null) { var(clusterId, _) = await ClusterIdentificationUtility.TupleGetClusterIdAndTypeAsync(fabricClient, token).ConfigureAwait(true); string jsonPayload = JsonConvert.SerializeObject( new { id = $"CO_{Guid.NewGuid()}", datetime = DateTime.UtcNow, clusterId = clusterId ?? string.Empty, source = ObserverConstants.ClusterObserverName, property = propertyName, healthScope = scope.ToString(), healthState = state.ToString(), healthEvaluation = unhealthyEvaluations, serviceName = serviceName ?? string.Empty, instanceName = instanceName ?? string.Empty, osPlatform = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Windows" : "Linux", }); await SendTelemetryAsync(jsonPayload, cancellationToken).ConfigureAwait(false); }
public static string GetErrorWarningNameFromFOCode(string id, HealthScope scope) { if (string.IsNullOrEmpty(id)) { return(string.Empty); } IDictionary <string, string> dict = AppErrorCodesDictionary; if (scope == HealthScope.Node) { dict = NodeErrorCodesDictionary; } return(dict.TryGetValue( id, out string err) != false ? err : string.Empty); }
/// <summary> /// Calls AI to report health. /// </summary> /// <param name="scope">Scope of health evaluation (Cluster, Node, etc.).</param> /// <param name="propertyName">Value of the property.</param> /// <param name="state">Health state.</param> /// <param name="unhealthyEvaluations">Unhealthy evaluations aggregated description.</param> /// <param name="source">Source of emission.</param> /// <param name="cancellationToken">CancellationToken instance.</param> /// <param name="serviceName">Optional: TraceTelemetry context cloud service name.</param> /// <param name="instanceName">Optional: TraceTelemetry context cloud instance name.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> public Task ReportHealthAsync( HealthScope scope, string propertyName, HealthState state, string unhealthyEvaluations, string source, CancellationToken cancellationToken, string serviceName = null, string instanceName = null) { if (!this.IsEnabled || cancellationToken.IsCancellationRequested) { return(Task.FromResult(1)); } try { cancellationToken.ThrowIfCancellationRequested(); var sev = (state == HealthState.Error) ? SeverityLevel.Error : (state == HealthState.Warning) ? SeverityLevel.Warning : SeverityLevel.Information; string healthInfo = string.Empty; if (!string.IsNullOrEmpty(unhealthyEvaluations)) { healthInfo += $"{Environment.NewLine}{unhealthyEvaluations}"; } var tt = new TraceTelemetry($"Service Fabric Health Report - {Enum.GetName(typeof(HealthScope), scope)}: {Enum.GetName(typeof(HealthState), state)} -> {source}:{propertyName}{healthInfo}", sev); tt.Context.Cloud.RoleName = serviceName; tt.Context.Cloud.RoleInstance = instanceName; this.telemetryClient.TrackTrace(tt); } catch (Exception e) { this.logger.LogWarning($"Unhandled exception in TelemetryClient.ReportHealthAsync:{Environment.NewLine}{e}"); throw; } return(Task.FromResult(0)); }