diff --git a/.vscode/cspell.json b/.vscode/cspell.json index cd1346732a..77305e988d 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -11,6 +11,8 @@ "*.exe", "*.a", "*.lib", + "*.yaml", + "**/libcurl-stress-test/README.md", ".github/CODEOWNERS", ".gitignore", ".vscode/cspell.json", diff --git a/sdk/core/azure-core/test/libcurl-stress-test/CMakeLists.txt b/sdk/core/azure-core/test/libcurl-stress-test/CMakeLists.txt index 1ef828894e..e802aaa385 100644 --- a/sdk/core/azure-core/test/libcurl-stress-test/CMakeLists.txt +++ b/sdk/core/azure-core/test/libcurl-stress-test/CMakeLists.txt @@ -17,10 +17,3 @@ target_link_libraries(azure-core-libcurl-stress-test PRIVATE azure-core) create_map_file(azure-core-libcurl-stress-test azure-core-libcurl-stress-test.map) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Dockerfile DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) - -find_program(DOCKER_EXECUTABLE docker) -#if docker is found try to build the docker image in the defined docker_build stage which should be run after build -if(DOCKER_EXECUTABLE) - add_custom_target(docker_build - COMMAND ${DOCKER_EXECUTABLE} build --build-arg targetTest=azure-core-libcurl-stress-test --build-arg build=on --tag=azuresdkforcpp/curlstress -f Dockerfile .) -endif() diff --git a/sdk/core/azure-core/test/libcurl-stress-test/Chart.yaml b/sdk/core/azure-core/test/libcurl-stress-test/Chart.yaml new file mode 100644 index 0000000000..8b3a5f87bf --- /dev/null +++ b/sdk/core/azure-core/test/libcurl-stress-test/Chart.yaml @@ -0,0 +1,16 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# SPDX-License-Identifier: MIT + +apiVersion: v2 +name: libcurl-stress-test +description: An example of c++ stress test +version: 0.0.1 +appVersion: v0.1 +annotations: + stressTest: 'true' # enable auto-discovery of this test via `find-all-stress-packages.ps1` + namespace: 'azuresdkforcpp' + +dependencies: +- name: stress-test-addons + version: 0.1.19 + repository: https://stresstestcharts.blob.core.windows.net/helm/ diff --git a/sdk/core/azure-core/test/libcurl-stress-test/Dockerfile b/sdk/core/azure-core/test/libcurl-stress-test/Dockerfile index 1373c598f4..1cdc7c7f49 100644 --- a/sdk/core/azure-core/test/libcurl-stress-test/Dockerfile +++ b/sdk/core/azure-core/test/libcurl-stress-test/Dockerfile @@ -1,3 +1,6 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# SPDX-License-Identifier: MIT + FROM mcr.microsoft.com/mirror/docker/library/ubuntu:22.04 ARG targetTest @@ -11,5 +14,3 @@ RUN chmod +x ./$targetTest RUN apt-get update -y RUN apt-get install valgrind -y -# execute under memcheck tool -RUN valgrind --tool=memcheck -s ./$targetTest $build diff --git a/sdk/core/azure-core/test/libcurl-stress-test/README.md b/sdk/core/azure-core/test/libcurl-stress-test/README.md new file mode 100644 index 0000000000..300534d165 --- /dev/null +++ b/sdk/core/azure-core/test/libcurl-stress-test/README.md @@ -0,0 +1,29 @@ +# Stress test prototype +This is work in progress. It's a prototype of how a stress test would look. This PR is to park the work in progress while being dealing with higher priority issues. +## Components +### Code (https://en.wikipedia.org/wiki/C%2B%2B) +The cpp file represents the code for the test, it will generate a number of invalid URLs and then issue CURL send commands. The requests are expected to fail. The point was that it exposes memory leaks in handling the error cases, which we fixed since. + +### Dockerfile (https://www.docker.com/) +Represents the build file for the container in which the test runs, it is based on ubuntu 22.04 , from mcr. +The main change from default ubuntu is making sure we have the valgrind tool installed. Valgrind is a heap monitoring tool that helps identify potential stack traces that might leak memory. While not 100% effective is is great at reducing the surface are for investigations. + +### Helm chart (https://helm.sh/) +Chart.yaml together with the bicep file(https://docs.microsoft.com/azure/azure-resource-manager/bicep/overview?tabs=bicep) and the deploy job file , represent the helm chart needed to deploy to the docker image built from the dockerfile to the stress cluster and execute the stress test. + +The helm chart creates a pod with a container based on the docker image, and executes the test under valgrind. + +To deploy the chart you will need to run "azure-sdk-for-cpp\eng\common\scripts\stress-testing> .\deploy-stress-tests.ps1 -Namespace azuresdkforcpp -SearchDirectory E:\src\azure-sdk-for-cpp\sdk\core\azure-core\test -PushImage" + +Where namaspace will be created if missing , search directory can be any folder where it will search for charts in it and all it's sub dirs, push image will call it to build the docker image. + +ATM the docker image is build by hand and harcoded in the chart to simplify matters. + +To build the image run "docker build -t stresstesttbiruti6oi24k.acr.io/azuresdkforcpp/curlstress:v8 --build-arg targetTest=azure-core-libcurl-stress-test --build-arg build=on ." + +To push to mcr : "docker push stresstesttbiruti6oi24k.acr.io/azuresdkforcpp/curlstress:v8" +Obviously after logging in to the acr "az acr login -n stresspgs7b6dif73rup6.azurecr.io" + +To use another image you will need to go to line 12 in deploy job and update with your new file. + +Once the deploy succeeds run " kubectl logs -n azuresdkforcpp -f libcurl-stress-test" to grab the logs in real time . \ No newline at end of file diff --git a/sdk/core/azure-core/test/libcurl-stress-test/libcurl_stress_test.cpp b/sdk/core/azure-core/test/libcurl-stress-test/libcurl_stress_test.cpp index c47b9d736d..698fc6fd8f 100644 --- a/sdk/core/azure-core/test/libcurl-stress-test/libcurl_stress_test.cpp +++ b/sdk/core/azure-core/test/libcurl-stress-test/libcurl_stress_test.cpp @@ -9,26 +9,19 @@ * the instructions to install and run the server before running this test. * */ + #define REQUESTS 100 #define WARMUP 100 #define ROUNDS 100 #include #include -#include -#include #include -#include -#include -#include -#include void SendRequest(std::string target) { std::cout << target << std::endl; - /* The transport adapter must allow insecure SSL certs. - If both curl and winHttp are available, curl is preferred for this test*/ - + // The transport adapter must allow insecure SSL certs. Azure::Core::Http::CurlTransportOptions curlOptions; curlOptions.SslVerifyPeer = false; auto implementationClient = std::make_shared(curlOptions); @@ -37,16 +30,15 @@ void SendRequest(std::string target) { Azure::Core::Context context; - // auto duration = std::chrono::milliseconds(1000); - // auto deadline = std::chrono::system_clock::now() + duration; auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, Azure::Core::Url(target)); - auto response = implementationClient->Send(request, context); //.WithDeadline(deadline)); + auto response = implementationClient->Send(request, context); // Make sure to pull all bytes from network. auto body = response->ExtractBodyStream()->ReadToEnd(); } catch (std::exception const&) { + // don't print exceptions, they are happening at each request, this is the point of the test } } @@ -60,11 +52,11 @@ void Operation(int repetitions) } } -int main(int argc, char** argv) // i can have either 0 or 2 params here +int main(int argc, char**) { - (void)argv; // to get rid of the unused warning - // some param was passed to the program , which happens only in build mode, not run of the docker - // file. thus we will run a quick test to make sure the executable runs. + // some param was passed to the program, doesn't matter what it is, + // it is meant for the moment to just run a quick iteration to check for sanity of the test. + // since prototype TODO: pass in warmup/rounds/requests as params. if (argc != 1) { std::cout << "--------------\tBUILD TEST\t--------------" << std::endl; diff --git a/sdk/core/azure-core/test/libcurl-stress-test/stress-test-resources.bicep b/sdk/core/azure-core/test/libcurl-stress-test/stress-test-resources.bicep new file mode 100644 index 0000000000..d008b28bfd --- /dev/null +++ b/sdk/core/azure-core/test/libcurl-stress-test/stress-test-resources.bicep @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT +// +// Dummy parameter to handle defaults the script passes in +param testApplicationOid string = '' + +resource config 'Microsoft.AppConfiguration/configurationStores@2020-07-01-preview' = { + name: 'config-${resourceGroup().name}' + location: resourceGroup().location + sku: { + name: 'Standard' + } +} + +output RESOURCE_GROUP string = resourceGroup().name +output AZURE_CLIENT_OID string = testApplicationOid diff --git a/sdk/core/azure-core/test/libcurl-stress-test/templates/deploy-job.yaml b/sdk/core/azure-core/test/libcurl-stress-test/templates/deploy-job.yaml new file mode 100644 index 0000000000..17c13ebee5 --- /dev/null +++ b/sdk/core/azure-core/test/libcurl-stress-test/templates/deploy-job.yaml @@ -0,0 +1,22 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# SPDX-License-Identifier: MIT +{{- include "stress-test-addons.deploy-job-template.from-pod" (list . "stress.deploy-example") -}} +{{- define "stress.deploy-example" -}} +metadata: + labels: + testName: "libcurl-stress-test" + name: "libcurl-stress-test" +spec: + containers: + - name: libcurl-stress-test + image: stresspgs7b6dif73rup6.azurecr.io/azuresdkforcpp/curlstress:latest + imagePullPolicy: Always + command: + [ + "valgrind", + "--tool=memcheck", + "-s", + "./azure-core-libcurl-stress-test", + ] + {{- include "stress-test-addons.container-env" . | nindent 6 }} +{{- end -}}