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

Commit bdcb1fa

Browse files
colincadamsc24t
authored andcommitted
Modify get_task_value to match comment. (#447)
1 parent 593c443 commit bdcb1fa

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

opencensus/stats/exporters/stackdriver_exporter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,10 @@ def get_task_value():
421421
""" getTaskValue returns a task label value in the format of
422422
"py-<pid>@<hostname>".
423423
"""
424-
task_value = "py@" + str(os.getpid())
425424
hostname = platform.uname()[1]
426-
task_value += hostname if hostname is not None else "localhost"
427-
return task_value
425+
if not hostname:
426+
hostname = "localhost"
427+
return "py-%s@%s" % (os.getpid(), hostname)
428428

429429

430430
def namespaced_view_name(view_name, metric_prefix):

tests/unit/stats/exporter/test_stackdriver_stats.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ def assertCorrectLabels(self, actual_labels, expected_labels,
291291
if include_opencensus:
292292
opencensus_tag = actual_labels.pop(stackdriver.OPENCENSUS_TASK)
293293
self.assertIsNotNone(opencensus_tag)
294-
self.assertIn("py@", opencensus_tag)
294+
self.assertIn("py-", opencensus_tag)
295295
self.assertDictEqual(actual_labels, expected_labels)
296296

297297
@mock.patch('opencensus.stats.exporters.stackdriver_exporter.'
@@ -1093,11 +1093,11 @@ def test_set_metric_labels_with_None(self):
10931093
'version', 'machine',
10941094
'processor'))
10951095
def test_get_task_value_with_hostname(self, mock_uname, mock_pid):
1096-
self.assertEqual(stackdriver.get_task_value(), "py@12345node")
1096+
self.assertEqual(stackdriver.get_task_value(), "py-12345@node")
10971097

10981098
@mock.patch('os.getpid', return_value=12345)
1099-
@mock.patch('platform.uname', return_value=('system', None, 'release',
1099+
@mock.patch('platform.uname', return_value=('system', '', 'release',
11001100
'version', 'machine',
11011101
'processor'))
11021102
def test_get_task_value_without_hostname(self, mock_uname, mock_pid):
1103-
self.assertEqual(stackdriver.get_task_value(), "py@12345localhost")
1103+
self.assertEqual(stackdriver.get_task_value(), "py-12345@localhost")

0 commit comments

Comments
 (0)