Hi sinka08.
My app has both ways of starting the app, the code-change option and the no code change option.
Depending on docker container variables, we start using EXEC NPM START
or EXEC CA-APM-RUN.
- With CA-APM-RUN, the application fails to boot.
- Without variables, the NPM start is executed
I tried having the no-code-change executed, and the probe.start() method and both did not work.
One of the questions I have is, how should I know/find out what is the URL HOST and port for the probe.start syntax. When using the no code change option, it ends up binding to a container in docker, but with the following errors:
-rw-r--r--. 1 nodejs nodejs 697 Mar 21 19:03 Probe-backend-pvd.log
sh-4.2$ cat Probe-backend-pvd.log
2018/03/21 19:01:22:805+00:00 - info: ProbeName Detection choosing the name: backend-pvd
2018/03/21 19:01:22:857+00:00 - info: Loading cluster probe
2018/03/21 19:01:22:857+00:00 - info: cluster probe: master
2018/03/21 19:01:22:913+00:00 - info: Noticed module: fs
2018/03/21 19:01:23:683+00:00 - info: Noticed module: express
2018/03/21 19:01:23:684+00:00 - info: Express 4.x Routing Mechanism
2018/03/21 19:01:23:684+00:00 - info: Loading Express probe
2018/03/21 19:01:23:685+00:00 - info: Probe express can be controlled by PBD
2018/03/21 19:01:37:878+00:00 - info: Noticed module: cluster
2018/03/21 19:03:35:237+00:00 - info: [Command Conn Error]Error: connect ETIMEDOUT 10.123.254.17:5005
Heres the script that we use :
#!/bin/bash
function nodejscollector_find(){
regex_appName='^[A-Za-z0-9]*$'
string="$NODEJSCOLLECTOR"
if [[ $string =~ $regex_appName ]]
then
echo "Internal nodejscollector"
return 1
else
echo "External nodejscollector"
return 0
fi
}
echo "========================================="
echo "Starting application"
echo "========================================="
env | sort
#### I have to validate if ARTIFACT_URL is available
if [ -n "$ARTIFACT_URL" ]
then
file=`basename "$ARTIFACT_URL"`
wget -q --no-check-certificate --connect-timeout=5 --read-timeout=10 --tries=2 -O "/tmp/$file" "$ARTIFACT_URL"
#### I have to unpackage the file to $APP_HOME
if [ $? -eq 0 ]
then
if [[ $ARTIFACT_URL = *.tar* ]]
then
tar -xzvf /tmp/$file -C "$APP_HOME" --strip-components=1
fi
if [[ $ARTIFACT_URL = *.tgz* ]]
then
tar -xzvf /tmp/$file -C "$APP_HOME" --strip-components=1
fi
if [[ $ARTIFACT_URL = *.zip* ]]
then
unzip -o /tmp/$file -d "$APP_HOME"
fi
else
echo "ERROR: while Downloading file from $ARTIFACT_URL"
return 1
fi
fi
if [ -n $NODE_PATH ]
then
APP_HOME="$APP_HOME/$NODE_PATH"
fi
pushd $APP_HOME
if [ ! -d "node_modules" ]
then
if [ -n "$NPM_REGISTRY" ]
then
npm config set strict-ssl false
npm config set registry $NPM_REGISTRY
fi
if [ -n "$NPM_LOGLEVEL" ]
then
npm config set loglevel $NPM_LOGLEVEL
fi
npm i
fi
echo "Copiando modulos do prometheus"
cp -r $IMAGE_SCRIPTS_HOME/express-prom-bundle $APP_HOME/node_modules
echo "Configurando chamada ao prometheus"
echo '' >> $APP_HOME/app.js
echo 'var promBundle = require("express-prom-bundle");' >> $APP_HOME/app.js
echo '' >> $APP_HOME/app.js
echo 'app.use(promBundle({' >> $APP_HOME/app.js
echo ' prefix: "prometheus:fecbackend"' >> $APP_HOME/app.js
echo '}));' >> $APP_HOME/app.js
QUALIFIED_HOST_NAME="${PROJECT_NAME}-$HOSTNAME"
if [ -n "${REGION}" ]
then
QUALIFIED_HOST_NAME="$QUALIFIED_HOST_NAME-${REGION}"
fi
QUALIFIED_APP_NAME="${APP_NAME}"
if [ -n "$NODEJSCOLLECTOR" ]
then
if nodejscollector_find; then
export COLLECTOR_AGENT_HOST=$(echo ${NODEJSCOLLECTOR} | awk -F':' '{print $1}')
export COLLECTOR_AGENT_PORT=$(echo ${NODEJSCOLLECTOR} | awk -F':' '{print $2}')
if [ -n "${JENKINS_BUILD_ID}" ]
then
QUALIFIED_APP_NAME="$QUALIFIED_APP_NAME-${JENKINS_BUILD_ID}"
fi
if [ -n "${JENKINS_JOB_NAME}" ]
then
QUALIFIED_APP_NAME="$QUALIFIED_APP_NAME-${JENKINS_JOB_NAME}"
fi
export CA_APM_PROBENAME=$QUALIFIED_APP_NAME"_devops"
#export CA_APM_PROBENAME=${POD_NAME}
export CA_APM_HOSTNAME=$QUALIFIED_HOST_NAME
echo "External NodejsCollector. Will send metrics to $COLLECTOR_AGENT_HOST:$COLLECTOR_AGENT_PORT with appName ${APP_NAME}"
exec ca-apm-run .
else
export COLLECTOR_AGENT_HOST=$(env | grep -i ${NODEJSCOLLECTOR}_PORT_5005_TCP_ADDR | awk -F'=' '{print $2}')
export COLLECTOR_AGENT_PORT=$(env | grep -i ${NODEJSCOLLECTOR}_PORT_5005_TCP_PORT | awk -F'=' '{print $2}')
if [ -n "${JENKINS_BUILD_ID}" ]
then
QUALIFIED_APP_NAME="$QUALIFIED_APP_NAME-${JENKINS_BUILD_ID}"
fi
if [ -n "${JENKINS_JOB_NAME}" ]
then
QUALIFIED_APP_NAME="$QUALIFIED_APP_NAME-${JENKINS_JOB_NAME}"
fi
export CA_APM_PROBENAME=$QUALIFIED_APP_NAME"_devops"
#export CA_APM_PROBENAME=${POD_NAME}
export CA_APM_HOSTNAME=$QUALIFIED_HOST_NAME
echo "Internal NodejsCollector. Will send metrics to $COLLECTOR_AGENT_HOST:$COLLECTOR_AGENT_PORT with appName ${APP_NAME}"
exec ca-apm-run .
fi
else
echo "NodejsCollector not defined. Will not send metrics to APM."
exec npm start
fi