My Functionは1時間に15回(4分ごとに)呼び出され、startQueryでクエリを実行します。約30分後に「無効な資格情報」エラーがランダムに発生します。すべての呼び出しが失敗するまで、頻繁に発生します。Google Cloud機能からBigQueryを呼び出しているランダムな「ApiError:無効な認証情報」
このクエリは、データセットのテーブルからデータを読み取り、オプションdestination
とwriteDisposition=WRITE_TRUNCATE
を使用して、別のデータセットにあるテーブルに結果を保存します。 2つのデータセットはEUにあります。
機能を再デプロイすると、問題が一時的に取り除かれます。
gcloud beta functions describe my-function
を呼び出すと、App Engineのデフォルトサービスアカウント:[email protected]
が使用されます。ここで
は、エラーの詳細は次のとおりです。
ApiError: Invalid Credentials
at Object.parseHttpRespBody (/user_code/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:192:30)
at Object.handleResp (/user_code/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:132:18)
at /user_code/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/src/util.js:465:12
at Request.onResponse [as _callback] (/user_code/node_modules/@google-cloud/bigquery/node_modules/retry-request/index.js:160:7)
at Request.self.callback (/user_code/node_modules/@google-cloud/bigquery/node_modules/request/request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/user_code/node_modules/@google-cloud/bigquery/node_modules/request/request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
編集
コード、剥奪:
const bigquery = require('@google-cloud/bigquery')();
const destinationDataset = bigquery.dataset('destinationDataset');
const destinationTable = dataset.table('destinationTable');
exports.aggregate = function aggregate (event) {
const message = event.data;
const attributes = message.attributes;
let job;
let destinationTable;
return Promise.resolve()
.then(() => {
if (attributes.partition == null) {
throw new Error('Partition time not provided. Make sure you have a "partitionTime" attribute in your message');
}
const query = 'SELECT ... FROM sourceTable WHERE _PARTITIONTIME = TIMESTAMP(@partitionTime)'; // The dataset is specified in the job options below
// Query options list: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query
// and: https://googlecloudplatform.github.io/google-cloud-node/#/docs/bigquery/0.9.6/bigquery?method=startQuery
const options = {
destination: destinationTable,
writeDisposition: 'WRITE_TRUNCATE',
query: query,
defaultDataset: { datasetId: 'sourceDataset' },
timeoutMs: 540000, // 9 minutes, same timeout as the Cloud Function
useLegacySql: false,
parameterMode: 'NAMED',
queryParameters: [{
name: 'partitionTime',
parameterType: { type: 'STRING' },
parameterValue: { value: attributes.partition }
}]
};
return bigquery.startQuery(options);
})
.then((results) => {
job = results[0];
console.log(`BigQuery job ${job.id} started, generating data in ${destinationTable.dataset.id}.${destinationTable.id}.`);
return job.promise();
})
.then((results) => {
// Get the job's status
return job.getMetadata();
})
.then((metadata) => {
// Check the job's status for errors
const errors = metadata[0].status.errors;
if (errors && errors.length > 0) {
throw errors;
}
})
// Only if a destination table is given
.then(() => {
console.log(`BigQuery job ${job.id} completed, data generated in ${destinationTable.dataset.id}.${destinationTable.id}.`);
})
.catch((err) => {
console.log(`Job failed for ${inspect(attributes)}: ${inspect(err)}`);
return Promise.reject(err);
});
};
BigQueryのオブジェクトを初期化しているときは、私は何のオプションを与えていないことに気づくでしょう:require('@google-cloud/bigquery')()
。
BigQueryジョブユーザとuse the RuntimeConfig APIのサービスアカウントを作成して、資格情報をgitの元にプッシュしないようにする必要がありますか?
なぜこのエラーがランダムに発生するのかという疑問が残っています。ファンクションログを見ると、真夜中から午後4時までのすべてのコールでエラーが発生し、午前5時36分までコールの3分の1でエラーが発生しました。そしてその時(4時間前)以来、それは一度も起こりませんでした。
編集2
これが成功したものに比べて失敗した呼び出しの頻度を示します。すべてのエラー(緑色)は、「無効な資格情報」エラーです。これらの7日間は何も触れられていませんでした。デプロイメントがなく、設定が変更されず、BigQueryでフィディングが発生しませんでした。
コードのサンプルを表示できますか? –
完了。 *編集*セクションが追加されました。 – nfo
同じ問題が発生しました。私は新しいクラウドストレージのアップロード(1分ごとに発生)から通知されたクラウド機能を持っており、関数は1分ごとに呼び出され、テーブルにロードするbigqueryを呼び出すだけで、この関数は2週間前に実行されましたApiErrorは今日まで問題なく、いつもではなく、数分でランダムに発生します。 これはGoogle側からの操作上の問題である必要があります – user5672998