Suivi des déploiements
Vous pouvez activer la fonction New Relic Suivi des modifications pour surveiller les événements de déploiement sur votre projet d’infrastructure cloud Commerce.
La collecte de données relative aux déploiements permet d’analyser l’impact des modifications apportées au déploiement sur les performances globales, telles que le CPU, la mémoire, le temps de réponse, etc. Voir Suivi des modifications à l’aide de NerdGraph dans la documentation de New Relic.
NR_API_URL
: point d’entrée de l’API New Relic, dans ce cas l’URL de l’API NerdGraphhttps://api.newrelic.com/graphql
NR_API_KEY
: créez une clé utilisateur, consultez Clés API New Relic dans la documentation de New Relic.NR_APP_GUID
: une entité qui transmet des données à New Relic possède un ID unique (GUID). Par exemple, pour l’activer dans un environnement d’évaluation, ajustez la variable cloudNR_APP_GUID
de l’environnement d’évaluation avec le GUID de l’entité d’évaluation de New Relic. Consultez les tutoriel En savoir plus sur les entités New Relic et NerdGraph : Afficher les données d’entité dans la documentation New Relic.
Activer le suivi des déploiements
Suivez les événements de déploiement de votre projet Commerce dans New Relic en créant une intégration script.
Pour activer les déploiements de suivi :
-
Sur votre station de travail locale, accédez au répertoire du projet.
-
Créez un fichier
action-integration.js
. Copiez le code suivant, collez-le dans le fichieraction-integration.js
et enregistrez-le :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();
-
Créez une intégration script à l’aide de la commande
magento-cloud
CLI et référencez le fichieraction-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>
Exemple de réponse :
code language-none 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(); | | | | +-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
-
Notez l’ID d’intégration pour une utilisation ultérieure. Dans cet exemple, l’ID est :
code language-none Created integration 767u4hathojjw (type: script)
Vous pouvez éventuellement vérifier l’intégration et noter l’ID d’intégration à l’aide de :
magento-cloud integration:list
-
Créez la variable d’environnement à l’aide des conditions préalables.
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>
-
Consulter le dernier journal d’activité.
code language-bash magento-cloud integration:activity:log <INTEGRATION_ID> -p <YOUR_PROJECT_ID> -e <YOUR_ENVIRONMENT_ID>
Réponse :
code language-none 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"}}}
-
Connectez-vous à votre compte New Relic.
-
Dans le menu de navigation de l’Explorateur, cliquez sur APM & Services. Sélectionnez le Name et le Account de votre environnement.
-
Sous Événements, cliquez sur Change tracking.