This is an automated email from the ASF dual-hosted git repository.
rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack-csbench.git
The following commit(s) were added to refs/heads/main by this push:
new e495242 Changing executeAPI to utilize POST request (#18)
e495242 is described below
commit e495242efc177d0a3fc2af2de35a367a213f9116
Author: Kevin Li <[email protected]>
AuthorDate: Sun Jul 13 20:53:01 2025 -0700
Changing executeAPI to utilize POST request (#18)
* Changing executeAPI to utilize POST request
* Adding changes to accomadate GET requestS
* Code Formatting Fix
* Adding last changes
* Update apirunner/apirunner.go
* Apply suggestions from code review
* Update apirunner/apirunner.go
---------
Co-authored-by: Kevin Li <[email protected]>
Co-authored-by: Suresh Kumar Anaparti <[email protected]>
---
apirunner/apirunner.go | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/apirunner/apirunner.go b/apirunner/apirunner.go
index 8a3987c..5767b7c 100644
--- a/apirunner/apirunner.go
+++ b/apirunner/apirunner.go
@@ -30,6 +30,7 @@ import (
"net/http"
"net/url"
"os"
+ "regexp"
"strconv"
"strings"
"time"
@@ -124,11 +125,16 @@ func executeAPIandCalculate(profileName string, apiURL
string, command string, p
var avgTime float64
var totalTime float64
var count float64
+ getRequestList :=
map[string]struct{}{"isaccountallowedtocreateofferingswithtags": {},
"readyforshutdown": {}, "cloudianisenabled": {}, "quotabalance": {},
+ "quotasummary": {}, "quotatarifflist": {}, "quotaisenabled": {},
"quotastatement": {}, "verifyoauthcodeandgetuser": {}}
+ _, isInGetRequestList := getRequestList[command]
+ isGetRequest, _ := regexp.MatchString("^(get|list|query|find)(\\w+)+$",
command)
+
if iterations != 1 {
log.Infof("Calling API %s for %d number of iterations with
parameters %s", command, iterations, params)
for i := 1; i <= iterations; i++ {
log.Infof("Started with iteration %d for the command
%s", i, command)
- elapsedTime, apicount, result := executeAPI(apiURL,
params)
+ elapsedTime, apicount, result := executeAPI(apiURL,
params, !(isGetRequest || isInGetRequestList))
count = apicount
if elapsedTime < minTime {
minTime = elapsedTime
@@ -145,7 +151,7 @@ func executeAPIandCalculate(profileName string, apiURL
string, command string, p
log.Infof("count [%.f] : Time in seconds [Min - %.2f] [Max -
%.2f] [Avg - %.2f]\n", count, minTime, maxTime, avgTime)
saveData(apiURL, count, minTime, maxTime, avgTime, page,
pagesize, keyword, profileName, command, dbProfile, reportAppend)
} else {
- elapsedTime, apicount, _ := executeAPI(apiURL, params)
+ elapsedTime, apicount, _ := executeAPI(apiURL, params,
!(isGetRequest || isInGetRequestList))
log.Infof("Elapsed time [%.2f seconds] for the count [%.0f]",
elapsedTime, apicount)
saveData(apiURL, count, elapsedTime, elapsedTime, elapsedTime,
page, pagesize, keyword, profileName, command, dbProfile, reportAppend)
}
@@ -251,12 +257,24 @@ func saveData(apiURL string, count float64, minTime
float64, maxTime float64, av
log.Info(message)
}
-func executeAPI(apiURL string, params url.Values) (float64, float64, bool) {
+func executeAPI(apiURL string, params url.Values, postRequest bool) (float64,
float64, bool) {
// Send the API request and calculate the time
- apiURL = fmt.Sprintf("%s?%s", apiURL, params.Encode())
+ var resp *http.Response
+ var err error
log.Infof("Running the API %s", apiURL)
start := time.Now()
- resp, err := http.Get(apiURL)
+ if postRequest {
+ dataBody := strings.NewReader(params.Encode())
+ resp, err = http.Post(
+ apiURL,
+ "application/x-www-form-urlencoded",
+ dataBody,
+ )
+ } else {
+ apiURL = fmt.Sprintf("%s?%s", apiURL, params.Encode())
+ resp, err = http.Get(apiURL)
+ }
+
APIscount++
if err != nil {
log.Infof("Error sending API request: %s with error %s\n",
apiURL, err)