Skip to content

Commit

Permalink
The 'slow transactions' metric with the Performancetest-runner as sou…
Browse files Browse the repository at this point in the history
…rce allows for ignoring transactions by name or by regular expression. Partially implements #1493.
  • Loading branch information
fniessink committed Oct 1, 2020
1 parent ebac98d commit f80e7c4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from bs4 import BeautifulSoup, Tag

from base_collectors import HTMLFileSourceCollector, SourceUpToDatenessCollector
from collector_utilities.functions import match_string_or_regular_expression
from collector_utilities.type import Response
from source_model import Entity, SourceMeasurement, SourceResponses

Expand All @@ -27,22 +28,33 @@ async def _parse_source_responses(self, responses: SourceResponses) -> SourceMea
entities = [self.__entity(transaction) for transaction in await self.__slow_transactions(responses)]
return SourceMeasurement(entities=entities)

@staticmethod
def __entity(transaction) -> Entity:
@classmethod
def __entity(cls, transaction) -> Entity:
"""Transform a transaction into a transaction entity."""
name = transaction.find("td", class_="name").string
name = cls.__name(transaction)
threshold = "high" if transaction.select("td.red.evaluated") else "warning"
return Entity(key=name, name=name, threshold=threshold)

async def __slow_transactions(self, responses: SourceResponses) -> List[Tag]:
"""Return the slow transactions in the performance test report."""
thresholds = self._parameter("thresholds")
transactions_to_ignore = self._parameter("transactions_to_ignore")

def include(transaction) -> bool:
"""Return whether the transaction should be included."""
return not match_string_or_regular_expression(self.__name(transaction), transactions_to_ignore)

slow_transactions: List[Tag] = []
for response in responses:
soup = await self._soup(response)
for color in thresholds:
slow_transactions.extend(soup.select(f"tr.transaction:has(> td.{color}.evaluated)"))
return slow_transactions
return [transaction for transaction in slow_transactions if include(transaction)]

@staticmethod
def __name(transaction) -> str:
"""Return the name of the transaction."""
return transaction.find("td", class_="name").string


class PerformanceTestRunnerSourceUpToDateness(PerformanceTestRunnerBaseClass, SourceUpToDatenessCollector):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ async def test_warning_only(self):
response = await self.collect(self.metric, get_request_text=html)
self.assert_measurement(response, value="1", entities=[dict(key="Name", name="Name", threshold="warning")])

async def test_ignore_transactions_by_name(self):
"""Test that transactions can be ignored by name."""
html = '<html><table class="details">' \
'<tr class="transaction"><td class="name">T1</td><td class="red evaluated"/></tr>' \
'<tr class="transaction"><td class="name">T2</td><td class="yellow evaluated"/></tr>' \
'<tr class="transaction"><td class="name">T3</td><td class="green evaluated"/></tr>' \
'</table></html>'
self.sources["source_id"]["parameters"]["transactions_to_ignore"] = ["T[1|3]"]
response = await self.collect(self.metric, get_request_text=html)
self.assert_measurement(response, value="1", entities=[dict(key="T2", name="T2", threshold="warning")])


class PerformanceTestRunnerSourceUpToDatenessTest(PerformanceTestRunnerTestCase):
"""Unit tests for the performancetest-runner source up-to-dateness collector."""
Expand Down
12 changes: 12 additions & 0 deletions components/server/src/data/datamodel.json
Original file line number Diff line number Diff line change
Expand Up @@ -4016,6 +4016,18 @@
"metrics": [
"slow_transactions"
]
},
"transactions_to_ignore": {
"name": "Transactions to ignore (regular expressions or transaction names)",
"short_name": "transactions to ignore",
"help": "Transactions to ignore can be specified by transaction name or by regular expression.",
"type": "multiple_choice_with_addition",
"placeholder": "none",
"mandatory": false,
"default_value": [],
"metrics": [
"slow_transactions"
]
}
},
"entities": {
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

- The 'slow transactions' metric with the Performancetest-runner as source allows for ignoring transactions by name or by regular expression. Partially implements [#1493](https://github.com/ICTU/quality-time/issues/1493).
- The 'tests' metric now also supports the percentage scale so it's possible to e.g. report the percentage of tests failed. Closes [#1494](https://github.com/ICTU/quality-time/issues/1494).

### Fixed
Expand Down
7 changes: 4 additions & 3 deletions docs/METRICS_AND_SOURCES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This document lists all [metrics](#metrics) that *Quality-time* can measure and
| Name | Description | Default target | Scale(s) | Default tags | Sources¹ |
| :--- | :---------- | :------------- | :------- | :----------- | :------- |
| Accessibility violations | The number of accessibility violations in the web user interface of the software. | ≦ 0 violations | count | accessibility | [Axe CSV](#accessibility-violations-from-axe-csv), [axe-selenium-python](#accessibility-violations-from-axe-selenium-python) |
| Commented-out code | The number of blocks of commented-out lines of code. | ≦ 0 blocks | count | maintainability | [SonarQube](#commented-out-code-from-sonarqube) |
| Commented out code | The number of blocks of commented out lines of code. | ≦ 0 blocks | count | maintainability | [SonarQube](#commented-out-code-from-sonarqube) |
| Complex units | The amount of units (classes, functions, methods, files) that are too complex. | ≦ 0 complex units | count (default), percentage | maintainability, testability | [SonarQube](#complex-units-from-sonarqube) |
| Dependencies | The amount of (outdated) dependencies | ≦ 0 dependencies | count (default), percentage | maintainability | [Composer](#dependencies-from-composer), [OWASP Dependency Check](#dependencies-from-owasp-dependency-check), [npm](#dependencies-from-npm), [pip](#dependencies-from-pip) |
| Duplicated lines | The amount of lines that are duplicated. | ≦ 0 lines | count (default), percentage | maintainability | [SonarQube](#duplicated-lines-from-sonarqube) |
Expand Down Expand Up @@ -68,7 +68,7 @@ This document lists all [metrics](#metrics) that *Quality-time* can measure and
| [Random](https://en.wikipedia.org/wiki/Special:Random) | A source that generates random numbers, for testing purposes. | ¹ |
| [Robot Framework](https://robotframework.org) | Robot Framework is a generic open source automation framework for acceptance testing, acceptance test driven development, and robotic process automation. | [Source up-to-dateness](#source-up-to-dateness-from-robot-framework), [Tests](#tests-from-robot-framework) |
| [Snyk](https://support.snyk.io/hc/en-us/articles/360003812458-Getting-started-with-the-CLI) | Snyk vulnerability report in JSON format | [Security warnings](#security-warnings-from-snyk) |
| [SonarQube](https://www.sonarqube.org) | SonarQube is an open-source platform for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells, and security vulnerabilities on 20+ programming languages. | [Commented-out code](#commented-out-code-from-sonarqube), [Complex units](#complex-units-from-sonarqube), [Duplicated lines](#duplicated-lines-from-sonarqube), [Size (LOC)](#size-(loc)-from-sonarqube), [Long units](#long-units-from-sonarqube), [Many parameters](#many-parameters-from-sonarqube), [Violation remediation effort](#violation-remediation-effort-from-sonarqube), [Source up-to-dateness](#source-up-to-dateness-from-sonarqube), [Security warnings](#security-warnings-from-sonarqube), [Suppressed violations](#suppressed-violations-from-sonarqube), [Tests](#tests-from-sonarqube), [Test branch coverage](#test-branch-coverage-from-sonarqube), [Test line coverage](#test-line-coverage-from-sonarqube), [Violations](#violations-from-sonarqube) |
| [SonarQube](https://www.sonarqube.org) | SonarQube is an open-source platform for continuous inspection of code quality to perform automatic reviews with static analysis of code to detect bugs, code smells, and security vulnerabilities on 20+ programming languages. | [Commented out code](#commented-out-code-from-sonarqube), [Complex units](#complex-units-from-sonarqube), [Duplicated lines](#duplicated-lines-from-sonarqube), [Size (LOC)](#size-(loc)-from-sonarqube), [Long units](#long-units-from-sonarqube), [Many parameters](#many-parameters-from-sonarqube), [Violation remediation effort](#violation-remediation-effort-from-sonarqube), [Source up-to-dateness](#source-up-to-dateness-from-sonarqube), [Security warnings](#security-warnings-from-sonarqube), [Suppressed violations](#suppressed-violations-from-sonarqube), [Tests](#tests-from-sonarqube), [Test branch coverage](#test-branch-coverage-from-sonarqube), [Test line coverage](#test-line-coverage-from-sonarqube), [Violations](#violations-from-sonarqube) |
| [TestNG](https://testng.org) | Test reports in the TestNG XML format. | [Source up-to-dateness](#source-up-to-dateness-from-testng), [Tests](#tests-from-testng) |
| [Trello](https://trello.com) | Trello is a collaboration tool that organizes projects into boards. | [Issues](#issues-from-trello), [Source up-to-dateness](#source-up-to-dateness-from-trello) |
| [Wekan](https://wekan.github.io) | Open-source kanban. | [Issues](#issues-from-wekan), [Source up-to-dateness](#source-up-to-dateness-from-wekan) |
Expand Down Expand Up @@ -103,7 +103,7 @@ This document lists all [metrics](#metrics) that *Quality-time* can measure and
| URL to an axe-selenium-python report in a human readable format | String | No | If provided, users clicking the source URL will visit this URL instead of the axe-selenium-report report in JSON format. |
| Username for basic authentication | String | No | |

### Commented-out code from SonarQube
### Commented out code from SonarQube

| Parameter | Type | Mandatory | Help |
| :-------- | :--- | :-------- | :--- |
Expand Down Expand Up @@ -362,6 +362,7 @@ This document lists all [metrics](#metrics) that *Quality-time* can measure and
| Password for basic authentication | Password | No | |
| Private token | Password | No | |
| Thresholds | Multiple choice | No | If provided, only count transactions that surpass the selected thresholds. |
| Transactions to ignore (regular expressions or transaction names) | Multiple choice with addition | No | Transactions to ignore can be specified by transaction name or by regular expression. |
| URL to a Performancetest-runner HTML report or a zip with Performancetest-runner HTML reports | URL | Yes | |
| Username for basic authentication | String | No | |

Expand Down

0 comments on commit f80e7c4

Please sign in to comment.