跳到主要内容
版本:v1.0

Webhook

Summary

Incoming Webhooks are your solution to bring data to Apache DevLake when there isn't a specific plugin ready for your DevOps tool. An Incoming Webhook allows users to actively push data to DevLake.

When you create an Incoming Webhook within DevLake, DevLake generates a unique URL. You can then post JSON payloads to this URL to push data directly to your DevLake instance.

In v0.14+, users can push "incidents" and "deployments" required by DORA metrics to DevLake via Incoming Webhooks.

Webhooks are meant to be used at the lowest level that you want to relate incidents with deployments. For example, if you want to relate incidents at the individual service level, you will need a webhook per service. If you wish to relate incidents at the product level, you will need a webhook for the product. This is because incidents on a project will be related to the last deployment on the project with a timestamp that is before the incident's timestamp. This is true regardless of the source of incidents or deployments.

Note: If you post incidents using webhook due to your tool not being supported but your deployments are collected via plugins automatically, you need to re-collect data for deployments for the posted incidents to get mapped to deployments based on timestamps. This is required for Change Failure Rate (DORA) metric to show up correctly for the project.

Diagram of the relationship between incidents and deployments:

Change Failure Reporting

Entities

Check out the Incoming Webhooks entities collected by this plugin.

Metrics

Metrics that can be calculated based on the data collected from Incoming Webhooks:

Configuration

API Sample Request

Deployment

If you want to collect deployment data from your system, you can use the incoming webhooks for deployment.

Payload Schema

You can copy the generated deployment curl commands to your CI/CD script to post deployments to Apache DevLake. Below is the detailed payload schema:

KeyRequiredNotes
id✔️ YesThis will be the unique ID of table cicd_deployments. This key replaced pipeline_id for clarity.
createdDate✖️ NoThe time this deploy pipeline starts. E.g. 2020-01-01T12:00:00+00:00
No default value.
startedDate✔️ YesThe time when the first deploy to a certain repo starts. E.g. 2020-01-01T12:00:00+00:00
No default value.
finishedDate✔️ YesThe time when the last deploy to a certain repo ends. E.g. 2020-01-01T12:00:00+00:00
No default value.
environment✖️ NoThe environment this deployment happens. For example, PRODUCTION STAGING TESTING DEVELOPMENT.
The default value is PRODUCTION
result✖️ Nodeployment result, one of the values : SUCCESS, FAILURE, ABORT, MANUAL,
The default value is SUCCESS.
displayTitle✖️ NoA readable title for the deployment.
name✖️ NoDeprecated.
deploymentCommits.repoUrl✔️ YesThe repo URL of the deployment commit
If there is a row in the domain layer table repos where repos.url equals repo_url, the repoId will be filled with repos.id.
deploymentCommits.repoId✖️ NoDeprecated.
deploymentCommits.refName✖️ NoThe branch/tag to deploy
No default value.
deploymentCommits.startedDate✔️ YesThe start time of the deploy to this repo. E.g. 2020-01-01T12:00:00+00:00
No default value.
deploymentCommits.finishedDate✔️ YesThe end time of the deploy to this repo. E.g. 2020-01-01T12:00:00+00:00
No default value.
deploymentCommits.commitSha✔️ YesCommit sha that triggers the deploy in this repo
deploymentCommits.commitMsg✖️ NoCommit sha of the deployment commit message
deploymentCommits.result✖️ NoThe result of the deploy to this repo. The default value is 'SUCCESS'
deploymentCommits.displayTitle✖️ NoA readable title for the deployment to this repo.
deploymentCommits.name✖️ NoDeprecated.

More information about these columns at the domain layer tables: cicd_deployments and cicd_deployment_commits.

Register a Deployment - Sample API Calls

The payload supports the deployment to one or multiple repositories (referring to the discussion).

Please replace the API_KEY with the real token generated after creating a webhook.

curl <devlake-host>/api/rest/plugins/webhook/1/deployments -X 'POST' -H 'Authorization: Bearer {API_KEY}' -d '{
"id": "required-id",
"createdDate":"2020-01-01T11:00:00+00:00",
"startedDate":"2020-01-01T12:00:00+00:00",
"finishedDate":"2020-01-02T13:00:00+00:00",
"environment":"PRODUCTION",
"result": "SUCCESS",
"displayTitle":"optional-custom-deploy-display-title",
"name": "optional-deployment-name. If you do not post a name, DevLake will generate one for you.",
"deploymentCommits":[
{
"repoUrl":"required-repo-url",
"refName": "optional-release-v0.17",
"startedDate":"2020-01-01T11:00:00+00:00",
"finishedDate":"2020-01-02T11:00:00+00:00",
"commitSha":"c1",
"commitMsg":"optional-msg-1",
"result":"SUCCESS",
"name":"optional, if null, it will be deployment for {commit_sha}",
"displayTitle":"optional-custom-deployment-commit-display-title-1"
},
{
"repoUrl":"repo-2",
"refName": "optional-release-v0.17",
"startedDate":"2020-01-01T11:00:00+00:00",
"finishedDate":"2020-01-02T11:00:00+00:00",
"commitSha":"c2",
"commitMsg":"optional-msg-2",
"result":"FAILURE",
"name":"optional, if null, it will be deployment for {commit_sha}",
"displayTitle":"optional-custom-deployment-commit-display-title-2"
}
]
}'

A real-world example - Push CircleCI deployments to DevLake

The following demo shows how to post "deployments" to DevLake from CircleCI. In this example, the CircleCI job 'deploy' is used to manage deployments.

version: 2.1

jobs:
build:
docker:
- image: cimg/base:stable
steps:
- checkout
- run:
name: "build"
command: |
echo Hello, World!

deploy:
docker:
- image: cimg/base:stable
steps:
- checkout
- run:
name: "deploy"
command: |
# The time a deploy started
started_date=`date '+%Y-%m-%dT%H:%M:%S%z'`

# Some deployment tasks here ...
echo Hello, World!

# Send the request to DevLake after deploy
# The values start with a '$CIRCLE_' are CircleCI's built-in variables
curl <devlake-host>/api/rest/plugins/webhook/1/deployments -X 'POST' -d "{
\"id\": \"$PIPELINE_ID\",
\"startedDate\":\"$started_date\",
\"finishedDate\":\"$finished_date\",
\"deploymentCommits\":\[
\{
\"commitSha\":\"$CIRCLE_SHA1\",
\"repoUrl\":\"$CIRCLE_REPOSITORY_URL\",
\}
\]
}"

workflows:
build_and_deploy_workflow:
jobs:
- build
- deploy

Incident / Issue

If you want to collect issue or incident data from your system, you can use the two webhooks for issues.

Register Issues - Update or Create Issues

POST <devlake-host>/api/rest/plugins/webhook/1/issues

needs to be called when an issue or incident is created. The body should be a JSON and include columns as follows:

KeynameRequiredNotes
url✖️ NoIssue's URL
issueKey✔️ YesIssue's key, needs to be unique in a connection
title✔️ Yes
description✖️ No
epicKey✖️ NoIssue's epic
type✖️ NoType, such as INCIDENT, BUG, REQUIREMENT
status✔️ YesIssue's status. Must be one of TODO DONE IN_PROGRESS
originalStatus✔️ YesStatus in your tool, such as created/open/closed/...
storyPoint✖️ No
resolutionDate✖️ NoResolved date, Format should be 2020-01-01T12:00:00+00:00
createdDate✔️ YesCreated date, Format should be 2020-01-01T12:00:00+00:00
updatedDate✖️ NoLast updated date, Format should be 2020-01-01T12:00:00+00:00
leadTimeMinutes✖️ NoHow long from this issue accepted to develop.
parentIssueKey✖️ No
priority✖️ No
originalEstimateMinutes✖️ No
timeSpentMinutes✖️ No
timeRemainingMinutes✖️ No
creatorId✖️ NoThe user id of the creator
creatorName✖️ NoThe username of the creator, it will just be used to display
assigneeId✖️ No
assigneeName✖️ No
severity✖️ No
component✖️ No

More information about these columns at the domain layer issues table.

Register Issues - Close Issues (Optional)

POST <devlake-host>/api/rest/plugins/webhook/1/issue/:issueId/close

needs to be called when an issue or incident is closed. Replace :issueId with specific strings and keep the body empty.

Register Issues - Sample API Calls

Sample CURL for creating an incident:

curl <devlake-host>/api/rest/plugins/webhook/1/issues -X 'POST' -d '{
"issueKey":"DLK-1234",
"title":"a feature from DLK",
"description":"",
"url":"",
"type":"INCIDENT",
"status":"TODO",
"createdDate":"2020-01-01T12:00:00+00:00",
"updatedDate":"2020-01-01T12:00:00+00:00",
"priority":"",
"severity":"",
"creatorId":"user1131",
"creatorName":"Nick name 1",
"assigneeId":"user1132",
"assigneeName":"Nick name 2"
}'

Sample CURL for Issue Closing:

curl <devlake-host>/api/rest/plugins/webhook/1/issue/DLK-1234/close -X 'POST'

References