-
Notifications
You must be signed in to change notification settings - Fork 150
Perf test for certs #3729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Perf test for certs #3729
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
99db07b
one commit to rule them all
gearama da41922
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama 3a87b5a
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama dce08e2
main merge
gearama a3bf3bc
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama 1df702a
error
gearama ff85b81
main merge
gearama f95c70d
error
gearama ffc77ee
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama 02d3393
main merge
gearama 29acacd
error
gearama 237ebb7
main merge
gearama 3bd6c57
error
gearama 3eeeac6
Merge branch 'main' of https://github.com/gearama/azure-sdk-for-cpp
gearama 9bfa519
Merge branch 'Azure:main' into main
gearama 0b1bad6
Merge branch 'Azure:main' into main
gearama 68ab415
example of perf test
gearama 32519f1
remove file
gearama 2a7c3d7
create certs and keys in post setup, use to run the test
gearama 3966fdd
PR comments
gearama File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
38 changes: 38 additions & 0 deletions
38
sdk/keyvault/azure-security-keyvault-certificates/test/perf/CMakeLists.txt
This file contains hidden or 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,38 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| # Configure CMake project. | ||
| cmake_minimum_required (VERSION 3.13) | ||
| project(azure-security-keyvault-certificates-perf LANGUAGES CXX) | ||
| set(CMAKE_CXX_STANDARD 14) | ||
| set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
|
||
| set( | ||
| AZURE_KEYVAULT_CERTIFICATES_PERF_TEST_HEADER | ||
| inc/azure/keyvault/certificates/test/get_certificate_test.hpp | ||
| ) | ||
|
|
||
| set( | ||
| AZURE_KEYVAULT_CERTIFICATES_PERF_TEST_SOURCE | ||
| src/azure_security_keyvault_certificates_perf_test.cpp | ||
| ) | ||
|
|
||
| # Name the binary to be created. | ||
| add_executable ( | ||
| azure-security-keyvault-certificates-perf | ||
| ${AZURE_KEYVAULT_CERTIFICATES_PERF_TEST_HEADER} ${AZURE_KEYVAULT_CERTIFICATES_PERF_TEST_SOURCE} | ||
| ) | ||
| create_per_service_target_build(keyvault azure-security-keyvault-certificates-perf) | ||
| create_map_file(azure-security-keyvault-certificates-perf azure-security-keyvault-certificates-perf.map) | ||
|
|
||
| # Include the headers from the project. | ||
| target_include_directories( | ||
| azure-security-keyvault-certificates-perf | ||
| PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/inc> | ||
| ) | ||
|
|
||
| # link the `azure-perf` lib together with any other library which will be used for the tests. | ||
| target_link_libraries(azure-security-keyvault-certificates-perf PRIVATE azure-identity azure-security-keyvault-certificates azure-perf) | ||
| # Make sure the project will appear in the test folder for Visual Studio CMake view | ||
| set_target_properties(azure-security-keyvault-certificates-perf PROPERTIES FOLDER "Tests/Keyvault") |
154 changes: 154 additions & 0 deletions
154
...ault-certificates/test/perf/inc/azure/keyvault/certificates/test/get_certificate_test.hpp
This file contains hidden or 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,154 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| /** | ||
| * @file | ||
| * @brief Test the overhead of getting a certificate. | ||
| * | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <azure/perf.hpp> | ||
|
|
||
| #include <azure/core/internal/environment.hpp> | ||
| #include <azure/identity.hpp> | ||
| #include <azure/keyvault/certificates.hpp> | ||
| #include <chrono> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| using namespace Azure::Core::_internal; | ||
|
|
||
| namespace Azure { | ||
| namespace Security { | ||
| namespace KeyVault { | ||
| namespace Certificates { | ||
| namespace Test { | ||
|
|
||
| /** | ||
| * @brief A test to measure getting a key performance. | ||
| * | ||
| */ | ||
| class GetCertificate : public Azure::Perf::PerfTest { | ||
| private: | ||
| std::string m_vaultUrl; | ||
| std::string m_certificateName; | ||
| std::string m_tenantId; | ||
| std::string m_clientId; | ||
| std::string m_secret; | ||
| std::shared_ptr<Azure::Identity::ClientSecretCredential> m_credential; | ||
| std::unique_ptr<Azure::Security::KeyVault::Certificates::CertificateClient> m_client; | ||
|
|
||
| public: | ||
| /** | ||
| * @brief Get the Ids and secret | ||
| * | ||
| */ | ||
| void Setup() override | ||
| { | ||
| m_vaultUrl = m_options.GetOptionOrDefault<std::string>( | ||
| "vaultUrl", Environment::GetVariable("AZURE_KEYVAULT_URL")); | ||
| m_tenantId = m_options.GetOptionOrDefault<std::string>( | ||
| "TenantId", Environment::GetVariable("AZURE_TENANT_ID")); | ||
| m_clientId = m_options.GetOptionOrDefault<std::string>( | ||
| "ClientId", Environment::GetVariable("AZURE_CLIENT_ID")); | ||
| m_secret = m_options.GetOptionOrDefault<std::string>( | ||
| "Secret", Environment::GetVariable("AZURE_CLIENT_SECRET")); | ||
| m_credential = std::make_shared<Azure::Identity::ClientSecretCredential>( | ||
| m_tenantId, m_clientId, m_secret); | ||
| m_client = std::make_unique<Azure::Security::KeyVault::Certificates::CertificateClient>( | ||
| m_vaultUrl, | ||
| m_credential, | ||
| InitClientOptions<Azure::Security::KeyVault::Certificates::CertificateClientOptions>()); | ||
| this->CreateRandomNameCertificate(); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Create a random named certificate. | ||
| * | ||
| */ | ||
| void CreateRandomNameCertificate() | ||
| { | ||
| std::string name("perf"); | ||
| int suffixLen = 10; | ||
| static const char alphanum[] | ||
| = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
| std::string suffix; | ||
| suffix.reserve(suffixLen); | ||
|
|
||
| for (int i = 0; i < suffixLen; ++i) | ||
| { | ||
| suffix += alphanum[rand() % (sizeof(alphanum) - 1)]; | ||
| } | ||
|
|
||
| m_certificateName = name + suffix; | ||
| CertificateCreateOptions options; | ||
| options.Policy.Subject = "CN=xyz"; | ||
| options.Policy.ValidityInMonths = 12; | ||
| options.Policy.Enabled = true; | ||
|
|
||
| options.Properties.Enabled = true; | ||
| options.Properties.Name = m_certificateName; | ||
| options.Policy.ContentType = CertificateContentType::Pkcs12; | ||
| options.Policy.IssuerName = "Self"; | ||
|
|
||
| LifetimeAction action; | ||
| action.LifetimePercentage = 80; | ||
| action.Action = CertificatePolicyAction::AutoRenew; | ||
| options.Policy.LifetimeActions.emplace_back(action); | ||
| auto duration = std::chrono::minutes(5); | ||
| auto deadline = std::chrono::system_clock::now() + duration; | ||
| Azure::Core::Context context; | ||
| auto response = m_client->StartCreateCertificate( | ||
| m_certificateName, options, context.WithDeadline(deadline)); | ||
| auto pollResult = response.PollUntilDone(std::chrono::milliseconds(2000)); | ||
gearama marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| /** | ||
| * @brief Construct a new GetCertificate test. | ||
| * | ||
| * @param options The test options. | ||
| */ | ||
| GetCertificate(Azure::Perf::TestOptions options) : PerfTest(options) {} | ||
|
|
||
| /** | ||
| * @brief Define the test | ||
| * | ||
| */ | ||
| void Run(Azure::Core::Context const&) override | ||
| { | ||
| auto t = m_client->GetCertificate(m_certificateName); | ||
| } | ||
|
|
||
| /** | ||
| * @brief Define the test options for the test. | ||
| * | ||
| * @return The list of test options. | ||
| */ | ||
| std::vector<Azure::Perf::TestOption> GetTestOptions() override | ||
| { | ||
| return { | ||
| {"vaultUrl", {"--vaultUrl"}, "The Key Vault Account.", 1, false}, | ||
| {"TenantId", {"--tenantId"}, "The tenant Id for the authentication.", 1, false}, | ||
| {"ClientId", {"--clientId"}, "The client Id for the authentication.", 1, false}, | ||
| {"Secret", {"--secret"}, "The secret for authentication.", 1, false, true}}; | ||
| } | ||
|
|
||
| /** | ||
| * @brief Get the static Test Metadata for the test. | ||
| * | ||
| * @return Azure::Perf::TestMetadata describing the test. | ||
| */ | ||
| static Azure::Perf::TestMetadata GetTestMetadata() | ||
| { | ||
| return { | ||
| "GetCertificate", "Get a certificate", [](Azure::Perf::TestOptions options) { | ||
| return std::make_unique<Azure::Security::KeyVault::Certificates::Test::GetCertificate>( | ||
| options); | ||
| }}; | ||
| } | ||
| }; | ||
|
|
||
| }}}}} // namespace Azure::Security::KeyVault::Certificates::Test | ||
18 changes: 18 additions & 0 deletions
18
...ty-keyvault-certificates/test/perf/src/azure_security_keyvault_certificates_perf_test.cpp
This file contains hidden or 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,18 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include <azure/perf.hpp> | ||
|
|
||
| #include "azure/keyvault/certificates/test/get_certificate_test.hpp" | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
|
|
||
| // Create the test list | ||
| std::vector<Azure::Perf::TestMetadata> tests{ | ||
| Azure::Security::KeyVault::Certificates::Test::GetCertificate::GetTestMetadata()}; | ||
|
|
||
| Azure::Perf::Program::Run(Azure::Core::Context::ApplicationContext, tests, argc, argv); | ||
|
|
||
| return 0; | ||
| } |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.