デプロイメントの追跡
New Relicを有効にできます 変更の追跡 クラウドインフラストラクチャプロジェクト上のCommerceのデプロイメントイベントを監視する機能。
Deployments データ収集は、CPU、メモリ、応答時間など、全体的なパフォーマンスに対するデプロイメントの変更の影響を分析するのに役立ちます。 参照: NerdGraph を使用した変更の追跡 が含まれる New Relic ドキュメント.
NR_API_URL
:New Relic API エンドポイント(ここでは NerdGraph API URL)https://api.newrelic.com/graphql
NR_API_KEY
:ユーザーキーを作成します。を参照してください New Relicの API キー が含まれる New Relic ドキュメント。NR_APP_GUID
:New Relicにデータをレポートするエンティティには、一意の ID (GUID)があります。 例えば、ステージング環境でを有効にするには、ステージング環境を調整しますNR_APP_GUID
を使用したクラウド変数 ステージングエンティティ GUID New Relicから を参照してください。 New Relic エンティティについて学ぶ および NerdGraph チュートリアル:エンティティ データの表示 が含まれる New Relic ドキュメント。
デプロイメントの追跡を有効にする
を作成して、New RelicでCommerce プロジェクトのデプロイメントイベントを追跡します。 script 統合。
トラック デプロイメントを有効にするには:
-
ローカルワークステーションで、をプロジェクトディレクトリに変更します。
-
を作成
action-integration.js
ファイル。 以下のコードをコピーして、に貼り付けます。action-integration.js
ファイルと保存:code language-javascript function trackDeployments() { const envName = activity.payload.environment.name; let variables; activity.payload.deployment.variables.forEach(function(variable) { if (variable.name === "env:NR_CONFIG") { variables = variable.value; } }); const config = JSON.parse(variables.replace(/'/g, '"')); const commitSha = activity.payload.commits ? activity.payload.commits[0].sha : activity.payload.environment.head_commit; const deploymentType = activity.type; if (!(envName in config)) { throw new Error('There is no configuration for ' + envName); } const configEnv = config[envName]; if (!configEnv.NR_APP_GUID || !configEnv.NR_API_KEY || !configEnv.NR_API_URL) { throw new Error('You must define the next configuation in the env variable NR_CONFIG: NR_APP_GUID, NR_API_KEY and NR_API_URL'); } const query = `mutation { changeTrackingCreateDeployment( deployment: { version: "${commitSha}", entityGuid: "${configEnv.NR_APP_GUID}", commit: "${commitSha}", changelog: "${deploymentType}" } ) { deploymentId entityGuid } }`; var resp = fetch(configEnv.NR_API_URL, { method: 'POST', headers: { 'Content-Type': 'application/json', 'API-Key': configEnv.NR_API_KEY }, body: JSON.stringify({ query }) }); if (!resp.ok) { console.log('Sending new relic change tracking failed: ' + resp.text()); } else { console.log(resp.text()); } } trackDeployments();
-
を作成 script を使用したの統合
magento-cloud
CLI コマンドと参照action-integration.js
ファイル。code language-bash magento-cloud integration:add --type script --events='environment.restore, environment.push, environment.branch, environment.activate, environment.synchronize, environment.initialize, environment.merge, environment.redeploy, environment.variable.create, environment.variable.delete, environment.variable.update' --file ./action-integration.js --project=<YOUR_PROJECT_ID> --environments=<YOUR_ENVIRONMENT_ID>
応答の例:
code language-terminal Created integration 767u4hathojjw (type: script) +-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------+ | Property | Value | +-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------+ | id | 767u4hathojjw | | type | script | | role | | | events | - environment.restore | | | - environment.push | | | - environment.branch | | | - environment.activate | | | - environment.synchronize | | | - environment.initialize | | | - environment.merge | | | - environment.redeploy | | | - environment.variable.create | | | - environment.variable.delete | | | - environment.variable.update | | environments | - staging | | | - production | | excluded_environments | { } | | states | - complete | | result | * | | script | function variables() { | | | var vars = {}; | | | activity.payload.deployment.variables.forEach(function(variable) { | | | vars[variable.name] = variable.value; | | | }); | | | return vars; | | | } | | | | | | function trackDeployments() { | | | const envName = activity.payload.environment.name; | | | | | | const config = JSON.parse(variables()['env:NR_CONFIG'].replace(/'/g, '"')); | | | const commitSha = activity.payload.commits ? activity.payload.commits[0].sha : activity.payload.environment.head_commit; | | | const deploymentType = activity.type; | | | | | | if (!(envName in config)) { | | | throw new Error('There is no configuration for ' + envName); | | | } | | | | | | const configEnv = config[envName]; | | | | | | if (!configEnv.NR_APP_GUID || !configEnv.NR_API_KEY || !configEnv.NR_API_URL) { | | | throw new Error('You must define the next configuation in the env variable NR_CONFIG: NR_APP_GUID, NR_API_KEY and NR_API_URL'); | | | } | | | | | | const query = `mutation { | | | changeTrackingCreateDeployment( | | | deployment: { | | | version: "${commitSha}", | | | entityGuid: "${configEnv.NR_APP_GUID}", | | | commit: "${commitSha}", | | | changelog: "${deploymentType}" | | | } | | | ) { | | | deploymentId | | | entityGuid | | | } | | | }`; | | | | | | var resp = fetch(configEnv.NR_API_URL, { | | | method: 'POST', | | | headers: { | | | 'Content-Type': 'application/json', | | | 'API-Key': configEnv.NR_API_KEY | | | }, | | | body: JSON.stringify({ | | | query | | | }) | | | }); | | | | | | if (!resp.ok) { | | | console.log('Sending new relic change tracking failed: ' + resp.text()); | | | } else { | | | console.log(resp.text()); | | | } | | | } | | | | | | trackDeployments(); | | | | +-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
-
後で使用するために、統合 ID をメモします。 この例では、ID はです。
code language-terminal Created integration 767u4hathojjw (type: script)
オプションで、統合を検証し、次を使用して統合 ID をメモすることができます。
magento-cloud integration:list
-
前提条件を使用して環境変数を作成します。
code language-bash magento-cloud variable:create --level project --name=env:NR_CONFIG --value='{"<YOUR_ENVIRONMENT_ID>":{"NR_API_KEY": "<YOUR_API_KEY>", "NR_API_URL": "https://api.newrelic.com/graphql", "NR_APP_GUID":"<YOUR_APP_GUID>"}}' -p <YOUR_PROJECT_ID>
-
最後のアクティビティログを確認します。
code language-bash magento-cloud integration:activity:log <INTEGRATION_ID> -p <YOUR_PROJECT_ID> -e <YOUR_ENVIRONMENT_ID>
応答:
code language-terminal Integration ID: 767u4hathojjw Activity ID: poxqidsfajkmg Type: integration.script Description: Running activity script Created: 2023-08-28T20:32:02+00:00 State: complete Log: HTTP request HTTP response {"data":{"changeTrackingCreateDeployment":{"deploymentId":"some-deployment-id","entityGuid":"SomeGUIDhere"}}}
-
にログイン New Relic アカウント.
-
エクスプローラーナビゲーションメニューで、 APM & Services. 環境を選択 Name および Account.
-
次の下 イベント を選択し、 Change tracking.