如果問題聽起來含糊不清,我很抱歉。這是我觀察的場景。健康管理中心的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屬性。感謝您的解釋! –