This example uses the Node.js serverless
toolset to create an AWS Lambda
function implemented in Python to handle websocket requests from a simulated
build system. Requests to the lambda function are logged to a DynamoDB database
so that the elapsed time of each step of the build process can be captured. The
lambda function reports build started
and build complete
events to Splunk
Infrastucture Monitoring along with metrics for the build and each step (
build_system.build_time_ms
and build_system.step_time_ms
, respectively)
A sample dashboard is provided illustrating usage of these metrics and annotation via events.
-
Install
serverless
from https://www.serverless.com/. This toolset is used to push lambda functions and supporting components as described via theserverless.yml
configuration.npm install -g serverless cd ci-webhook-handler npm init --yes npm install --save serverless-python-requirements
-
Review the info in
serverless.yml
. You can change the names of the resources inserverless.yml
, but you'll need to make corresponding changes to the lambda function. -
Create an AWS Credential for serverless to deploy
There are several options for connecting. See : https://www.serverless.com/framework/docs/providers/aws/guide/credentials/
-
Package the necessary python libraries with the runtime.
serverless
uses Docker to build a custom runtime by pulling the AWS runtime as a docker image and including dependencies declared inrequirements.txt
into that image to form a custom runtime. NOTE: THIS MAY TAKE A VERY LONG TIME THE FIRST RUN (if it has to pull base images from AWS Docker repo and rundocker build
)serverless deploy
When that is complete you should see the lambda URL denoted under
endpoints:
as the solePOST
endpoint -
The configuration in
serverless.yml
sets up a secret using AWS Secrets Manager to store your Splunk Infrastructure Monitoring credentials. This secret is by default namedSignalFx/Ingest
. You will need to edit that secret and set the secret values for two keysSignalFxRealm
andSignalFxToken
. -
At this point you should have a running lambda function which you can test at the command line via (using the lambda URL which was returned from the
serverless deploy
command):curl -X POST -H "Content-Type: application/json" -d '{ "environment": "env01", "buildId": "abc321", "eventType": "start_build", "buildStep": "start", "status": "success" }' <lambda_url>
(wait a few seconds)
curl -X POST -H "Content-Type: application/json" -d '{ "environment": "env01", "buildId": "abc321", "eventType": "build_step", "buildStep": "step1", "status": "success" }' <lambda_url>
(wait a few seconds)
curl -X POST -H "Content-Type: application/json" -d '{ "environment": "env01", "buildId": "abc321", "eventType": "build_complete", "buildStep": "finito", "status": "success" }' <lambda_url>
-
You should now be able to log into Splunk Infrastructure Monitoring and create a new chart showing metrics
build_system.build_time_ms
andbuild_system.step_time_ms
. -
You can generate some fake data with:
python3 generate-test-events.py <lambda_url> <environment>
-
You can import the custom dashboard
dashboard_Build System Demo.json
. You should see metrics and events depicted in that dashboard.