1
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?

dora-teamのfourkeysダッシュボードを展開する手順

Last updated at Posted at 2025-07-02

はじめに

DevOps Research and Assessment(DORA)チームが提唱しているFourKeysという指標があります。
FourKeysに関しては以下を参照。

そして、自分の環境でもFourKeysを計測しようと思い、FourKeysプロジェクトを展開しようと思ったのですが、
最終更新から日が経っていたこともあり、ところどころ手順通りでは動作しませんでした。

その為、現在(2025/07/02)の上手くいった手順を書き残しておきます。

リソースの展開手順

手順は以下のREADMEを参考に進めます。

0. 事前準備

  1. 課金が有効になっている Google Cloud プロジェクトを用意
  2. 用意したプロジェクトでオーナー権限を付与

1. CloudShellを開く

CloudShellからデプロイを推奨されているため。

2. プロジェクト ID を示す環境変数を設定

READMEの1.と同じ。

export PROJECT_ID="YOUR_PROJECT_ID"

3. fourkeys リポジトリのクローン & ディレクトリ移動

READMEの2.と同じ。

git clone https://github.com/dora-team/fourkeys.git && cd fourkeys

4. event-handlerにパッケージ追加

READMEのまま手順を進めると、event-handlerコンテナにsixパッケージが不足していてエラーになった。
その為、予めsixパッケージを含めるようにする必要がある。

/fourkeys/event-handler/requirements.txt
# 追加
six

5. GCR から GARへの移行

fourkeysプロジェクトでは、GCR(Container Registry)を使用している。
しかし、GCRは2025/03/18に廃止されたためGAR(Artifact Registry)に移行する必要がある。

移行コマンドの実行

gcloud artifacts docker upgrade migrate --projects=$PROJECT_ID

各cloudbuild.yamlの修正

cd ~/fourkeys

# dashboardのcloudbuild.yaml修正
sed -i 's|gcr.io/$PROJECT_ID/|us-docker.pkg.dev/$PROJECT_ID/gcr.io/|g' dashboard/cloudbuild.yaml

# event-handlerのcloudbuild.yaml修正
sed -i 's|gcr.io/$PROJECT_ID/|us-docker.pkg.dev/$PROJECT_ID/gcr.io/|g' event-handler/cloudbuild.yaml

# bq-workersのcloudbuild.yaml修正
sed -i 's|gcr.io/$PROJECT_ID/|us-docker.pkg.dev/$PROJECT_ID/gcr.io/|g' bq-workers/parsers.cloudbuild.yaml

Terraformテンプレートの修正

terraform/modules/fourkeys/locals.tf
data "google_project" "project" {
  project_id = var.project_id
}

locals {
  cloud_build_service_account = "${data.google_project.project.number}@cloudbuild.gserviceaccount.com"
  # 移行先のArtifact Registryリポジトリ設定
  artifact_registry_url = "us-docker.pkg.dev/${var.project_id}/gcr.io"
  event_handler_container_url = var.event_handler_container_url == "" ? format("%s/event-handler", local.artifact_registry_url) : var.event_handler_container_url
  dashboard_container_url     = var.dashboard_container_url == "" ? format("%s/fourkeys-grafana-dashboard", local.artifact_registry_url) : var.dashboard_container_url
  github_parser_url = var.github_parser_url == "" ? format("%s/github-parser", local.artifact_registry_url) : var.github_parser_url
  gitlab_parser_url = var.gitlab_parser_url == "" ? format("%s/gitlab-parser", local.artifact_registry_url) : var.gitlab_parser_url
  cloud_build_parser_url = var.cloud_build_parser_url == "" ? format("%s/cloud-build-parser", local.artifact_registry_url) : var.cloud_build_parser_url
  tekton_parser_url = var.tekton_parser_url == "" ? format("%s/tekton-parser", local.artifact_registry_url) : var.tekton_parser_url
  circleci_parser_url = var.circleci_parser_url == "" ? format("%s/circleci-parser", local.artifact_registry_url) : var.circleci_parser_url
  pagerduty_parser_url = var.pagerduty_parser_url == "" ? format("%s/pagerduty-parser", local.artifact_registry_url) : var.pagerduty_parser_url
  services = var.enable_apis ? [
    "bigquery.googleapis.com",
    "cloudbuild.googleapis.com",
    "run.googleapis.com",
    "secretmanager.googleapis.com",
  ] : []
}

6. イベントハンドラ用のコンテナをビルドし、GARにプッシュ

READMEの3.と同じ。

gcloud builds submit dashboard --config=dashboard/cloudbuild.yaml --project $PROJECT_ID && \
gcloud builds submit event-handler --config=event-handler/cloudbuild.yaml --project $PROJECT_ID

7. パーサー用のコンテナをビルドし、GARにプッシュ

READMEの4.と同じ。

gcloud builds submit bq-workers --config=bq-workers/parsers.cloudbuild.yaml --project $PROJECT_ID --substitutions=_SERVICE=github

8. 作業ディレクトリを移動し、terraform.tfvars.exampleをterraform.tfvarsに

READMEの5.と同じ。

cd terraform/example && mv terraform.tfvars.example terraform.tfvars

9. terraform.tfvarsの変数の値を変更

必要に応じて値を変更。

example
project_id = "<PROJECT_ID>"
region = "us-central1"
bigquery_region = "US"
parsers = ["github"]

10. terraformの実行

READMEの7.と同じ。

Terraformを初期化

terraform init

変更のプレビュー

terraform plan

リソースを展開

terraform apply

Mockデータの作成手順

1. イベントハンドラーのURLを環境変数にエクスポート

READMEの内容では以下ですが、実行してみると空でした。

export WEBHOOK=`gcloud run services list --project $PROJECT_ID | grep event-handler | awk '{print $4}'`

そのため、以下のコマンドを実行しURLを変数WEBHOOKに設定しました。

gcloud run services describe event-handler --region=us-central1 --project=$PROJECT_ID

2. イベントハンドラのシークレットを環境変数にエクスポート

READMEと同じ。

export SECRET=`gcloud secrets versions access 1 --secret=event-handler --project $PROJECT_ID`

3. generate_data.pyを実行

READMEと同じ。

python3 data-generator/generate_data.py --vc_system=github

4. bq を使用してテーブルに生成されたデータを表示

READMEと同じ。

bq query --project_id $PROJECT_ID 'SELECT * FROM four_keys.events_raw WHERE source = "githubmock";'

ダッシュボードの確認

URLにアクセス

Mockデータの作成時、設定したWEBHOOKのURLにアクセスすればダッシュボードが確認できる。
反映が即時ではないのか、作成直後はNo dataと表示される。
image.png

少し時間が経てば、Mockデータで見られるようになる。
image.png

注意点

  • terraformで作成するcloudrunがパブリック公開される

おわりに

READMEで手順があったので楽勝だと思ったのですが、色々なエラーが押し寄せてきて気づいたら大変でした。
GCPをほとんど触っておらず不慣れだったということもありますが…。

一先ず展開はできるはずなので、これから触る人の一助になれば幸いです。

1
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
1
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?