Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
ui-middleware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Source Software
OX App Suite
Core
ui-middleware
Commits
723b96e9
Commit
723b96e9
authored
3 years ago
by
maik.schaefer
Committed by
richard.petersen
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
add metrics for startup and file cache counts
parent
952dd84c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
spec/server_test.js
+3
-0
3 additions, 0 deletions
spec/server_test.js
src/createApp.js
+9
-0
9 additions, 0 deletions
src/createApp.js
src/files.js
+17
-2
17 additions, 2 deletions
src/files.js
with
29 additions
and
2 deletions
spec/server_test.js
+
3
−
0
View file @
723b96e9
...
...
@@ -36,6 +36,9 @@ describe('Manifest service', () => {
process
.
env
.
CACHE_TTL
=
30000
})
// Some say, this is not necessary to test
// But failing startups due to code errors in the probes will cause this to not work
// Therefore, we should keep this
it
(
'
is healthy
'
,
async
()
=>
{
const
response
=
await
request
(
app
).
get
(
'
/healthy
'
)
expect
(
response
.
statusCode
).
toBe
(
200
)
...
...
This diff is collapsed.
Click to expand it.
src/createApp.js
+
9
−
0
View file @
723b96e9
...
...
@@ -13,6 +13,7 @@ import health from '@cloudnative/health-connect'
// Prometheus middleware for standard api metrics
import
promBundle
from
'
express-prom-bundle
'
import
promClient
from
'
prom-client
'
// Swagger UI for api-docs
import
swaggerUi
from
'
swagger-ui-express
'
...
...
@@ -26,6 +27,11 @@ const swaggerDocument = yaml.load(fs.readFileSync('./src/swagger.yaml', 'utf8'))
const
bypass
=
(
request
)
=>
ignorePaths
.
includes
(
request
.
path
)
const
metricsMiddleware
=
promBundle
({
bypass
,
includePath
:
true
})
const
startUpTimeGauge
=
new
promClient
.
Gauge
({
name
:
'
manifest_service_startup_time
'
,
help
:
'
Time to warm up cache
'
})
export
function
createApp
()
{
// The app returned by express() is in fact a JavaScript Function, designed to be passed to Node’s HTTP servers as a callback to handle requests.
...
...
@@ -36,6 +42,7 @@ export function createApp () {
const
healthCheck
=
new
health
.
HealthChecker
()
const
startupCheck
=
new
health
.
StartupCheck
(
'
warmup cache
'
,
async
function
()
{
const
stopTimer
=
startUpTimeGauge
.
startTimer
()
try
{
const
viteManifests
=
await
loadViteManifests
()
const
deps
=
viteManifestToDeps
(
viteManifests
)
...
...
@@ -43,6 +50,8 @@ export function createApp () {
}
catch
(
e
)
{
logger
.
error
(
`Failed to get dependencies:
${
e
.
message
}
`
)
throw
e
}
finally
{
stopTimer
()
}
})
healthCheck
.
registerStartupCheck
(
startupCheck
)
...
...
This diff is collapsed.
Click to expand it.
src/files.js
+
17
−
2
View file @
723b96e9
import
fetch
from
'
node-fetch
'
import
crypto
from
'
crypto
'
import
{
config
}
from
'
./config.js
'
import
promClient
from
'
prom-client
'
import
{
getLogger
}
from
'
./logger.js
'
async
function
fetchData
(
path
,
baseUrl
)
{
const
response
=
await
fetch
(
new
URL
(
path
,
baseUrl
))
...
...
@@ -13,6 +15,15 @@ async function fetchData (path, baseUrl) {
content
}]
}
const
fileCounter
=
new
promClient
.
Counter
({
name
:
'
manifest_service_file_cache_fetches
'
,
help
:
'
Number of fetched files
'
})
const
fileErrorCounter
=
new
promClient
.
Counter
({
name
:
'
manifest_service_file_cache_fetch_errors
'
,
help
:
'
Number of errors while fetching files
'
})
class
FileCache
{
constructor
()
{
this
.
_cache
=
{}
...
...
@@ -32,13 +43,17 @@ class FileCache {
(
m
?.
css
?.
indexOf
(
file
)
>=
0
)
)
if
(
!
manifest
)
{
console
.
error
(
'
could not find manifest for
'
,
file
)
getLogger
()
.
error
(
'
could not find manifest for
'
,
file
)
return
null
}
return
await
fetchData
(
file
,
manifest
.
meta
.
baseUrl
)
}
catch
(
e
)
{
console
.
error
(
e
)
}
}
catch
(
e
)
{
fileErrorCounter
.
inc
()
getLogger
().
error
(
e
)
}
}))).
filter
(
data
=>
Array
.
isArray
(
data
)
&&
data
.
length
===
2
))
}
fileCounter
.
inc
(
result
.
length
)
return
result
}()))
this
.
_cache
=
cache
...
...
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