Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB] Provide extra failure information from Balancer response #1309

Merged
merged 6 commits into from
Dec 21, 2022

Conversation

garyparrot
Copy link
Collaborator

Resolve #1308.

{
  "done": false,
  "generated": true,
  "id": "4110d2b7-d7b4-42ec-8527-aee453d0e33e",
  "report": {
    "function": "WeightCompositeClusterCost[{\"org.astraea.common.cost.ReplicaLeaderCost@5f041d67\" weight 1.0}, {\"org.astraea.common.cost.ReplicaSizeCost@5d0bc877\" weight 1.0}]"
  },
  "scheduled": false
}

現在 Balancer Web API 遇到找不到更好計劃的情況時,GET /balancer/{id} 回傳的結果看起來像上面的 json,內容沒有太多關於計劃沒生出來的提示,使用者看到可能會很混淆。會造成這個的主要原因是 Balancer#offer 回傳 Optional<Balancer.Plan>,由於 Optional 的存在我們基本上不知道為什麼計劃沒辦法被生成出來,也不清楚目前叢集的 ClusterCost 分數(initial cluster cost),基本上 initial cluster cost 就算找不到更好的計劃也可以計算出來,但因為 Optional 的關係這個資訊只有在計劃真的計算出來時才能提供(最早 BalancerHandler 的設計是儘管找不到更好的計劃,也能提供 initial cost,但因為 Balancer#retryOffer 的 PR,這個計算 initial cost 的邏輯被迫從 Handler 移動到 Balancer 界面裡面,因此這個訊息被迫和 Balancer.Plan 綁定)。

這個 PR 做下面的修正

  1. Balancer#offer()Balancer#retryOffer 現在直接回傳 Balancer.Plan
  2. Balancer.Plan 只剩下 initial cost 和一個新字串 description 兩個欄位
  3. Balancer.Plan#description 是這個計劃的 metadata 字串,由 Balancer 的實作填寫,這個資訊會放到 Report 中
  4. 新增一個物件 Balancer.ProposalPlan,他繼承 Balancer.Plan,多了三個欄位: proposed cost, proposed cluster, move cost

然後順便修正了一個 bug

  • 儘管 Balance Plan 沒有計算出 Proposal,我們也能執行他,只是什麼事情都不會發生,現在修改行為成:嘗試執行沒有 proposal 的計劃會丟出 IllegalStateException

下面是新的沒產生可用計劃的 GET /balancer/{id} 回應

{
  "done": false,
  "generated": true,
  "id": "3352599c-edd7-4552-b61b-989dce709483",
  "report": {
    "cost": 1,
    "description": "Unable to find a better log allocation",
    "function": "WeightCompositeClusterCost[{\"org.astraea.app.web.BalancerHandlerTest$IncreasingCost@3f6177f8\" weight 1.0}]"
  },
  "scheduled": false
}

* Now `Balancer.Plan` means a plan that might contain proposal.
* Extract some proposal exclusive fields into `Balancer.ProposalPlan`.
* Implement `Balancer.Plan#asProposalPlan`, which try to convert current
  plan into a `Balancer.ProposalPlan`.
* Change the return type of `Balancer#offer` to `Balancer.Plan`.
@garyparrot garyparrot self-assigned this Dec 19, 2022
Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@garyparrot garyparrot merged commit dbd4113 into opensource4you:main Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[WEB] Provide extra failure information from Balancer
2 participants