Skip to content

Commit e369ade

Browse files
committed
0.2.0
1 parent 88c8df3 commit e369ade

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.6
2+
current_version = 0.2.0
33
commit = False
44
tag = False
55
files = setup.py netuitive/__init__.py

HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
History
44
-------
55

6+
0.2.0 (2016-07-22)
7+
---------------------
8+
9+
* sanitize metric names
10+
611
0.1.6 (2016-05-20)
712
---------------------
813

netuitive/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
__author__ = 'Netuitive, Inc'
4-
__version__ = '0.1.6'
4+
__version__ = '0.2.0'
55

66
from .client import Client # nopep8
77
from .element import Element # nopep8

netuitive/element.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
from .attribute import Attribute
24
from .metric import Metric
35
from .sample import Sample
@@ -28,6 +30,14 @@ def __init__(self, ElementType='SERVER', location=None):
2830
if location is not None:
2931
self.location = location
3032

33+
def _sanitize(self, s):
34+
"""
35+
Sanitize the name of a metric to remove unwanted chars
36+
37+
"""
38+
39+
return re.sub('[^a-zA-Z0-9\\._-]', '_', s)
40+
3141
def add_attribute(self, name, value):
3242
"""
3343
:param name: Name of the attribute
@@ -117,25 +127,27 @@ def add_sample(self,
117127
else:
118128
Tags = None
119129

130+
metricIdSan = self._sanitize(metricId)
131+
120132
if len(self.metrics) > 0:
121133
t = list(self.metrics)
122134

123-
if metricId not in t:
135+
if metricIdSan not in t:
124136
self.metrics.append(
125-
Metric(metricId,
137+
Metric(metricIdSan,
126138
metricType,
127139
sparseDataStrategy,
128140
unit,
129141
Tags))
130142
else:
131143
self.metrics.append(
132-
Metric(metricId,
144+
Metric(metricIdSan,
133145
metricType,
134146
sparseDataStrategy,
135147
unit,
136148
Tags))
137149

138-
self.samples.append(Sample(metricId,
150+
self.samples.append(Sample(metricIdSan,
139151
timestamp *
140152
1000,
141153
value,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
setup(
2626
name='netuitive',
27-
version='0.1.6',
27+
version='0.2.0',
2828
description="Python Client for Netuitive Cloud",
2929
long_description=readme + '\n\n' + history,
3030
author="Netuitive",

tests/test_netuitive.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ def test_with_cnt(self):
333333
self.assertEqual(
334334
a.samples[0].cnt, 3)
335335

336+
def test_add_sanitize(self):
337+
a = netuitive.Element()
338+
a.add_sample(
339+
'mongo.wiredTiger.cache.eviction$server populating queue,:but not evicting pages', 1434110794, 1, 'COUNTER', host='hostname')
340+
341+
self.assertEqual(a.metrics[
342+
0].id, 'mongo.wiredTiger.cache.eviction_server_populating_queue__but_not_evicting_pages')
343+
336344
def test_post_format(self):
337345
a = netuitive.Element()
338346

0 commit comments

Comments
 (0)