-
Notifications
You must be signed in to change notification settings - Fork 703
Adding Resource to MetricRecord #1209
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
Changes from 7 commits
a553731
859b7fc
b291bd2
91c8602
319c1bb
664931a
e825196
cde9642
e9dcd4e
86a493a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
) | ||
from opentelemetry.sdk.metrics.export.controller import PushController | ||
from opentelemetry.sdk.metrics.export.processor import Processor | ||
from opentelemetry.sdk.resources import Resource | ||
|
||
|
||
# pylint: disable=protected-access | ||
|
@@ -49,12 +50,13 @@ def test_export(self): | |
) | ||
labels = {"environment": "staging"} | ||
aggregator = SumAggregator() | ||
record = MetricRecord(metric, labels, aggregator) | ||
result = '{}(data="{}", labels="{}", value={})'.format( | ||
record = MetricRecord(metric, labels, aggregator, meter.resource) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to have a test that tests to see if the resource created in the metric record matches the resource in the meterprovider. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the ConsoleMetricsExporter to show the resource and updated the test to validate it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be better to remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spec does specify that a |
||
result = '{}(data="{}", labels="{}", value={}, resource={})'.format( | ||
ConsoleMetricsExporter.__name__, | ||
metric, | ||
labels, | ||
aggregator.checkpoint, | ||
meter.resource.attributes, | ||
) | ||
with mock.patch("sys.stdout") as mock_stdout: | ||
exporter.export([record]) | ||
|
@@ -64,7 +66,7 @@ def test_export(self): | |
class TestProcessor(unittest.TestCase): | ||
def test_checkpoint_set(self): | ||
meter = metrics.MeterProvider().get_meter(__name__) | ||
processor = Processor(True) | ||
processor = Processor(True, meter.resource) | ||
aggregator = SumAggregator() | ||
metric = metrics.Counter( | ||
"available memory", "available memory", "bytes", int, meter | ||
|
@@ -81,13 +83,13 @@ def test_checkpoint_set(self): | |
self.assertEqual(records[0].aggregator, aggregator) | ||
|
||
def test_checkpoint_set_empty(self): | ||
processor = Processor(True) | ||
processor = Processor(True, Resource.create_empty()) | ||
records = processor.checkpoint_set() | ||
self.assertEqual(len(records), 0) | ||
|
||
def test_finished_collection_stateless(self): | ||
meter = metrics.MeterProvider().get_meter(__name__) | ||
processor = Processor(False) | ||
processor = Processor(False, meter.resource) | ||
aggregator = SumAggregator() | ||
metric = metrics.Counter( | ||
"available memory", "available memory", "bytes", int, meter | ||
|
@@ -102,7 +104,7 @@ def test_finished_collection_stateless(self): | |
|
||
def test_finished_collection_stateful(self): | ||
meter = metrics.MeterProvider().get_meter(__name__) | ||
processor = Processor(True) | ||
processor = Processor(True, meter.resource) | ||
aggregator = SumAggregator() | ||
metric = metrics.Counter( | ||
"available memory", "available memory", "bytes", int, meter | ||
|
@@ -117,7 +119,7 @@ def test_finished_collection_stateful(self): | |
|
||
def test_processor_process_exists(self): | ||
meter = metrics.MeterProvider().get_meter(__name__) | ||
processor = Processor(True) | ||
processor = Processor(True, meter.resource) | ||
aggregator = SumAggregator() | ||
aggregator2 = SumAggregator() | ||
metric = metrics.Counter( | ||
|
@@ -138,7 +140,7 @@ def test_processor_process_exists(self): | |
|
||
def test_processor_process_not_exists(self): | ||
meter = metrics.MeterProvider().get_meter(__name__) | ||
processor = Processor(True) | ||
processor = Processor(True, meter.resource) | ||
aggregator = SumAggregator() | ||
metric = metrics.Counter( | ||
"available memory", "available memory", "bytes", int, meter | ||
|
@@ -157,7 +159,7 @@ def test_processor_process_not_exists(self): | |
|
||
def test_processor_process_not_stateful(self): | ||
meter = metrics.MeterProvider().get_meter(__name__) | ||
processor = Processor(True) | ||
processor = Processor(True, meter.resource) | ||
aggregator = SumAggregator() | ||
metric = metrics.Counter( | ||
"available memory", "available memory", "bytes", int, meter | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
Take a look at this comment. I believe we should actually decouple
Tracer
fromTracerProvider
, and equivalently,Meter
fromMeterProvider
by removing thesource
attribute. We should be passing in configuration through theProvider
into the constructor of bothTracer
andMeter
.resource
would be one of those configurations. Not sure if you want to do this as part of this PR however.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.
It looks like issue #1181 already tracks this work, I'd rather do this as a follow up to this PR.