我对配置文件的格式有一些问题。我有一些类似这样的服务帐户文件
{
"type": "service_account",
"project_id": "my-project",
"private_key_id": "XXXXX_my_private_key_id_XXXXXXX",
"private_key": "-----BEGIN PRIVATE KEY-----\nXXXXXXX_my_private_key___\nXXXXX_another_line_here_XXXXX\nXXXXXX_final_line_XXXXXX==\n-----END PRIVATE KEY-----\n",
"client_email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0c6175217c7e6366696f784c6f63617c6d627522656d61226b7f697e7a656f696d6f6f63796278226f6361" rel="noreferrer noopener nofollow">[email protected]</a>",
"client_id": "123456",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/my-project%40company.iam.gserviceaccount.com"
}
以及我放入 /etc/grafana/provisioning/datasources/all.yaml
中的配置文件
看起来像这样
apiVersion: 1
# list of datasources to insert/update depending
# what's available in the database
datasources:
# <string, required> name of the datasource. Required
- name: bigquery-project
type: doitintl-bigquery-datasource
access: proxy
isDefault: true
jsonData:
authenticationType: jwt
clientEmail: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4c9dd89d4d6cbcec1c7d0e4c7cbc9d4c5cadd8acdc5c98ac3d7c1d6d2cdc7c1c5c7c7cbd1cad08ac7cbc9" rel="noreferrer noopener nofollow">[email protected]</a>
defaultProject: my-default-project
tokenUri: https://accounts.google.com/o/oauth2/token
secureJsonData:
privateKey: "-----BEGIN PRIVATE KEY-----\nXXXXXXX_my_private_key___\nXXXXX_another_line_here_XXXXX\nXXXXXX_final_line_XXXXXX==\n-----END PRIVATE KEY-----\n"
version: 2
readOnly: false
但是当我单击“保存并测试”时,出现了一些错误。我想我的配置文件格式错误。
我尝试使用 UI 上传服务帐户文件,测试通过,我能够查询 BQ。然而,当我这样做时,我在 /etc/grafana/provisioning/datasources
中找不到任何文件来获取它的示例。
我正在 Docker 容器中执行自定义 Grafana 镜像
### file system hierarchy of the project
.
├── Dockerfile
└── provisioning
├── dashborads
└── datasources
└── all.yaml
### Docker file
ARG GRAFANA_VERSION=6.5.3
FROM grafana/grafana:$GRAFANA_VERSION
ENV GF_AUTH_DISABLE_LOGIN_FORM "true"
ENV GF_AUTH_ANONYMOUS_ENABLED "true"
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
ENV GF_INSTALL_PLUGINS "doitintl-bigquery-datasource 1.0.4"
我运行容器的方式
docker run -d -p 3000:3000 -v $(pwd)/provisioning:/etc/grafana/provisioning massy/custom-grafana
我通过卷提供配置文件。
配置文件有什么问题? 当我们在 Grafana 中添加数据源时,配置文件不是会自动更新吗? (如果没有创建那么它将是?) 当我测试 bigquery 插件时如何获取日志?
编辑
当我尝试在“新仪表板”部分添加虚拟 SQL 查询时,这就是我得到的结果
lvl=eror msg="Failed to get access token" logger=data-proxy-log error="private key should be a PEM or plain PKCS1 or PKCS8; parse error: asn1: structure error: tags don't match (16 vs {class:0 tag:28 length:110 isCompound:true}) {optional:false explicit:false application:false private:false defaultValue:<nil> tag:<nil> stringType:0 timeType:0 set:false omitEmpty:false} pkcs1PrivateKey @2"
t=2020-01-22T10:02:18+0000 lvl=info msg=Requesting logger=data-proxy-log url=https://www.googleapis.com/bigquery/v2/projects/undefined/queries
t=2020-01-22T10:02:18+0000 lvl=info msg="Request Completed" logger=context userId=0 orgId=1 uname= method=POST path=/api/datasources/proxy/1/bigquery/v2/projects/undefined/queries status=401 remote_addr=172.17.0.1 time_ms=55 size=304 referer="http://localhost:3000/dashboard/new?panelId=2&edit&fullscreen&orgId=1&gettingstarted"
我在容器上做了一个docker日志
最佳答案
这是配置文件的正确格式
apiVersion: 1
datasources:
- name: bigquery-project
type: doitintl-bigquery-datasource
access: proxy
isDefault: true
jsonData:
authenticationType: jwt
clientEmail: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="80edf9adf0f2efeae5e3f4c0e3efedf0e1eef9aee9e1edaee7f3e5f2f6e9e3e5e1e3e3eff5eef4aee3efed" rel="noreferrer noopener nofollow">[email protected]</a>
defaultProject: my-default-project
tokenUri: https://accounts.google.com/o/oauth2/token
secureJsonData:
privateKey: |
-----BEGIN PRIVATE KEY-----
XXXXXXX_my_private_key___
XXXXX_another_line_here_XXXXX
XXXXXX_final_line_XXXXXX
-----END PRIVATE KEY-----
version: 2
readOnly: false
两个配置文件之间存在差异:
- https://grafana.com/grafana/plugins/doitintl-bigquery-datasource?version=1.0.4
- https://github.com/doitintl/bigquery-grafana#example-of-provisioning-a-file
GitHub 上的格式正确
关于docker - 在 Grafana 中使用 BigQuery 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59840012/