Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Standard Metrics - Outgoing Requests Per Second#729

Merged
reyang merged 96 commits intocensus-instrumentation:masterfrom
lzchen:metrics
Jul 30, 2019
Merged

Standard Metrics - Outgoing Requests Per Second#729
reyang merged 96 commits intocensus-instrumentation:masterfrom
lzchen:metrics

Conversation

@lzchen
Copy link
Copy Markdown
Contributor

@lzchen lzchen commented Jul 24, 2019

Part of [#695]. Standard metric for outgoing requests per second. Outgoing requests is under "dependencies".
Tracks requests made from application using the requests library. Other http libraries include urllib2 (python2 exclusive), urllib(python3 exclusive) and urllib3 (both) which might be introduced in the future.

Outgoing request rate is not part of Azure Monitor's standard metrics, so to see the data, view them under "customMetrics" in Kusto.

image

@lzchen
Copy link
Copy Markdown
Contributor Author

lzchen commented Jul 26, 2019

This PR also includes the implementation of a thread context, named "is_exporter_thread", which is a flag set whenever the thread being run is one that has an exporter in it. This is to prevent spans and metrics being generated if the requests are being sent from an exporter. This includes ignoring span generation with applications configured to use opencensus-ext-requests and opencensus-ext-httplib, as well as metric collection from all opencensus exporters.

from opencensus.ext.azure.common.transport import TransportMixin

logger = logging.getLogger(__name__)
if 'is_exporter_thread' not in RuntimeContext.snapshot().keys():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess there is a better place for this instead of the log_exporter.
Going forward in OpenTelemetry we're trying to remove the requirement of having to register slots.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right. Instead of checking and changing the RuntimeContext for every exporter, we use a slot in the execution context now instead and simply import the module in each exporter.

STANDARD_METRICS = [AvailableMemoryMetric, ProcessCPUMetric,
ProcessMemoryMetric, ProcessorTimeMetric]
STANDARD_METRICS = [AvailableMemoryMetric, DependencyRateMetric,
ProcessCPUMetric, ProcessMemoryMetric,
Copy link
Copy Markdown
Contributor

@reyang reyang Jul 26, 2019

Choose a reason for hiding this comment

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

Personally I think it could be better to put each item on its own line, no strong opinion though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I like it better as well. Makes it less annoying to reformat and alphabetize.

try:
# Check if request was sent from an exporter. If so, do not wrap.
disable_from_exporter = RuntimeContext.is_exporter_thread
if disable_from_exporter:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor, would it be better to put if RuntimeContext.is_exporter_thread: directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is true.

_exporter_slot = RuntimeContext.register_slot('is_exporter_thread', False)
_tracer_slot = RuntimeContext.register_slot('tracer', noop_tracer.NoopTracer())

def is_exporter_thread():
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Curious, why do we need this instead of using RuntimeContext.is_exporter_thread directly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

  1. There should only be a single way to read/modify the same piece of data. It would be quite awkward to read using RuntimeContext and write using execution_context

  2. Consistency with the other execution_context slots.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There should only be a single way to read/modify the same piece of data. It would be quite awkward to read using RuntimeContext and write using execution_context

This single way would be RuntimeContext.is_exporter_thread.

Consistency with the other execution_context slots.

We're in the direction to remove execution_context.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would be strange to have execution_context imported but not used.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see. Okay for this PR, we should clean this up once we say goodbye to execution_context.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please clean up

.

@googlebot
Copy link
Copy Markdown

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

Copy link
Copy Markdown
Contributor

@reyang reyang left a comment

Choose a reason for hiding this comment

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

LGTM.

# No retry policy, log output
logger.warning('Transient client side error %s.', ex)
return
finally:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's great that we can say goodbye to this :)

@reyang reyang merged commit aa8846a into census-instrumentation:master Jul 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants