Any way to track custom statistics in locust - python

Locust is a great and simple load testing tool. By default it only tracks response times and content length from which it can deduce RPS, etc. Is there any way to track custom statistics in locust as well?
In my case a site Im testing returns couple of stats via headers. For example a count of SQL queries within a request. It would be very helpful to track some of these statistics in conjunction to tracking standard response times.
I do not see any way to do that in locust however. Is there a simple way for doing that?
Only customization I could see is setting url names in a request in docs.
Manually storing some of the stats is not that straight forward either as locust is distributed so would like to avoid doing anything custom.
edit
There is an example how custom stats can be passed around however that does not show up in the UI and requires custom export. Any way to add additional data in locust which will get logged both in UI and data export?
Maybe something like:
class MyTaskSet(TaskSet):
#task
def my_task(self):
response = self.client.get("/foo")
self.record(foo=response.headers.get('x-foo'))

As far as I know, there is no simple way of visualizing custom data in Locust. However, by looking at https://github.com/locustio/locust/blob/master/locust/main.py#L370, you could easily replace main locust run function and inject some custom logic to https://github.com/locustio/locust/blob/master/locust/web.py. This seem to be a low hanging fruit for the Locust devs to make this part of code more adjustable out of the box so I'd suggest opening issue in their GitHub.

Related

Tool to Compare Locust Load Test Results

I'm looking for any recommendations on a tools that can be used to compare load test statistics that Locust outputs. Currently, after each run, Locust produces either an HTML page in its Web UI or a CSV file. I would like to compare these documents over the course of multiple test runs to see, for example, if a release degrades performance.
I've reviewed the list of locust extensions and found nothing.
You can check out locust-influx package or Locust Monitoring with Grafana in Just 15 Minutes article.
The idea is that Locust will be sending the results to InfluxDB and you will be able to come up with a Grafana dashboard visualising and comparing different test run results.
I like Dmitri T's answer. I've also considered JTL Reporter in the past but never got approval from my company to use it.
The use case is the same as with Grafana like Dmitri suggested, using Locust's event hooks to create "listeners" that ship off Locust's stats to a service to store, analyze, and visualize the data to facilitate run comparisons.
https://jtlreporter.site/docs/integrations/locust
Locust Dashboards (a part of locust-plugins stores results in Postgres/Timescale, reporting in Grafana) has a useful view for comparing runs over time.
https://github.com/SvenskaSpel/locust-plugins/tree/master/locust_plugins/dashboards

Is it possible to load a Google Ads custom report via API into production DB

Looking through the API documentation it seems that there's currently no way to access a custom report via the API. If this is, in fact, the case, is there a workaround to make this possible?
The goal is to get a modified version of this report shown on the web interface:
No, you need to build the report yourself and call it with the API unfortunately.
Depending on how complex the report is, it can be done pretty quickly. You can quickly generate the GAQL needed for your APU query using this tool: https://developers.google.com/google-ads/api/fields/v7/overview_query_builder
This will save you typing out all the resources manually, and will even validate it for you.
If you're stuck, let us know what report you're trying to generate and we can help with the GAQL.

How to remove my own instagram followers with Python?

I want to remove my own instagram followers without blocking them, using python.
I have seen many, many, many, many instagram python libraries online that allow you to stop or start following a person, but that is not what I'm looking for; I don't want to remove who I am following or start following someone, I want to remove people who are following me.
I looked into the official documentation of Instagram's HTTP API trying to make my own solution, but I couldn't find the documentation of this action under any endpoint ( I assume it should be under /friends/ ).
I vaguely remember some library that used to do this, but I cannot find it. Does anyone know of a good way to achieve this, preferably via passing an inclusion/exclusion list for the followers I want to have as a result?
I found a solution in an old library that does something similar. You can't directly remove followers through most tools, but if you block and then unblock a user, the effect you want is achieved. Example code:
# https://instagram-private-api.readthedocs.io/en/latest/_modules/instagram_private_api/endpoints/friendships.html
import instagramPrivateApi
# ...
# Implement a Client class that inherits FriendshipMixin
api = new Client()
api.friendships_block(uid)
api.friendships_unblock(uid)
Here is the API endPoint for removing a follower https://www.instagram.com/web/friendships/{user_id}/remove_follower/
You can do a post request on this URL with appropriate headers and that can do the job.

How do I set custom "trace_id" for Datadog tracing?

How do I set custom "trace_id" for Datadog tracing? I searched high and low but can't find an answer to this. I suspect it's not supported. Would really appreciate it if I can get some help here.
As an example, if I can do the following in multiple files, then I can view these spans together in the Datadog UI since they all have the same trace ID:
#tracer.wrap(service='foo', resource='bar')
def bar(self, ttt):
span = tracer.current_span()
span.set_trace_id("my_customer_trace_id")
It turns out that trace id can be set via HTTP endpoint https://docs.datadoghq.com/api/v1/tracing/#send-traces. There doesn't seem to be an option for sending traces to the agent directly.
This can still be useful if the performance penalty of making HTTP calls is not a concern, i.e., if you are not working on a real-time system.
I am not well familiar with Datadog UI, but I see that ddtrace allow you to set tags:
span.set_tag('your_own_id', '12345')

Displaying objects connections with flask

I have a DB table which refers to itself. For example let's say I have a list of employees, some of them are other employees' bosses. Of course I have SQLAlchemy objects of this table.
I want to visualize the connections with a graph - each employee is a node, and a line is connecting each employee to his boss.
Is there a way to do it using flask? Or any other python or web framework?
You could render this client-side using a JavaScript graphing library like D3 or Google Charts. Retrieve and process your records using SQLAlchemy and Python, structure the data as per your graphing library's specifications, set up your element with a little JS, send your data over, and then render it in HTML. You'll get a pretty, interactive, and mutable graph of your choosing.
Still, this is a Python question. If you're allergic to JavaScript, you could use a Python library, such as the ones recommended here. A lot of those are more geared towards generating static plots, though. That's fine if you want to embed an image into your page or prepare it for a presentation, but it isn't very lively.
If you want to go interactive in the browser, but really don't want to touch any JS, you could conceivably use a Python wrapper for one of the aforementioned graphing libraries and let the wrapper write the JS for you. You're going to run into some JS at one point or another, whether you're the one generating it or not. Why not have the satisfaction and flexibility of doing it yourself? :)

Categories