Skip to content

Adds metrics helper test fixture#514

Open
Stringy wants to merge 1 commit intomainfrom
giles/metrics-test-utils
Open

Adds metrics helper test fixture#514
Stringy wants to merge 1 commit intomainfrom
giles/metrics-test-utils

Conversation

@Stringy
Copy link
Copy Markdown
Contributor

@Stringy Stringy commented Apr 15, 2026

Description

During the work on rate limiting tests in #499, I thought it might be useful to have a metrics fixture to get a snapshot of the metrics to reason about Fact's state.

Checklist

  • Investigated and inspected CI test results
  • Updated documentation accordingly

Automated testing

  • Added unit tests
  • Added integration tests
  • Added regression tests

If any of these don't apply, please comment below.

Testing Performed

CI is enough.

Comment thread tests/metrics.py
Comment on lines +47 to +51
if name.startswith(cls._PREFIX):
name = name[len(cls._PREFIX):]
if name.endswith(cls._TOTAL_SUFFIX):
name = name[:-len(cls._TOTAL_SUFFIX)]
return name
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if name.startswith(cls._PREFIX):
name = name[len(cls._PREFIX):]
if name.endswith(cls._TOTAL_SUFFIX):
name = name[:-len(cls._TOTAL_SUFFIX)]
return name
return name.removeprefix(cls._PREFIX).removesuffix(cls._TOTAL_SUFFIX)

Comment thread tests/test_rate_limit.py
if len(parts) >= 2:
dropped_count = int(parts[1])
break
ss = metrics.snapshot()
Copy link
Copy Markdown
Contributor

@JoukoVirtanen JoukoVirtanen Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[ultra nit] I don't like ss. I guess the the less a variable is used the shorter it can be, but I would still prefer metric_snapshot here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ss is fine (fascist undertones aside), metric_snapshot is too long, if we want to change it we can go with either snap or snapshot.

I also see ss is only used in the next line, so it could all be shortened to a single line without needing to define ss at all.

@JoukoVirtanen
Copy link
Copy Markdown
Contributor

Please rebase and remove get_metric_value.

Comment thread tests/metrics.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered using the parser included in the prometheus client_python package instead of building our own? https://prometheus.github.io/client_python/parser/

If you have and still decided to build our own I'll take a closer look at the code in this file.

Comment thread tests/test_rate_limit.py
if len(parts) >= 2:
dropped_count = int(parts[1])
break
ss = metrics.snapshot()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ss is fine (fascist undertones aside), metric_snapshot is too long, if we want to change it we can go with either snap or snapshot.

I also see ss is only used in the next line, so it could all be shortened to a single line without needing to define ss at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants