Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Add PrometheusMetricsFactory #142

Merged

Conversation

eundoosong
Copy link
Contributor

As discussed in PR 129 with @yurishkuro, PrometheusMetricsFactory is ready for review.

Signed-off-by: Eundoo Song eundoo.song@gmail.com

Signed-off-by: Eundoo Song <eundoo.song@gmail.com>
@coveralls
Copy link

coveralls commented Mar 16, 2018

Coverage Status

Coverage increased (+0.1%) to 93.883% when pulling 4814b3e on eundoosong:add_prometheus_metrics_factory into 58173eb on jaegertracing:master.

@eundoosong
Copy link
Contributor Author

eundoosong commented Mar 16, 2018

@yurishkuro
If you see the coverage result, it is decreased because pytest-cov works as if there is no unit-testing for prometheus_metrics.py
I don’t want to run unit-testing(pytest) and coverage(pytest-cov) on PrometheusMetricsFactory if prometheus_client is not installed.
So skipif decorator provided by pytest is added in test_prometheus_metrics.py for unit-testing skipping, which works good.

@pytest.mark.skipif('prometheus_client' not in sys.modules,  
                                     reason="requires prometheus_client")
class TestPrometheusMetricsFactory:
    def test_prometheus_metrics_counter(self):
        ....

But I can’t find any similar way(conditional skip) to do the same in pytest-cov.
Options only provided by pytest-cov is adding "exclude list" into .coveragerc’s omit for file OR "# pragma: no cover" for code in a file.
They are fixed list, not like conditional thing, and no co-working with pytest

I have no idea how get the coverage passed in ci-testing.
Would you please give better suggestion on this?

Alternatively, I prepared update-coveragerc.sh for adding a file path in “omit” when a library is not installed. If it looks good, I can merge this.
https://github.com/eundoosong/jaeger-client-python/blob/prometheus_poc/scripts/update-coveragerc.sh

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks great. I just have a couple organizational questions:

  1. what benefits do you see in placing the new class in a subdirectory instead of, say, jaeger_client/prometheus.py? E.g.
from jaeger_client.prometheus import PrometheusMetricsFactory
  1. our main readme is not very large, I would add the Prometheus instructions there instead of hiding in a subdirectory (where it's much harder for people to find).

@yurishkuro
Copy link
Member

I don’t want to run unit-testing(pytest) and coverage(pytest-cov) on PrometheusMetricsFactory if prometheus_client is not installed.

Why not always run them? prometheus_client can be declared as dev dependency, as we do with other modules like opentracing instrumentation or tchannel (https://github.com/jaegertracing/jaeger-client-python/blob/master/setup.py#L64)

… setup.py

Signed-off-by: Eundoo Song <eundoo.song@gmail.com>
Signed-off-by: Eundoo Song <eundoo.song@gmail.com>
Signed-off-by: Eundoo Song <eundoo.song@gmail.com>
@eundoosong
Copy link
Contributor Author

eundoosong commented Mar 17, 2018

@yurishkuro

  1. prometheus_client as dev dependency
    Agree, it is more simple and clear. Thanks.

  2. What benefits do you see in placing the new class in a subdirectory instead of, say, jaeger_client/prometheus.py?
    I think prometheus_metrics is somewhat not part of jaeger client, it's more like an optional plugin for metrics purpose.
    And probably there might be other metrics coming in the future too. So, I moved it to the subdirectory.
    Please tell me your thoughts,

  3. Add Prometheus instructions in main readme.
    Agree.

Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I think prometheus_metrics is somewhat not part of jaeger client, it's more like an optional plugin for metrics purpose. And probably there might be other metrics coming in the future too. So, I moved it to the subdirectory.

fair enough. I'd just ask you to DRY the naming, i.e

# instead of this
from jaeger_client.metrics_factory.prometheus_metrics import PrometheusMetricsFactory

# support this
from jaeger_client.metrics.prometheus import PrometheusMetricsFactory

README.md Outdated
@@ -138,6 +138,21 @@ The B3 codec assumes it will receive lowercase HTTP headers, as this seems
to be the standard in the popular frameworks like Flask and Django.
Please make sure your framework does the same.

## Prometheus metrics
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to move this to L83 as level-4 header, i.e. as a subsection of Configuration/Production.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved

README.md Outdated
config = Config(
config={},
service_name='your-app-name',
metrics_factory=PrometheusMetricsFactory(namespace=service_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe namespace='your-app-name' for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add namespace='your-app-name'

@eundoosong
Copy link
Contributor Author

eundoosong commented Mar 18, 2018

instead of this
from jaeger_client.metrics_factory.prometheus_metrics import PrometheusMetricsFactory

support this
from jaeger_client.metrics.prometheus import PrometheusMetricsFactory

Earlier, I named metrics as subdirectory, but naming conflict error came like below since metrics.py and metrics subdirectory existed in the same location.
So I simply renamed to metrics_factory to resolve the conflict.
If you have better idea (or better naming), please tell me.

$ python example_prometheus.py
Traceback (most recent call last):
  File "example_prometheus.py", line 3, in <module>
    from jaeger_client import Config
  File "/Users/eundusong/dev/opensource/jaeger/dev/jaeger-client-python/jaeger_client/__init__.py", line 26, in <module>
    from .tracer import Tracer  # noqa
  File "/Users/eundusong/dev/opensource/jaeger/dev/jaeger-client-python/jaeger_client/tracer.py", line 33, in <module>
    from .metrics import Metrics, LegacyMetricsFactory
ImportError: cannot import name Metrics

rename prometheus_metrics.py to prometheus.py

Signed-off-by: Eundoo Song <eundoo.song@gmail.com>
@yurishkuro
Copy link
Member

Earlier, I named metrics as subdirectory, but naming conflict error came like below since metrics.py ...

I see. I just put a PR #143 that moves metrics.py into a subdirectory. It looks like it's backwards compatible. Let's merge that first, then you can rebase and move your code to jaeger_client/metrics/prometheus.py

@eundoosong eundoosong force-pushed the add_prometheus_metrics_factory branch from 52a78c2 to c0c5099 Compare March 19, 2018 05:44
move test_prometheus.py to tests from test/metrics

Signed-off-by: eundoo-song <eundoo.song@samsung.com>
@eundoosong
Copy link
Contributor Author

@yurishkuro
moved to "metrics/"
Ready to be merged, or is there anything else missing?

@yurishkuro
Copy link
Member

looks great. Thanks!

@yurishkuro yurishkuro merged commit 5da7d0e into jaegertracing:master Mar 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants