Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
feat: adding quickstart resources (#196)
Browse files Browse the repository at this point in the history
* adding quickstart resources

Signed-off-by: jetzlstorfer <juergen.etzlstorfer@dynatrace.com>

* small tweaks

Signed-off-by: jetzlstorfer <juergen.etzlstorfer@dynatrace.com>

* initial commit

Signed-off-by: jetzlstorfer <juergen.etzlstorfer@dynatrace.com>

* adding git clone

Signed-off-by: jetzlstorfer <juergen.etzlstorfer@dynatrace.com>

* job executor manifest

Signed-off-by: jetzlstorfer <juergen.etzlstorfer@dynatrace.com>
  • Loading branch information
Jürgen Etzlstorfer authored Oct 11, 2021
1 parent c58f804 commit 43ed263
Show file tree
Hide file tree
Showing 20 changed files with 1,095 additions and 0 deletions.
1 change: 1 addition & 0 deletions quickstart/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
remediation_trigger.json
3 changes: 3 additions & 0 deletions quickstart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Quickstart

All files needed for the quickstart guide on https://keptn.sh/docs/quickstart/ are maintained here.
73 changes: 73 additions & 0 deletions quickstart/automated-operations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash
set -e

#source <(curl -s https://raw.githubusercontent.com/keptn/keptn/0.8.5/test/utils.sh)

function print_headline() {
HEADLINE=$1

echo ""
echo "---------------------------------------------------------------------"
echo $HEADLINE
echo "---------------------------------------------------------------------"
echo ""
}

# wait for a deployment to be up and running
function wait_for_deployment_in_namespace() {
DEPLOYMENT=$1; NAMESPACE=$2;
RETRY=0; RETRY_MAX=10;

while [[ $RETRY -lt $RETRY_MAX ]]; do
DEPLOYMENT_LIST=$(eval "kubectl get deployments -n ${NAMESPACE} | awk '/$DEPLOYMENT /'" | awk '{print $1}') # list of multiple deployments when starting with the same name
if [[ -z "$DEPLOYMENT_LIST" ]]; then
RETRY=$((RETRY+1))
echo "Retry: ${RETRY}/${RETRY_MAX} - Deployment not found - waiting 5s for deployment ${DEPLOYMENT} in namespace ${NAMESPACE}"
sleep 5
else
READY_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.status.availableReplicas}')
WANTED_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.spec.replicas}')
UNAVAILABLE_REPLICAS=$(eval kubectl get deployments "$DEPLOYMENT" -n "$NAMESPACE" -o=jsonpath='{$.status.unavailableReplicas}')
if [[ "$READY_REPLICAS" = "$WANTED_REPLICAS" && "$UNAVAILABLE_REPLICAS" = "" ]]; then
echo "Found deployment ${DEPLOYMENT} in namespace ${NAMESPACE}: ${DEPLOYMENT_LIST}"
break
else
RETRY=$((RETRY+1))
echo "Retry: ${RETRY}/${RETRY_MAX} - Unsufficient replicas for deployment - waiting 5s for deployment ${DEPLOYMENT} in namespace ${NAMESPACE}"
sleep 5
fi
fi
done

if [[ $RETRY == "$RETRY_MAX" ]]; then
print_error "Could not find deployment ${DEPLOYMENT} in namespace ${NAMESPACE}"
exit 1
fi
}

PROJECT="podtatohead"
SERVICE="helloservice"

print_headline "Preparation of Auto-remediation in Production"

echo "Adding SLIs for Prometheus"
keptn add-resource --project=$PROJECT --stage=production --service=$SERVICE --resource=./demo/prometheus/sli.yaml --resourceUri=prometheus/sli.yaml
echo "Adding SLO definition file for the quality gate"
keptn add-resource --project=$PROJECT --stage=production --service=$SERVICE --resource=./demo/slo.yaml --resourceUri=slo.yaml
echo "Adding Remediation Configuration"
keptn add-resource --project=$PROJECT --stage=production --service=$SERVICE --resource=./demo/remediation.yaml --resourceUri=remediation.yaml

print_headline "Deploy Job Executor"

kubectl apply -f ./demo/job/job-executor.yaml
keptn add-resource --project=$PROJECT --service=$SERVICE --stage=production --resource=./demo/job/config.yaml --resourceUri=job/config.yaml

wait_for_deployment_in_namespace "job-executor-service" "keptn"

print_headline "Simulate Alert (Problem)"
echo -e "{\"type\": \"sh.keptn.event.production.remediation.triggered\",\"specversion\":\"1.0\",\"source\":\"https:\/\/github.com\/keptn\/keptn\/prometheus-service\",\"id\": \"f2b878d3-03c0-4e8f-bc3f-454bc1b3d79d\", \"time\": \"2019-06-07T07:02:15.64489Z\", \"contenttype\": \"application\/json\", \"data\": {\"project\": \"podtatohead\",\"stage\": \"production\",\"service\": \"helloservice\",\"problem\": { \"problemTitle\": \"out_of_memory\",\"rootCause\": \"Response time degradation\"}}}" > remediation_trigger.json | keptn send event -f remediation_trigger.json

print_headline "Have a look at the Keptn Bridge and explore the demo project"

echo "You can simulate a new problem any time by executing the following command:"
echo "keptn send event -f remediation_trigger.json"
13 changes: 13 additions & 0 deletions quickstart/clean-project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
set -e

keptn delete project podtatohead
# rm -rf podtato-head
kubectl delete deploy -n keptn prometheus-service --ignore-not-found=true
kubectl delete deploy -n keptn prometheus-sli-service --ignore-not-found=true
kubectl delete secret -n keptn prometheus-credentials-podtatohead --ignore-not-found=true
kubectl delete ns monitoring --ignore-not-found=true
kubectl delete ns podtatohead-hardening --ignore-not-found=true
kubectl delete ns podtatohead-production --ignore-not-found=true


4 changes: 4 additions & 0 deletions quickstart/demo/helm/endpoints.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deploymentURIsLocal:
- "http://helloservice.podtatohead-hardening:80"


Binary file added quickstart/demo/helm/helloservice.tgz
Binary file not shown.
6 changes: 6 additions & 0 deletions quickstart/demo/helm/helloservice/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
appVersion: 1.16.0
description: A Helm chart for Kubernetes
name: podtatoserver
type: application
version: 0.1.0
25 changes: 25 additions & 0 deletions quickstart/demo/helm/helloservice/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloservice
namespace: {{ .Release.Namespace }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: helloservice
template:
metadata:
labels:
app: helloservice
spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: {{ .Values.image}}
imagePullPolicy: Always
ports:
- containerPort: 9000
env:
- name: PORT
value: "9000"
14 changes: 14 additions & 0 deletions quickstart/demo/helm/helloservice/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: helloservice
namespace: {{ .Release.Namespace }}
spec:
selector:
app: helloservice
ports:
- name: http
port: 80
protocol: TCP
targetPort: 9000
type: ClusterIP
2 changes: 2 additions & 0 deletions quickstart/demo/helm/helloservice/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
image: ghcr.io/podtato-head/podtatoserver:v0.1.1
replicaCount: 1
14 changes: 14 additions & 0 deletions quickstart/demo/jmeter/jmeter.conf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
spec_version: '0.1.0'
workloads:
- teststrategy: performance
vuser: 35
loopcount: 600
script: jmeter/load.jmx
acceptederrorrate: 1.0
- teststrategy: performance_light
vuser: 50
loopcount: 50
script: jmeter/load.jmx
acceptederrorrate: 1.0

228 changes: 228 additions & 0 deletions quickstart/demo/jmeter/load.jmx
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.4">
<hashTree>
<TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
<stringProp name="TestPlan.comments"></stringProp>
<boolProp name="TestPlan.functional_mode">false</boolProp>
<boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
<elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
<collectionProp name="Arguments.arguments">
<elementProp name="SERVER_URL" elementType="Argument">
<stringProp name="Argument.name">SERVER_URL</stringProp>
<stringProp name="Argument.value">ec2-54-164-164-121.compute-1.amazonaws.com</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="DefaultThinkTime" elementType="Argument">
<stringProp name="Argument.name">DefaultThinkTime</stringProp>
<stringProp name="Argument.value">250</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="DT_LTN" elementType="Argument">
<stringProp name="Argument.name">DT_LTN</stringProp>
<stringProp name="Argument.value">TestJune03</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="SERVER_PORT" elementType="Argument">
<stringProp name="Argument.name">SERVER_PORT</stringProp>
<stringProp name="Argument.value">80</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="LoopCount" elementType="Argument">
<stringProp name="Argument.name">LoopCount</stringProp>
<stringProp name="Argument.value">1000</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="CHECK_PATH" elementType="Argument">
<stringProp name="Argument.name">CHECK_PATH</stringProp>
<stringProp name="Argument.value">/</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="PROTOCOL" elementType="Argument">
<stringProp name="Argument.name">PROTOCOL</stringProp>
<stringProp name="Argument.value">http</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
<elementProp name="VUCount" elementType="Argument">
<stringProp name="Argument.name">VUCount</stringProp>
<stringProp name="Argument.value">10</stringProp>
<stringProp name="Argument.metadata">=</stringProp>
</elementProp>
</collectionProp>
</elementProp>
<stringProp name="TestPlan.user_define_classpath"></stringProp>
</TestPlan>
<hashTree>
<ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
<stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
<elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
<boolProp name="LoopController.continue_forever">false</boolProp>
<stringProp name="LoopController.loops">${__P(LoopCount,${LoopCount})}</stringProp>
</elementProp>
<stringProp name="ThreadGroup.num_threads">${__P(VUCount,${VUCount})}</stringProp>
<stringProp name="ThreadGroup.ramp_time">1</stringProp>
<longProp name="ThreadGroup.start_time">1536064517000</longProp>
<longProp name="ThreadGroup.end_time">1536064517000</longProp>
<boolProp name="ThreadGroup.scheduler">false</boolProp>
<stringProp name="ThreadGroup.duration">120</stringProp>
<stringProp name="ThreadGroup.delay"></stringProp>
<boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
</ThreadGroup>
<hashTree>
<CookieManager guiclass="CookiePanel" testclass="CookieManager" testname="HTTP Cookie Manager" enabled="true">
<collectionProp name="CookieManager.cookies"/>
<boolProp name="CookieManager.clearEachIteration">false</boolProp>
<boolProp name="CookieManager.controlledByThreadGroup">false</boolProp>
</CookieManager>
<hashTree/>
<HeaderManager guiclass="HeaderPanel" testclass="HeaderManager" testname="HTTP Header Manager" enabled="true">
<collectionProp name="HeaderManager.headers">
<elementProp name="" elementType="Header">
<stringProp name="Header.name">Cache-Control</stringProp>
<stringProp name="Header.value">no-cache</stringProp>
</elementProp>
<elementProp name="" elementType="Header">
<stringProp name="Header.name">Content-Type</stringProp>
<stringProp name="Header.value">application/json</stringProp>
</elementProp>
<elementProp name="" elementType="Header">
<stringProp name="Header.name">json</stringProp>
<stringProp name="Header.value">true</stringProp>
</elementProp>
</collectionProp>
</HeaderManager>
<hashTree/>
<BeanShellPreProcessor guiclass="TestBeanGUI" testclass="BeanShellPreProcessor" testname="Set Dynatrace Headers" enabled="true">
<stringProp name="filename"></stringProp>
<stringProp name="parameters">load.jmx</stringProp>
<boolProp name="resetInterpreter">false</boolProp>
<stringProp name="script">

import org.apache.jmeter.util.JMeterUtils;
import org.apache.jmeter.protocol.http.control.HeaderManager;
import java.io;
import java.util;

// -------------------------------------------------------------------------------------
// Generate the x-dynatrace-test header
// -------------------------------------------------------------------------------------
String LTN=JMeterUtils.getProperty(&quot;DT_LTN&quot;);
if((LTN == null) || (LTN.length() == 0)) {
if(vars != null) {
LTN = vars.get(&quot;DT_LTN&quot;);
}
}
if(LTN == null) LTN = &quot;NoTestName&quot;;

String LSN = (bsh.args.length &gt; 0) ? bsh.args[0] : &quot;Test Scenario&quot;;
String TSN = sampler.getName();
String VU = ctx.getThreadGroup().getName() + ctx.getThreadNum();
String headerValue = &quot;LSN=&quot;+ LSN + &quot;;TSN=&quot; + TSN + &quot;;LTN=&quot; + LTN + &quot;;VU=&quot; + VU + &quot;;&quot;;

// -------------------------------------------
// Set header
// -------------------------------------------
HeaderManager hm = sampler.getHeaderManager();
hm.removeHeaderNamed(&quot;x-dynatrace-test&quot;);
hm.add(new org.apache.jmeter.protocol.http.control.Header(&quot;x-dynatrace-test&quot;, headerValue));

</stringProp>
</BeanShellPreProcessor>
<hashTree/>
<HTTPSamplerProxy guiclass="HttpTestSampleGui" testclass="HTTPSamplerProxy" testname="homepage" enabled="true">
<elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" enabled="true">
<collectionProp name="Arguments.arguments"/>
</elementProp>
<stringProp name="HTTPSampler.domain">${__P(SERVER_URL,${SERVER_URL})}</stringProp>
<stringProp name="HTTPSampler.port">${__P(SERVER_PORT,${SERVER_PORT})}</stringProp>
<stringProp name="HTTPSampler.protocol">${__P(PROTOCOL,${PROTOCOL})}</stringProp>
<stringProp name="HTTPSampler.contentEncoding"></stringProp>
<stringProp name="HTTPSampler.path">/</stringProp>
<stringProp name="HTTPSampler.method">GET</stringProp>
<boolProp name="HTTPSampler.follow_redirects">true</boolProp>
<boolProp name="HTTPSampler.auto_redirects">false</boolProp>
<boolProp name="HTTPSampler.use_keepalive">true</boolProp>
<boolProp name="HTTPSampler.DO_MULTIPART_POST">false</boolProp>
<boolProp name="HTTPSampler.BROWSER_COMPATIBLE_MULTIPART">true</boolProp>
<stringProp name="HTTPSampler.embedded_url_re"></stringProp>
<stringProp name="HTTPSampler.connect_timeout"></stringProp>
<stringProp name="HTTPSampler.response_timeout"></stringProp>
</HTTPSamplerProxy>
<hashTree/>
<ConstantTimer guiclass="ConstantTimerGui" testclass="ConstantTimer" testname="Default Think Time" enabled="true">
<stringProp name="ConstantTimer.delay">{__P(ThinkTime,${DefaultThinkTime})}</stringProp>
</ConstantTimer>
<hashTree/>
</hashTree>
<ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>false</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<threadCounts>true</threadCounts>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
<ResultCollector guiclass="SummaryReport" testclass="ResultCollector" testname="Summary Report" enabled="true">
<boolProp name="ResultCollector.error_logging">false</boolProp>
<objProp>
<name>saveConfig</name>
<value class="SampleSaveConfiguration">
<time>true</time>
<latency>true</latency>
<timestamp>true</timestamp>
<success>true</success>
<label>true</label>
<code>true</code>
<message>true</message>
<threadName>true</threadName>
<dataType>true</dataType>
<encoding>false</encoding>
<assertions>true</assertions>
<subresults>true</subresults>
<responseData>false</responseData>
<samplerData>false</samplerData>
<xml>false</xml>
<fieldNames>true</fieldNames>
<responseHeaders>false</responseHeaders>
<requestHeaders>false</requestHeaders>
<responseDataOnError>false</responseDataOnError>
<saveAssertionResultsFailureMessage>true</saveAssertionResultsFailureMessage>
<assertionsResultsToSave>0</assertionsResultsToSave>
<bytes>true</bytes>
<sentBytes>true</sentBytes>
<url>true</url>
<threadCounts>true</threadCounts>
<idleTime>true</idleTime>
<connectTime>true</connectTime>
</value>
</objProp>
<stringProp name="filename"></stringProp>
</ResultCollector>
<hashTree/>
</hashTree>
</hashTree>
</jmeterTestPlan>
Loading

0 comments on commit 43ed263

Please sign in to comment.