Skip to content

Commit

Permalink
Minor docs and test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rycus86 committed Mar 21, 2019
1 parent 66e559a commit 7aa9da9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
13 changes: 10 additions & 3 deletions prometheus_flask_exporter/__init__.py
Expand Up @@ -11,7 +11,6 @@
from werkzeug.exceptions import HTTPException
from prometheus_client import Counter, Histogram, Gauge, Summary
from prometheus_client import generate_latest, CONTENT_TYPE_LATEST
import prometheus_client


NO_PREFIX = '#no_prefix'
Expand Down Expand Up @@ -102,9 +101,17 @@ def __init__(self, app, path='/metrics',
self._export_defaults = export_defaults
self._defaults_prefix = defaults_prefix or 'flask'
self.buckets = buckets
self.registry = registry or prometheus_client.REGISTRY
self.version = __version__

if registry:
self.registry = registry
else:
# load the default registry from the underlying
# Prometheus library here for easier unit testing
# see https://github.com/rycus86/prometheus_flask_exporter/pull/20
from prometheus_client import REGISTRY as DEFAULT_REGISTRY
self.registry = DEFAULT_REGISTRY

if kwargs.get('group_by_endpoint') is True:
warnings.warn(
'The `group_by_endpoint` argument of `PrometheusMetrics` is '
Expand Down Expand Up @@ -537,4 +544,4 @@ def info(self, name, description, labelnames=None, labelvalues=None, **labels):
return gauge


__version__ = '0.6.0'
__version__ = '0.7.0'
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -6,15 +6,15 @@
setup(
name='prometheus_flask_exporter',
packages=['prometheus_flask_exporter'],
version='0.6.0',
version='0.7.0',
description='Prometheus metrics exporter for Flask',
long_description=long_description,
long_description_content_type='text/markdown',
license='MIT',
author='Viktor Adam',
author_email='rycus86@gmail.com',
url='https://github.com/rycus86/prometheus_flask_exporter',
download_url='https://github.com/rycus86/prometheus_flask_exporter/archive/0.6.0.tar.gz',
download_url='https://github.com/rycus86/prometheus_flask_exporter/archive/0.7.0.tar.gz',
keywords=['prometheus', 'flask', 'monitoring', 'exporter'],
classifiers=[
'Development Status :: 4 - Beta',
Expand Down
9 changes: 6 additions & 3 deletions tests/unittest_helper.py
Expand Up @@ -2,8 +2,9 @@
import sys
import unittest

import prometheus_client
from flask import Flask
from prometheus_client import CollectorRegistry

from prometheus_flask_exporter import PrometheusMetrics


Expand All @@ -19,9 +20,11 @@ def setUp(self):
self.app.testing = True
self.client = self.app.test_client()

# reset the underlying Prometheus registry
prometheus_client.REGISTRY = prometheus_client.CollectorRegistry(auto_describe=True)

def metrics(self, **kwargs):
registry = kwargs.pop('registry', CollectorRegistry(auto_describe=True))
return PrometheusMetrics(self.app, registry=registry, **kwargs)
return PrometheusMetrics(self.app, registry=kwargs.pop('registry', None), **kwargs)

def assertMetric(self, name, value, *labels, **kwargs):
if labels:
Expand Down

0 comments on commit 7aa9da9

Please sign in to comment.