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
4435e282
Commit
4435e282
authored
2 years ago
by
julian.baeume
Browse files
Options
Downloads
Patches
Plain Diff
add first dedicated metrics to analyse cache behaviour
this should help to get insights about how the caches are filled locally
parent
20c4e7bb
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
src/files.js
+9
-0
9 additions, 0 deletions
src/files.js
src/manifests.js
+1
-1
1 addition, 1 deletion
src/manifests.js
src/version.js
+27
-0
27 additions, 0 deletions
src/version.js
with
37 additions
and
1 deletion
src/files.js
+
9
−
0
View file @
4435e282
...
...
@@ -7,12 +7,19 @@ import { NotFoundError } from './errors.js'
import
*
as
redis
from
'
./redis.js
'
import
zlib
from
'
node:zlib
'
import
{
promisify
}
from
'
node:util
'
import
{
Gauge
}
from
'
prom-client
'
const
gzip
=
promisify
(
zlib
.
gzip
)
const
compressFileSize
=
Number
(
process
.
env
.
COMPRESS_FILE_SIZE
)
const
compressionMimeTypes
=
(
process
.
env
.
COMPRESS_FILE_TYPES
||
''
).
replace
(
/
([
.+*?^$()[
\]
{}|
])
/g
,
'
\\
$1
'
).
split
(
'
'
)
const
compressionWhitelistRegex
=
new
RegExp
(
`^(
${
compressionMimeTypes
.
join
(
'
|
'
)}
)($|;)`
,
'
i
'
)
export
const
fileCacheSizeGauge
=
new
Gauge
({
name
:
'
file_cache_size
'
,
help
:
'
Number of entries in file cache
'
})
export
function
createWritable
(
body
)
{
if
(
typeof
body
!==
'
string
'
&&
!
(
body
instanceof
Buffer
))
return
JSON
.
stringify
(
body
)
return
body
...
...
@@ -96,6 +103,7 @@ export function getFile ({ version, path }) {
if
(
body
)
{
logger
.
debug
(
`[Files] Resolve from redis:
${
key
}
`
)
fileCacheSizeGauge
.
inc
()
return
(
cache
.
getCache
()[
key
]
=
{
body
,
...
JSON
.
parse
(
meta
)
})
}
}
...
...
@@ -113,6 +121,7 @@ export function getFile ({ version, path }) {
// overwrite cache with synchronous data
logger
.
debug
(
`[Files] Store in memory:
${
key
}
`
)
fileCacheSizeGauge
.
inc
()
return
(
cache
.
getCache
()[
key
]
=
dataFromServer
)
})()
...
...
This diff is collapsed.
Click to expand it.
src/manifests.js
+
1
−
1
View file @
4435e282
...
...
@@ -27,7 +27,7 @@ export async function fetchViteManifests () {
return
viteManifests
.
reduce
((
memo
,
manifest
)
=>
Object
.
assign
(
memo
,
manifest
),
{})
}
export
function
getViteManifests
({
version
})
{
export
async
function
getViteManifests
({
version
})
{
return
cache
.
get
(
getRedisKey
({
version
,
name
:
'
viteManifests
'
}),
()
=>
fetchViteManifests
())
}
...
...
This diff is collapsed.
Click to expand it.
src/version.js
+
27
−
0
View file @
4435e282
...
...
@@ -3,9 +3,27 @@ import { getRedisKey, hash } from './util.js'
import
{
logger
}
from
'
./logger.js
'
import
*
as
cache
from
'
./cache.js
'
import
*
as
redis
from
'
./redis.js
'
import
{
Gauge
}
from
'
prom-client
'
import
{
getViteManifests
}
from
'
./manifests.js
'
let
latestVersion
const
manifestFileEntriesGauge
=
new
Gauge
({
name
:
'
manifest_file_entries
'
,
help
:
'
Number of entries in merged vite manifest (number of all known files)
'
,
async
collect
()
{
const
version
=
latestVersion
this
.
set
({
version
},
Object
.
keys
(
await
getViteManifests
({
version
})).
length
)
},
labelNames
:
[
'
version
'
]
})
const
versionUpdateGauge
=
new
Gauge
({
name
:
'
version_update_event
'
,
help
:
'
Timestamp of a version update event
'
,
labelNames
:
[
'
version
'
]
})
export
const
fetchLatestVersion
=
async
()
=>
{
const
infos
=
await
Promise
.
all
(
configMap
.
urls
.
map
(
async
baseUrl
=>
{
try
{
...
...
@@ -36,6 +54,7 @@ export async function getLatestVersion () {
const
version
=
await
redis
.
client
.
get
(
getRedisKey
({
name
:
'
latestVersion
'
}))
if
(
version
)
{
logger
.
info
(
`[Version] Got initial version from redis: '
${
version
}
'`
)
versionUpdateGauge
.
setToCurrentTime
({
version
})
return
(
latestVersion
=
version
)
}
}
...
...
@@ -61,6 +80,7 @@ export function registerLatestVersionListener (client) {
if
(
channel
!==
key
)
return
logger
.
info
(
`[Version] Received 'updateLatestVersion' event. Clearing cache. New version: '
${
version
}
'`
)
await
configMap
.
load
()
versionUpdateGauge
.
setToCurrentTime
({
version
})
cache
.
clear
()
latestVersion
=
version
})
...
...
@@ -73,6 +93,12 @@ export async function updateVersionProcessor () {
getLatestVersion
(),
fetchLatestVersion
()
])
// don't wait for the data, can be done in background
getViteManifests
({
fetchedVersion
}).
then
(
manifests
=>
{
manifestFileEntriesGauge
.
set
({
version
:
fetchedVersion
},
Object
.
keys
(
manifests
).
length
)
})
if
(
storedVersion
===
fetchedVersion
)
{
logger
.
info
(
`[Version] No new version has been found. No update needed. Current version:
${
storedVersion
}
`
)
return
fetchedVersion
...
...
@@ -91,6 +117,7 @@ export async function updateVersionProcessor () {
await
redis
.
client
.
set
(
getRedisKey
({
name
:
'
prevProcessedVersion
'
}),
fetchedVersion
)
}
}
else
{
versionUpdateGauge
.
setToCurrentTime
({
version
:
latestVersion
})
// if redis is disabled, this will only be trigger by a setInterval and not from a redis event
logger
.
info
(
'
[Version] Clear local cache due to version update.
'
)
cache
.
clear
()
...
...
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