教學課程:使用 Azure Chaos Studio 排程週期性實驗

Azure Chaos Studio 可讓您執行混亂實驗,刻意讓應用程式或服務的一部分失敗,以確認它能夠針對這些失敗進行復原。 定期執行這些混亂實驗會很有用,以確保應用程式的復原能力未回歸或符合合規性需求。 在本教學課程中,您會使用 邏輯應用程式 來觸發實驗,每天執行一次。

在本教學課程中,您會了解如何:

  • 建立邏輯應用程式。
  • 設定邏輯應用程式以觸發混亂實驗,每天啟動一次。
  • 測試邏輯應用程式是否已正確設定。

必要條件

建立邏輯應用程式

邏輯應用程式是可根據排程執行的自動化工作流程。 本教學課程中使用的邏輯應用程式會使用週期排程啟動混亂實驗。

  1. 使用您的 Azure 帳戶認證,登入 Azure 入口網站。 在 Azure 首頁上,選取 [ 建立資源]。

  2. 在 [Azure Marketplace] 功能表上,選取 [整合>邏輯應用程式]。

    Screenshot that shows the Azure Marketplace menu with Integration and Logic App selected.

  3. 在 [ 建立邏輯應用程式 ] 窗格上,提供有關您要建立之邏輯應用程式的相關信息。

    Screenshot that shows the Logic App creation pane and the information to provide for the new logic app.

    屬性 Description
    訂用帳戶 <Azure-訂閱-名稱> 您的 Azure 訂用帳戶名稱。 此範例使用 Azure Chaos Studio 示範
    資源群組 chaosstudiodemo 用來組織相關資源之 Azure 資源群組的名稱。 此範例會建立名為 chaosstudiodemo 的新資源群組。
    類型 耗用 邏輯應用程式資源類型。 設定為 [ 取用]。
    名稱 scheduleExperiment 邏輯應用程式的名稱,只能包含字母、數位、連字元、底線、括弧和句點。 此範例使用 scheduleExperiment
    位置 美國東部 要儲存邏輯應用程式資訊的區域。 此範例使用 美國東部。
    啟用記錄分析 No 設定邏輯應用程式的診斷記錄。 設定為 [否]。
  4. 當您完成時,選取 [檢閱 + 建立]。 在 Azure 驗證邏輯應用程式的相關信息之後,選取 [ 建立]。

  5. 在 Azure 部署您的應用程式之後,選取 [移至資源]。

    Azure 會開啟 Logic Apps 範本選取窗格,其中顯示簡介影片、常用的觸發程式和邏輯應用程式範本模式。

新增週期觸發程式

接下來,新增迴圈 觸發程式,其會根據指定的排程執行工作流程。 每個邏輯應用程式都必須以觸發程式開頭,而觸發程式會在發生特定事件或新數據符合特定條件時引發。

  1. 向下卷動至 [範本] 區段的影片和一般觸發程式區段,然後選取 [空白邏輯應用程式]。

    Screenshot that shows the Logic Apps template selection pane with Blank Logic App selected.

  2. 在 [Logic Apps 設計工具] 搜尋方塊中,輸入 週期 ,然後選取名為 Recurrence 的觸發程式。

    Screenshot that shows the Logic Apps Designer search box that contains the recurrence search term and in the Triggers list, the Recurrence trigger appears selected.

  3. 在 [ 週期 ] 圖形上 ,選取省略號...) 按鈕,然後選取 [ 重新命名]。 使用開始混亂實驗的描述, 將觸發程式重新命名為每天早上

    Screenshot that shows the ellipses button selected, the Settings list open, and the Rename command selected.

  4. 在觸發程式內,依照這裡所述變更這些屬性。

    Screenshot that shows the changes to the trigger's interval and frequency.

    屬性 必填 Description
    間隔 Yes 1 檢查之間要等候的間隔數目
    頻率 Yes 用於週期的時間單位
  5. 在 [間隔] 和 [頻率]下,開啟 [新增參數] 清單。 選取這些屬性以新增至觸發程式:

    • 這些小時
    • 在幾分鐘

    Screenshot that shows the opened Add new parameter list and these selected properties: On these days, At these hours, and At these minutes.

  6. 現在,請設定屬性的值,如這裡所示並說明。

    Screenshot that shows the action properties set to the values as described in the following table.

    屬性 Description
    這些小時 8 只有在您將 [頻率] 設定為 [] 或 [日] 時,才能使用此設定。 針對此週期,選取一天中的小時。 這個範例會在 8 小時標記執行。
    在幾分鐘 00 只有在您將 [頻率] 設定為 [] 或 [日] 時,才能使用此設定。 針對此週期,選取當天的分鐘數。 這個範例會在零小時標記上執行一次。

    此觸發程式會在上午 8:00 引發每個工作日。 [ 預覽] 方塊會顯示週期排程。 如需詳細資訊,請參閱排程工作和工作流程和工作流程動作和觸發程式。

  7. 儲存邏輯應用程式。 在設計師工具列上選取儲存

新增執行混亂實驗動作

現在您已擁有觸發程式,請新增 啟動實驗的動作 。 本教學課程使用叫用 資源作業 動作來啟動實驗。

  1. 在邏輯應用程式設計工具的 [週期觸發程式] 底下,選取 [ 新增步驟]。

  2. 在 [選擇作業] 下,輸入 [叫用資源作業]。 選取名為 Invoke 資源作業的 [動作] 底下的選項。

    Screenshot that shows the search bar filled in with Invoke resource operation.

  3. 設定儲存實驗的正確 用戶,然後選取 [ 登入]。

  4. 登入該租使用者的 Azure 帳戶。

  5. 現在,請設定動作屬性的值,如下所示並說明。

    Screenshot that shows the properties set to the values as described in the following table.

    屬性 Description
    訂用帳戶 <Azure-訂閱-名稱> 部署混亂實驗的 Azure 訂用帳戶名稱。 此範例使用 Azure Chaos Studio 示範
    資源群組 <Resource-group-name> 部署混亂實驗之資源群組的名稱。 此範例使用 chaosstudiodemo
    資源提供者 Microsoft.Chaos Chaos Studio 資源提供者。
    簡短資源標識碼 experiments/<Resource-group-name> 混亂實驗的名稱前面加上 實驗/
    用戶端 API 版本 2023-11-01 Chaos Studio REST API 版本。
    動作名稱 start Chaos Studio 實驗動作的名稱。 一律 啟動
  6. 儲存邏輯應用程式。 在設計師工具列上選取儲存

測試邏輯應用程式

現在,測試邏輯應用程式,以確定它已成功啟動您的實驗。

  1. 關閉 Logic Apps 設計工具。

  2. 在邏輯應用程式概觀上,選取 [執行觸發程序>執行]。

    Screenshot that shows the Run Trigger option.

  3. 移至 Azure 入口網站 中的混亂實驗,並確認 [狀態] 已設定為 [正在執行]。

    Screenshot that shows the experiment status.

清除資源

如果您不打算繼續使用此應用程式,請使用下列步驟刪除邏輯應用程式:

  1. 在邏輯應用程式概觀上,選取 [ 刪除]。
  2. 輸入邏輯應用程式名稱,然後選取 [ 刪除]。

下一步

現在您已設定實驗的排程,您可以: