【问题标题】:Service health status doesn't update in azure service fabric explorer from Health Manager?服务运行状况不会在运行状况管理器的 Azure 服务结构资源管理器中更新?
【发布时间】:2016-11-10 03:09:37
【问题描述】:

如果问题听起来含糊不清,我深表歉意。这是我观察到的场景。

我创建了一个包含 2 个无状态服务的 Azure Service Fabric 应用程序 (POC)。

  1. Service-1 在第一次迭代中最初报告它的运行状况为OK 存活时间为 5 分钟,然后等待 2 分钟(随机配置等待 2 分钟)。
  2. 10 秒后,Service-2 将其运行状况报告为 错误 在其第一次迭代中的生存时间为 10 。即使这样也要等 2 分钟。

此时,Service Fabric Explorer 正确地将 Service-1's 状态显示为 OK 并将 Service-2's 状态显示为错误。 如预期的那样

  1. 同时,Service-1 的第二次迭代开始并报告它现在的状态为 ERROR
  2. 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


    【解决方案1】:

    由于第二个健康属性与第一个健康属性不同(因为您是根据迭代命名它们),所以第一个健康属性将一直保留到其 TTL,然后具有由 RemoveWhenExpired 属性定义的行为(即默认情况下为 false,因此它会保留)。第一个属性不会被“OK”健康报告覆盖,因为它是“不同的属性”。我敢打赌,在 SFX 中,您实际上会看到这两个属性。他们需要具有相同的名称才能按您期望的方式工作。更多信息是here

    【讨论】:

    • 知道了。我没有设置 RemoveWhenExpired 属性。谢谢解释!
    猜你喜欢
    • 1970-01-01
    • 2017-01-30
    • 2020-05-07
    • 2016-03-16
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    • 2016-01-22
    • 1970-01-01
    相关资源
    最近更新 更多