示例#1
0
        public void ReportHealth(IList <RoleInstance> roleInstances, TimeSpan validityPeriod)
        {
            // start with an initial assumption that health is okay.
            const HealthState InputHealthState = HealthState.Ok;

            try
            {
                HealthState serviceHealthState = (roleInstances == null || roleInstances.Count == 0)
                    ? HealthState.Warning
                    : GetRoleInstanceHealth(roleInstances, InputHealthState, healthPolicyManager);

                string description = GetServiceHealthDescription(roleInstances, serviceHealthState);

                // Specify a time to live. In case infrastructure service is down, the health report shows up as warning (or error)
                var hi = new HealthInformation(
                    Constants.HealthReportSourceId,
                    RoleInstanceHealthConstants.HealthReportReplicaHealthWatchdogStatus,
                    serviceHealthState)
                {
                    Description       = description,
                    TimeToLive        = validityPeriod != TimeSpan.Zero ? validityPeriod : TimeSpan.MaxValue,
                    RemoveWhenExpired = true
                };

                // Construct this name ourselves since there is currently a bug where the service Uri which
                // could have been passed in all the way from ServiceFactory's CreateReplica is an empty string.
                var serviceUri = new Uri(ServiceNamePrefix + configSection.Name);

                // We'll roll up the health to the service level bypassing the replica and partition health.
                // Since only 1 replica is actively doing something and there is only a single partition of
                // this service, rolling up health higher is preferred since it can catch the user's eyes a
                // little bit faster.
                var healthReport = new ServiceHealthReport(serviceUri, hi);

                healthClient.ReportHealth(healthReport);
            }
            catch (Exception ex)
            {
                Trace.WriteWarning(
                    RoleInstanceHealthConstants.TraceType,
                    "Unable to report health from role instance health watchdog. Error(s): {0}",
                    ex.GetMessage());
            }
        }
示例#2
0
        private void UpdateCoordinatorStatusHealthProperty(HealthState serviceHealthState, string description)
        {
            var hi = new HealthInformation(
                Constants.HealthReportSourceId,
                Constants.CoordinatorStatus,
                serviceHealthState)
            {
                Description = description,
            };

            var serviceUri   = this.factoryArgs.ServiceName;
            var healthReport = new ServiceHealthReport(serviceUri, hi);

            healthClient.ReportHealth(healthReport);
        }