0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Cloud Run JobsのエラーをSlackに通知する

Last updated at Posted at 2025-05-27

1. Slack 通知チャネルを準備する

  1. GCP コンソール → Notification channels を開く
  2. Slack セクションで Add new をクリックし、ワークスペースとチャンネルを認可・登録する

2. Logs Explorer でクエリを作成

  1. GCP コンソール → Logs Explorer を開く

  2. クエリ欄に以下を入力し、Run で結果を確認

    resource.type="cloud_run_job"
    severity="ERROR"
    (
        resource.labels.job_name="your-cloud-run-jobs-name"
    )
    

    ORを使って、複数のCloud Run Jobsを選択することもできます

    resource.type="cloud_run_job"
    severity="ERROR"
    (
        resource.labels.job_name="your-cloud-run-jobs-name-1"
        OR resource.labels.job_name="your-cloud-run-jobs-name-2"
    )
    

    自動生成ログを除外したい場合は、以下のようにlogNameを使って絞り込めます

    resource.type="cloud_run_job"
    severity="ERROR"
    (
        resource.labels.job_name="your-cloud-run-jobs-name"
    )
    logName="projects/your-project-id/logs/run.googleapis.com%2Fstdout"
    

3. ログベースのアラートを作成

  1. Logs Explorer の結果画面上部、操作 メニュー → ログアラートの作成 を選択

  2. Alert details ペインで以下を設定:

    項目 設定例
    Alert Policy Name Your Alert Policy Name
    Policy severity Error
    Documentation - Markdown を選択
    - Add documentation に以下を記述:
    *Job*: `${resource.labels.job_name}`  
    *Error*: `${log.extracted_label.error_message}`  
    

    ${log.extracted_label.error_message} は次のステップで抽出するログ本文です

  3. Choose logs to include in the alert 画面で、先ほどのクエリがそのまま入っていることを確認

  4. Extract log labels を使って、ログ本文を取り出すラベルを追加

    ラベルを追加 ボタンをクリック

    項目 設定内容
    Display name error_message
    Log field name textPayload
    正規表現 ^(.*)$(全文キャプチャ)
  5. Set notification frequency and autoclose duration画面で、通知の間隔とインシデントの自動クローズ期間を設定

    項目 設定例
    通知の間隔 5分
    インシデントの自動クローズ期間 7日
  6. Notification channels で先ほど作成した Slack チャネルを選択 → Save

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?