如果问题听起来含糊不清,我很抱歉。这是我观察的场景。健康管理中心的Azure服务结构浏览器中的服务运行状况不会更新?
我创建了一个具有2个无状态服务的azure服务结构应用程序(POC)。
Service-1
最初的报告是健康OK与生存时间的第一次迭代5分钟和2分钟等待(任意配置的等待2分钟)。- 10秒后,
Service-2
报告它的健康错误与存活时间为10秒在其第一次迭代。即使这样也等待2分钟。
此时,Service fabric explorer正确显示Service-1's
状态为OK,Service-2's
状态为Error。 AS EXPECTED。
- 同时,
Service-1
开始和报告第二次迭代它现在的地位错误。 - 服务-2的第二次迭代也启动并现在报告其状态为好吧。
预期:服务织物探险家将显示Service-1's
状态错误和Service-2's
地位确定。
实际:两种服务都显示为错误。
不服务fabric explorer每次刷新时都会从Health Manager中获取运行状况状态?如果是这样,为什么我将两个服务的状态显示为错误?下面
代码以供参考: 服务-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);
}
明白了。我没有设置RemoveWhenExpired属性。感谢您的解释! –