MCPcopy Index your code
hub / github.com/prometheus/client_python / _parse_remaining_text

Function _parse_remaining_text

prometheus_client/openmetrics/parser.py:142–231  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

140
141
142def _parse_remaining_text(text):
143 split_text = text.split(" ", 1)
144 val = _parse_value(split_text[0])
145 if len(split_text) == 1:
146 # We don't have timestamp or exemplar
147 return val, None, None
148
149 timestamp = []
150 exemplar_value = []
151 exemplar_timestamp = []
152 exemplar_labels = None
153
154 state = 'timestamp'
155 text = split_text[1]
156
157 it = iter(text)
158 in_quotes = False
159 for char in it:
160 if char == '"':
161 in_quotes = not in_quotes
162 if in_quotes:
163 continue
164 if state == 'timestamp':
165 if char == '#' and not timestamp:
166 state = 'exemplarspace'
167 elif char == ' ':
168 state = 'exemplarhash'
169 else:
170 timestamp.append(char)
171 elif state == 'exemplarhash':
172 if char == '#':
173 state = 'exemplarspace'
174 else:
175 raise ValueError("Invalid line: " + text)
176 elif state == 'exemplarspace':
177 if char == ' ':
178 state = 'exemplarstartoflabels'
179 else:
180 raise ValueError("Invalid line: " + text)
181 elif state == 'exemplarstartoflabels':
182 if char == '{':
183 label_start = _next_unquoted_char(text, '{')
184 label_end = _last_unquoted_char(text, '}')
185 exemplar_labels = parse_labels(text[label_start + 1:label_end], True)
186 state = 'exemplarparsedlabels'
187 else:
188 raise ValueError("Invalid line: " + text)
189 elif state == 'exemplarparsedlabels':
190 if char == '}':
191 state = 'exemplarvaluespace'
192 elif state == 'exemplarvaluespace':
193 if char == ' ':
194 state = 'exemplarvalue'
195 else:
196 raise ValueError("Invalid line: " + text)
197 elif state == 'exemplarvalue':
198 if char == ' ' and not exemplar_value:
199 raise ValueError("Invalid line: " + text)

Callers 1

_parse_sampleFunction · 0.85

Calls 6

_parse_valueFunction · 0.85
_next_unquoted_charFunction · 0.85
_last_unquoted_charFunction · 0.85
parse_labelsFunction · 0.85
_parse_timestampFunction · 0.85
ExemplarClass · 0.85

Tested by

no test coverage detected