Git Product home page Git Product logo

perfmetrics's People

Contributors

hathawsh avatar hugovk avatar jamadden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

perfmetrics's Issues

Enhancement: Allow runtime re-configuration for Metric

Currently, a library author decorates their code with things like @Metric(rate=0.1) to specify a 10% capture rate. If a user of that library wants to set a different capture rate, they're out of luck.

A rough workaround is to have the library author introduce a level of abstraction, for example an environment variable:

rate = float(os.environ.get('SAMPLE_RATE', '0.1'))

class Foo:
    @Metric(method=True, rate=rate)
    def thing(self): 
        pass

That gets complicated quick if you want to allow for different rates on the same object or module, etc.

Idea: Let a user directly manipulate the parameters after applying the decorator:

from library import Foo
Foo.thing.rate = 0.5

(Bonus points: have this library maintain a registry of known metrics, and allow retrieving the Metric object by name --- allowing for multiples.)

This would mean that the closure (call_with_metric) that's capturing the parameters and wrapping the decorated object would need to become a more active object. When it's used in a class, being a descriptor would be a good way to allow customization while still preserving speed.

Add LICENSE file

This repo is licensed under the Repoze (BSD-derived) license. We should state that clearly with a LICENSE file.

Support for statsd sets

Statsd supports a Set metric type for "... counting unique occurences of events between flushes ...". The existing statsd client implemented here doesn't provide a public method suitable for sending metrics of this type. Would you be willing to accept a PR implementing this functionality?

@Metric/@metricmethod break zope.interface validation of method signatures

This surprised me today. I changed an interface signature and expected test failures to alert me that the implementations no longer correctly implemented the method (because I hadn't updated their signatures yet). But that didn't happen. It turns out that the call_with_metric wrapper that's being returned from the decorator takes *args, **kwargs and that's enough to break signature introspection as far as zope.interface is concerned.

Interestingly, it doesn't break signature display as far as IPython is concerned.

I'm not sure there's anything much we can do here other than document this.

Unittests leak sockets

Running zope.testrunner.layer.UnitTests tests:
  Set up zope.testrunner.layer.UnitTests in 0.000 seconds.
  Running:
    24/51 (47.1%)//lib/python3.7/unittest/case.py:628: ResourceWarning: unclosed <socket.socket fd=6, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_DGRAM, proto=17, laddr=('::', 62098, 0, 0)>
  testMethod()
ResourceWarning: Enable tracemalloc to get the object allocation traceback
    26/51 (51.0%)//lib/python3.7/unittest/case.py:628: ResourceWarning: unclosed <socket.socket fd=6, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_DGRAM, proto=17, laddr=('::', 0, 0, 0)>
  testMethod()
ResourceWarning: Enable tracemalloc to get the object allocation traceback
    30/51 (58.8%)//lib/python3.7/site-packages/perfmetrics/__init__.py:61: ResourceWarning: unclosed <socket.socket fd=6, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_DGRAM, proto=17, laddr=('::', 0, 0, 0)>
  ClientStack.default = client
ResourceWarning: Enable tracemalloc to get the object allocation traceback
    32/51 (62.7%)//lib/python3.7/unittest/case.py:628: ResourceWarning: unclosed <socket.socket fd=6, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_DGRAM, proto=17, laddr=('::', 62099, 0, 0)>
  testMethod()
ResourceWarning: Enable tracemalloc to get the object allocation traceback
    35/51 (68.6%)//lib/python3.7/site-packages/perfmetrics/tests/test_statsd.py:27: ResourceWarning: unclosed <socket.socket fd=6, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_DGRAM, proto=17, laddr=('::', 0, 0, 0)>
  obj.udp_sock = DummySocket()
ResourceWarning: Enable tracemalloc to get the object allocation traceback

FakeStatsdClient should define __bool__ to be true

It defines __len__ and is thus falsey until a packet has been sent. But it's common for client code to write if statsd_client(): ..., leading to branches getting missed.

This would potentially be a breaking change for existing tests, so perhaps this should go in a subclass.

ETA: I doubt that's much of an issue, and I don't want to perpetuate the difference between the testing class and the other classes.

Compile with cython?

To reduce the overhead of the decorators.

We'd need to benchmark to see if its worthwhile.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.