Skip to content

Commit

Permalink
Optimize web-server.js and metrics. (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
wanpf authored Oct 16, 2023
1 parent ff73ce5 commit b01c4b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 10 additions & 5 deletions pjs/http/codec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
((
{ metrics } = pipy.solve('lib/metrics.js'),
acceptedMetric = metrics.fgwHttpCurrentConnections.withLabels('accepted'),
activeMetric = metrics.fgwHttpCurrentConnections.withLabels('active'),
handledMetric = metrics.fgwHttpCurrentConnections.withLabels('handled'),
fgwHttpRequestsTotal = metrics.fgwHttpRequestsTotal,

) => pipy()

.export('http', {
Expand All @@ -11,14 +16,14 @@
.pipeline()
.handleStreamStart(
() => (
metrics.fgwHttpCurrentConnections.withLabels('accepted').increase(),
metrics.fgwHttpCurrentConnections.withLabels('active').increase()
acceptedMetric.increase(),
activeMetric.increase()
)
)
.handleStreamEnd(
() => (
metrics.fgwHttpCurrentConnections.withLabels('handled').increase(),
metrics.fgwHttpCurrentConnections.withLabels('active').decrease()
handledMetric.increase(),
activeMetric.decrease()
)
)
.demuxHTTP().to(
Expand All @@ -27,7 +32,7 @@
msg => (
__http = msg?.head,
__request = { head: msg?.head, reqTime: Date.now() },
metrics.fgwHttpRequestsTotal.increase()
fgwHttpRequestsTotal.increase()
)
)
.handleMessageEnd(
Expand Down
4 changes: 1 addition & 3 deletions pjs/server/web-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,7 @@
.replaceMessage(
msg => (
(_path = msg?.head?.path) && (
_uri = _path.split('?')[0]
),
_uri && (_uri.indexOf('/../') < 0) && (
_uri = _path.split('?')[0],
_tryFiles = tryFilesCache.get(__route)?.(_uri),
(_tryFiles || [_uri]).find(
tf => (
Expand Down

0 comments on commit b01c4b9

Please sign in to comment.