Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation for extract line numbers in metrics #1781

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions docs/writing_buildspecs/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,47 @@ which shows the name of captured metrics and its corresponding values.

.. command-output:: buildtest inspect query metric_regex_example_with_re

Extract line numbers in Metrics
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

We can specify ``linenum`` property in metrics to capture text from a specific line.
In the first example, we will define 2 metrics **second_line** and **without_linenum** using ``regex``
The former metrics captures the text ``This is line: 2``, whereas the latter captures the text ``This is line: 1``.

.. literalinclude:: ../tutorials/metrics/metrics_regex_with_linenum.yml
:language: yaml
:emphasize-lines: 6-30

Let's build the test and take a look at the metrics for this test.

.. dropdown:: ``buildtest build -b tutorials/metrics/metrics_regex_with_linenum.yml``

.. command-output:: buildtest build -b tutorials/metrics/metrics_regex_with_linenum.yml

.. dropdown:: ``buildtest inspect query metric_regex_with_linenum_example``

.. command-output:: buildtest inspect query metric_regex_with_linenum_example


``linenum`` property can also be applied with file regular expression (``file_regex``). In the example below,
we define 2 metrics with the same regular expression defined via `exp`. Its worth noting that the regular expression
will attempt to find the first match. When `linenum` is specified the content from file is extracted by line first
and regular expression is applied afterwards.

.. literalinclude:: ../tutorials/metrics/metrics_file_regex_with_linenum.yml
:language: yaml
:emphasize-lines: 6-28

Let's build the test and take a look at the captured metrics.

.. dropdown:: ``buildtest build -b tutorials/metrics/metrics_file_regex_with_linenum.yml``

.. command-output:: buildtest build -b tutorials/metrics/metrics_file_regex_with_linenum.yml

.. dropdown:: ``buildtest inspect query metric_file_regex_with_linenum_example``

.. command-output:: buildtest inspect query metric_file_regex_with_linenum_example

Invalid Metrics
~~~~~~~~~~~~~~~~~

Expand Down
6 changes: 0 additions & 6 deletions tutorials/metrics/metrics_regex_with_linenum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ buildspecs:
regex:
exp: 'This is line: \d'
stream: stdout
linenum_to_stderr:
type: str
regex:
exp: 'This is line: \d'
stream: stderr
linenum: 2
status:
assert_eq:
comparisons:
Expand Down
Loading