diff --git a/deployment/grafana-dashboards/Redis-Caches.json b/deployment/grafana-dashboards/Redis-Caches.json index d163deb5c60..c37964503b1 100644 --- a/deployment/grafana-dashboards/Redis-Caches.json +++ b/deployment/grafana-dashboards/Redis-Caches.json @@ -21,6 +21,30 @@ "version": "v0" } } + }, + { + "kind": "AnnotationQuery", + "spec": { + "enable": true, + "hide": false, + "iconColor": "#B877D9", + "name": "Pod start", + "query": { + "datasource": { + "name": "PROM_DATASOURCE_UID" + }, + "group": "prometheus", + "kind": "DataQuery", + "spec": {}, + "version": "v0" + }, + "legacyOptions": { + "expr": "process_start_time_seconds * 1000 and on (pod) hive_cache_requests_total{feature=~\"$feature\"}", + "textFormat": "{{pod}}", + "titleFormat": "Pod start", + "useValueForTime": true + } + } } ], "cursorSync": "Crosshair", @@ -95,11 +119,11 @@ "orientation": "horizontal", "showUnfilled": true, "valueMode": "color", - "namePlacement": "left", - "sizing": "auto", - "minVizHeight": 16, + "namePlacement": "top", + "sizing": "manual", + "minVizHeight": 32, "minVizWidth": 8, - "maxVizHeight": 300, + "maxVizHeight": 32, "legend": { "showLegend": false }, @@ -107,6 +131,10 @@ "calcs": ["lastNotNull"], "fields": "", "values": false + }, + "text": { + "titleSize": 12, + "valueSize": 13 } } } @@ -132,7 +160,7 @@ "group": "prometheus", "kind": "DataQuery", "spec": { - "expr": "sort(100 * sum by (feature) (increase(hive_cache_requests_total{feature=~\"$feature\", result=~\"hit|graced_hit\"}[$__range])) / (sum by (feature) (increase(hive_cache_requests_total{feature=~\"$feature\"}[$__range])) > 0))", + "expr": "sort(100 * sum by (feature) (increase(hive_cache_requests_total{feature=~\"$feature\", result=\"hit\"}[$__range])) / (sum by (feature) (increase(hive_cache_requests_total{feature=~\"$feature\"}[$__range])) > 0))", "legendFormat": "{{feature}}", "instant": true, "range": false @@ -146,10 +174,10 @@ "transformations": [] } }, - "description": "Share of lookups served from the cache (memory or Redis) per feature in the selected range. Graced hits (stale values served within their grace period) count as hits.", + "description": "Share of lookups that were fresh hits, per feature in the selected range.\n\n**Fresh hit**: the entry was still within its TTL. It is returned as is and nothing is loaded from the source (usually the database).\n\n**Stale hit**: the entry was past its TTL but still within its grace period. The old value is returned immediately and the entry is reloaded from the source in the background, so the caller gets a fast answer but the source is queried anyway. Stale hits are not counted here; see Stale hit rate.\n\nEverything else is a miss: no usable entry was found.", "id": 2, "links": [], - "title": "Hit rate (range)", + "title": "Fresh hit rate (range)", "vizConfig": { "group": "bargauge", "kind": "VizConfig", @@ -191,11 +219,11 @@ "orientation": "horizontal", "showUnfilled": true, "valueMode": "color", - "namePlacement": "left", - "sizing": "auto", - "minVizHeight": 16, + "namePlacement": "top", + "sizing": "manual", + "minVizHeight": 32, "minVizWidth": 8, - "maxVizHeight": 300, + "maxVizHeight": 32, "legend": { "showLegend": false }, @@ -203,6 +231,10 @@ "calcs": ["lastNotNull"], "fields": "", "values": false + }, + "text": { + "titleSize": 12, + "valueSize": 13 } } } @@ -228,7 +260,7 @@ "group": "prometheus", "kind": "DataQuery", "spec": { - "expr": "sort(100 * sum by (feature) (increase(hive_cache_requests_total{feature=~\"$feature\", result=~\"hit|graced_hit\", layer=\"redis\"}[$__range])) / (sum by (feature) (increase(hive_cache_requests_total{feature=~\"$feature\", layer!=\"memory\"}[$__range])) > 0))", + "expr": "sort(100 * sum by (feature) (increase(hive_cache_requests_total{feature=~\"$feature\", result=\"hit\", layer=\"redis\"}[$__range])) / (sum by (feature) (increase(hive_cache_requests_total{feature=~\"$feature\", layer!=\"memory\"}[$__range])) > 0))", "legendFormat": "{{feature}}", "instant": true, "range": false @@ -242,7 +274,7 @@ "transformations": [] } }, - "description": "Share of lookups that reached Redis and found an entry, per feature. Lookups answered by the in-memory layer of BentoCache caches are left out, so this shows how useful the Redis copy is.", + "description": "Share of lookups not answered from memory that found a fresh entry in Redis, per feature. Stale hits count as not found, because BentoCache does not report which layer a stale entry came from. Caches without a Redis layer are not listed.", "id": 3, "links": [], "title": "Redis hit rate (range)", @@ -287,11 +319,11 @@ "orientation": "horizontal", "showUnfilled": true, "valueMode": "color", - "namePlacement": "left", - "sizing": "auto", - "minVizHeight": 16, + "namePlacement": "top", + "sizing": "manual", + "minVizHeight": 32, "minVizWidth": 8, - "maxVizHeight": 300, + "maxVizHeight": 32, "legend": { "showLegend": false }, @@ -299,6 +331,10 @@ "calcs": ["lastNotNull"], "fields": "", "values": false + }, + "text": { + "titleSize": 12, + "valueSize": 13 } } } @@ -439,7 +475,7 @@ "transformations": [] } }, - "description": "Cache lookups per second, per feature and result.", + "description": "Cache lookups per second, per feature and result.\n\n- `hit` is a fresh hit: the entry was still within its TTL, and nothing is loaded from the source (usually the database).\n- `graced_hit` is a stale hit: the entry was past its TTL but still within its grace period. The old value is returned immediately and the entry is reloaded from the source in the background.\n- `miss`: no usable entry was found.", "id": 5, "links": [], "title": "Lookups per second", @@ -530,7 +566,7 @@ "group": "prometheus", "kind": "DataQuery", "spec": { - "expr": "100 * sum by (feature) (rate(hive_cache_requests_total{feature=~\"$feature\", result=~\"hit|graced_hit\"}[$__rate_interval])) / (sum by (feature) (rate(hive_cache_requests_total{feature=~\"$feature\"}[$__rate_interval])) > 0)", + "expr": "100 * sum by (feature) (rate(hive_cache_requests_total{feature=~\"$feature\", result=\"hit\"}[$__rate_interval])) / (sum by (feature) (rate(hive_cache_requests_total{feature=~\"$feature\"}[$__rate_interval])) > 0)", "legendFormat": "{{feature}}" }, "version": "v0" @@ -542,10 +578,10 @@ "transformations": [] } }, - "description": "Share of lookups served from the cache (memory or Redis), per feature.", + "description": "Share of lookups that were fresh hits over time, per feature.\n\n**Fresh hit**: the entry was still within its TTL. It is returned as is and nothing is loaded from the source (usually the database).\n\n**Stale hit**: the entry was past its TTL but still within its grace period. The old value is returned immediately and the entry is reloaded from the source in the background, so the caller gets a fast answer but the source is queried anyway. Stale hits are not counted here; see Stale hit rate.", "id": 6, "links": [], - "title": "Hit rate", + "title": "Fresh hit rate", "vizConfig": { "group": "timeseries", "kind": "VizConfig", @@ -634,7 +670,7 @@ "group": "prometheus", "kind": "DataQuery", "spec": { - "expr": "100 * sum by (feature) (rate(hive_cache_requests_total{feature=~\"$feature\", result=~\"hit|graced_hit\", layer=\"redis\"}[$__rate_interval])) / (sum by (feature) (rate(hive_cache_requests_total{feature=~\"$feature\", layer!=\"memory\"}[$__rate_interval])) > 0)", + "expr": "100 * sum by (feature) (rate(hive_cache_requests_total{feature=~\"$feature\", result=\"hit\", layer=\"redis\"}[$__rate_interval])) / (sum by (feature) (rate(hive_cache_requests_total{feature=~\"$feature\", layer!=\"memory\"}[$__rate_interval])) > 0)", "legendFormat": "{{feature}}" }, "version": "v0" @@ -646,7 +682,7 @@ "transformations": [] } }, - "description": "Share of lookups that reached Redis and found an entry, per feature (in-memory hits left out).", + "description": "Share of lookups not answered from memory that found a fresh entry in Redis, per feature. Stale hits count as not found.", "id": 7, "links": [], "title": "Redis hit rate", @@ -738,7 +774,7 @@ "group": "prometheus", "kind": "DataQuery", "spec": { - "expr": "sum by (feature, layer) (rate(hive_cache_requests_total{feature=~\"$feature\", result=~\"hit|graced_hit\"}[$__rate_interval]))", + "expr": "sum by (feature, layer) (rate(hive_cache_requests_total{feature=~\"$feature\", result=\"hit\"}[$__rate_interval]))", "legendFormat": "{{feature}} {{layer}}" }, "version": "v0" @@ -750,10 +786,10 @@ "transformations": [] } }, - "description": "Hits per second by where they were served from: memory (BentoCache L1, schema explorer in-memory cache) or redis.", + "description": "Fresh hits per second by the layer that served them: memory (BentoCache L1, schema explorer in-memory cache) or redis. Stale hits carry no layer and are left out.", "id": 8, "links": [], - "title": "Hits by layer", + "title": "Fresh hits by layer", "vizConfig": { "group": "timeseries", "kind": "VizConfig", @@ -821,109 +857,812 @@ } } } - } - }, - "layout": { - "kind": "RowsLayout", - "spec": { - "rows": [ - { - "kind": "RowsLayoutRow", + }, + "panel-9": { + "kind": "Panel", + "spec": { + "data": { + "kind": "QueryGroup", "spec": { - "collapse": false, - "title": "Overview", - "layout": { - "kind": "AutoGridLayout", - "spec": { - "columnWidthMode": "standard", - "maxColumnCount": 3, - "rowHeightMode": "tall", - "items": [ - { - "kind": "AutoGridLayoutItem", - "spec": { - "element": { - "kind": "ElementReference", - "name": "panel-1" - } - } - }, - { - "kind": "AutoGridLayoutItem", - "spec": { - "element": { - "kind": "ElementReference", - "name": "panel-2" - } - } - }, - { - "kind": "AutoGridLayoutItem", + "queries": [ + { + "kind": "PanelQuery", + "spec": { + "hidden": false, + "refId": "A", + "query": { + "datasource": { + "name": "PROM_DATASOURCE_UID" + }, + "group": "prometheus", + "kind": "DataQuery", "spec": { - "element": { - "kind": "ElementReference", - "name": "panel-3" - } - } + "expr": "sort_desc(100 * sum by (feature) (increase(hive_cache_requests_total{feature=~\"$feature\", result=\"graced_hit\"}[$__range])) / (sum by (feature) (increase(hive_cache_requests_total{feature=~\"$feature\"}[$__range])) > 0))", + "legendFormat": "{{feature}}", + "instant": true, + "range": false + }, + "version": "v0" } - ] + } } - } + ], + "queryOptions": {}, + "transformations": [] } }, - { - "kind": "RowsLayoutRow", + "description": "Share of lookups that were stale hits, per feature in the selected range.\n\n**Stale hit**: the entry was past its TTL but still within its grace period. The old value is returned immediately and the entry is reloaded from the source in the background, so the caller gets a fast answer but the source is queried anyway.\n\n**Fresh hit**: the entry was still within its TTL. It is returned as is and nothing is loaded from the source (usually the database).\n\nA high stale share means lookups of the same key arrive further apart than the TTL, so the cache rarely saves a load from the source. Caches without a grace period cannot have stale hits and stay at 0%.", + "id": 9, + "links": [], + "title": "Stale hit rate (range)", + "vizConfig": { + "group": "bargauge", + "kind": "VizConfig", + "version": "13.3.0-32457798232", "spec": { - "collapse": false, - "title": "Volume", - "layout": { - "kind": "AutoGridLayout", - "spec": { - "columnWidthMode": "standard", - "maxColumnCount": 2, - "rowHeightMode": "standard", - "items": [ - { - "kind": "AutoGridLayoutItem", - "spec": { - "element": { - "kind": "ElementReference", - "name": "panel-4" - } + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "noValue": "-", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "yellow", + "value": 20 + }, + { + "color": "red", + "value": 50 } - }, - { - "kind": "AutoGridLayoutItem", + ] + }, + "unit": "percent", + "min": 0, + "max": 100, + "decimals": 1 + }, + "overrides": [] + }, + "options": { + "displayMode": "basic", + "orientation": "horizontal", + "showUnfilled": true, + "valueMode": "color", + "namePlacement": "top", + "sizing": "manual", + "minVizHeight": 32, + "minVizWidth": 8, + "maxVizHeight": 32, + "legend": { + "showLegend": false + }, + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "text": { + "titleSize": 12, + "valueSize": 13 + } + } + } + } + } + }, + "panel-10": { + "kind": "Panel", + "spec": { + "data": { + "kind": "QueryGroup", + "spec": { + "queries": [ + { + "kind": "PanelQuery", + "spec": { + "hidden": false, + "refId": "A", + "query": { + "datasource": { + "name": "PROM_DATASOURCE_UID" + }, + "group": "prometheus", + "kind": "DataQuery", "spec": { - "element": { - "kind": "ElementReference", - "name": "panel-5" - } - } + "expr": "100 * sum by (feature) (rate(hive_cache_requests_total{feature=~\"$feature\", result=\"graced_hit\"}[$__rate_interval])) / (sum by (feature) (rate(hive_cache_requests_total{feature=~\"$feature\"}[$__rate_interval])) > 0)", + "legendFormat": "{{feature}}" + }, + "version": "v0" } - ] + } } - } + ], + "queryOptions": {}, + "transformations": [] } }, - { - "kind": "RowsLayoutRow", + "description": "Share of lookups that were stale hits over time, per feature.\n\n**Stale hit**: the entry was past its TTL but still within its grace period. The old value is returned immediately and the entry is reloaded from the source in the background, so the caller gets a fast answer but the source is queried anyway.\n\n**Fresh hit**: the entry was still within its TTL. It is returned as is and nothing is loaded from the source (usually the database).", + "id": 10, + "links": [], + "title": "Stale hit rate", + "vizConfig": { + "group": "timeseries", + "kind": "VizConfig", + "version": "13.3.0-32457798232", "spec": { - "collapse": false, - "title": "Hit rate", - "layout": { - "kind": "AutoGridLayout", - "spec": { - "columnWidthMode": "standard", - "maxColumnCount": 3, - "rowHeightMode": "standard", - "items": [ - { - "kind": "AutoGridLayoutItem", - "spec": { - "element": { - "kind": "ElementReference", - "name": "panel-6" + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 8, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 2, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": true, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "noValue": "0", + "unit": "percent", + "min": 0, + "max": 100 + }, + "overrides": [] + }, + "options": { + "legend": { + "calcs": ["mean", "max"], + "displayMode": "table", + "placement": "bottom", + "showLegend": true, + "sortBy": "Mean", + "sortDesc": true + }, + "tooltip": { + "hideZeros": false, + "mode": "multi", + "sort": "desc" + } + } + } + } + } + }, + "panel-11": { + "kind": "Panel", + "spec": { + "id": 11, + "title": "Does a cache duration need adjusting?", + "description": "How to read the hit rates on this dashboard to decide whether a TTL or grace period should change.", + "links": [], + "data": { + "kind": "QueryGroup", + "spec": { + "queries": [], + "transformations": [], + "queryOptions": {} + } + }, + "vizConfig": { + "kind": "VizConfig", + "group": "text", + "version": "", + "spec": { + "options": { + "code": { + "language": "plaintext", + "showLineNumbers": false, + "showMiniMap": false + }, + "content": "A **fresh hit** is served from an entry within its TTL. A **stale hit** is served from an entry past its TTL but within its grace period, and reloaded in the background.\n\nRead the Overview row per feature, over a day or more.\n\n| What you see | What it means | What to do |\n| --- | --- | --- |\n| Fresh high, stale near 0% | Keys are looked up again within the TTL. It is long enough, and may be longer than needed. | Leave it, or shorten it using the Entry age row. |\n| Stale high | Keys are looked up again only after the TTL, so most lookups still reload. | Raise the TTL, if a value that old is acceptable. |\n| Fresh and stale both low | Entries are gone before the next lookup, or keys are only looked up once. | Raise the TTL (or grace period). If the hit rates do not follow, the duration is not the cause. |\n\nMisses with other causes: a dip after a *Pod start* marker (empty memory layer), Redis evictions (see the *Redis Dashboard*), and features that are not read-through caches (`schema:publish`, `oauth-cache`, `integration-state`, `hive:oidcDomainChallenge`).\n\nSizing a duration: a TTL just above the p99 age of fresh hits keeps 99% of them fresh, and a grace period just above the p99 age of stale hits still serves 99% of them. An entry is stored for its grace period if it has one, otherwise for its TTL. Entry age is only recorded for the Redis-backed `bentocache:` features; change the others in steps and compare.", + "mode": "markdown" + }, + "fieldConfig": { + "defaults": {}, + "overrides": [] + } + } + } + } + }, + "panel-12": { + "kind": "Panel", + "spec": { + "data": { + "kind": "QueryGroup", + "spec": { + "queries": [ + { + "kind": "PanelQuery", + "spec": { + "hidden": false, + "refId": "A", + "query": { + "datasource": { + "name": "PROM_DATASOURCE_UID" + }, + "group": "prometheus", + "kind": "DataQuery", + "spec": { + "expr": "sort_desc(histogram_quantile(0.5, sum by (feature, le) (increase(hive_cache_entry_age_seconds_bucket{feature=~\"$feature\", result=\"hit\"}[$__range]))) >= 0)", + "legendFormat": "{{feature}}", + "instant": true, + "range": false + }, + "version": "v0" + } + } + } + ], + "queryOptions": {}, + "transformations": [] + } + }, + "description": "Half of the fresh hits read an entry younger than this. Entry age is the time since the entry was written; only the Redis-backed `bentocache:` features record it.", + "id": 12, + "links": [], + "title": "Fresh hit age, median (range)", + "vizConfig": { + "group": "bargauge", + "kind": "VizConfig", + "version": "13.3.0-32457798232", + "spec": { + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "noValue": "-", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + }, + "unit": "s", + "min": 0 + }, + "overrides": [] + }, + "options": { + "displayMode": "basic", + "orientation": "horizontal", + "showUnfilled": true, + "valueMode": "color", + "namePlacement": "top", + "sizing": "manual", + "minVizHeight": 32, + "minVizWidth": 8, + "maxVizHeight": 32, + "legend": { + "showLegend": false + }, + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "text": { + "titleSize": 12, + "valueSize": 13 + } + } + } + } + } + }, + "panel-13": { + "kind": "Panel", + "spec": { + "data": { + "kind": "QueryGroup", + "spec": { + "queries": [ + { + "kind": "PanelQuery", + "spec": { + "hidden": false, + "refId": "A", + "query": { + "datasource": { + "name": "PROM_DATASOURCE_UID" + }, + "group": "prometheus", + "kind": "DataQuery", + "spec": { + "expr": "sort_desc(histogram_quantile(0.99, sum by (feature, le) (increase(hive_cache_entry_age_seconds_bucket{feature=~\"$feature\", result=\"hit\"}[$__range]))) >= 0)", + "legendFormat": "{{feature}}", + "instant": true, + "range": false + }, + "version": "v0" + } + } + } + ], + "queryOptions": {}, + "transformations": [] + } + }, + "description": "99% of the fresh hits read an entry younger than this, so a TTL just above it keeps them fresh. A value close to the TTL means entries are read for their whole life. Entry age is the time since the entry was written; only the Redis-backed `bentocache:` features record it.", + "id": 13, + "links": [], + "title": "Fresh hit age, p99 (range)", + "vizConfig": { + "group": "bargauge", + "kind": "VizConfig", + "version": "13.3.0-32457798232", + "spec": { + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "noValue": "-", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + }, + "unit": "s", + "min": 0 + }, + "overrides": [] + }, + "options": { + "displayMode": "basic", + "orientation": "horizontal", + "showUnfilled": true, + "valueMode": "color", + "namePlacement": "top", + "sizing": "manual", + "minVizHeight": 32, + "minVizWidth": 8, + "maxVizHeight": 32, + "legend": { + "showLegend": false + }, + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "text": { + "titleSize": 12, + "valueSize": 13 + } + } + } + } + } + }, + "panel-14": { + "kind": "Panel", + "spec": { + "data": { + "kind": "QueryGroup", + "spec": { + "queries": [ + { + "kind": "PanelQuery", + "spec": { + "hidden": false, + "refId": "A", + "query": { + "datasource": { + "name": "PROM_DATASOURCE_UID" + }, + "group": "prometheus", + "kind": "DataQuery", + "spec": { + "expr": "sort_desc(histogram_quantile(0.5, sum by (feature, le) (increase(hive_cache_entry_age_seconds_bucket{feature=~\"$feature\", result=\"graced_hit\"}[$__range]))) >= 0)", + "legendFormat": "{{feature}}", + "instant": true, + "range": false + }, + "version": "v0" + } + } + } + ], + "queryOptions": {}, + "transformations": [] + } + }, + "description": "Half of the stale hits read an entry younger than this. Just above the TTL means keys that are looked up continuously; far above it means keys that come back after a long gap. Entry age is the time since the entry was written; only the Redis-backed `bentocache:` features record it.", + "id": 14, + "links": [], + "title": "Stale hit age, median (range)", + "vizConfig": { + "group": "bargauge", + "kind": "VizConfig", + "version": "13.3.0-32457798232", + "spec": { + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "noValue": "-", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + }, + "unit": "s", + "min": 0 + }, + "overrides": [] + }, + "options": { + "displayMode": "basic", + "orientation": "horizontal", + "showUnfilled": true, + "valueMode": "color", + "namePlacement": "top", + "sizing": "manual", + "minVizHeight": 32, + "minVizWidth": 8, + "maxVizHeight": 32, + "legend": { + "showLegend": false + }, + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "text": { + "titleSize": 12, + "valueSize": 13 + } + } + } + } + } + }, + "panel-15": { + "kind": "Panel", + "spec": { + "data": { + "kind": "QueryGroup", + "spec": { + "queries": [ + { + "kind": "PanelQuery", + "spec": { + "hidden": false, + "refId": "A", + "query": { + "datasource": { + "name": "PROM_DATASOURCE_UID" + }, + "group": "prometheus", + "kind": "DataQuery", + "spec": { + "expr": "sort_desc(histogram_quantile(0.99, sum by (feature, le) (increase(hive_cache_entry_age_seconds_bucket{feature=~\"$feature\", result=\"graced_hit\"}[$__range]))) >= 0)", + "legendFormat": "{{feature}}", + "instant": true, + "range": false + }, + "version": "v0" + } + } + } + ], + "queryOptions": {}, + "transformations": [] + } + }, + "description": "99% of the stale hits read an entry younger than this, so a grace period just above it still serves them. Entries are stored for the whole grace period. Entry age is the time since the entry was written; only the Redis-backed `bentocache:` features record it.", + "id": 15, + "links": [], + "title": "Stale hit age, p99 (range)", + "vizConfig": { + "group": "bargauge", + "kind": "VizConfig", + "version": "13.3.0-32457798232", + "spec": { + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "noValue": "-", + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + }, + "unit": "s", + "min": 0 + }, + "overrides": [] + }, + "options": { + "displayMode": "basic", + "orientation": "horizontal", + "showUnfilled": true, + "valueMode": "color", + "namePlacement": "top", + "sizing": "manual", + "minVizHeight": 32, + "minVizWidth": 8, + "maxVizHeight": 32, + "legend": { + "showLegend": false + }, + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + }, + "text": { + "titleSize": 12, + "valueSize": 13 + } + } + } + } + } + } + }, + "layout": { + "kind": "RowsLayout", + "spec": { + "rows": [ + { + "kind": "RowsLayoutRow", + "spec": { + "title": "How to use this dashboard", + "collapse": false, + "layout": { + "kind": "GridLayout", + "spec": { + "items": [ + { + "kind": "GridLayoutItem", + "spec": { + "x": 0, + "y": 0, + "width": 24, + "height": 12, + "element": { + "kind": "ElementReference", + "name": "panel-11" + } + } + } + ] + } + } + } + }, + { + "kind": "RowsLayoutRow", + "spec": { + "collapse": false, + "title": "Overview", + "layout": { + "kind": "AutoGridLayout", + "spec": { + "columnWidthMode": "custom", + "maxColumnCount": 4, + "rowHeightMode": "custom", + "items": [ + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-1" + } + } + }, + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-2" + } + } + }, + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-9" + } + } + }, + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-3" + } + } + } + ], + "columnWidth": 310, + "rowHeight": 516 + } + } + } + }, + { + "kind": "RowsLayoutRow", + "spec": { + "collapse": false, + "title": "Entry age", + "layout": { + "kind": "AutoGridLayout", + "spec": { + "columnWidthMode": "custom", + "maxColumnCount": 4, + "rowHeightMode": "custom", + "items": [ + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-12" + } + } + }, + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-13" + } + } + }, + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-14" + } + } + }, + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-15" + } + } + } + ], + "columnWidth": 310, + "rowHeight": 224 + } + } + } + }, + { + "kind": "RowsLayoutRow", + "spec": { + "collapse": false, + "title": "Volume", + "layout": { + "kind": "AutoGridLayout", + "spec": { + "columnWidthMode": "standard", + "maxColumnCount": 2, + "rowHeightMode": "standard", + "items": [ + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-4" + } + } + }, + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-5" + } + } + } + ] + } + } + } + }, + { + "kind": "RowsLayoutRow", + "spec": { + "collapse": false, + "title": "Hit rate", + "layout": { + "kind": "AutoGridLayout", + "spec": { + "columnWidthMode": "standard", + "maxColumnCount": 2, + "rowHeightMode": "standard", + "items": [ + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-6" + } + } + }, + { + "kind": "AutoGridLayoutItem", + "spec": { + "element": { + "kind": "ElementReference", + "name": "panel-10" } } }, diff --git a/packages/services/api/src/modules/auth/providers/organization-access-token-validation-cache.ts b/packages/services/api/src/modules/auth/providers/organization-access-token-validation-cache.ts index bd83f47996b..b33680342b8 100644 --- a/packages/services/api/src/modules/auth/providers/organization-access-token-validation-cache.ts +++ b/packages/services/api/src/modules/auth/providers/organization-access-token-validation-cache.ts @@ -16,7 +16,7 @@ export class OrganizationAccessTokenValidationCache { constructor() { this.cache = new BentoCache({ default: 'organizationAccessTokenValidation', - plugins: [cacheMetricsPlugin('bentocache:organization-access-token-validation')], + plugins: [cacheMetricsPlugin('bentocache:organization-access-token-validation', ['memory'])], stores: { organizationAccessTokenValidation: bentostore().useL1Layer( memoryDriver({ diff --git a/packages/services/api/src/modules/oidc-integrations/providers/oidc-integration.store.ts b/packages/services/api/src/modules/oidc-integrations/providers/oidc-integration.store.ts index 5ea2d6a54ec..55e9c514ee0 100644 --- a/packages/services/api/src/modules/oidc-integrations/providers/oidc-integration.store.ts +++ b/packages/services/api/src/modules/oidc-integrations/providers/oidc-integration.store.ts @@ -6,7 +6,7 @@ import { sha256 } from '../../auth/lib/supertokens-at-home/crypto'; import { Logger } from '../../shared/providers/logger'; import { REDIS_INSTANCE, type Redis } from '../../shared/providers/redis'; -const domainChallengeMetrics = createCacheMetrics('hive:oidcDomainChallenge'); +const domainChallengeMetrics = createCacheMetrics('hive:oidcDomainChallenge', ['redis']); const SharedOIDCIntegrationDomainFieldsModel = z.object({ id: z.uuid(), diff --git a/packages/services/api/src/modules/organization/providers/organization-access-tokens-cache.ts b/packages/services/api/src/modules/organization/providers/organization-access-tokens-cache.ts index 5954a5810fb..aa28a7dc36a 100644 --- a/packages/services/api/src/modules/organization/providers/organization-access-tokens-cache.ts +++ b/packages/services/api/src/modules/organization/providers/organization-access-tokens-cache.ts @@ -4,7 +4,7 @@ import { redisDriver } from 'bentocache/drivers/redis'; import { Inject, Injectable, Scope } from 'graphql-modules'; import { PostgresDatabasePool } from '@hive/postgres'; import { AuthorizationPolicyStatement } from '../../auth/lib/authz'; -import { cacheMetricsPlugin } from '../../shared/lib/bentocache-cache-metrics'; +import { cacheMetricsPlugin, entryAgeSerializer } from '../../shared/lib/bentocache-cache-metrics'; import { Logger } from '../../shared/providers/logger'; import { REDIS_INSTANCE, type Redis } from '../../shared/providers/redis'; import { Groups } from './groups'; @@ -45,7 +45,12 @@ export class OrganizationAccessTokensCache { ) { this.cache = new BentoCache({ default: 'organizationAccessTokens', - plugins: [cacheMetricsPlugin('bentocache:organization-access-tokens')], + plugins: [ + cacheMetricsPlugin('bentocache:organization-access-tokens', ['memory', 'redis'], { + entryAge: true, + }), + ], + serializer: entryAgeSerializer, stores: { organizationAccessTokens: bentostore() .useL1Layer( diff --git a/packages/services/api/src/modules/schema/providers/schema-explorer-cache.ts b/packages/services/api/src/modules/schema/providers/schema-explorer-cache.ts index 5dab7953769..d807e0faeff 100644 --- a/packages/services/api/src/modules/schema/providers/schema-explorer-cache.ts +++ b/packages/services/api/src/modules/schema/providers/schema-explorer-cache.ts @@ -16,7 +16,7 @@ import { REDIS_INSTANCE, type Redis } from '../../shared/providers/redis'; const RECENTLY_EVICTED_WINDOW_MS = 60 * 60 * 1000; /** Shared cache metrics, labelled with the Redis key prefix of the snapshots. */ -const cacheMetrics = createCacheMetrics('schema-explorer-snapshot'); +const cacheMetrics = createCacheMetrics('schema-explorer-snapshot', ['memory', 'redis']); const requests = new metrics.Counter({ name: 'api_schema_explorer_cache_requests_total', diff --git a/packages/services/api/src/modules/shared/lib/bentocache-cache-metrics.spec.ts b/packages/services/api/src/modules/shared/lib/bentocache-cache-metrics.spec.ts index f6cc39a3421..8f998281e53 100644 --- a/packages/services/api/src/modules/shared/lib/bentocache-cache-metrics.spec.ts +++ b/packages/services/api/src/modules/shared/lib/bentocache-cache-metrics.spec.ts @@ -1,32 +1,61 @@ import { BentoCache, bentostore } from 'bentocache'; import { memoryDriver } from 'bentocache/drivers/memory'; import { metrics } from '@hive/service-common'; -import { cacheMetricsPlugin } from './bentocache-cache-metrics'; +import { cacheMetricsPlugin, entryAgeSerializer } from './bentocache-cache-metrics'; async function counterValue(name: string, labels: Record) { const metric = await metrics.register.getSingleMetric(name)?.get(); - return ( - metric?.values.find(value => - Object.entries(labels).every(([key, label]) => value.labels[key] === label), - )?.value ?? 0 - ); + return metric?.values.find(value => + Object.entries(labels).every(([key, label]) => value.labels[key] === label), + )?.value; +} + +async function entryAgeSum(feature: string, result: string) { + const metric = await metrics.register.getSingleMetric('hive_cache_entry_age_seconds')?.get(); + return metric?.values.find( + value => + 'metricName' in value && + value.metricName === 'hive_cache_entry_age_seconds_sum' && + value.labels.feature === feature && + value.labels.result === result, + )?.value; } test('records misses, writes and hits of a BentoCache in the shared cache metrics', async () => { + vi.useFakeTimers({ toFake: ['Date'] }); const feature = 'test:bentocache-cache-metrics'; const cache = new BentoCache({ default: 'store', - plugins: [cacheMetricsPlugin(feature)], + plugins: [cacheMetricsPlugin(feature, ['memory'], { entryAge: true })], + serializer: entryAgeSerializer, + grace: '1h', stores: { store: bentostore().useL1Layer(memoryDriver({ maxItems: 10 })) }, }); - await cache.getOrSet({ key: 'a', factory: () => 1 }); - await cache.getOrSet({ key: 'a', factory: () => 1 }); - await cache.getOrSet({ key: 'a', factory: () => 1 }); + await expect( + counterValue('hive_cache_requests_total', { feature, result: 'hit', layer: 'memory' }), + ).resolves.toBe(0); + await expect(entryAgeSum(feature, 'graced_hit')).resolves.toBe(0); + + await cache.getOrSet({ key: 'a', factory: () => ({ id: 1 }) }); + vi.advanceTimersByTime(10_000); + await cache.getOrSet({ key: 'a', factory: () => ({ id: 1 }) }); + await cache.getOrSet({ key: 'a', factory: () => ({ id: 1 }) }); expect(await counterValue('hive_cache_requests_total', { feature, result: 'miss' })).toBe(1); expect(await counterValue('hive_cache_writes_total', { feature })).toBe(1); expect( await counterValue('hive_cache_requests_total', { feature, result: 'hit', layer: 'memory' }), ).toBe(2); + await expect(entryAgeSum(feature, 'hit')).resolves.toBe(20); + + await cache.expire({ key: 'a' }); + vi.advanceTimersByTime(5_000); + await cache.getOrSet({ key: 'a', factory: () => ({ id: 1 }) }); + + await expect( + counterValue('hive_cache_requests_total', { feature, result: 'graced_hit', layer: '' }), + ).resolves.toBe(1); + await expect(entryAgeSum(feature, 'graced_hit')).resolves.toBe(15); + vi.useRealTimers(); }); diff --git a/packages/services/api/src/modules/shared/lib/bentocache-cache-metrics.ts b/packages/services/api/src/modules/shared/lib/bentocache-cache-metrics.ts index d1b0cfd3283..1dd5efa0a5e 100644 --- a/packages/services/api/src/modules/shared/lib/bentocache-cache-metrics.ts +++ b/packages/services/api/src/modules/shared/lib/bentocache-cache-metrics.ts @@ -1,22 +1,50 @@ -import type { BentoCachePlugin } from 'bentocache/types'; -import { createCacheMetrics } from '@hive/service-common'; +import type { BentoCachePlugin, CacheSerializer } from 'bentocache/types'; +import { createCacheMetrics, type CacheLayer } from '@hive/service-common'; + +const createdAtByValue = new WeakMap(); + +/** + * BentoCache does not pass an entry's creation time to its hit event, so this serializer notes it + * for each entry read from a driver, keyed by the value the hit event then carries. + * Only object values are tracked. + */ +export const entryAgeSerializer: CacheSerializer = { + serialize: value => JSON.stringify(value), + deserialize(raw) { + const entry = JSON.parse(raw); + if (typeof entry?.createdAt === 'number' && entry.value && typeof entry.value === 'object') { + createdAtByValue.set(entry.value, entry.createdAt); + } + return entry; + }, +}; + +function entryAgeSeconds(value: unknown) { + const createdAt = value && typeof value === 'object' ? createdAtByValue.get(value) : undefined; + return createdAt === undefined ? undefined : (Date.now() - createdAt) / 1000; +} /** * Records the hits, misses and writes of a BentoCache instance in the shared * `hive_cache_requests_total` and `hive_cache_writes_total` metrics. * `feature` should be the Redis key prefix of the cache's L2 layer. + * Entry ages are recorded when `entryAge` is set and the BentoCache uses `entryAgeSerializer`. */ -export function cacheMetricsPlugin(feature: string): BentoCachePlugin { - const metrics = createCacheMetrics(feature); +export function cacheMetricsPlugin( + feature: string, + layers: CacheLayer[], + options: { entryAge?: boolean } = {}, +): BentoCachePlugin { + const metrics = createCacheMetrics(feature, layers, options); return { register(bentocache) { bentocache.on('cache:hit', event => { - const layer = event.layer === 'l1' ? 'memory' : 'redis'; + const ageSeconds = entryAgeSeconds(event.value); if (event.graced) { - metrics.gracedHit(layer); + metrics.gracedHit(ageSeconds); } else { - metrics.hit(layer); + metrics.hit(event.layer === 'l1' ? 'memory' : 'redis', ageSeconds); } }); bentocache.on('cache:miss', () => metrics.miss()); diff --git a/packages/services/api/src/modules/shared/providers/distributed-cache.ts b/packages/services/api/src/modules/shared/providers/distributed-cache.ts index cd5c2c3f50b..76eb9b06413 100644 --- a/packages/services/api/src/modules/shared/providers/distributed-cache.ts +++ b/packages/services/api/src/modules/shared/providers/distributed-cache.ts @@ -34,7 +34,7 @@ export class DistributedCache { */ ttlSeconds: number; }): Promise { - const metrics = createCacheMetrics(feature); + const metrics = createCacheMetrics(feature, ['redis']); const redisKey = `${feature}:${key}`; const cached = await this.get(redisKey); if (cached) { diff --git a/packages/services/api/src/modules/shared/providers/ephemeral-state-store.ts b/packages/services/api/src/modules/shared/providers/ephemeral-state-store.ts index 4300b111f3a..2194081c771 100644 --- a/packages/services/api/src/modules/shared/providers/ephemeral-state-store.ts +++ b/packages/services/api/src/modules/shared/providers/ephemeral-state-store.ts @@ -14,7 +14,7 @@ export abstract class EphemeralStateStore { const state = randomBytes(32).toString('hex'); const key = `${this.keyPrefix}:${sha256(state)}`; await this.redis.set(key, JSON.stringify(this.model.parse(data)), 'EX', 60 * 5); - createCacheMetrics(this.keyPrefix).write(); + createCacheMetrics(this.keyPrefix, ['redis']).write(); return state; } @@ -22,7 +22,7 @@ export abstract class EphemeralStateStore { async get(state: string): Promise | null> { const key = `${this.keyPrefix}:${sha256(state)}`; const encodedData = await this.redis.getdel(key); - const metrics = createCacheMetrics(this.keyPrefix); + const metrics = createCacheMetrics(this.keyPrefix, ['redis']); if (!encodedData) { // Unknown, expired or already used state. metrics.miss(); diff --git a/packages/services/api/src/modules/target/providers/targets-by-id-cache.ts b/packages/services/api/src/modules/target/providers/targets-by-id-cache.ts index de243751b3d..e7ae9def6e4 100644 --- a/packages/services/api/src/modules/target/providers/targets-by-id-cache.ts +++ b/packages/services/api/src/modules/target/providers/targets-by-id-cache.ts @@ -4,7 +4,7 @@ import { redisDriver } from 'bentocache/drivers/redis'; import { Inject, Injectable, Scope } from 'graphql-modules'; import type { Target } from '../../../shared/entities'; import { isUUID } from '../../../shared/is-uuid'; -import { cacheMetricsPlugin } from '../../shared/lib/bentocache-cache-metrics'; +import { cacheMetricsPlugin, entryAgeSerializer } from '../../shared/lib/bentocache-cache-metrics'; import { REDIS_INSTANCE, type Redis } from '../../shared/providers/redis'; import { TargetStore } from './target-store'; @@ -24,7 +24,10 @@ export class TargetsByIdCache { ) { this.cache = new BentoCache({ default: 'targetsById', - plugins: [cacheMetricsPlugin('bentocache:targetsById')], + plugins: [ + cacheMetricsPlugin('bentocache:targetsById', ['memory', 'redis'], { entryAge: true }), + ], + serializer: entryAgeSerializer, stores: { targetsById: bentostore() .useL1Layer( diff --git a/packages/services/api/src/modules/target/providers/targets-by-slug-cache.ts b/packages/services/api/src/modules/target/providers/targets-by-slug-cache.ts index da6eeb8665d..5683b2af77b 100644 --- a/packages/services/api/src/modules/target/providers/targets-by-slug-cache.ts +++ b/packages/services/api/src/modules/target/providers/targets-by-slug-cache.ts @@ -2,7 +2,7 @@ import { BentoCache, bentostore } from 'bentocache'; import { memoryDriver } from 'bentocache/drivers/memory'; import { redisDriver } from 'bentocache/drivers/redis'; import { Inject, Injectable, Scope } from 'graphql-modules'; -import { cacheMetricsPlugin } from '../../shared/lib/bentocache-cache-metrics'; +import { cacheMetricsPlugin, entryAgeSerializer } from '../../shared/lib/bentocache-cache-metrics'; import { REDIS_INSTANCE, type Redis } from '../../shared/providers/redis'; import { TargetStore } from './target-store'; @@ -22,7 +22,10 @@ export class TargetsBySlugCache { ) { this.cache = new BentoCache({ default: 'targetsBySlug', - plugins: [cacheMetricsPlugin('bentocache:targetsBySlug')], + plugins: [ + cacheMetricsPlugin('bentocache:targetsBySlug', ['memory', 'redis'], { entryAge: true }), + ], + serializer: entryAgeSerializer, stores: { targetsBySlug: bentostore() .useL1Layer( diff --git a/packages/services/api/src/modules/token/providers/target-token-cache.ts b/packages/services/api/src/modules/token/providers/target-token-cache.ts index 9ed95850f5a..71a72b9775b 100644 --- a/packages/services/api/src/modules/token/providers/target-token-cache.ts +++ b/packages/services/api/src/modules/token/providers/target-token-cache.ts @@ -6,7 +6,7 @@ import { PostgresDatabasePool } from '@hive/postgres'; import { TaskScheduler } from '@hive/workflows/kit'; import { PurgeTargetTokensTask } from '@hive/workflows/tasks/purge-target-tokens'; import type { Token } from '../../../shared/entities'; -import { cacheMetricsPlugin } from '../../shared/lib/bentocache-cache-metrics'; +import { cacheMetricsPlugin, entryAgeSerializer } from '../../shared/lib/bentocache-cache-metrics'; import { Logger } from '../../shared/providers/logger'; import { REDIS_INSTANCE, type Redis } from '../../shared/providers/redis'; import { hashTargetToken, TargetTokenStorage } from './target-token-storage'; @@ -32,7 +32,10 @@ export class TargetTokenCache { ) { this.cache = new BentoCache({ default: 'targetTokens', - plugins: [cacheMetricsPlugin('bentocache:target-tokens')], + plugins: [ + cacheMetricsPlugin('bentocache:target-tokens', ['memory', 'redis'], { entryAge: true }), + ], + serializer: entryAgeSerializer, stores: { targetTokens: bentostore({ prefix: 'bentocache:target-tokens' }) .useL1Layer( diff --git a/packages/services/schema/src/cache.ts b/packages/services/schema/src/cache.ts index f907632147e..5e86131c377 100644 --- a/packages/services/schema/src/cache.ts +++ b/packages/services/schema/src/cache.ts @@ -65,7 +65,7 @@ export function createCache(options: { } const ttlMs = options.ttlMs; - const cacheMetrics = createCacheMetrics(prefix); + const cacheMetrics = createCacheMetrics(prefix, ['redis']); async function readAction(id: string): Promise | null> { const action = await redis.get(id); diff --git a/packages/services/service-common/src/cache-metrics.ts b/packages/services/service-common/src/cache-metrics.ts index 215f1090985..68bcd4795cd 100644 --- a/packages/services/service-common/src/cache-metrics.ts +++ b/packages/services/service-common/src/cache-metrics.ts @@ -4,7 +4,7 @@ const cacheRequests = new promClient.Counter({ name: 'hive_cache_requests_total', help: 'Cache lookups per feature. feature is the Redis key prefix the cache writes under.', // result: hit, graced_hit (stale value served within its grace period) or miss. - // layer: memory or redis for hits; empty for misses. + // layer: memory or redis for hits; empty for graced hits and misses. labelNames: ['feature', 'result', 'layer'], }); @@ -14,11 +14,18 @@ const cacheWrites = new promClient.Counter({ labelNames: ['feature'], }); +const cacheEntryAge = new promClient.Histogram({ + name: 'hive_cache_entry_age_seconds', + help: 'Time since a cache entry was written, observed each time it is read. result: hit or graced_hit.', + labelNames: ['feature', 'result'], + buckets: [1, 5, 15, 30, 60, 120, 300, 360, 600, 1_800, 3_600, 10_800, 21_600, 43_200, 86_400], +}); + export type CacheLayer = 'memory' | 'redis'; export type CacheMetrics = { - hit(layer: CacheLayer): void; - gracedHit(layer: CacheLayer): void; + hit(layer: CacheLayer, ageSeconds?: number): void; + gracedHit(ageSeconds?: number): void; miss(): void; write(): void; }; @@ -27,14 +34,37 @@ export type CacheMetrics = { * Records hits, misses and writes of one cache. * `feature` should be the Redis key prefix of the cache, so these metrics line up with a scan of * the keyspace grouped by prefix. + * `layers` are the layers the cache has, and `entryAge` says that it passes an age with its hits. + * Every series the cache can emit is created at zero. */ -export function createCacheMetrics(feature: string): CacheMetrics { +export function createCacheMetrics( + feature: string, + layers: CacheLayer[], + options: { entryAge?: boolean } = {}, +): CacheMetrics { + for (const layer of layers) { + cacheRequests.inc({ feature, result: 'hit', layer }, 0); + } + cacheRequests.inc({ feature, result: 'graced_hit', layer: '' }, 0); + cacheRequests.inc({ feature, result: 'miss', layer: '' }, 0); + cacheWrites.inc({ feature }, 0); + if (options.entryAge) { + cacheEntryAge.zero({ feature, result: 'hit' }); + cacheEntryAge.zero({ feature, result: 'graced_hit' }); + } + return { - hit(layer) { + hit(layer, ageSeconds) { cacheRequests.inc({ feature, result: 'hit', layer }); + if (ageSeconds !== undefined) { + cacheEntryAge.observe({ feature, result: 'hit' }, ageSeconds); + } }, - gracedHit(layer) { - cacheRequests.inc({ feature, result: 'graced_hit', layer }); + gracedHit(ageSeconds) { + cacheRequests.inc({ feature, result: 'graced_hit', layer: '' }); + if (ageSeconds !== undefined) { + cacheEntryAge.observe({ feature, result: 'graced_hit' }, ageSeconds); + } }, miss() { cacheRequests.inc({ feature, result: 'miss', layer: '' }); diff --git a/packages/services/workflows/src/tasks/schema-explorer-snapshot-build.ts b/packages/services/workflows/src/tasks/schema-explorer-snapshot-build.ts index 70e46d30088..91a250be84d 100644 --- a/packages/services/workflows/src/tasks/schema-explorer-snapshot-build.ts +++ b/packages/services/workflows/src/tasks/schema-explorer-snapshot-build.ts @@ -19,7 +19,7 @@ import type { Context } from '../context'; import { defineTask, implementTask } from '../kit.js'; import { createSchemaObject } from '../lib/schema/provider'; -const cacheMetrics = createCacheMetrics('schema-explorer-snapshot'); +const cacheMetrics = createCacheMetrics('schema-explorer-snapshot', []); export const SchemaExplorerSnapshotBuildTask = defineTask({ name: 'schemaExplorerSnapshotBuild',