-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de6531f
commit b61c818
Showing
21 changed files
with
755 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Workflow for building the demo service | ||
|
||
name: Build Service | ||
|
||
# Controls when the action will run. | ||
on: | ||
# Triggers the workflow on push or pull request events but only for the main branch | ||
pull_request: | ||
branches: [ main ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
build: | ||
# The type of runner that the job will run on | ||
runs-on: ubuntu-latest | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
id: go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 1.22 | ||
cache: false | ||
|
||
# Fetches all necessary go packages and builds the project | ||
- name: Build | ||
run: | | ||
go build -o anomaly-simulation-service | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
name: Create and publish an OCI image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Determine next version and push tag | ||
id: semantic-release | ||
uses: codfish/semantic-release-action@v3 | ||
with: | ||
tag-format: 'v${version}' | ||
branches: | | ||
[ 'main' ] | ||
plugins: | | ||
['@semantic-release/commit-analyzer', '@semantic-release/release-notes-generator', '@semantic-release/github'] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Log in to the container registry (GitHub packages) | ||
if: steps.semantic-release.outputs.new-release-published == 'true' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
if: steps.semantic-release.outputs.new-release-published == 'true' | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
# Set version tag based on semantic release output | ||
type=semver,pattern=v{{version}},value=${{ steps.semantic-release.outputs.release-version }} | ||
# Set latest tag | ||
type=raw,value=latest | ||
- name: Build and push Docker image | ||
if: steps.semantic-release.outputs.new-release-published == 'true' | ||
id: push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
anomaly-simulation-service | ||
|
||
# Test binary, build with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# IntelliJ Idea | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# syntax=docker/dockerfile:1 | ||
FROM golang:1.22 | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod *.go ./ | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o /anomaly-simulation-service | ||
|
||
EXPOSE 8080 | ||
|
||
CMD ["/anomaly-simulation-service"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# Generic demo service | ||
|
||
Purpose of this service is to simulate specific anomaly situations, such as: | ||
|
||
- Slowdowns | ||
- Failures | ||
- Increase in resource consumption | ||
- Process crashes | ||
- Calls to one or more other services | ||
|
||
Therefore, this generic service can be used to build all kinds of variable demo | ||
situations with either flat or deep call trees. | ||
|
||
The service listenes on following HTTP resource pathes: | ||
- GET '/' normal page return | ||
- POST '/config' service receives anomaly config as a HTTP POST message with a JSON config payload that is defined below. | ||
|
||
Thanks to [Wolfgang Beer](https://github.com/wolfgangB33r) for the initial implementation of this service. | ||
|
||
## Usage | ||
|
||
Start service by specifying a listening port: | ||
`./service.exe 8090` | ||
Start the service multiple times and let the services call each other | ||
`./service.exe 8090` | ||
`./service.exe 8091` | ||
|
||
## Dynamically reconfigure the service | ||
|
||
Push a http POST request to /config on your started service. | ||
|
||
## Config JSON body | ||
|
||
Count always represents the number of service requests that suffer from that anomaly, e.g.: a count of 5 means the next 5 service requests are affected. | ||
A crash anomaly kills the service process with the given exit code. The resource anomaly allocates a matrix of 100x100 elements multiplied by the given severity. | ||
Callees let you specify the callees this service calls with each service request. Specifying callees allows you to build dynamic multi-level service call trees. | ||
In case the attribute 'Balanced' is set to 'true', the callees are equally iterated with each request. | ||
|
||
```json | ||
{ | ||
"ErrorConfig": { | ||
"ResponseCode": 500, | ||
"Count": 5 | ||
}, | ||
"SlowdownConfig": { | ||
"SlowdownMillis": 500, | ||
"Count": 1 | ||
}, | ||
"CrashConfig": { | ||
"Code": 3 | ||
}, | ||
"ResourceConfig": { | ||
"Severity": 5, | ||
"Count": 2 | ||
}, | ||
"Callees": [ | ||
{ | ||
"Adr": "http://www.example.com", | ||
"Count": 10 | ||
}, | ||
{ | ||
"Adr": "http://www.orf.at", | ||
"Count": 3 | ||
}, | ||
{ | ||
"Adr": "http://localhost:8090", | ||
"Count": 3 | ||
} | ||
], | ||
"Balanced": true | ||
} | ||
``` | ||
|
||
## Example topology | ||
|
||
The `example1/start.sh` shell script copies the generic demo service into 6 individual services. Starts those 6 services on the same machine on 6 different ports and configures them to call them each other in the topology shown by Dynatrace below: | ||
|
||
![](examples/example1/example1.png) | ||
|
||
## Balanced example | ||
|
||
The `balancer/start.sh` shell script copies the generic demo service into 6 individual services. Starts those 6 services on the same machine on 6 different ports and configures them to form a balancer and worker pool topology, as it is shown by Dynatrace below: | ||
|
||
![](examples/balancer/balancer.png) | ||
|
||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
pkill balancer | ||
pkill worker | ||
|
||
sleep 5 | ||
|
||
cp ../../anomaly-simulation-service balancer | ||
cp ../../anomaly-simulation-service worker | ||
|
||
./balancer 9000& | ||
DT_IGNOREDYNAMICPORT=true DT_NODE_ID=1 ./worker 9100& | ||
DT_IGNOREDYNAMICPORT=true DT_NODE_ID=2 ./worker 9200& | ||
DT_IGNOREDYNAMICPORT=true DT_NODE_ID=3 ./worker 9300& | ||
DT_IGNOREDYNAMICPORT=true DT_NODE_ID=4 ./worker 9400& | ||
DT_IGNOREDYNAMICPORT=true DT_NODE_ID=5 ./worker 9500& | ||
|
||
sleep 5 | ||
|
||
curl -i -X POST \ | ||
-H "Content-Type:application/json" \ | ||
-d \ | ||
'{ | ||
"Callees" : [ | ||
{ "Adr" : "http://localhost:9100", "Count" : 1 }, | ||
{ "Adr" : "http://localhost:9200", "Count" : 1 }, | ||
{ "Adr" : "http://localhost:9300", "Count" : 1 }, | ||
{ "Adr" : "http://localhost:9400", "Count" : 1 }, | ||
{ "Adr" : "http://localhost:9500", "Count" : 1 } | ||
], | ||
"Balanced" : true | ||
}' \ | ||
'http://localhost:9000/config' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# first, configure the balancer to only send to 2 workers instead of previously 5 | ||
|
||
curl -i -X POST \ | ||
-H "Content-Type:application/json" \ | ||
-d \ | ||
'{ | ||
"Callees" : [ | ||
{ "Adr" : "http://localhost:9400", "Count" : 3 }, | ||
{ "Adr" : "http://localhost:9500", "Count" : 3 } | ||
], | ||
"Balanced" : true | ||
}' \ | ||
'http://localhost:9000/config' | ||
|
||
# then, slowdown the remaining 2 workers because of the load shift | ||
|
||
sleep 80 | ||
|
||
curl -i -X POST \ | ||
-H "Content-Type:application/json" \ | ||
-d \ | ||
'{ | ||
"SlowdownConfig" : { | ||
"SlowdownMillis" : 500, | ||
"Count" : 3000 | ||
}, | ||
"Callees" : [ | ||
] | ||
}' \ | ||
'http://localhost:9400/config' | ||
|
||
curl -i -X POST \ | ||
-H "Content-Type:application/json" \ | ||
-d \ | ||
'{ | ||
"SlowdownConfig" : { | ||
"SlowdownMillis" : 500, | ||
"Count" : 3000 | ||
}, | ||
"Callees" : [ | ||
] | ||
}' \ | ||
'http://localhost:9500/config' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
pkill customerAPI | ||
pkill sideService | ||
pkill calcService | ||
pkill restService | ||
pkill recomService | ||
pkill modelService | ||
|
||
sleep 5 | ||
|
||
cp ../../anomaly-simulation-service customerAPI | ||
cp ../../anomaly-simulation-service sideService | ||
cp ../../anomaly-simulation-service calcService | ||
cp ../../anomaly-simulation-service restService | ||
cp ../../anomaly-simulation-service recomService | ||
cp ../../anomaly-simulation-service modelService | ||
|
||
./customerAPI 8080 > customerapi.log 2>&1 & | ||
./sideService 8081 > sideservice.log 2>&1 & | ||
./calcService 8082 > calcservice.log 2>&1 & | ||
./restService 8083 > restservice.log 2>&1 & | ||
./recomService 8084 > recomservice.log 2>&1 & | ||
./modelService 8085 > modelservice.log 2>&1 & | ||
|
||
sleep 5 | ||
|
||
curl -i -X POST \ | ||
-H "Content-Type:application/json" \ | ||
-d \ | ||
'{ | ||
"Callees" : [ | ||
{ "Adr" : "http://localhost:8081", "Count" : 2 }, | ||
{ "Adr" : "http://localhost:8082", "Count" : 3 }, | ||
{ "Adr" : "http://www.example.com", "Count" : 1 } | ||
] | ||
}' \ | ||
'http://localhost:8080/config' | ||
|
||
curl -i -X POST \ | ||
-H "Content-Type:application/json" \ | ||
-d \ | ||
'{ | ||
"Callees" : [ | ||
{ "Adr" : "http://localhost:8083", "Count" : 2 }, | ||
{ "Adr" : "http://localhost:8084", "Count" : 2 }, | ||
{ "Adr" : "http://www.example.com", "Count" : 1 } | ||
] | ||
}' \ | ||
'http://localhost:8081/config' | ||
|
||
curl -i -X POST \ | ||
-H "Content-Type:application/json" \ | ||
-d \ | ||
'{ | ||
"Callees" : [ | ||
{ "Adr" : "http://localhost:8085", "Count" : 2 }, | ||
{ "Adr" : "http://www.example.com", "Count" : 1 } | ||
] | ||
}' \ | ||
'http://localhost:8084/config' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
curl -i -X POST \ | ||
-H "Content-Type:application/json" \ | ||
-d \ | ||
'{ | ||
"CrashConfig" : { | ||
"Code" : 9 | ||
}, | ||
"Callees" : [ | ||
] | ||
}' \ | ||
'http://localhost:8002/config' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
curl -i -X POST \ | ||
-H "Content-Type:application/json" \ | ||
-d \ | ||
'{ | ||
"ResourceConfig" : { | ||
"Severity" : 100, | ||
"Count" : 30000 | ||
}, | ||
"Callees" : [ | ||
] | ||
}' \ | ||
'http://localhost:8006/config' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
echo Triggering a slowdown of the database service by 50ms | ||
curl -i -X POST \ | ||
-H "Content-Type:application/json" \ | ||
-d \ | ||
'{ | ||
"SlowdownConfig" : { | ||
"SlowdownMillis" : 150, | ||
"Count" : 10000 | ||
}, | ||
"Callees" : [ | ||
] | ||
}' \ | ||
'http://localhost:9305/config' |
Oops, something went wrong.