Skip to content

Commit

Permalink
perf: swap order of escape regexes to avoid lookahead (#546)
Browse files Browse the repository at this point in the history
* swap regex order to avoid lookahead

* changelog

* changelog formatting apparently
  • Loading branch information
ngavalas authored and SimenB committed Mar 9, 2023
1 parent 9619380 commit 73ee423
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- Refactor `escapeString` helper in `lib/registry.js` to improve performance and
avoid an unnecessarily complex regex.

### Added

- Support for OpenMetrics and Exemplars
Expand All @@ -27,6 +24,8 @@ project adheres to [Semantic Versioning](http://semver.org/).
- Refactor `getMetricAsPrometheusString` method in the `Registry` class to use `Array.prototype.join`
instead of loop of string concatenations.
- Also use `Array.prototype.map`, and object spread instead of an explicit `for` loop
- Refactor `escapeString` helper in `lib/registry.js` to improve performance and
avoid an unnecessarily complex regex.
- changed: updated the sample output in `example/default-metrics.js`
- `summary` metrics now has a `pruneAgedBuckets` config parameter
to remove entries without any new values in the last `maxAgeSeconds`.
Expand Down
2 changes: 1 addition & 1 deletion lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function escapeLabelValue(str) {
return escapeString(str).replace(/"/g, '\\"');
}
function escapeString(str) {
return str.replace(/\n/g, '\\n').replace(/\\(?!n)/g, '\\\\');
return str.replace(/\\/g, '\\\\').replace(/\n/g, '\\n');
}
function standardizeCounterName(name) {
return name.replace(/_total$/, '');
Expand Down

0 comments on commit 73ee423

Please sign in to comment.