En este documento, se describen las plantillas y el código de muestra disponibles
para ayudarte a crear monitores sintéticos. Las funciones de muestra están disponibles en la
Google Cloud/synthetics-sdk-nodjs
Repositorio de GitHub.
Si escribes pruebas y no dependes de una plantilla, asegúrate de que tu prueba
pase, a menos que se arroje Error
. Recomendaciones
Usa la biblioteca de Assert
para asegurarte de que
Cuando se producen fallas, estas se atribuyen a la línea de código adecuada.
Plantillas genéricas
Las plantillas genéricas están configuradas para recopilar datos de seguimiento y registro de las solicitudes HTTP salientes. La solución aprovecha la Módulo auto-instrumentation-node de OpenTelemetry y el registrador de winston. Debido a la dependencia de los productos de código abierto, habrá cambios en la estructura de los datos de seguimiento y de registro. Por lo tanto, el seguimiento y los datos de registro solo se deben usar con fines de depuración.
Puedes implementar tu propio enfoque para recopilar datos de registro y seguimiento para llamadas salientes.
de las solicitudes HTTP. En un ejemplo de enfoque personalizado,
consulta la clase SyntheticAutoInstrumentation
.
Muestra genérica de Node.js
En el ejemplo de generic-synthetic-nodejs
, se ilustra
cómo consultar una URL. Esta muestra contiene lo mismo que la función predeterminada
que muestra la consola de Google Cloud. Para ver la muestra completa, haz clic en more_vert Más y, luego, selecciona Ver en GitHub.
Muestra de TypeScript
La muestra de generic-synthetic-typescript
ilustra cómo consultar una URL. Para ver la muestra completa, haz clic en more_vert Más y, luego, selecciona Ver en GitHub.
Plantilla de Puppeteer
Si usas Puppeteer, considera comenzar con la muestra de generic-puppeteer-nodejs
.
Configuración obligatoria de Puppeteer
Para usar Puppeteer, asegúrate de completar los siguientes pasos:
Incluye
.puppeteerrc.cjs
en el directorio del código fuente de tu Función de Cloud Run:Agrega la siguiente secuencia de comandos al archivo
package.json
de tu Función de Cloud Run:"scripts": { "gcp-build": "node node_modules/puppeteer/install.mjs" },
Muestra de Puppeteer
En la muestra de generic-puppeteer-nodejs
, se muestra cómo usar Puppeteer con tu función de Cloud Run. Para ver la muestra completa, haz clic en more_vert Más.
y, luego, selecciona Ver en GitHub.
Plantilla de Selenium WebDriver
Si usas Selenium WebDriver, considera comenzar con la muestra de generic-selenium-nodejs
. La muestra
que está disponible en GitHub e incluye un archivo index.js
y package.json
.
Para ver la muestra completa, haz clic en more_vert Más y, luego, selecciona Ver en GitHub.
Plantilla de moca
Si escribes pruebas que dependen de la plantilla Mocha, haz lo siguiente:
considere si una secuencia de pruebas debe continuar, o detenerse, cuando una
se produce un error. Para detener una secuencia de pruebas después de una falla, debes establecer la marca bail
.
Para un ejemplo de extremo a extremo que incluye la implementación de una API, una prueba Mocha de muestra para los extremos de la API y cómo configurar el monitor sintético, consulta el blog Instructivo sobre la supervisión sintética de Google Cloud.
En el ejemplo de mocha-url-ok
, se ilustra cómo
una función de Cloud Run puede invocar un
Paquete de pruebas Mocha que proporciona un paquete de pruebas de muestra.
Para ver la muestra completa, haz clic en more_vert Más.
y, luego, selecciona Ver en GitHub.
Plantilla de vínculo roto
El broken-links-ok
ilustra cómo configurar un verificador de vínculos rotos.
Para esta plantilla, solo debes especificar los valores del objeto options
. Esta
especifica el URI que se probará y los parámetros de la prueba.
Si usas Puppeteer, asegúrate de completar el Pasos necesarios para la configuración de Puppeteer
Para ver la muestra completa, haz clic en more_vert Más y, luego, selecciona Ver en GitHub.
¿Qué sigue?
- Crea un monitor sintético
- Cómo crear un verificador de vínculos rotos
- Cómo administrar monitores sintéticos
- Explora los resultados del monitor sintético