-
Notifications
You must be signed in to change notification settings - Fork 648
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
[WIP] Views API Prototype #596
Merged
Merged
Changes from 30 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
7419bda
view
lzchen aa7562a
remove label keys
lzchen 4a7f6dd
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
lzchen e43a984
Remove meter ref, aggregator for
lzchen 4d4351f
view manager as part of meter
lzchen e667bc8
fix tests
lzchen 5d9ae6f
seperate aggregations from aggregators
lzchen 554dafb
default aggregations
lzchen f8997ca
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
lzchen 8331f1b
Add label key logic
lzchen d93f159
aggregate config and histogram
lzchen 53cc0f7
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
lzchen e966f7e
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
lzchen adce43e
views
lzchen 864b644
fix observer
lzchen fea636f
fix lastvalue
lzchen af6d003
fix tests
lzchen 176aa55
fix tests
lzchen 12402f7
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
lzchen 8e3a903
changelog
lzchen 9e7332f
fix tests
lzchen 3eb7dcd
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
lzchen ac3734c
lint
lzchen 82a154c
lint
lzchen 55ad347
lint
lzchen fbeaf34
lint
lzchen 778223e
lint
lzchen 4875769
lint
lzchen f793247
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
lzchen d7fbcef
Merge branch 'master' into views
lzchen 45e96f3
fix state
lzchen 0b22ef7
Merge branch 'views' of https://github.com/lzchen/opentelemetry-pytho…
lzchen 2a55926
fix test
lzchen b74fb2d
Merge branch 'master' into views
lzchen a510eb0
Create new aggregator per ViewData, config dict
cnnradams 54594c8
ViewData references, equality updates
cnnradams 8baa90e
Histogram updates
cnnradams 765e8ef
updates
cnnradams bba29d5
fix batcher
cnnradams d609602
Merge pull request #8 from cnnradams/views
lzchen 4b49cb7
Fix View hash
c24t de145ce
Wrap, blacken
c24t 93c3808
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
lzchen 2962561
Merge branch 'views' of https://github.com/lzchen/opentelemetry-pytho…
lzchen 58212ba
fix teests
lzchen f0e74b7
test
lzchen a8ab8de
lint
lzchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Copyright The OpenTelemetry Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
""" | ||
This example shows how to use the different modes to capture metrics. | ||
It shows the usage of the direct, bound and batch calling conventions. | ||
""" | ||
from opentelemetry import metrics | ||
from opentelemetry.sdk.metrics import ( | ||
MeterProvider, | ||
UpDownCounter, | ||
ValueRecorder, | ||
) | ||
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter | ||
from opentelemetry.sdk.metrics.export.aggregate import ( | ||
HistogramAggregator, | ||
LastValueAggregator, | ||
MinMaxSumCountAggregator, | ||
SumAggregator, | ||
) | ||
from opentelemetry.sdk.metrics.view import View, ViewConfig | ||
|
||
# Use the meter type provided by the SDK package | ||
metrics.set_meter_provider(MeterProvider()) | ||
meter = metrics.get_meter(__name__) | ||
metrics.get_meter_provider().start_pipeline(meter, ConsoleMetricsExporter(), 5) | ||
|
||
requests_counter = meter.create_metric( | ||
name="requests", | ||
description="number of requests", | ||
unit="1", | ||
value_type=int, | ||
metric_type=UpDownCounter, | ||
) | ||
|
||
requests_size = meter.create_metric( | ||
name="requests_size", | ||
description="size of requests", | ||
unit="1", | ||
value_type=int, | ||
metric_type=ValueRecorder, | ||
) | ||
|
||
# Views are used to define an aggregation type and label keys to aggregate by | ||
# for a given metric | ||
|
||
# Two views with the same metric and aggregation type but different label keys | ||
# With ViewConfig.LABEL_KEYS, all labels but the ones defined in label_keys are | ||
# dropped from the aggregation | ||
counter_view1 = View( | ||
requests_counter, | ||
SumAggregator(), | ||
label_keys=["environment"], | ||
config=ViewConfig.LABEL_KEYS, | ||
) | ||
counter_view2 = View( | ||
requests_counter, | ||
MinMaxSumCountAggregator(), | ||
label_keys=["os_type"], | ||
config=ViewConfig.LABEL_KEYS, | ||
) | ||
# This view has ViewConfig set to UNGROUPED, meaning all recorded metrics take | ||
# the labels directly without and consideration for label_keys | ||
counter_view3 = View( | ||
requests_counter, | ||
LastValueAggregator(), | ||
label_keys=["environment"], # is not used due to ViewConfig.UNGROUPED | ||
config=ViewConfig.UNGROUPED, | ||
) | ||
# This view uses the HistogramAggregator which accepts an option config | ||
# parameter to specify the bucket ranges | ||
size_view = View( | ||
requests_size, | ||
HistogramAggregator(config=[20, 40, 60, 80, 100]), | ||
label_keys=["environment"], # is not used due to ViewConfig.UNGROUPED | ||
config=ViewConfig.UNGROUPED, | ||
) | ||
|
||
# Register the views to the view manager to use the views. Views MUST be | ||
# registered before recording metrics. Metrics that are recorded without | ||
# views defined for them will use a default for that type of metric | ||
meter.register_view(counter_view1) | ||
meter.register_view(counter_view2) | ||
meter.register_view(counter_view3) | ||
meter.register_view(size_view) | ||
|
||
# The views will evaluate the labels passed into the record and aggregate upon | ||
# the unique labels that are generated | ||
# view1 labels will evaluate to {"environment": "staging"} | ||
# view2 labels will evaluate to {"os_type": linux} | ||
# view3 labels will evaluate to {"environment": "staging", "os_type": "linux"} | ||
requests_counter.add(100, {"environment": "staging", "os_type": "linux"}) | ||
|
||
# Since this is using the HistogramAggregator, the bucket counts will be reflected | ||
# with each record | ||
requests_size.record(25, {"test": "value"}) | ||
requests_size.record(-3, {"test": "value"}) | ||
requests_size.record(200, {"test": "value"}) | ||
|
||
input("...\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this isn't used, maybe this parameter should just be the signal that you want to use the LABEL_KEYS configuration, rather than having it only being used in that one case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting thought. I don't know what is more confusing, the ignoring of the ViewConfig if label_keys is defined or the ignoring of the keys if ViewConfig.Ungrouped is defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not combine them into one struct that contains both the config and the data that it needs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if they are combined to one struct, i'm not sure if it eases the confusion? There's still implicit behavior that is occurring if both values are supplied, even as arguments to a struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I was thinking more of a class that could indicate both the type and the attributes needed to implement it, and constructors that made it clear what was required for what. Or something along those lines.