From 0ab76574bacdbeb909d9bb056dbf509687fd9121 Mon Sep 17 00:00:00 2001 From: Sven Pfennig Date: Thu, 14 Mar 2024 11:53:50 +0100 Subject: [PATCH] add logger Signed-off-by: Sven Pfennig --- podtato-head/README.md | 18 ++++++ .../chart/templates/deployment-entry.yaml | 4 ++ .../podtato-head-microservices/values.yaml | 25 ++++++++ podtato-head/test/loadtest/script.js | 62 +++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 podtato-head/podtato-head-microservices/values.yaml create mode 100644 podtato-head/test/loadtest/script.js diff --git a/podtato-head/README.md b/podtato-head/README.md index cf7d394..9193342 100644 --- a/podtato-head/README.md +++ b/podtato-head/README.md @@ -62,12 +62,30 @@ helm upgrade \ ``` ## Exercise 1: Add Logging +```sh +cagro add env-logger +``` +```rust +env_logger::init(); + +debug!("this is a debug {}", "message"); +error!("this is printed by default"); +info!("Now going to start the server!"; +``` +Update helm chart: +```sh + --set entry.env[0].name=RUST_LOG \ + --set entry.env[0].value=info \ +``` ## Exercise 2: Health Checks - [ ] Startup Probe - [ ] Readiness Probe - [ ] Liveness Probe +```sh +helm upgrade --install podtato-head ./delivery/chart -f podtato-head-microservices/values.yaml +``` ## Exercise 3: Add Metrics - Metrics Endpoint diff --git a/podtato-head/delivery/chart/templates/deployment-entry.yaml b/podtato-head/delivery/chart/templates/deployment-entry.yaml index 5efe177..1574fe1 100644 --- a/podtato-head/delivery/chart/templates/deployment-entry.yaml +++ b/podtato-head/delivery/chart/templates/deployment-entry.yaml @@ -68,6 +68,10 @@ spec: httpGet: path: / port: http + startupProbe: + httpGet: + path: / + port: http resources: {{- toYaml .Values.resources | nindent 12 }} volumeMounts: diff --git a/podtato-head/podtato-head-microservices/values.yaml b/podtato-head/podtato-head-microservices/values.yaml new file mode 100644 index 0000000..0ddd1ee --- /dev/null +++ b/podtato-head/podtato-head-microservices/values.yaml @@ -0,0 +1,25 @@ + +images: + repositoryDirname: "" + pullPolicy: Always +entry: + repositoryBasename: podtato-head-entry + runtimeClassName: wasmedge + env: + - name: RUST_LOG + value: info +hat: + repositoryBasename: podtato-head-parts + runtimeClassName: wasmedge +leftLeg: + repositoryBasename: podtato-head-parts + runtimeClassName: wasmedge +leftArm: + repositoryBasename: podtato-head-parts + runtimeClassName: wasmedge +rightLeg: + repositoryBasename: podtato-head-parts + runtimeClassName: wasmedge +rightArm: + repositoryBasename: podtato-head-parts + runtimeClassName: wasmedge \ No newline at end of file diff --git a/podtato-head/test/loadtest/script.js b/podtato-head/test/loadtest/script.js new file mode 100644 index 0000000..8fe40eb --- /dev/null +++ b/podtato-head/test/loadtest/script.js @@ -0,0 +1,62 @@ +import http from 'k6/http'; +import { check, sleep } from 'k6'; + +export const options = { + // A number specifying the number of VUs to run concurrently. + vus: 10, + // A string specifying the total duration of the test run. + duration: '30s', + + // The following section contains configuration options for execution of this + // test script in Grafana Cloud. + // + // See https://grafana.com/docs/grafana-cloud/k6/get-started/run-cloud-tests-from-the-cli/ + // to learn about authoring and running k6 test scripts in Grafana k6 Cloud. + // + // ext: { + // loadimpact: { + // // The ID of the project to which the test is assigned in the k6 Cloud UI. + // // By default tests are executed in default project. + // projectID: "", + // // The name of the test in the k6 Cloud UI. + // // Test runs with the same name will be grouped. + // name: "script.js" + // } + // }, + + // Uncomment this section to enable the use of Browser API in your tests. + // + // See https://grafana.com/docs/k6/latest/using-k6-browser/running-browser-tests/ to learn more + // about using Browser API in your test scripts. + // + // scenarios: { + // // The scenario name appears in the result summary, tags, and so on. + // // You can give the scenario any name, as long as each name in the script is unique. + // ui: { + // // Executor is a mandatory parameter for browser-based tests. + // // Shared iterations in this case tells k6 to reuse VUs to execute iterations. + // // + // // See https://grafana.com/docs/k6/latest/using-k6/scenarios/executors/ for other executor types. + // executor: 'shared-iterations', + // options: { + // browser: { + // // This is a mandatory parameter that instructs k6 to launch and + // // connect to a chromium-based browser, and use it to run UI-based + // // tests. + // type: 'chromium', + // }, + // }, + // }, + // } +}; + +// The function that defines VU logic. +// +// See https://grafana.com/docs/k6/latest/examples/get-started-with-k6/ to learn more +// about authoring k6 scripts. +// +export default function() { + const res = http.get('http://localhost:9000/parts/hat/hat.svg'); + check(res, { 'status was 200': (r) => r.status == 200 }); + sleep(1); +}