GoogleCloudPlatform / GoogleCloudPlatform/cloud-logging-data-source-plugin

grafana_data_source creation w/ terraform causes consistent Plugin Error

オープン
#202 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
TypeScript
スター
24
フォーク
17
平均マージ
13時間 11分
マージ済み PR(30日)
11

説明

I've created the datasource manually via the UI using JWT and the plugin works great, however I tried to mimic the setup in our prod grafana instance with the same plugin version (latest) as of today and got errors.

The datasource is created correctly, however we see this error when trying to utilise it in UI Explorer:
An error occurred within the plugin

We're already managing our Google Cloud Monitoring datasources via code w/o any issues like so:

resource "grafana_data_source" "metrics_cm" {
  provider = grafana.prod
  name     = "Cloud Monitoring - Metrics"
  type     = "stackdriver" # taken from grafana docs
  uid      = "<UUID>"
  json_data_encoded = jsonencode({
    authenticationType = "jwt"
    clientEmail        = "<SA_NAME>@<GCP_ACCOUNT_ID>.iam.gserviceaccount.com"
    defaultProject     = "GCP_ACCOUNT_ID"
    tokenUri           = "https://oauth2.googleapis.com/token"
  })
  secure_json_data_encoded = jsonencode({
    privateKey = data.google_secret_manager_secret_version.metrics-bq-datasource-private-key.secret_data
  })
}

I tried a very similar approach for the cloud-logging & verified the format of the data_encoded fields is accurate by importing the "test" instance which was created by the UI:

resource "grafana_data_source" "cloudlogging_peng_renovate" {
  provider = grafana.prod
  name     = "Cloud Logging - Renovate Logs"
  type     = "googlecloud-logging-datasource"

  json_data_encoded = jsonencode({
    authenticationType = "jwt"
    clientEmail        = "<SA_NAME>@<GCP_ACCOUNT_ID>.iam.gserviceaccount.com"
    defaultProject     = "GCP_ACCOUNT_ID"
    tokenUri           = "https://oauth2.googleapis.com/token"
    pdcInjected     = true
  })

  secure_json_data_encoded = jsonencode({
    privateKey = data.google_secret_manager_secret_version.plat-eng-renovate-private-key.secret_data
  })
}

These keys are in the same format for Cloud Monitoring & Cloud Logging secrets, and are extracted from the same JWT generated & uploaded manually in the UI for our test instance (which works):

-----BEGIN PRIVATE KEY-----\n<KEY_CONTENT>\n-----END PRIVATE KEY-----\n

This privateKey content works fine for Cloud Monitoring Datasource, but as mentioned above fails for Cloud Logging.

I also verified the UI HTTP request content is the same as the data we are providing in our terraform example:

{
...
  "name": "Cloud Logging - Renovate",
  "type": "googlecloud-logging-datasource",
...
  "jsonData": {
    "authenticationType": "jwt",
    "pdcInjected": true,
    "clientEmail": "<SA_NAME>@<GCP_ACCOUNT_ID>.iam.gserviceaccount.com",
    "defaultProject": "GCP_ACCOUNT_ID",
    "tokenUri": "https://oauth2.googleapis.com/token"
  },
  "secureJsonFields": { "privateKey": true },
...
  "apiVersion": "",
  "secureJsonData": {
    "privateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvg...stripped...+CaQjPULhx\n-----END PRIVATE KEY-----\n"
  }
}

I feel like the terraform datasource module might be stripping/malforming the privateKey content, and so it the datasource isn't created the same as when setting up via raw JWT and UI. Any help with this would be great!

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リポジトリのファイルやテストは指定されていません。まず Terraform で管理されている googlecloud-logging-datasource を再現し、その privateKey ペイロードを動作している UI リクエストと比較してください。UI Explorer で datasource が正常に読み込まれれば作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
gcp, grafana, terraform
領域
cloud, devops, observability-sre
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
静か
明瞭さ
おおむね明確
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。