Wrk load testing, Post request with payload from json file - load-testing

Does wrk support specifying a json body with a path to a file like vegeta load testing?
https://github.com/tsenart/vegeta
Also is there a way to overwrite variables in the post request body payload?
For example if I have a payload like
{
"id": "{{value}}"
}
Is there a way to inject and overwrite {{value}} during wrk run time with unique and different values?

Related

Rest Assured - Send POST Request (Content-Type : multipart/form-data) with Static JSON Payload and Files to be uploaded

I want to send a POST Request where -
Content Type is "multipart / form-data".
In "Body" section, I have 2 params -> body - {static JSON Payload}, files - {any file, say .log file}
In Rest Assured Code, I am able to get the Static JSON Payload in String format with below code -
String jsonFilePath = "<<Path to JSON File>>/Test_new.json";
String response = given().log().all().header("X-AUTH-TOKEN",res).body(new String(Files.readAllBytes(Paths.get(jsonFilePath)))).
when().post("<<POST RESOURCE URL>>").
then().log().body().assertThat().statusCode(200).extract().response().asString();
When running this code, only with Static JSON Payload, I am getting "415" error code.
Questions -
How can we successfully make this kind of call in Rest Assured?
When I want to upload files as well with this call, how to do that?
You need to use multiPart() methods for uploading files, not body() method. For example:
File json = new File("src/test/resources/test_new.json");
File file = new File("src/test/resources/debug.log");
given().log().all()
.multiPart("files", file)
.multiPart("body", json, "application/json")
.post("your_url");

Microsoft Graph (OneDrive) API - Resumable Upload Content-Type

I am trying to create the upload PUT request for the OneDrive API. It's the large file "resumable upload" version which requires the createUploadSession.
I have read the Microsoft docs here: As a warning the docs are VERY inaccurate and full of factual errors...
The docs simply say:
PUT
https://sn3302.up.1drv.com/up/fe6987415ace7X4e1eF866337Content-Length:
26Content-Range: bytes 0-25/128 <bytes 0-25 of the
file>
I am authenticated and have the upload session created, however when I pass the JSON body containing my binary file I receive this error:
{ "error": {
"code": "BadRequest",
"message": "Property file in payload has a value that does not match schema.", .....
Can anyone point me at the schema definition? Or explain how the JSON should be constructed?
As a side question, am I right in using "application/json" for this at all? What format should the request use?
Just to confirm, I am able to see the temp file created ready and waiting on OneDrive for the upload, so I know I'm close.
Thanks for any help!
If you're uploading the entire file in a single request then why do you use upload session when you can use the simple PUT request?
url = https://graph.microsoft.com/v1.0/{user_id}/items/{parent_folder_ref_id}:/{filename}:/content
and "Content-Type": "text/plain" header and in body simply put the file bytes.
If for some reason I don't understand you have to use single-chunk upload session then:
Create upload session (you didn't specified any problems here so i'm not elaborating)
Get uploadUrl from createUploadSession response and send PUT request with the following headers:
2.1 "Content-Length": str(file_size_in_bytes)
2.2 "Content-Range": "bytes 0-{file_size_in_bytes - 1}/{file_size_in_bytes}"
2.3 "Content-Type": "text/plain"
Pass the file bytes in body.
Note that in the PUT request the body is not json but simply bytes (as specified by the content-type header.
Also note that max chuck size is 4MB so if your file is larger than that, you will have to split into more than one chunks.
Goodlcuk

telegraf http input plugin

I am trying to create a proof on concept using the TICK stack for monitoring. I have the helloworld stack running and showing CPU/Docker metrics.
I am trying to use the telegraf http input plugin to pull from an http endpoint:
From the docs i have simply configured the URL, GET and type (Set to json)
[[inputs.http]]
## One or more URLs from which to read formatted metrics
urls = [
"http://localhost:500/Queues"
]
method = "GET"
data_format = "json"
However nothing appears in Influx/Chronograf.
I can modify the endpoint to suit any changes there, but what am i doing wrong in telegraf config ?
I think I had the same struggle. For me the following conf worked:
[[inputs.http]]
name_override ="restservice_health"
urls = [
"https://localhost:5001/health"
]
method = "GET"
data_format = "value"
data_type = "string"
In this way, it appeared in Influxdb under the name "restservice_health" (allthough this option is not important for the example, so you could leave it out).
First, you would have to look at the result of the http://localhost:500/Queues request to make sure that it's a valid JSON object.
Then, depending on what is returned from that endpoint, you may have to configure the JSON parser, for example by setting json_query to a GJSON query to navigate the JSON response to the data you need.

Susbstitute environment variables in request body of HttpRequest plugin of Jenkins

I am using HTTP Request Plugin to make calls to a REST based Web service. In those calls I want to pass the console output URL in request body in JSON format.
I am constructing the console output URL using environment variable ${BUILD_URL}/console.
Environment variable substitution is working for the URL but not for the request body. Any suggestions on code changes that need to be made to the plugin code to make it work. Can someone please share information on how exactly does Jenkins does variable substitution and why it is not working in this case.
Below is the JSON request body:
{'state':'4', 'short_description':'${BUILD_URL}console'}
I was able to figure out the solution. Tested and confirmed that it's working.
You need to add below line in HttpRequest.java's perform method:
public boolean perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener){ throws InterruptedException, IOException
requestBody = evaluate(requestBody, build.getBuildVariableResolver(), envVars);
//rest of the code as it is
}
Just make sure you add line to evaluate requestBody member for presence of environment variables in it before you call performHttpRequest(build, listener, evaluatedUrl, params) method.

Proxying MultiPart form requests in Grails

I have a Grails controller that receives a DefaultMultipartHttpServletRequest like so:
def myController() {
DefaultMultipartHttpServletRequest proxyRequest = (DefaultMultipartHttpServletRequest) request
}
This controller acts as a proxy by taking pieces of this request and then resends the request to another destination.
For non-multipart requests, this worked fine, I did something like:
IProxyService service = (IProxyService) clientFactory.create()
Response response = service.doPOST(proxyRequest.getRequestBody())
Where proxyRequest.getRequestBody() contains a JSON block containing the request payload.
However, I do not know how to get this to work with multipart request payload, since the request body is no longer a simple block of JSON, but something like the following (taken from Chrome devtools):
How can I can pass this request payload through using my proxy service above, where doPost takes a String?
Have you tried
def parameterValue = request.getParameter("parameterName")
to get the parameter value?
If you see the method signatures for DefaultMultipartHttpServletRequest you will see there are methods for getting the files and other parameters separately because the request body is getting used to both upload the file and to pass in other parameters.

Resources