Skip to content
This repository was archived by the owner on Oct 18, 2021. It is now read-only.

Commit fda4b92

Browse files
authored
Merge pull request #4 from nikkhn/metadata
Updated for project name references
2 parents 344f576 + db25026 commit fda4b92

File tree

13 files changed

+164
-285
lines changed

13 files changed

+164
-285
lines changed

.eslintrc.json

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
11
{
2-
"extends": [
3-
"wikimedia/server"
4-
],
5-
"plugins": ["json", "jsdoc"],
6-
"rules": {
7-
"array-bracket-spacing": "off",
8-
"camelcase": [
9-
"error",
10-
{
11-
"properties": "never"
12-
}
13-
],
14-
"computed-property-spacing": "off",
15-
"indent": ["off", 4],
16-
"jsdoc/no-undefined-types": "off",
17-
"no-multi-spaces": "off",
18-
"no-shadow": "off",
19-
"no-underscore-dangle": "off",
20-
"no-unused-vars": [
21-
"error",
22-
{
23-
"args": "none"
24-
}
25-
],
26-
"space-in-parens": ["error", "never"]
27-
}
2+
"extends": [
3+
"wikimedia/server",
4+
"wikimedia/jsdoc"
5+
],
6+
"rules": {
7+
"array-bracket-spacing": "off",
8+
"camelcase": [
9+
"error",
10+
{
11+
"properties": "never"
12+
}
13+
],
14+
"computed-property-spacing": "off",
15+
"indent": ["off", 4],
16+
"no-multi-spaces": "off",
17+
"no-shadow": "off",
18+
"no-undefined": "off",
19+
"no-underscore-dangle": "off",
20+
"no-unused-vars": [
21+
"error",
22+
{
23+
"args": "none"
24+
}
25+
],
26+
"space-in-parens": ["error", "never"],
27+
"jsdoc/no-undefined-types": "off"
28+
},
29+
"overrides": [
30+
{
31+
"files": [ "**/*.json", "**/*.jsonc" ],
32+
"extends": "wikimedia/json"
33+
}
34+
]
2835
}

.gitignore

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
node_modules/
1+
Dockerfile
2+
.idea/
3+
.vscode/
4+
5+
coverage
6+
.nyc_output
7+
config.yaml
8+
node_modules
9+
npm-debug.log
10+
package-lock.json
11+
12+
.eslintcache

.pipeline/blubber.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ variants:
1616
includes: [build]
1717
apt: { packages: [ca-certificates] }
1818
entrypoint: [node, server.js]
19+
runs: { environment: { APP_CONFIG_PATH: ./config.dev.yaml } }
1920
test:
2021
includes: [build]
2122
apt: { packages: [ca-certificates] }
@@ -27,3 +28,4 @@ variants:
2728
copies: [prep]
2829
node: { env: production }
2930
entrypoint: [node, server.js]
31+
runs: { environment: { APP_CONFIG_PATH: ./config.prod.yaml } }

LICENSE

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Apache License
1+
Apache License
22
Version 2.0, January 2004
33
http://www.apache.org/licenses/
44

@@ -178,15 +178,15 @@
178178
APPENDIX: How to apply the Apache License to your work.
179179

180180
To apply the Apache License to your work, attach the following
181-
boilerplate notice, with the fields enclosed by brackets "[]"
181+
boilerplate notice, with the fields enclosed by brackets "{}"
182182
replaced with your own identifying information. (Don't include
183183
the brackets!) The text should be enclosed in the appropriate
184184
comment syntax for the file format. We also recommend that a
185185
file or class name and description of purpose be included on the
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright {yyyy} {name of copyright owner}
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.
@@ -199,3 +199,4 @@
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201201
limitations under the License.
202+

config.dev.yaml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,24 @@ worker_heap_limit_mb: 250
1010
# Logger info
1111
logging:
1212
level: trace
13-
# streams:
14-
# # Use syslog -> logstash
15-
# - type: syslog
16-
# host: localhost
17-
# port: 10514
18-
# prefix: '@cee: '
13+
# name: <your app name>
14+
# streams:
15+
# - type: syslog
16+
# host: localhost
17+
# port: 10514
18+
# prefix: '@cee: '
19+
# name: node
1920

20-
# Statsd metrics reporter
2121
metrics:
22-
#type: log
23-
#host: localhost
24-
#port: 8125
22+
# - type: prometheus
23+
# port: 9000
24+
# Statsd metrics reporter
25+
# - type: statsd
26+
# host: localhost
27+
# port: 8125
2528

2629
services:
27-
- name: service-template-node
30+
- name: service-scaffold-node
2831
# a relative path or the name of an npm package, if different from name
2932
module: ./app.js
3033
# optionally, a version constraint of the npm package
@@ -61,7 +64,7 @@ services:
6164
# - user-agent
6265
# - x-request-id
6366
# the user agent to use when issuing requests
64-
# user_agent: service-template-node
67+
# user_agent: service-scaffold-node
6568
# max JSON POST body size limit
6669
# max_body_size: 100kb
6770
# the template used for contacting the MW API

config.prod.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ worker_heap_limit_mb: 500
1010
# Logger info
1111
logging:
1212
level: warn
13-
# streams:
14-
# # Use syslog -> logstash
15-
# - type: syslog
16-
# host: localhost
17-
# port: 10514
18-
# prefix: '@cee: '
13+
# name: <your app name>
14+
streams:
15+
- type: syslog
16+
host: localhost
17+
port: 10514
18+
prefix: '@cee: '
19+
name: node
1920

2021
# Statsd metrics reporter
2122
metrics:
@@ -24,7 +25,7 @@ metrics:
2425
port: 8125
2526

2627
services:
27-
- name: service-template-node
28+
- name: service-scaffold-node
2829
# a relative path or the name of an npm package, if different from name
2930
module: ./app.js
3031
# optionally, a version constraint of the npm package
@@ -61,7 +62,7 @@ services:
6162
# - user-agent
6263
# - x-request-id
6364
# the user agent to use when issuing requests
64-
# user_agent: service-template-node
65+
# user_agent: service-scaffold-node
6566
# max JSON POST body size limit
6667
# max_body_size: 100kb
6768
# the template used for contacting the MW API

lib/util.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,26 @@ function errForLog(err) {
101101
function wrapRouteHandlers(route, app) {
102102

103103
route.router.stack.forEach((routerLayer) => {
104-
let path = (route.path + routerLayer.route.path.slice(1))
104+
const path = (route.path + routerLayer.route.path.slice(1))
105105
.replace(/\/:/g, '/--')
106106
.replace(/^\//, '')
107107
.replace(/[/?]+$/, '');
108-
path = app.metrics.normalizeName(path || 'root');
109108
routerLayer.route.stack.forEach((layer) => {
110109
const origHandler = layer.handle;
110+
const metric = app.metrics.makeMetric({
111+
type: 'Histogram',
112+
name: 'router',
113+
prometheus: {
114+
name: 'express_router_request_duration_seconds',
115+
help: 'request duration handled by router in seconds',
116+
staticLabels: app.metrics.getServiceLabel(),
117+
buckets: [0.01, 0.05, 0.1, 0.3, 1]
118+
},
119+
labels: {
120+
names: ['path', 'method', 'status'],
121+
omitLabelNames: true
122+
}
123+
});
111124
layer.handle = (req, res, next) => {
112125
const startTime = Date.now();
113126
BBPromise.try(() => origHandler(req, res, next))
@@ -117,13 +130,7 @@ function wrapRouteHandlers(route, app) {
117130
if (statusCode < 100 || statusCode > 599) {
118131
statusCode = 500;
119132
}
120-
const statusClass = `${Math.floor(statusCode / 100)}xx`;
121-
const stat = `${path}.${req.method}.`;
122-
app.metrics.endTiming([
123-
stat + statusCode,
124-
stat + statusClass,
125-
`${stat}ALL`
126-
], startTime);
133+
metric.endTiming(startTime, [path || 'root', req.method, statusCode]);
127134
});
128135
};
129136
});

0 commit comments

Comments
 (0)