question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Request: Cause requests to be ignored from stats collection

See original GitHub issue

I’d like to be able to annotate some requests to be ignored from collection in stats.

(The use case is that we have to create/delete models during setup and teardown, and since we don’t have access to the DB this has to be done through the API. These requests shouldn’t show up in the stats at the end. I know it doesn’t make sense to ignore these since they’re part of the “lifecycle” of the task set, but that’s the ask.)

Here’s what I’ve got so far:

IGNORE_REQUEST = False

def conditional_request_success(*args, **kwargs):
    if not IGNORE_REQUEST:
        return on_request_success(*args, **kwargs)


def conditional_request_failure(*args, **kwargs):
    if not IGNORE_REQUEST:
        return on_request_failure(*args, **kwargs)


events.request_success -= on_request_success
events.request_success += conditional_request_success
events.request_failure -= on_request_failure
events.request_failure += conditional_request_failure


class IgnoreRequestContextManager(object):
    def __enter__(self):
        global IGNORE_REQUEST
        IGNORE_REQUEST = True

    def __exit__(self, *args, **kwargs):
        global IGNORE_REQUEST
        IGNORE_REQUEST = False


ignore_request = IgnoreRequestContextManager

And then I can:

    def setup(self):
        with ignore_request():
            self.login()
            self.create_setup_models()
            ...

This is obviously not thread-safe of course. I can update it to use threadlocals, but is this the best way to go about this in the absence of an official feature?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
heymancommented, Jul 19, 2018

Could you make the HTTP requests - that you don’t want to track stats for - with just Requests (or some other client), instead of using the Locust client? Something like:

import requests
requests.post(...)

Alternatively, you could reset all the stats once the setup has completed (though that method wouldn’t work well if you want to exclude tear down requests that are made after the requests that you want to track):

from locust.stats import global_stats
global_stats.clear_all()
0reactions
cyberwcommented, Oct 31, 2019

Closing due to lack of activity. Feel free to reopen if this is important to you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Block preferences: "Not Renewable - Item has Requests" is ...
Description. We activated the rule "Not renewable - Item has requests" in the block preferences but it appears to be ignored.
Read more >
Wikipedia:Ignored feature requests
You can discuss them first at m:MediaWiki feature request and bug report discussion. ... and is explicitly not for the requesting of new...
Read more >
12 Managing Optimizer Statistics: Basic Topics
Set the STATISTICS_LEVEL initialization level to BASIC to disable collection of all advisories and statistics, including Automatic SQL Tuning Advisor. Note:.
Read more >
Customer Feature Requests - Zoho Cares
A request (and even a bug) should be a common item that can be attached to multiple customers. In this way, when we...
Read more >
Configuring sampling rules - AWS X-Ray
Sampling rules tell the X-Ray SDK how many requests to record for a set of criteria. By default, the X-Ray SDK records the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found