Skip to content

Commit

Permalink
Optimizations for tuples using. Removed unused types transformations. (
Browse files Browse the repository at this point in the history
  • Loading branch information
umax authored and brian-brazil committed Mar 28, 2018
1 parent ac9ef69 commit 1a16fd0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions prometheus_client/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,11 +537,11 @@ def labels(self, *labelvalues, **labelkwargs):
if labelkwargs:
if sorted(labelkwargs) != sorted(self._labelnames):
raise ValueError('Incorrect label names')
labelvalues = tuple([unicode(labelkwargs[l]) for l in self._labelnames])
labelvalues = tuple(unicode(labelkwargs[l]) for l in self._labelnames)
else:
if len(labelvalues) != len(self._labelnames):
raise ValueError('Incorrect label count')
labelvalues = tuple([unicode(l) for l in labelvalues])
labelvalues = tuple(unicode(l) for l in labelvalues)
with self._lock:
if labelvalues not in self._metrics:
self._metrics[labelvalues] = self._wrappedClass(self._name, self._labelnames, labelvalues, **self._kwargs)
Expand All @@ -551,15 +551,15 @@ def remove(self, *labelvalues):
'''Remove the given labelset from the metric.'''
if len(labelvalues) != len(self._labelnames):
raise ValueError('Incorrect label count')
labelvalues = tuple([unicode(l) for l in labelvalues])
labelvalues = tuple(unicode(l) for l in labelvalues)
with self._lock:
del self._metrics[labelvalues]

def _samples(self):
with self._lock:
metrics = self._metrics.copy()
for labels, metric in metrics.items():
series_labels = list(dict(zip(self._labelnames, labels)).items())
series_labels = list(zip(self._labelnames, labels))
for suffix, sample_labels, value in metric._samples():
yield (suffix, dict(series_labels + list(sample_labels.items())), value)

Expand Down

0 comments on commit 1a16fd0

Please sign in to comment.