服务健康状态不会在 Health Manager 的 azure service fabric explorer 中更新?
Service health status doesn't update in azure service fabric explorer from Health Manager?
如果问题听起来含糊不清,我深表歉意。这是我观察到的情况。
我创建了一个带有 2 个无状态服务的 azure 服务结构应用程序 (POC)。
Service-1
最初报告它的健康状况为 OK 在第一次迭代中有 5 分钟的生存时间 并等待等待 2 分钟(随机配置等待 2 分钟)。
- 10 秒后,
Service-2
报告其健康状况为 错误 生存时间为 10 秒 在第一次迭代中。连这个都要等2分钟
此时,Service fabric explorer 正确显示 Service-1's
状态为正常,Service-2's
状态为错误。 符合预期。
- 与此同时,
Service-1
的第二次迭代开始并报告其状态为 ERROR。
- Service-2 的第二次迭代也开始并报告其状态为 OK 现在。
预期:Service fabric explorer 将显示 Service-1's
状态为错误,Service-2's
状态为正常。
ACTUAL:两项服务都显示为错误。
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);
}
由于第二个生命值 属性 与第一个生命值 属性 不同(因为您是根据迭代命名它们),第一个生命值 属性 将一直保留到其 TTL然后使其行为由 RemoveWhenExpired 属性 定义(默认情况下为 false,因此它将保留)。第一个 属性 不会被“OK”健康报告覆盖,因为它是 "different property"。在 SFX 中,我敢打赌您实际上会看到这两个属性。他们需要具有相同的名称才能按照您期望的方式工作。更多信息 here.
如果问题听起来含糊不清,我深表歉意。这是我观察到的情况。
我创建了一个带有 2 个无状态服务的 azure 服务结构应用程序 (POC)。
Service-1
最初报告它的健康状况为 OK 在第一次迭代中有 5 分钟的生存时间 并等待等待 2 分钟(随机配置等待 2 分钟)。- 10 秒后,
Service-2
报告其健康状况为 错误 生存时间为 10 秒 在第一次迭代中。连这个都要等2分钟
此时,Service fabric explorer 正确显示 Service-1's
状态为正常,Service-2's
状态为错误。 符合预期。
- 与此同时,
Service-1
的第二次迭代开始并报告其状态为 ERROR。 - Service-2 的第二次迭代也开始并报告其状态为 OK 现在。
预期:Service fabric explorer 将显示 Service-1's
状态为错误,Service-2's
状态为正常。
ACTUAL:两项服务都显示为错误。
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);
}
由于第二个生命值 属性 与第一个生命值 属性 不同(因为您是根据迭代命名它们),第一个生命值 属性 将一直保留到其 TTL然后使其行为由 RemoveWhenExpired 属性 定义(默认情况下为 false,因此它将保留)。第一个 属性 不会被“OK”健康报告覆盖,因为它是 "different property"。在 SFX 中,我敢打赌您实际上会看到这两个属性。他们需要具有相同的名称才能按照您期望的方式工作。更多信息 here.