Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics Implementation #160

Merged
merged 96 commits into from
Sep 27, 2019
Merged

Metrics Implementation #160

merged 96 commits into from
Sep 27, 2019

Conversation

lzchen
Copy link
Contributor

@lzchen lzchen commented Sep 22, 2019

This PR is the first part of finishing [#155]. Implements the Metric SDK in the following ways:

  1. Meter implementation + loader
  2. Metric instruments (gauge, counter, measure)
  3. Handles for metric instruments
  4. RecordBatch

Additional changes include:

  1. Using Tuple instead of List for label values
  2. Using a generic update function as an interface to the add(), set() and record() functions for the metric handles.
  3. Example included in example app.

TODOs:

  1. Implement record() behaviour for MeasureMetric
  2. Observer + callback mechanism for Gauge RFC
  3. Label sets + required/optional label keys + record directly through metric instrument RFC
  4. Locks for handles?

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

I'm still reviewing this, but it looks like DefaultMetric (and etc.) addresses my main concern. After a quick pass I don't see any obvious blockers.


ValueT = TypeVar("ValueT", int, float)
Copy link
Member

Choose a reason for hiding this comment

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

Not to bikeshed on type annotations, but you don't need this or MetricT below unless you want the generic type for something. E.g. to declare that a function's return type matches one of its argument's type. As I understand it Union[int, float] would do the same thing here.

Copy link
Contributor Author

@lzchen lzchen Sep 27, 2019

Choose a reason for hiding this comment

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

I think according to @Oberon00 , mypy cannot deduce the actual return type of the parameter/function if Union is used, although I'm not really sure now what is meant by that. As well, sphinx does not seem to be able to read TypeVar in the docs.

This comment, I was using Union previously.

Copy link
Member

@Oberon00 Oberon00 Sep 27, 2019

Choose a reason for hiding this comment

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

Yes that seems indeed unused. Maybe I mixed something up in that comment, I'll have a closer look later. But as this PR discussion is getting too long and this is certainly no blocker, I guess we can make a follow-up for that.

EDIT: See #160 (comment), they would make sense.

opentelemetry-api/src/opentelemetry/metrics/__init__.py Outdated Show resolved Hide resolved
@@ -28,3 +39,105 @@ def ns_to_iso_str(nanoseconds):
"""Get an ISO 8601 string from time_ns value."""
ts = datetime.datetime.fromtimestamp(nanoseconds / 1e9)
return ts.strftime("%Y-%m-%dT%H:%M:%S.%fZ")


class BoundedList(Sequence):
Copy link
Member

Choose a reason for hiding this comment

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

Why move these in this PR if you're not using them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, the Meter implementation has no concept of limits on certain data objects (handle, metric), but could possibly have those limitations in the future, in which it can leverage these data structures. They also seem reusable enough to put in utils.py. I remember there was a comment about moving it to a common place. I don't have a strong opinion though.

@lzchen lzchen requested a review from Oberon00 September 27, 2019 02:34

ValueT = TypeVar("ValueT", int, float)
Copy link
Member

@Oberon00 Oberon00 Sep 27, 2019

Choose a reason for hiding this comment

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

Yes that seems indeed unused. Maybe I mixed something up in that comment, I'll have a closer look later. But as this PR discussion is getting too long and this is certainly no blocker, I guess we can make a follow-up for that.

EDIT: See #160 (comment), they would make sense.

label_keys: Sequence[str] = None,
enabled: bool = True,
monotonic: bool = False,
) -> "Metric":
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
) -> "Metric":
) -> metrics_api.MetricT:

https://docs.python.org/3/library/typing.html#generics

And now I remember the reason for ValueT: I thought we should make a MetricT[ValueT] to make mypy detect all cases where we could run into the "wrong value type" check at lint-time.

@lzchen lzchen requested a review from c24t September 27, 2019 15:25
Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

Nice SDK test improvements. No more blocking comments from me, thanks for tackling this beast of a PR.

Some things to follow up on after this is merged:

@lzchen
Copy link
Contributor Author

lzchen commented Sep 27, 2019

@c24t
Can you explain a bit more about adding no-op tests for the DefaultMetricHandle methods?
Currently, DefaultMetricHandle does not have any methods. Are you referring to the case where users try to use an actual handle counterhandle.add but they accidently loaded the default?

@c24t
Copy link
Member

c24t commented Sep 27, 2019

Are you referring to the case where users try to use an actual handle counterhandle.add but they accidently loaded the default?

Sorry, my comment wasn't clear. That's exactly what I mean -- testing that using DefaultMetricHandle in place of a CounterHandle (or etc.) doesn't crash the app or give the user back the wrong type of object (especially null) for some call.

Since nothing is using data yet, I think your tests actually do cover this, but we'll have to revisit when we hook up exporters.

@lzchen lzchen merged commit 764d317 into open-telemetry:master Sep 27, 2019
hectorhdzg added a commit to hectorhdzg/opentelemetry-python that referenced this pull request Oct 21, 2019
for start_time and end_time

Make lint happy

Addressing comments

Addressing comments

Allowing 0 as start and end time

Fix lint issues

Metrics API RFC 0003 cont'd (open-telemetry#136)

* Create functions

Comments for Meter

More comments

Add more comments

Fix typos

* fix lint

* Fix lint

* fix typing

* Remove options, constructors, seperate labels

* Consistent naming for float and int

* Abstract time series

* Use ABC

* Fix typo

* Fix docs

* seperate measure classes

* Add examples

* fix lint

* Update to RFC 0003

* Add spancontext, measurebatch

* Fix docs

* Fix comments

* fix lint

* fix lint

* fix lint

* skip examples

* white space

* fix spacing

* fix imports

* fix imports

* LabelValues to str

* Black formatting

* fix isort

* Remove aggregation

* Fix names

* Remove aggregation from docs

* Fix lint

* metric changes

* Typing

* Fix lint

* Fix lint

* Add space

* Fix lint

* fix comments

* address comments

* fix comments

Adding a working propagator, adding to integrations and example (open-telemetry#137)

Adding a full, end-to-end example of propagation at work in the
example application, including a test.

Adding the use of propagators into the integrations.

Metrics API RFC 0009 (open-telemetry#140)

* Create functions

Comments for Meter

More comments

Add more comments

Fix typos

* fix lint

* Fix lint

* fix typing

* Remove options, constructors, seperate labels

* Consistent naming for float and int

* Abstract time series

* Use ABC

* Fix typo

* Fix docs

* seperate measure classes

* Add examples

* fix lint

* Update to RFC 0003

* Add spancontext, measurebatch

* Fix docs

* Fix comments

* fix lint

* fix lint

* fix lint

* skip examples

* white space

* fix spacing

* fix imports

* fix imports

* LabelValues to str

* Black formatting

* fix isort

* Remove aggregation

* Fix names

* Remove aggregation from docs

* Fix lint

* metric changes

* Typing

* Fix lint

* Fix lint

* Add space

* Fix lint

* fix comments

* handle, recordbatch

* docs

* Update recordbatch

* black

* Fix typo

* remove ValueType

* fix lint

Console exporter (open-telemetry#156)

Make use_span more flexible (closes open-telemetry#147). (open-telemetry#154)

Co-Authored-By: Reiley Yang <[email protected]>
Co-Authored-By: Chris Kleinknecht <[email protected]>

WSGI fixes (open-telemetry#148)

Fix http.url.
Don't delay calling wrapped app.

Skeleton for azure monitor exporters (open-telemetry#151)

Add link to docs to README (open-telemetry#170)

Move example app to the examples folder (open-telemetry#172)

WSGI: Fix port 80 always appended in http.host (open-telemetry#173)

Build and host docs via github action (open-telemetry#167)

Add missing license boilerplate to a few files (open-telemetry#176)

sdk/trace/exporters: add batch span processor exporter (open-telemetry#153)

The exporters specification states that two built-in span processors should be
implemented, the simple processor span and the batch processor span.

This commit implements the latter, it is mainly based on the opentelemetry/java
one.

The algorithm implements the following logic:
- a condition variable is used to notify the worker thread in case the queue
is half full, so that exporting can start before the queue gets full and spans
are dropped.
- export is called each schedule_delay_millis if there is a least one new span
to export.
- when the processor is shutdown all remaining spans are exported.

Implementing W3C TraceContext (fixes open-telemetry#116) (open-telemetry#180)

* Implementing TraceContext (fixes open-telemetry#116)

This introduces a w3c TraceContext propagator, primarily inspired by opencensus.

fix time conversion bug (open-telemetry#182)

Introduce Context.suppress_instrumentation (open-telemetry#181)

Metrics Implementation (open-telemetry#160)

* Create functions

Comments for Meter

More comments

Add more comments

Fix typos

* fix lint

* Fix lint

* fix typing

* Remove options, constructors, seperate labels

* Consistent naming for float and int

* Abstract time series

* Use ABC

* Fix typo

* Fix docs

* seperate measure classes

* Add examples

* fix lint

* Update to RFC 0003

* Add spancontext, measurebatch

* Fix docs

* Fix comments

* fix lint

* fix lint

* fix lint

* skip examples

* white space

* fix spacing

* fix imports

* fix imports

* LabelValues to str

* Black formatting

* fix isort

* Remove aggregation

* Fix names

* Remove aggregation from docs

* Fix lint

* metric changes

* Typing

* Fix lint

* Fix lint

* Add space

* Fix lint

* fix comments

* handle, recordbatch

* docs

* Update recordbatch

* black

* Fix typo

* remove ValueType

* fix lint

* sdk

* metrics

* example

* counter

* Tests

* Address comments

* ADd tests

* Fix typing and examples

* black

* fix lint

* remove override

* Fix tests

* mypy

* fix lint

* fix type

* fix typing

* fix tests

* isort

* isort

* isort

* isort

* noop

* lint

* lint

* fix tuple typing

* fix type

* black

* address comments

* fix type

* fix lint

* remove imports

* default tests

* fix lint

* usse sequence

* remove ellipses

* remove ellipses

* black

* Fix typo

* fix example

* fix type

* fix type

* address comments

Implement Azure Monitor Exporter (open-telemetry#175)

Span add override parameters for start_time and end_time (open-telemetry#179)

CONTRIBUTING.md: Fix clone URL (open-telemetry#177)

Add B3 exporter to alpha release table (open-telemetry#164)

Update README for alpha release (open-telemetry#189)

Update Contributing.md doc (open-telemetry#194)

Add **simple** client/server examples (open-telemetry#191)

Remove unused dev-requirements.txt (open-telemetry#200)

The requirements are contained in tox.ini now.

Fx bug in BoundedList for Python 3.4 and add tests (open-telemetry#199)

* fix bug in BoundedList for python 3.4 and add tests

collections.deque.copy() was introduced in python 3.5, this commit changes
that by the deque constructor and adds some tests to BoundedList and BoundedDict
to avoid similar problems in the future.

Also, improve docstrings of BoundedList and BoundedDict classes

Move util.time_ns to API. (open-telemetry#205)

Add Jaeger exporter (open-telemetry#174)

This adds a Jeager exporter for OpenTelemetry.  This exporter is based
on https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-jaeger.

The exporter uses thrift and can be configured to send data to the agent and
also to a remote collector.

There is a long discussion going on about how to include generated files
in the repo, so for now just put them here.

Add code coverage

Revert latest commit

Fix some "errors" found by mypy. (open-telemetry#204)

Fix some errors found by mypy (split from open-telemetry#201).

Update README for new milestones (open-telemetry#218)

Refactor current span handling for newly created spans. (open-telemetry#198)

1. Make Tracer.start_span() simply create and start the Span,
   without setting it as the current instance.
2. Add an extra Tracer.start_as_current_span() to create the
   Span and set it as the current instance automatically.

Co-Authored-By: Chris Kleinknecht <[email protected]>

Add set_status to Span (open-telemetry#213)

Initial commit

Initial version
srikanthccv pushed a commit to srikanthccv/opentelemetry-python that referenced this pull request Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants