(samples)
| 274 | """ |
| 275 | |
| 276 | def sample_line(samples): |
| 277 | if samples.labels: |
| 278 | labelstr = '{0}'.format(','.join( |
| 279 | # Label values always support UTF-8 |
| 280 | ['{}="{}"'.format( |
| 281 | openmetrics.escape_label_name(k, escaping), openmetrics._escape(v, openmetrics.ALLOWUTF8, False)) |
| 282 | for k, v in sorted(samples.labels.items())])) |
| 283 | else: |
| 284 | labelstr = '' |
| 285 | timestamp = '' |
| 286 | if samples.timestamp is not None: |
| 287 | # Convert to milliseconds. |
| 288 | timestamp = f' {int(float(samples.timestamp) * 1000):d}' |
| 289 | if escaping != openmetrics.ALLOWUTF8 or openmetrics._is_valid_legacy_metric_name(samples.name): |
| 290 | if labelstr: |
| 291 | labelstr = '{{{0}}}'.format(labelstr) |
| 292 | return f'{openmetrics.escape_metric_name(samples.name, escaping)}{labelstr} {floatToGoString(samples.value)}{timestamp}\n' |
| 293 | maybe_comma = '' |
| 294 | if labelstr: |
| 295 | maybe_comma = ',' |
| 296 | return f'{{{openmetrics.escape_metric_name(samples.name, escaping)}{maybe_comma}{labelstr}}} {floatToGoString(samples.value)}{timestamp}\n' |
| 297 | |
| 298 | output = [] |
| 299 | for metric in registry.collect(): |
no test coverage detected