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

Commit f109f0a

Browse files
authored
Minor Releases (#776)
* Bump versions * Apply Requests library spec fidelity * Fixes value for `http.route` in Flask middleware * Standard Metrics - Incoming Requests Per Second (#758) * Incoming requests for Python3 * python2 support * change namespace * add tests * More tests * Fix lint * Fix lint * Add test * Add CHANGELOG * Hotfix/django flask pyramid status code * Fixed requests contrib to raise original exceptions
1 parent bcda851 commit f109f0a

File tree

42 files changed

+1069
-112
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1069
-112
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,32 @@
22

33
## Unreleased
44

5+
## 0.7.3
6+
Released 2019-08-26
7+
8+
- Added `http code` to `grpc code` status code mapping on `utils`
9+
([#746](https://github.com/census-instrumentation/opencensus-python/pull/746))
10+
- Updated `django`, `flask`, `httplib`, `requests` and `pyramid` modules
11+
([#755](https://github.com/census-instrumentation/opencensus-python/pull/755))
12+
- Updated `requests` module
13+
([#771](https://github.com/census-instrumentation/opencensus-python/pull/771))
14+
15+
## 0.7.2
16+
Released 2019-08-16
17+
18+
- Fix GCP resource loading for certain environments
19+
([#761](https://github.com/census-instrumentation/opencensus-python/pull/761))
20+
21+
## 0.7.1
22+
Released 2019-08-05
23+
24+
- Added `set_status` to `span`
25+
([#738](https://github.com/census-instrumentation/opencensus-python/pull/738))
26+
- Update released stackdriver exporter version
27+
28+
## 0.7.0
29+
Released 2019-07-31
30+
531
## 0.7.2
632
Released 2019-08-16
733

contrib/opencensus-ext-azure/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Unreleased
44

5+
## 0.7.1
6+
Released 2019-08-26
7+
8+
- Standard metrics incoming requests per second
9+
([#758](https://github.com/census-instrumentation/opencensus-python/pull/758))
10+
511
## 0.7.0
612
Released 2019-07-31
713

contrib/opencensus-ext-azure/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ Below is a list of standard metrics that are currently available:
153153

154154
- Available Memory (bytes)
155155
- CPU Processor Time (percentage)
156+
- Incoming Request Rate (per second)
156157
- Outgoing Request Rate (per second)
157158
- Process CPU Usage (percentage)
158159
- Process Private Bytes (bytes)

contrib/opencensus-ext-azure/opencensus/ext/azure/common/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = '0.7.0'
15+
__version__ = '0.7.1'

contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@
1616
from opencensus.metrics.export.metric_producer import MetricProducer
1717
from opencensus.ext.azure.metrics_exporter.standard_metrics.cpu \
1818
import ProcessorTimeMetric
19-
from opencensus.ext.azure.metrics_exporter.standard_metrics.dependency \
19+
from opencensus.ext.azure.metrics_exporter.standard_metrics.http_dependency \
2020
import DependencyRateMetric
2121
from opencensus.ext.azure.metrics_exporter.standard_metrics.memory \
2222
import AvailableMemoryMetric
2323
from opencensus.ext.azure.metrics_exporter.standard_metrics.process \
2424
import ProcessCPUMetric
2525
from opencensus.ext.azure.metrics_exporter.standard_metrics.process \
2626
import ProcessMemoryMetric
27+
from opencensus.ext.azure.metrics_exporter.standard_metrics.http_requests \
28+
import RequestsRateMetric
2729

2830
# List of standard metrics to track
2931
STANDARD_METRICS = [AvailableMemoryMetric,
3032
DependencyRateMetric,
3133
ProcessCPUMetric,
3234
ProcessMemoryMetric,
33-
ProcessorTimeMetric]
35+
ProcessorTimeMetric,
36+
RequestsRateMetric]
3437

3538

3639
def register_metrics():

contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/dependency.py renamed to contrib/opencensus-ext-azure/opencensus/ext/azure/metrics_exporter/standard_metrics/http_dependency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __call__(self):
7676
value over the elapsed time.
7777
7878
:rtype: :class:`opencensus.metrics.export.gauge.DerivedLongGauge`
79-
:return: The gauge representing the available memory metric
79+
:return: The gauge representing the outgoing requests metric
8080
"""
8181
gauge = DerivedDoubleGauge(
8282
DependencyRateMetric.NAME,
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Copyright 2019, OpenCensus Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import sys
16+
import time
17+
18+
from opencensus.metrics.export.gauge import DerivedDoubleGauge
19+
if sys.version_info < (3,):
20+
from BaseHTTPServer import HTTPServer
21+
else:
22+
from http.server import HTTPServer
23+
24+
requests_map = dict()
25+
ORIGINAL_CONSTRUCTOR = HTTPServer.__init__
26+
27+
28+
def request_patch(func):
29+
def wrapper(self=None):
30+
func(self)
31+
count = requests_map.get('count', 0)
32+
requests_map['count'] = count + 1
33+
return wrapper
34+
35+
36+
def server_patch(*args, **kwargs):
37+
if len(args) >= 3:
38+
handler = args[2]
39+
if handler:
40+
# Patch the handler methods if they exist
41+
if "do_DELETE" in dir(handler):
42+
handler.do_DELETE = request_patch(handler.do_DELETE)
43+
if "do_GET" in dir(handler):
44+
handler.do_GET = request_patch(handler.do_GET)
45+
if "do_HEAD" in dir(handler):
46+
handler.do_HEAD = request_patch(handler.do_HEAD)
47+
if "do_OPTIONS" in dir(handler):
48+
handler.do_OPTIONS = request_patch(handler.do_OPTIONS)
49+
if "do_POST" in dir(handler):
50+
handler.do_POST = request_patch(handler.do_POST)
51+
if "do_PUT" in dir(handler):
52+
handler.do_PUT = request_patch(handler.do_PUT)
53+
result = ORIGINAL_CONSTRUCTOR(*args, **kwargs)
54+
return result
55+
56+
57+
def setup():
58+
# Patch the HTTPServer handler to track request information
59+
HTTPServer.__init__ = server_patch
60+
61+
62+
class RequestsRateMetric(object):
63+
NAME = "\\ASP.NET Applications(??APP_W3SVC_PROC??)\\Requests/Sec"
64+
65+
def __init__(self):
66+
setup()
67+
68+
@staticmethod
69+
def get_value():
70+
current_count = requests_map.get('count', 0)
71+
current_time = time.time()
72+
last_count = requests_map.get('last_count', 0)
73+
last_time = requests_map.get('last_time')
74+
last_result = requests_map.get('last_result', 0)
75+
76+
try:
77+
# last_time is None the very first time this function is called
78+
if last_time is not None:
79+
elapsed_seconds = current_time - last_time
80+
interval_count = current_count - last_count
81+
result = interval_count / elapsed_seconds
82+
else:
83+
result = 0
84+
requests_map['last_time'] = current_time
85+
requests_map['last_count'] = current_count
86+
requests_map['last_result'] = result
87+
return result
88+
except ZeroDivisionError:
89+
# If elapsed_seconds is 0, exporter call made too close to previous
90+
# Return the previous result if this is the case
91+
return last_result
92+
93+
def __call__(self):
94+
""" Returns a derived gauge for incoming requests per second
95+
96+
Calculated by obtaining by getting the number of incoming requests
97+
made to an HTTPServer within an elapsed time and dividing that value
98+
over the elapsed time.
99+
100+
:rtype: :class:`opencensus.metrics.export.gauge.DerivedLongGauge`
101+
:return: The gauge representing the incoming requests metric
102+
"""
103+
gauge = DerivedDoubleGauge(
104+
RequestsRateMetric.NAME,
105+
'Incoming Requests per second',
106+
'rps',
107+
[])
108+
gauge.create_default_time_series(RequestsRateMetric.get_value)
109+
return gauge

0 commit comments

Comments
 (0)