From ae56d8c0eb18e2aefd2938291616ed1ac24dc366 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Julian=20B=C3=A4ume?= <julian.baeume@open-xchange.com>
Date: Mon, 4 Apr 2022 16:17:24 +0200
Subject: [PATCH] unify name prefix of metrics exposed using promclient

Change the prefix to reflect the "new" name of the service. May be this even should be configurable at some point.

This is a breaking change.
---
 src/createApp.js |  2 +-
 src/files.js     | 19 +++++++++++++++++--
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/createApp.js b/src/createApp.js
index f6998f6..564780f 100644
--- a/src/createApp.js
+++ b/src/createApp.js
@@ -26,7 +26,7 @@ import { viteManifestToDeps } from './util.js'
 const swaggerDocument = yaml.load(fs.readFileSync('./src/swagger.yaml', 'utf8'))
 
 const startUpTimeGauge = new promClient.Gauge({
-  name: 'manifest_service_startup_time',
+  name: 'core_ui_middleware_startup_time',
   help: 'Time to warm up cache'
 })
 
diff --git a/src/files.js b/src/files.js
index 815f7d6..b787fde 100644
--- a/src/files.js
+++ b/src/files.js
@@ -24,13 +24,24 @@ async function fetchData (path, baseUrl, appendix) {
 }
 
 const fileCounter = new promClient.Counter({
-  name: 'manifest_service_file_cache_fetches',
+  name: 'core_ui_middleware_file_cache_fetches',
   help: 'Number of fetched files'
 })
 const fileErrorCounter = new promClient.Counter({
-  name: 'manifest_service_file_cache_fetch_errors',
+  name: 'core_ui_middleware_file_cache_fetch_errors',
   help: 'Number of errors while fetching files'
 })
+
+const pullThroughRequestCounter = new promClient.Counter({
+  name: 'core_ui_middleware_file_cache_pull_through_request_count',
+  help: 'Number of files requested after warmup (not referenced in manifest)'
+})
+
+const pullThroughCacheCounter = new promClient.Counter({
+  name: 'core_ui_middleware_file_cache_pull_through_cache_size',
+  help: 'Number of files added after warmup (not referenced in manifest)'
+})
+
 class FileCache {
   constructor () {
     this._cache = {}
@@ -47,6 +58,8 @@ class FileCache {
     this._isCaching = true
 
     logger.debug('beginning to warm up cache')
+    pullThroughCacheCounter.reset()
+    pullThroughRequestCounter.reset()
     const cache = Object.fromEntries(await (async function () {
       const files = Object.keys(deps)
       const chunkSize = 50
@@ -91,10 +104,12 @@ class FileCache {
 
   async fetchAndStore (path) {
     if (config.urls.length === 0) await config.load()
+    pullThroughRequestCounter.inc()
     const [[key, value]] =
       (await Promise.allSettled(config.urls.map(baseUrl => fetchData(path, baseUrl))))
         .filter(r => r.status === 'fulfilled').map(r => r.value)
     this._cache[key.slice(1)] = value
+    pullThroughCacheCounter.inc()
     return value
   }
 
-- 
GitLab