Tracciare le distribuzioni
È possibile abilitare New Relic Rileva modifiche per monitorare gli eventi di distribuzione nel progetto di infrastruttura cloud Commerce.
La raccolta dati sulle distribuzioni consente di analizzare l’impatto delle modifiche apportate alle prestazioni complessive, ad esempio CPU, memoria, tempo di risposta e altro ancora. Consulta Tracciare le modifiche utilizzando NerdGraph nel Documentazione di New Relic.
NR_API_URL
: endpoint API New Relic, in questo caso URL API NerdGraphhttps://api.newrelic.com/graphql
NR_API_KEY
: crea una chiave utente, vedi Chiavi API New Relic nel New Relic documentazione.NR_APP_GUID
: un’entità che segnala i dati a New Relic ha un ID univoco (GUID). Ad esempio, per abilitare in un ambiente di staging, regola l'ambiente di stagingNR_APP_GUID
variabile cloud con GUID entità di gestione temporanea da New Relic. Consulta la Informazioni sulle entità New Relic e Esercitazione NerdGraph: visualizzare i dati delle entità nel New Relic documentazione.
Abilita tracciamento distribuzioni
Monitora gli eventi di implementazione del progetto Commerce in New Relic creando un’ script integrazione.
Per abilitare le distribuzioni di tracciamento:
-
Sulla workstation locale, passa alla directory del progetto.
-
Creare un
action-integration.js
file. Copia il seguente codice e incollalo inaction-integration.js
file e salva: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();
-
Creare un script integrazione tramite
magento-cloud
Comando CLI e riferimento aaction-integration.js
file.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>
Risposta di esempio:
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(); | | | | +-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
-
Prendi nota dell’ID integrazione per un utilizzo successivo. In questo esempio, l’ID è:
code language-terminal Created integration 767u4hathojjw (type: script)
Facoltativamente, puoi verificare l’integrazione e annotare l’ID integrazione utilizzando:
magento-cloud integration:list
-
Crea la variabile di ambiente utilizzando i prerequisiti.
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>
-
Esaminare l'ultimo registro attività.
code language-bash magento-cloud integration:activity:log <INTEGRATION_ID> -p <YOUR_PROJECT_ID> -e <YOUR_ENVIRONMENT_ID>
Risposta:
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"}}}
-
Accedi al tuo Account New Relic.
-
Nel menu di navigazione di Explorer, fai clic su APM & Services. Seleziona l’ambiente Name e Account.
-
Sotto Eventi, fai clic su Change tracking.