Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
persona
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hexang 息壤平台
persona
Commits
54aeac23
Commit
54aeac23
authored
12 years ago
by
Zachary Carter
Browse files
Options
Downloads
Patches
Plain Diff
move metrics to router: avoids headers not being forwarded and caching - issue #2040
parent
ff995941
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bin/router
+5
-0
5 additions, 0 deletions
bin/router
lib/metrics.js
+3
-0
3 additions, 0 deletions
lib/metrics.js
lib/static/views.js
+0
-1
0 additions, 1 deletion
lib/static/views.js
tests/metrics-header-test.js
+93
-0
93 additions, 0 deletions
tests/metrics-header-test.js
with
101 additions
and
1 deletion
bin/router
+
5
−
0
View file @
54aeac23
...
...
@@ -13,6 +13,7 @@ urlparse = require('urlparse'),
express
=
require
(
'
express
'
);
const
metrics
=
require
(
'
../lib/metrics.js
'
),
wsapi
=
require
(
'
../lib/wsapi.js
'
),
config
=
require
(
'
../lib/configuration.js
'
),
heartbeat
=
require
(
'
../lib/heartbeat.js
'
),
...
...
@@ -146,6 +147,10 @@ wsapi.routeSetup(app, {
//catch-all
app
.
use
(
function
(
req
,
res
,
next
)
{
// log metrics
if
(
req
.
url
===
'
/sign_in
'
)
metrics
.
userEntry
(
req
);
forward
(
static_url
+
req
.
url
,
req
,
res
,
function
(
err
)
{
...
...
This diff is collapsed.
Click to expand it.
lib/metrics.js
+
3
−
0
View file @
54aeac23
...
...
@@ -56,6 +56,9 @@ function setupLogger() {
mkdir_p
(
log_path
);
var
filename
=
path
.
join
(
log_path
,
configuration
.
get
(
'
process_type
'
)
+
"
-metrics.json
"
);
if
(
process
.
env
.
METRICS_LOG_FILE
)
{
filename
=
process
.
env
.
METRICS_LOG_FILE
;
}
LOGGER
=
new
(
winston
.
Logger
)({
transports
:
[
new
(
winston
.
transports
.
File
)({
filename
:
filename
})],
...
...
This diff is collapsed.
Click to expand it.
lib/static/views.js
+
0
−
1
View file @
54aeac23
...
...
@@ -91,7 +91,6 @@ exports.setup = function(app) {
// this should probably be an internal redirect
// as soon as relative paths are figured out.
app
.
get
(
'
/sign_in
'
,
function
(
req
,
res
,
next
)
{
metrics
.
userEntry
(
req
);
renderCachableView
(
req
,
res
,
'
dialog.ejs
'
,
{
title
:
_
(
'
A Better Way to Sign In
'
),
layout
:
'
dialog_layout.ejs
'
,
...
...
This diff is collapsed.
Click to expand it.
tests/metrics-header-test.js
0 → 100755
+
93
−
0
View file @
54aeac23
#!/usr/bin/env node
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
require
(
'
./lib/test_env.js
'
);
const
assert
=
require
(
'
assert
'
),
fs
=
require
(
'
fs
'
),
path
=
require
(
'
path
'
),
http
=
require
(
'
http
'
),
vows
=
require
(
'
vows
'
),
start_stop
=
require
(
'
./lib/start-stop.js
'
),
wsapi
=
require
(
'
./lib/wsapi.js
'
),
urlparse
=
require
(
'
urlparse
'
);
var
suite
=
vows
.
describe
(
'
metrics header test
'
);
suite
.
options
.
error
=
false
;
// allow this unit test to be targeted
var
SERVER_URL
=
process
.
env
[
'
SERVER_URL
'
]
||
'
http://127.0.0.1:10002/
'
;
process
.
env
.
METRICS_LOG_FILE
=
path
.
resolve
(
path
.
join
(
__dirname
,
'
data
'
,
'
metrics.json
'
));
if
(
!
process
.
env
[
'
SERVER_URL
'
])
{
// start up a pristine server if we're locally testing
start_stop
.
addStartupBatches
(
suite
);
}
// now parse out host, port and scheme
var
purl
=
urlparse
(
SERVER_URL
);
const
method
=
(
purl
.
scheme
===
'
https
'
)
?
require
(
'
https
'
)
:
require
(
'
http
'
);
function
doRequest
(
path
,
headers
,
cb
)
{
var
req
=
method
.
request
({
port
:
purl
.
port
,
host
:
purl
.
host
,
path
:
path
,
headers
:
headers
,
agent
:
false
},
function
(
res
)
{
req
.
abort
();
cb
(
null
,
res
);
});
req
.
on
(
'
error
'
,
function
(
e
)
{
cb
(
e
);
});
req
.
end
();
}
suite
.
addBatch
({
'
/sign_in
'
:
{
topic
:
function
()
{
doRequest
(
'
/sign_in
'
,
{
'
user-agent
'
:
'
Test Runner
'
,
'
x-real-ip
'
:
'
123.0.0.1
'
,
'
referer
'
:
'
https://persona.org
'
},
this
.
callback
);
},
"
metrics log exists
"
:
{
topic
:
function
(
err
,
r
)
{
if
(
fs
.
existsSync
(
process
.
env
.
METRICS_LOG_FILE
))
{
this
.
callback
();
}
else
{
fs
.
watchFile
(
process
.
env
.
METRICS_LOG_FILE
,
null
,
this
.
callback
);
}
},
"
metric fields are logged properly
"
:
function
(
event
,
filename
)
{
var
metrics
=
JSON
.
parse
(
fs
.
readFileSync
(
process
.
env
.
METRICS_LOG_FILE
,
"
utf8
"
).
trim
());
var
message
=
JSON
.
parse
(
metrics
.
message
);
assert
.
equal
(
message
.
ip
,
"
123.0.0.1
"
);
assert
.
equal
(
message
.
rp
,
"
https://persona.org
"
);
assert
.
equal
(
message
.
browser
,
"
Test Runner
"
);
fs
.
unwatchFile
(
process
.
env
.
METRICS_LOG_FILE
);
}
}
}
});
suite
.
addBatch
({
'
clean up
'
:
function
()
{
fs
.
unlink
(
process
.
env
.
METRICS_LOG_FILE
);
delete
process
.
env
.
METRICS_LOG_FILE
;
}
});
// shut the server down and cleanup
if
(
!
process
.
env
[
'
SERVER_URL
'
])
{
start_stop
.
addShutdownBatches
(
suite
);
}
// run or export the suite.
if
(
process
.
argv
[
1
]
===
__filename
)
suite
.
run
();
else
suite
.
export
(
module
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment