【发布时间】:2016-11-10 03:09:37
【问题描述】:
如果问题听起来含糊不清,我深表歉意。这是我观察到的场景。
我创建了一个包含 2 个无状态服务的 Azure Service Fabric 应用程序 (POC)。
-
Service-1在第一次迭代中最初报告它的运行状况为OK 存活时间为 5 分钟,然后等待 2 分钟(随机配置等待 2 分钟)。 - 10 秒后,
Service-2将其运行状况报告为 错误 在其第一次迭代中的生存时间为 10 秒。即使这样也要等 2 分钟。
此时,Service Fabric Explorer 正确地将 Service-1's 状态显示为 OK 并将 Service-2's 状态显示为错误。 如预期的那样。
- 同时,
Service-1的第二次迭代开始并报告它现在的状态为 ERROR。 - Service-2 的第二次迭代现在也开始并报告其状态为 OK。
预期:Service Fabric Explorer 会将Service-1's 状态显示为错误,Service-2's 状态显示为正常。
实际:两个服务都显示为错误。
Service 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);
}
【问题讨论】:
标签: c# azure azure-service-fabric