如果这个问题听起来含糊不清,我很抱歉。下面是我观察到的情况。
我已经用两个无状态服务创建了一个天蓝色服务结构应用程序(POC)。
Service-1最初将其健康状况报告为OK,在第一次迭代中存活时间为5分钟,等待2分钟(随机配置等待2分钟)。Service-2将其健康状况报告为Error,在其第一次迭代中以10 秒的时间存活。就连这个也要等两分钟。此时,Service资源管理器正确地显示Service-1's状态为OK,Service-2's状态为Error。如预期的,。
Service-1的第二次迭代开始并报告其状态为ERROR。预期的:Service将显示Service-1's状态为ERROR,Service-2's状态显示为OK。
实际:这两个服务都显示为错误。
Service fabric explorer不是每次刷新时都会从health那里获得健康状态吗?如果是这样的话,为什么我被显示为这两个服务的错误状态?
以下代码供参考: Service-1:
long iterations = 0;
if (iterations++%2 == 0)
{
var healthInformation = new HealthInformation("Service-1", $"{this.Context.ServiceName}-OK-{iterations}-Property",
HealthState.Ok);
healthInformation.TimeToLive = TimeSpan.FromSeconds(300);
var healthReport = new StatelessServiceInstanceHealthReport(this.Context.PartitionId,
this.Context.InstanceId, healthInformation);
fabricClient.HealthManager.ReportHealth(healthReport);
ServiceEventSource.Current.ServiceMessage(this, "Logged OK health from {0}", this.Context.ServiceName);
await Task.Delay(TimeSpan.FromSeconds(120), cancellationToken);
}
else
{
var healthInformation = new HealthInformation("Service-1", $"{this.Context.ServiceName}-Error-{iterations}-Property",
HealthState.Error);
healthInformation.TimeToLive = TimeSpan.FromSeconds(10);
var healthReport = new StatelessServiceInstanceHealthReport(this.Context.PartitionId,
this.Context.InstanceId, healthInformation);
fabricClient.HealthManager.ReportHealth(healthReport);
ServiceEventSource.Current.ServiceMessage(this, "Logged Error health from {0}", this.Context.ServiceName);
await Task.Delay(TimeSpan.FromSeconds(120), cancellationToken);
}服务-2:
long iterations = 0;
if (iterations++ % 2 == 0)
{
var healthInformation = new HealthInformation("StatelessService2", $"{this.Context.ServiceName}-Error-{iterations}-Property",
HealthState.Error);
healthInformation.TimeToLive = TimeSpan.FromSeconds(10);
var healthReport = new StatelessServiceInstanceHealthReport(this.Context.PartitionId,
this.Context.InstanceId, healthInformation);
fabricClient.HealthManager.ReportHealth(healthReport);
ServiceEventSource.Current.ServiceMessage(this, "Logged Error from {0}" , this.Context.ServiceName);
await Task.Delay(TimeSpan.FromSeconds(120), cancellationToken);
}
else
{
var healthInformation = new HealthInformation("StatelessService2", $"{this.Context.ServiceName}-OK-{iterations}-Property",
HealthState.Ok);
healthInformation.TimeToLive = TimeSpan.FromSeconds(300);
var healthReport = new StatelessServiceInstanceHealthReport(this.Context.PartitionId,
this.Context.InstanceId, healthInformation);
fabricClient.HealthManager.ReportHealth(healthReport);
ServiceEventSource.Current.ServiceMessage(this, "Logged OK from {0}" ,this.Context.ServiceName);
await Task.Delay(TimeSpan.FromSeconds(120), cancellationToken);
}发布于 2016-11-09 19:09:37
由于第二个健康属性不同于第一个健康属性(因为您是根据迭代来命名它们),第一个健康属性将一直保留到其TTL,然后具有由RemoveWhenExpired属性定义的行为(默认情况下为false,因此它将保持不变)。第一个属性不会被“OK”健康报告覆盖,因为这是一个“不同的属性”。在SFX中,我打赌你会看到这两个属性。他们需要有相同的名字才能像你所期望的那样工作。更多信息是这里。
https://stackoverflow.com/questions/40506787
复制相似问题