@@ -103,15 +103,17 @@ def _parse_labels(labels_string):
103103
104104
105105# If we have multiple values only consider the first
106- def _parse_value (s ):
106+ def _parse_value_and_timestamp (s ):
107107 s = s .lstrip ()
108108 separator = " "
109109 if separator not in s :
110110 separator = "\t "
111- i = s .find (separator )
112- if i == - 1 :
113- return s
114- return s [:i ]
111+ values = [value .strip () for value in s .split (separator ) if value .strip ()]
112+ if not values :
113+ return float (s ), None
114+ value = float (values [0 ])
115+ timestamp = (float (values [- 1 ])/ 1000 ) if len (values ) > 1 else None
116+ return value , timestamp
115117
116118
117119def _parse_sample (text ):
@@ -123,8 +125,8 @@ def _parse_sample(text):
123125 # We ignore the starting curly brace
124126 label = text [label_start + 1 :label_end ]
125127 # The value is after the label end (ignoring curly brace and space)
126- value = float ( _parse_value ( text [label_end + 2 :]) )
127- return Sample (name , _parse_labels (label ), value )
128+ value , timestamp = _parse_value_and_timestamp ( text [label_end + 2 :])
129+ return Sample (name , _parse_labels (label ), value , timestamp )
128130
129131 # We don't have labels
130132 except ValueError :
@@ -135,8 +137,8 @@ def _parse_sample(text):
135137 name_end = text .index (separator )
136138 name = text [:name_end ]
137139 # The value is after the name
138- value = float ( _parse_value ( text [name_end :]) )
139- return Sample (name , {}, value )
140+ value , timestamp = _parse_value_and_timestamp ( text [name_end :])
141+ return Sample (name , {}, value , timestamp )
140142
141143
142144def text_fd_to_metric_families (fd ):
0 commit comments