From 57d53de40255afd45ea1f6add7ecf32a3434bc97 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 24 May 2023 10:47:05 +0200 Subject: [PATCH 01/10] Increase the number of buckets --- meilisearch/src/metrics.rs | 15 +++++++++++---- meilisearch/src/routes/metrics.rs | 5 ++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/meilisearch/src/metrics.rs b/meilisearch/src/metrics.rs index f6fdf756d..c518db941 100644 --- a/meilisearch/src/metrics.rs +++ b/meilisearch/src/metrics.rs @@ -4,12 +4,19 @@ use prometheus::{ register_int_gauge_vec, HistogramVec, IntCounterVec, IntGauge, IntGaugeVec, }; -const HTTP_RESPONSE_TIME_CUSTOM_BUCKETS: &[f64; 14] = &[ - 0.0005, 0.0008, 0.00085, 0.0009, 0.00095, 0.001, 0.00105, 0.0011, 0.00115, 0.0012, 0.0015, - 0.002, 0.003, 1.0, -]; +/// Create evenly distributed buckets +fn create_buckets() -> [f64; N] { + let mut array = [0.0; N]; + + for i in 0..N { + array[i] = ((i + 1) as f64) / N as f64; + } + + array +} lazy_static! { + pub static ref HTTP_RESPONSE_TIME_CUSTOM_BUCKETS: [f64; 100] = create_buckets(); pub static ref HTTP_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!( opts!("http_requests_total", "HTTP requests total"), &["method", "path"] diff --git a/meilisearch/src/routes/metrics.rs b/meilisearch/src/routes/metrics.rs index 874a1a5a5..83cd50542 100644 --- a/meilisearch/src/routes/metrics.rs +++ b/meilisearch/src/routes/metrics.rs @@ -17,7 +17,7 @@ pub fn configure(config: &mut web::ServiceConfig) { pub async fn get_metrics( index_scheduler: GuardedData, Data>, - auth_controller: GuardedData, Data>, + auth_controller: Data, ) -> Result { let auth_filters = index_scheduler.filters(); if !auth_filters.all_indexes_authorized() { @@ -28,8 +28,7 @@ pub async fn get_metrics( return Err(error); } - let response = - create_all_stats((*index_scheduler).clone(), (*auth_controller).clone(), auth_filters)?; + let response = create_all_stats((*index_scheduler).clone(), auth_controller, auth_filters)?; crate::metrics::MEILISEARCH_DB_SIZE_BYTES.set(response.database_size as i64); crate::metrics::MEILISEARCH_INDEX_COUNT.set(response.indexes.len() as i64); From 1b601f70c671969a0db05eee65e4c911b9d91716 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 25 May 2023 11:08:16 +0200 Subject: [PATCH 02/10] increase the bucketing of requests --- meilisearch/src/metrics.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/meilisearch/src/metrics.rs b/meilisearch/src/metrics.rs index c518db941..7ee5241db 100644 --- a/meilisearch/src/metrics.rs +++ b/meilisearch/src/metrics.rs @@ -5,18 +5,18 @@ use prometheus::{ }; /// Create evenly distributed buckets -fn create_buckets() -> [f64; N] { - let mut array = [0.0; N]; - - for i in 0..N { - array[i] = ((i + 1) as f64) / N as f64; - } - - array +fn create_buckets() -> [f64; 29] { + (0..10) + .chain((10..100).step_by(10)) + .chain((100..=1000).step_by(100)) + .map(|i| i as f64 / 1000.) + .collect::>() + .try_into() + .unwrap() } lazy_static! { - pub static ref HTTP_RESPONSE_TIME_CUSTOM_BUCKETS: [f64; 100] = create_buckets(); + pub static ref HTTP_RESPONSE_TIME_CUSTOM_BUCKETS: [f64; 29] = create_buckets(); pub static ref HTTP_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!( opts!("http_requests_total", "HTTP requests total"), &["method", "path"] From c433bdd1cd11f18f75358141556c9224589cce51 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 25 May 2023 12:58:13 +0200 Subject: [PATCH 03/10] add a view for the task queue in the metrics --- grafana-dashboards/dashboard.json | 2275 +++++++++++++++++------------ index-scheduler/src/lib.rs | 30 +- meilisearch/src/metrics.rs | 3 + meilisearch/src/routes/metrics.rs | 6 + 4 files changed, 1352 insertions(+), 962 deletions(-) diff --git a/grafana-dashboards/dashboard.json b/grafana-dashboards/dashboard.json index 53865ad56..015831173 100644 --- a/grafana-dashboards/dashboard.json +++ b/grafana-dashboards/dashboard.json @@ -1,1007 +1,1360 @@ { - "annotations": { - "list": [ - { - "builtIn": 1, - "datasource": { - "type": "datasource", - "uid": "grafana" - }, - "enable": true, - "hide": true, - "iconColor": "rgba(0, 211, 255, 1)", - "name": "Annotations & Alerts", - "target": { - "limit": 100, - "matchAny": false, - "tags": [], - "type": "dashboard" - }, + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "datasource", + "uid": "grafana" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "target": { + "limit": 100, + "matchAny": false, + "tags": [], "type": "dashboard" + }, + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 4, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "datasource": { + "type": "prometheus" + }, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 14, + "panels": [], + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "refId": "A" } - ] + ], + "title": "Web application metrics", + "type": "row" }, - "editable": true, - "fiscalYearStartMonth": 0, - "graphTooltip": 0, - "id": 1, - "links": [], - "liveNow": false, - "panels": [ - { - "collapsed": false, - "datasource": { - "type": "prometheus" - }, - "gridPos": { - "h": 1, - "w": 24, - "x": 0, - "y": 0 - }, - "id": 14, - "panels": [], - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "i51CxikVz" - }, - "refId": "A" - } - ], - "title": "Web application metrics", - "type": "row" + { + "datasource": { + "type": "prometheus" }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "continuous-YlBl" - }, - "decimals": 0, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - }, - "unit": "bytes" + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-YlBl" }, - "overrides": [] - }, - "gridPos": { - "h": 6, - "w": 4, - "x": 0, - "y": 1 - }, - "id": 2, - "interval": "5s", - "options": { - "orientation": "auto", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false - }, - "showThresholdLabels": false, - "showThresholdMarkers": true, - "text": {} - }, - "pluginVersion": "9.0.5", - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "editorMode": "builder", - "exemplar": true, - "expr": "meilisearch_db_size_bytes{job=\"meilisearch\", instance=\"$instance\"}", - "interval": "", - "legendFormat": "", - "range": true, - "refId": "A" - } - ], - "title": "Database Size", - "type": "gauge" - }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "fieldConfig": { - "defaults": { - "color": { - "fixedColor": "purple", - "mode": "fixed" - }, - "decimals": 0, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - } - ] - }, - "unit": "none" - }, - "overrides": [] - }, - "gridPos": { - "h": 6, - "w": 4, - "x": 4, - "y": 1 - }, - "id": 22, - "interval": "5s", - "options": { - "orientation": "auto", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false - }, - "showThresholdLabels": false, - "showThresholdMarkers": true, - "text": {} - }, - "pluginVersion": "9.0.5", - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "editorMode": "builder", - "exemplar": true, - "expr": "meilisearch_index_count{job=\"meilisearch\", instance=\"$instance\"}", - "interval": "", - "legendFormat": "", - "range": true, - "refId": "A" - } - ], - "title": "Indexes Count", - "type": "gauge" - }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "thresholds" - }, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - } - ] - } - }, - "overrides": [] - }, - "gridPos": { - "h": 6, - "w": 4, - "x": 8, - "y": 1 - }, - "id": 18, - "options": { - "orientation": "auto", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false - }, - "showThresholdLabels": false, - "showThresholdMarkers": true, - "text": {} - }, - "pluginVersion": "9.0.5", - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "editorMode": "builder", - "expr": "meilisearch_index_docs_count{job=\"meilisearch\", index=\"$Index\", instance=\"$instance\"}", - "hide": false, - "range": true, - "refId": "A" - } - ], - "title": "Total Documents", - "type": "gauge" - }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "thresholds" - }, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - } - }, - "overrides": [] - }, - "gridPos": { - "h": 6, - "w": 4, - "x": 12, - "y": 1 - }, - "id": 19, - "options": { - "orientation": "auto", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false - }, - "showThresholdLabels": false, - "showThresholdMarkers": true, - "text": {} - }, - "pluginVersion": "9.0.5", - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "editorMode": "builder", - "exemplar": true, - "expr": "round(increase(http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[1h]))", - "interval": "", - "legendFormat": "", - "range": true, - "refId": "A" - } - ], - "title": "Total Searches (1h)", - "type": "gauge" - }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "thresholds" - }, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - } - ] - } - }, - "overrides": [] - }, - "gridPos": { - "h": 6, - "w": 4, - "x": 16, - "y": 1 - }, - "id": 20, - "options": { - "orientation": "auto", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false - }, - "showThresholdLabels": false, - "showThresholdMarkers": true, - "text": {} - }, - "pluginVersion": "9.0.5", - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "editorMode": "builder", - "exemplar": true, - "expr": "round(increase(http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[24h]))", - "interval": "", - "legendFormat": "", - "range": true, - "refId": "A" - } - ], - "title": "Total Searches (24h)", - "type": "gauge" - }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "thresholds" - }, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - } - ] - } - }, - "overrides": [] - }, - "gridPos": { - "h": 6, - "w": 4, - "x": 20, - "y": 1 - }, - "id": 21, - "options": { - "orientation": "auto", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false - }, - "showThresholdLabels": false, - "showThresholdMarkers": true, - "text": {} - }, - "pluginVersion": "9.0.5", - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "editorMode": "builder", - "exemplar": true, - "expr": "round(increase(http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[30d]))", - "interval": "", - "legendFormat": "", - "range": true, - "refId": "A" - } - ], - "title": "Total Searches (30d)", - "type": "gauge" - }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "continuous-YlBl" - }, - "custom": { - "axisLabel": "", - "axisPlacement": "auto", - "barAlignment": 0, - "drawStyle": "line", - "fillOpacity": 15, - "gradientMode": "none", - "hideFrom": { - "legend": false, - "tooltip": false, - "viz": false + "decimals": 0, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null }, - "lineInterpolation": "linear", - "lineWidth": 1, - "pointSize": 5, - "scaleDistribution": { - "type": "linear" - }, - "showPoints": "never", - "spanNulls": false, - "stacking": { - "group": "A", - "mode": "none" - }, - "thresholdsStyle": { - "mode": "off" + { + "color": "red", + "value": 80 } + ] + }, + "unit": "bytes" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 0, + "y": 1 + }, + "id": 2, + "interval": "5s", + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "text": {} + }, + "pluginVersion": "9.5.2", + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "meilisearch_db_size_bytes{job=\"meilisearch\", instance=\"$instance\"}", + "interval": "", + "legendFormat": "", + "range": true, + "refId": "A" + } + ], + "title": "Database Size", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "fixedColor": "purple", + "mode": "fixed" + }, + "decimals": 0, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 4, + "y": 1 + }, + "id": 22, + "interval": "5s", + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "text": {} + }, + "pluginVersion": "9.5.2", + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "meilisearch_index_count{job=\"meilisearch\", instance=\"$instance\"}", + "interval": "", + "legendFormat": "", + "range": true, + "refId": "A" + } + ], + "title": "Indexes Count", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 8, + "y": 1 + }, + "id": 18, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "text": {} + }, + "pluginVersion": "9.5.2", + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "expr": "meilisearch_index_docs_count{job=\"meilisearch\", index=\"$Index\", instance=\"$instance\"}", + "hide": false, + "range": true, + "refId": "A" + } + ], + "title": "Total Documents", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 12, + "y": 1 + }, + "id": 19, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "text": {} + }, + "pluginVersion": "9.5.2", + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "round(increase(http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[1h]))", + "interval": "", + "legendFormat": "", + "range": true, + "refId": "A" + } + ], + "title": "Total Searches (1h)", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 16, + "y": 1 + }, + "id": 20, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "text": {} + }, + "pluginVersion": "9.5.2", + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "round(increase(http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[24h]))", + "interval": "", + "legendFormat": "", + "range": true, + "refId": "A" + } + ], + "title": "Total Searches (24h)", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 20, + "y": 1 + }, + "id": 21, + "options": { + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true, + "text": {} + }, + "pluginVersion": "9.5.2", + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "round(increase(http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[30d]))", + "interval": "", + "legendFormat": "", + "range": true, + "refId": "A" + } + ], + "title": "Total Searches (30d)", + "type": "gauge" + }, + { + "datasource": { + "type": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-YlBl" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 15, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false }, - "decimals": 2, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" } }, - "overrides": [] - }, - "gridPos": { - "h": 11, - "w": 12, - "x": 0, - "y": 7 - }, - "id": 1, - "interval": "5s", - "options": { - "legend": { - "calcs": [], - "displayMode": "list", - "placement": "right" - }, - "tooltip": { - "mode": "single", - "sort": "none" - } - }, - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "editorMode": "builder", - "exemplar": true, - "expr": "rate(http_requests_total{instance=\"$instance\", job=\"meilisearch\"}[5m])", - "interval": "", - "legendFormat": "{{method}} {{path}}", - "range": true, - "refId": "A" - } - ], - "title": "HTTP requests per second (All Indexes)", - "type": "timeseries" - }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "continuous-YlBl" - }, - "custom": { - "axisLabel": "", - "axisPlacement": "auto", - "barAlignment": 0, - "drawStyle": "line", - "fillOpacity": 15, - "gradientMode": "none", - "hideFrom": { - "legend": false, - "tooltip": false, - "viz": false + "decimals": 2, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null }, - "lineInterpolation": "linear", - "lineWidth": 1, - "pointSize": 5, - "scaleDistribution": { - "type": "linear" - }, - "showPoints": "never", - "spanNulls": false, - "stacking": { - "group": "A", - "mode": "none" - }, - "thresholdsStyle": { - "mode": "off" + { + "color": "red", + "value": 80 } - }, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - }, - "unit": "s" - }, - "overrides": [] - }, - "gridPos": { - "h": 11, - "w": 12, - "x": 12, - "y": 7 - }, - "id": 3, - "interval": "5s", - "options": { - "legend": { - "calcs": [], - "displayMode": "list", - "placement": "right" - }, - "tooltip": { - "mode": "single", - "sort": "none" + ] } }, - "pluginVersion": "8.1.4", - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "editorMode": "builder", - "exemplar": true, - "expr": "rate(http_response_time_seconds_sum{instance=\"$instance\", job=\"meilisearch\"}[5m]) / rate(http_response_time_seconds_count[5m])", - "interval": "", - "legendFormat": "{{method}} {{path}}", - "range": true, - "refId": "A" - } - ], - "title": "Mean response time (All Indexes)", - "type": "timeseries" + "overrides": [] }, - { - "cards": {}, + "gridPos": { + "h": 11, + "w": 12, + "x": 0, + "y": 7 + }, + "id": 1, + "interval": "5s", + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "rate(http_requests_total{instance=\"$instance\", job=\"meilisearch\"}[5m])", + "interval": "", + "legendFormat": "{{method}} {{path}}", + "range": true, + "refId": "A" + } + ], + "title": "HTTP requests per second (All Indexes)", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-YlBl" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 15, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "s" + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 12, + "x": 12, + "y": 7 + }, + "id": 3, + "interval": "5s", + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "8.1.4", + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "rate(http_response_time_seconds_sum{instance=\"$instance\", job=\"meilisearch\"}[5m]) / rate(http_response_time_seconds_count[5m])", + "interval": "", + "legendFormat": "{{method}} {{path}}", + "range": true, + "refId": "A" + } + ], + "title": "Mean response time (All Indexes)", + "type": "timeseries" + }, + { + "cards": {}, + "color": { + "cardColor": "#b4ff00", + "colorScale": "sqrt", + "colorScheme": "interpolateBlues", + "exponent": 0.5, + "mode": "spectrum" + }, + "dataFormat": "tsbuckets", + "datasource": { + "type": "prometheus" + }, + "fieldConfig": { + "defaults": { + "custom": { + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "scaleDistribution": { + "type": "linear" + } + } + }, + "overrides": [] + }, + "gridPos": { + "h": 12, + "w": 24, + "x": 0, + "y": 18 + }, + "heatmap": {}, + "hideZeroBuckets": false, + "highlightCards": true, + "id": 16, + "legend": { + "show": false + }, + "options": { + "calculate": false, + "calculation": {}, + "cellGap": 2, + "cellValues": {}, "color": { - "cardColor": "#b4ff00", - "colorScale": "sqrt", - "colorScheme": "interpolateBlues", "exponent": 0.5, - "mode": "spectrum" + "fill": "#b4ff00", + "mode": "scheme", + "reverse": false, + "scale": "exponential", + "scheme": "Blues", + "steps": 128 }, - "dataFormat": "tsbuckets", - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" + "exemplars": { + "color": "rgba(255,0,255,0.7)" }, - "gridPos": { - "h": 12, - "w": 24, - "x": 0, - "y": 18 + "filterValues": { + "le": 1e-9 }, - "heatmap": {}, - "hideZeroBuckets": false, - "highlightCards": true, - "id": 16, "legend": { "show": false }, - "pluginVersion": "8.1.4", - "reverseYBuckets": false, - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "editorMode": "builder", - "exemplar": true, - "expr": "sum by(le) (increase(http_response_time_seconds_bucket{path=\"/indexes/$Index/search\", instance=\"$instance\", job=\"meilisearch\"}[30s]))", - "format": "heatmap", - "interval": "", - "legendFormat": "{{le}}", - "range": true, - "refId": "A" - } - ], - "title": "Response time distribution over time (`POST /indexes/:index/search`)", + "rowsFrame": { + "layout": "auto" + }, + "showValue": "never", "tooltip": { "show": true, - "showHistogram": false + "yHistogram": false }, - "type": "heatmap", - "xAxis": { - "show": true - }, - "xBucketNumber": 10, "yAxis": { + "axisPlacement": "left", "decimals": 2, - "format": "s", - "logBase": 1, - "show": true - }, - "yBucketBound": "auto", - "yBucketNumber": 10 + "reverse": false, + "unit": "s" + } }, - { - "collapsed": false, - "datasource": { - "type": "prometheus", - "uid": "i51CxikVz" - }, - "gridPos": { - "h": 1, - "w": 24, - "x": 0, - "y": 30 - }, - "id": 12, - "panels": [], - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "i51CxikVz" - }, - "refId": "A" - } - ], - "title": "System metrics", - "type": "row" + "pluginVersion": "9.5.2", + "reverseYBuckets": false, + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "sum by(le) (increase(http_response_time_seconds_bucket{path=\"/indexes/$Index/search\", instance=\"$instance\", job=\"meilisearch\"}[30s]))", + "format": "heatmap", + "interval": "", + "legendFormat": "{{le}}", + "range": true, + "refId": "A" + } + ], + "title": "Response time distribution over time (`POST /indexes/:index/search`)", + "tooltip": { + "show": true, + "showHistogram": false }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "continuous-YlBl" - }, - "custom": { - "axisLabel": "", - "axisPlacement": "auto", - "barAlignment": 0, - "drawStyle": "line", - "fillOpacity": 15, - "gradientMode": "none", - "hideFrom": { - "legend": false, - "tooltip": false, - "viz": false - }, - "lineInterpolation": "linear", - "lineWidth": 1, - "pointSize": 5, - "scaleDistribution": { - "type": "linear" - }, - "showPoints": "never", - "spanNulls": false, - "stacking": { - "group": "A", - "mode": "none" - }, - "thresholdsStyle": { - "mode": "off" - } - }, - "decimals": 2, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] - }, - "unit": "percentunit" - }, - "overrides": [] - }, - "gridPos": { - "h": 11, - "w": 12, - "x": 0, - "y": 31 - }, - "id": 4, - "interval": "5s", - "options": { - "legend": { - "calcs": [], - "displayMode": "list", - "placement": "bottom" - }, - "tooltip": { - "mode": "single", - "sort": "none" - } - }, - "targets": [ - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "editorMode": "builder", - "exemplar": true, - "expr": "rate(process_cpu_seconds_total{job=\"meilisearch\", instance=\"$instance\"}[1m])", - "interval": "", - "legendFormat": "process", - "range": true, - "refId": "A" - }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "exemplar": true, - "expr": "sum(rate(container_cpu_usage_seconds_total{name='mongodb-redis'}[1m])) by (name)", - "interval": "", - "legendFormat": "container", - "refId": "B" - } - ], - "title": "CPU usage", - "type": "timeseries" + "type": "heatmap", + "xAxis": { + "show": true }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "continuous-YlBl" + "xBucketNumber": 10, + "yAxis": { + "decimals": 2, + "format": "s", + "logBase": 1, + "show": true + }, + "yBucketBound": "auto", + "yBucketNumber": 10 + }, + { + "datasource": { + "type": "prometheus", + "uid": "bb3298a4-9acf-4da1-b86a-813f29f50888" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 15, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false }, - "custom": { - "axisLabel": "MiB", - "axisPlacement": "left", - "barAlignment": 0, - "drawStyle": "line", - "fillOpacity": 15, - "gradientMode": "none", - "hideFrom": { - "legend": false, - "tooltip": false, - "viz": false - }, - "lineInterpolation": "linear", - "lineWidth": 1, - "pointSize": 5, - "scaleDistribution": { - "type": "linear" - }, - "showPoints": "never", - "spanNulls": false, - "stacking": { - "group": "A", - "mode": "none" - }, - "thresholdsStyle": { - "mode": "off" - } + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" }, - "mappings": [], - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - }, - { - "color": "red", - "value": 80 - } - ] + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" } }, - "overrides": [] - }, - "gridPos": { - "h": 11, - "w": 12, - "x": 12, - "y": 31 - }, - "id": 5, - "interval": "5s", - "options": { - "legend": { - "calcs": [], - "displayMode": "list", - "placement": "bottom" + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] }, - "tooltip": { - "mode": "single", - "sort": "none" - } + "unit": "none" }, - "targets": [ + "overrides": [ { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" + "__systemRef": "hideSeriesFrom", + "matcher": { + "id": "byNames", + "options": { + "mode": "exclude", + "names": [ + "succeeded " + ], + "prefix": "All except:", + "readOnly": true + } }, - "editorMode": "builder", - "exemplar": true, - "expr": "process_resident_memory_bytes{job=\"meilisearch\", instance=\"$instance\"} / 1024 / 1024", - "interval": "", - "legendFormat": "process", - "range": true, - "refId": "A" - }, - { - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "exemplar": true, - "expr": "container_memory_usage_bytes{name=\"mongodb-redis\"} / 1024 / 1024", - "interval": "", - "legendFormat": "container", - "refId": "B" + "properties": [ + { + "id": "custom.hideFrom", + "value": { + "legend": false, + "tooltip": false, + "viz": true + } + } + ] } - ], - "title": "Memory usage", - "type": "timeseries" - } - ], - "refresh": "5s", - "schemaVersion": 36, - "style": "dark", - "tags": [], - "templating": { - "list": [ - { - "current": { - "selected": false, - "text": "localhost:7700", - "value": "localhost:7700" - }, - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "definition": "label_values(instance)", - "hide": 0, - "includeAll": false, - "label": "Instance", - "multi": false, - "name": "instance", - "options": [], - "query": { - "query": "label_values(instance)", - "refId": "StandardVariableQuery" - }, - "refresh": 1, - "regex": "", - "skipUrlSync": false, - "sort": 0, - "type": "query" + ] + }, + "gridPos": { + "h": 11, + "w": 12, + "x": 0, + "y": 30 + }, + "id": 23, + "interval": "5s", + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "right", + "showLegend": true }, - { - "current": { - "selected": false, - "text": "movie-collection", - "value": "movie-collection" - }, - "datasource": { - "type": "prometheus", - "uid": "1MRsknzVz" - }, - "definition": "label_values(index)", - "hide": 0, - "includeAll": false, - "label": "index", - "multi": false, - "name": "Index", - "options": [], - "query": { - "query": "label_values(index)", - "refId": "StandardVariableQuery" - }, - "refresh": 1, - "regex": "", - "skipUrlSync": false, - "sort": 0, - "type": "query" + "tooltip": { + "mode": "single", + "sort": "none" } - ] + }, + "pluginVersion": "8.1.4", + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "nb_tasks{instance=\"$instance\", job=\"meilisearch\", kind=\"statuses\"}", + "interval": "", + "legendFormat": "{{value}} ", + "range": true, + "refId": "A" + } + ], + "title": "Number of tasks by statuses", + "type": "timeseries" }, - "time": { - "from": "now-15m", - "to": "now" + { + "datasource": { + "type": "prometheus", + "uid": "bb3298a4-9acf-4da1-b86a-813f29f50888" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 15, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 12, + "x": 12, + "y": 30 + }, + "id": 24, + "interval": "5s", + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "8.1.4", + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "nb_tasks{instance=\"$instance\", job=\"meilisearch\", kind=\"types\"}", + "interval": "", + "legendFormat": "{{value}} ", + "range": true, + "refId": "A" + } + ], + "title": "Number of tasks by types", + "type": "timeseries" }, - "timepicker": { - "refresh_intervals": [ - "5s", - "10s", - "30s", - "1m", - "5m" - ] + { + "datasource": { + "type": "prometheus", + "uid": "bb3298a4-9acf-4da1-b86a-813f29f50888" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 15, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "none" + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 12, + "x": 0, + "y": 41 + }, + "id": 25, + "interval": "5s", + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "8.1.4", + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "nb_tasks{instance=\"$instance\", job=\"meilisearch\", kind=\"indexes\"}", + "interval": "", + "legendFormat": "{{value}} ", + "range": true, + "refId": "A" + } + ], + "title": "Number of tasks by indexes", + "type": "timeseries" }, - "timezone": "", - "title": "Meilisearch", - "uid": "7wcZ94dnz", - "version": 47, - "weekStart": "" - } \ No newline at end of file + { + "collapsed": false, + "datasource": { + "type": "prometheus", + "uid": "i51CxikVz" + }, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 52 + }, + "id": 12, + "panels": [], + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "i51CxikVz" + }, + "refId": "A" + } + ], + "title": "System metrics", + "type": "row" + }, + { + "datasource": { + "type": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-YlBl" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 15, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "decimals": 2, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percentunit" + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 12, + "x": 0, + "y": 53 + }, + "id": 4, + "interval": "5s", + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "rate(process_cpu_seconds_total{job=\"meilisearch\", instance=\"$instance\"}[1m])", + "interval": "", + "legendFormat": "process", + "range": true, + "refId": "A" + }, + { + "datasource": { + "type": "prometheus" + }, + "exemplar": true, + "expr": "sum(rate(container_cpu_usage_seconds_total{name='mongodb-redis'}[1m])) by (name)", + "interval": "", + "legendFormat": "container", + "refId": "B" + } + ], + "title": "CPU usage", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-YlBl" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "MiB", + "axisPlacement": "left", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 15, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 12, + "x": 12, + "y": 53 + }, + "id": 5, + "interval": "5s", + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "process_resident_memory_bytes{job=\"meilisearch\", instance=\"$instance\"} / 1024 / 1024", + "interval": "", + "legendFormat": "process", + "range": true, + "refId": "A" + }, + { + "datasource": { + "type": "prometheus" + }, + "exemplar": true, + "expr": "container_memory_usage_bytes{name=\"mongodb-redis\"} / 1024 / 1024", + "interval": "", + "legendFormat": "container", + "refId": "B" + } + ], + "title": "Memory usage", + "type": "timeseries" + } + ], + "refresh": "5s", + "schemaVersion": 38, + "style": "dark", + "tags": [], + "templating": { + "list": [ + { + "current": { + "selected": false, + "text": "localhost:7700", + "value": "localhost:7700" + }, + "datasource": { + "type": "prometheus", + "uid": "bb3298a4-9acf-4da1-b86a-813f29f50888" + }, + "definition": "label_values(instance)", + "hide": 0, + "includeAll": false, + "label": "Instance", + "multi": false, + "name": "instance", + "options": [], + "query": { + "query": "label_values(instance)", + "refId": "StandardVariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + }, + { + "current": { + "selected": false, + "text": "mieli", + "value": "mieli" + }, + "datasource": { + "type": "prometheus", + "uid": "bb3298a4-9acf-4da1-b86a-813f29f50888" + }, + "definition": "label_values(index)", + "hide": 0, + "includeAll": false, + "label": "index", + "multi": false, + "name": "Index", + "options": [], + "query": { + "query": "label_values(index)", + "refId": "StandardVariableQuery" + }, + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 0, + "type": "query" + } + ] + }, + "time": { + "from": "now-5m", + "to": "now" + }, + "timepicker": { + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m" + ] + }, + "timezone": "", + "title": "Meilisearch", + "uid": "7wcZ94dnz", + "version": 6, + "weekStart": "" +} \ No newline at end of file diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index af20ba1ae..a05be8afb 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -31,7 +31,7 @@ mod uuid_codec; pub type Result = std::result::Result; pub type TaskId = u32; -use std::collections::HashMap; +use std::collections::{BTreeMap, HashMap}; use std::ops::{Bound, RangeBounds}; use std::path::{Path, PathBuf}; use std::sync::atomic::AtomicBool; @@ -737,6 +737,34 @@ impl IndexScheduler { Ok(tasks) } + pub fn get_stats(&self) -> Result>> { + let rtxn = self.read_txn()?; + + let mut res = BTreeMap::new(); + + res.insert( + "statuses".to_string(), + enum_iterator::all::() + .map(|s| Ok((s.to_string(), self.get_status(&rtxn, s)?.len()))) + .collect::>>()?, + ); + res.insert( + "types".to_string(), + enum_iterator::all::() + .map(|s| Ok((s.to_string(), self.get_kind(&rtxn, s)?.len()))) + .collect::>>()?, + ); + res.insert( + "indexes".to_string(), + self.index_tasks + .iter(&rtxn)? + .map(|res| Ok(res.map(|(name, bitmap)| (name.to_string(), bitmap.len()))?)) + .collect::>>()?, + ); + + Ok(res) + } + /// Return true iff there is at least one task associated with this index /// that is processing. pub fn is_index_processing(&self, index: &str) -> Result { diff --git a/meilisearch/src/metrics.rs b/meilisearch/src/metrics.rs index 7ee5241db..4982e19b7 100644 --- a/meilisearch/src/metrics.rs +++ b/meilisearch/src/metrics.rs @@ -40,4 +40,7 @@ lazy_static! { HTTP_RESPONSE_TIME_CUSTOM_BUCKETS.to_vec() ) .expect("Can't create a metric"); + pub static ref NB_TASKS: IntGaugeVec = + register_int_gauge_vec!(opts!("nb_tasks", "Number of tasks"), &["kind", "value"]) + .expect("Can't create a metric"); } diff --git a/meilisearch/src/routes/metrics.rs b/meilisearch/src/routes/metrics.rs index 83cd50542..d3cee4de5 100644 --- a/meilisearch/src/routes/metrics.rs +++ b/meilisearch/src/routes/metrics.rs @@ -39,6 +39,12 @@ pub async fn get_metrics( .set(value.number_of_documents as i64); } + for (kind, value) in index_scheduler.get_stats()? { + for (value, count) in value { + crate::metrics::NB_TASKS.with_label_values(&[&kind, &value]).set(count as i64); + } + } + let encoder = TextEncoder::new(); let mut buffer = vec![]; encoder.encode(&prometheus::gather(), &mut buffer).expect("Failed to encode metrics"); From 35d5556f1f08d762f9cbc9e8b25375b3a937221c Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 25 May 2023 17:41:53 +0200 Subject: [PATCH 04/10] prefix all the metrics by meilisearch_ --- grafana-dashboards/dashboard.json | 108 +++++++++++------------------- meilisearch/src/metrics.rs | 14 ++-- meilisearch/src/middleware.rs | 4 +- meilisearch/src/routes/metrics.rs | 4 +- 4 files changed, 51 insertions(+), 79 deletions(-) diff --git a/grafana-dashboards/dashboard.json b/grafana-dashboards/dashboard.json index 015831173..ec5d8530b 100644 --- a/grafana-dashboards/dashboard.json +++ b/grafana-dashboards/dashboard.json @@ -24,7 +24,7 @@ "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, - "id": 4, + "id": 2, "links": [], "liveNow": false, "panels": [ @@ -59,20 +59,17 @@ "fieldConfig": { "defaults": { "color": { - "mode": "continuous-YlBl" + "mode": "continuous-GrYlRd" }, "decimals": 0, "mappings": [], + "min": 0, "thresholds": { "mode": "absolute", "steps": [ { "color": "green", "value": null - }, - { - "color": "red", - "value": 80 } ] }, @@ -89,6 +86,9 @@ "id": 2, "interval": "5s", "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", "orientation": "auto", "reduceOptions": { "calcs": [ @@ -97,9 +97,7 @@ "fields": "", "values": false }, - "showThresholdLabels": false, - "showThresholdMarkers": true, - "text": {} + "textMode": "auto" }, "pluginVersion": "9.5.2", "targets": [ @@ -117,7 +115,7 @@ } ], "title": "Database Size", - "type": "gauge" + "type": "stat" }, { "datasource": { @@ -243,7 +241,8 @@ }, { "datasource": { - "type": "prometheus" + "type": "prometheus", + "uid": "c4085c47-f6d3-45dd-b761-6809055bb749" }, "fieldConfig": { "defaults": { @@ -295,7 +294,7 @@ }, "editorMode": "builder", "exemplar": true, - "expr": "round(increase(http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[1h]))", + "expr": "round(increase(meilisearch_http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[1h]))", "interval": "", "legendFormat": "", "range": true, @@ -307,7 +306,8 @@ }, { "datasource": { - "type": "prometheus" + "type": "prometheus", + "uid": "c4085c47-f6d3-45dd-b761-6809055bb749" }, "fieldConfig": { "defaults": { @@ -355,7 +355,7 @@ }, "editorMode": "builder", "exemplar": true, - "expr": "round(increase(http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[24h]))", + "expr": "round(increase(meilisearch_http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[24h]))", "interval": "", "legendFormat": "", "range": true, @@ -367,7 +367,8 @@ }, { "datasource": { - "type": "prometheus" + "type": "prometheus", + "uid": "c4085c47-f6d3-45dd-b761-6809055bb749" }, "fieldConfig": { "defaults": { @@ -415,7 +416,7 @@ }, "editorMode": "builder", "exemplar": true, - "expr": "round(increase(http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[30d]))", + "expr": "round(increase(meilisearch_http_requests_total{method=\"POST\", path=\"/indexes/$Index/search\", job=\"meilisearch\"}[30d]))", "interval": "", "legendFormat": "", "range": true, @@ -427,7 +428,8 @@ }, { "datasource": { - "type": "prometheus" + "type": "prometheus", + "uid": "c4085c47-f6d3-45dd-b761-6809055bb749" }, "fieldConfig": { "defaults": { @@ -509,7 +511,7 @@ }, "editorMode": "builder", "exemplar": true, - "expr": "rate(http_requests_total{instance=\"$instance\", job=\"meilisearch\"}[5m])", + "expr": "rate(meilisearch_http_requests_total{instance=\"$instance\", job=\"meilisearch\"}[5m])", "interval": "", "legendFormat": "{{method}} {{path}}", "range": true, @@ -643,7 +645,7 @@ "overrides": [] }, "gridPos": { - "h": 12, + "h": 11, "w": 24, "x": 0, "y": 18 @@ -664,9 +666,9 @@ "exponent": 0.5, "fill": "#b4ff00", "mode": "scheme", - "reverse": false, + "reverse": true, "scale": "exponential", - "scheme": "Blues", + "scheme": "RdYlBu", "steps": 128 }, "exemplars": { @@ -688,7 +690,7 @@ }, "yAxis": { "axisPlacement": "left", - "decimals": 2, + "decimals": 0, "reverse": false, "unit": "s" } @@ -730,10 +732,7 @@ "yBucketNumber": 10 }, { - "datasource": { - "type": "prometheus", - "uid": "bb3298a4-9acf-4da1-b86a-813f29f50888" - }, + "datasource": {}, "fieldConfig": { "defaults": { "color": { @@ -785,38 +784,13 @@ }, "unit": "none" }, - "overrides": [ - { - "__systemRef": "hideSeriesFrom", - "matcher": { - "id": "byNames", - "options": { - "mode": "exclude", - "names": [ - "succeeded " - ], - "prefix": "All except:", - "readOnly": true - } - }, - "properties": [ - { - "id": "custom.hideFrom", - "value": { - "legend": false, - "tooltip": false, - "viz": true - } - } - ] - } - ] + "overrides": [] }, "gridPos": { "h": 11, "w": 12, "x": 0, - "y": 30 + "y": 29 }, "id": 23, "interval": "5s", @@ -840,7 +814,7 @@ }, "editorMode": "builder", "exemplar": true, - "expr": "nb_tasks{instance=\"$instance\", job=\"meilisearch\", kind=\"statuses\"}", + "expr": "meilisearch_nb_tasks{instance=\"$instance\", job=\"meilisearch\", kind=\"statuses\"}", "interval": "", "legendFormat": "{{value}} ", "range": true, @@ -851,10 +825,7 @@ "type": "timeseries" }, { - "datasource": { - "type": "prometheus", - "uid": "bb3298a4-9acf-4da1-b86a-813f29f50888" - }, + "datasource": {}, "fieldConfig": { "defaults": { "color": { @@ -912,7 +883,7 @@ "h": 11, "w": 12, "x": 12, - "y": 30 + "y": 29 }, "id": 24, "interval": "5s", @@ -936,7 +907,7 @@ }, "editorMode": "builder", "exemplar": true, - "expr": "nb_tasks{instance=\"$instance\", job=\"meilisearch\", kind=\"types\"}", + "expr": "meilisearch_nb_tasks{instance=\"$instance\", job=\"meilisearch\", kind=\"types\"}", "interval": "", "legendFormat": "{{value}} ", "range": true, @@ -947,10 +918,7 @@ "type": "timeseries" }, { - "datasource": { - "type": "prometheus", - "uid": "bb3298a4-9acf-4da1-b86a-813f29f50888" - }, + "datasource": {}, "fieldConfig": { "defaults": { "color": { @@ -1008,7 +976,7 @@ "h": 11, "w": 12, "x": 0, - "y": 41 + "y": 40 }, "id": 25, "interval": "5s", @@ -1032,7 +1000,7 @@ }, "editorMode": "builder", "exemplar": true, - "expr": "nb_tasks{instance=\"$instance\", job=\"meilisearch\", kind=\"indexes\"}", + "expr": "meilisearch_nb_tasks{instance=\"$instance\", job=\"meilisearch\", kind=\"indexes\"}", "interval": "", "legendFormat": "{{value}} ", "range": true, @@ -1052,7 +1020,7 @@ "h": 1, "w": 24, "x": 0, - "y": 52 + "y": 51 }, "id": 12, "panels": [], @@ -1130,7 +1098,7 @@ "h": 11, "w": 12, "x": 0, - "y": 53 + "y": 52 }, "id": 4, "interval": "5s", @@ -1233,7 +1201,7 @@ "h": 11, "w": 12, "x": 12, - "y": 53 + "y": 52 }, "id": 5, "interval": "5s", @@ -1355,6 +1323,6 @@ "timezone": "", "title": "Meilisearch", "uid": "7wcZ94dnz", - "version": 6, + "version": 3, "weekStart": "" } \ No newline at end of file diff --git a/meilisearch/src/metrics.rs b/meilisearch/src/metrics.rs index 4982e19b7..07c7706bf 100644 --- a/meilisearch/src/metrics.rs +++ b/meilisearch/src/metrics.rs @@ -17,8 +17,8 @@ fn create_buckets() -> [f64; 29] { lazy_static! { pub static ref HTTP_RESPONSE_TIME_CUSTOM_BUCKETS: [f64; 29] = create_buckets(); - pub static ref HTTP_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!( - opts!("http_requests_total", "HTTP requests total"), + pub static ref MEILISEARCH_HTTP_REQUESTS_TOTAL: IntCounterVec = register_int_counter_vec!( + opts!("meilisearch_http_requests_total", "Meilisearch HTTP requests total"), &["method", "path"] ) .expect("Can't create a metric"); @@ -33,14 +33,16 @@ lazy_static! { &["index"] ) .expect("Can't create a metric"); - pub static ref HTTP_RESPONSE_TIME_SECONDS: HistogramVec = register_histogram_vec!( + pub static ref MEILISEARCH_HTTP_RESPONSE_TIME_SECONDS: HistogramVec = register_histogram_vec!( "http_response_time_seconds", "HTTP response times", &["method", "path"], HTTP_RESPONSE_TIME_CUSTOM_BUCKETS.to_vec() ) .expect("Can't create a metric"); - pub static ref NB_TASKS: IntGaugeVec = - register_int_gauge_vec!(opts!("nb_tasks", "Number of tasks"), &["kind", "value"]) - .expect("Can't create a metric"); + pub static ref MEILISEARCH_NB_TASKS: IntGaugeVec = register_int_gauge_vec!( + opts!("meilisearch_nb_tasks", "Meilisearch Number of tasks"), + &["kind", "value"] + ) + .expect("Can't create a metric"); } diff --git a/meilisearch/src/middleware.rs b/meilisearch/src/middleware.rs index 080a52634..a8c981dca 100644 --- a/meilisearch/src/middleware.rs +++ b/meilisearch/src/middleware.rs @@ -52,11 +52,11 @@ where if is_registered_resource { let request_method = req.method().to_string(); histogram_timer = Some( - crate::metrics::HTTP_RESPONSE_TIME_SECONDS + crate::metrics::MEILISEARCH_HTTP_RESPONSE_TIME_SECONDS .with_label_values(&[&request_method, request_path]) .start_timer(), ); - crate::metrics::HTTP_REQUESTS_TOTAL + crate::metrics::MEILISEARCH_HTTP_REQUESTS_TOTAL .with_label_values(&[&request_method, request_path]) .inc(); } diff --git a/meilisearch/src/routes/metrics.rs b/meilisearch/src/routes/metrics.rs index d3cee4de5..3c9a52e26 100644 --- a/meilisearch/src/routes/metrics.rs +++ b/meilisearch/src/routes/metrics.rs @@ -41,7 +41,9 @@ pub async fn get_metrics( for (kind, value) in index_scheduler.get_stats()? { for (value, count) in value { - crate::metrics::NB_TASKS.with_label_values(&[&kind, &value]).set(count as i64); + crate::metrics::MEILISEARCH_NB_TASKS + .with_label_values(&[&kind, &value]) + .set(count as i64); } } From c9b65677bf153571df274cf959719311821bfc8c Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 25 May 2023 18:30:30 +0200 Subject: [PATCH 05/10] return the on disk size actually used by meilisearch --- grafana-dashboards/dashboard.json | 219 ++++++++++++++---------- index-scheduler/src/index_mapper/mod.rs | 6 +- index-scheduler/src/lib.rs | 6 + meilisearch-auth/src/lib.rs | 5 + meilisearch-auth/src/store.rs | 5 + meilisearch/src/metrics.rs | 7 +- meilisearch/src/routes/metrics.rs | 1 + meilisearch/src/routes/mod.rs | 12 +- 8 files changed, 169 insertions(+), 92 deletions(-) diff --git a/grafana-dashboards/dashboard.json b/grafana-dashboards/dashboard.json index ec5d8530b..b546b4969 100644 --- a/grafana-dashboards/dashboard.json +++ b/grafana-dashboards/dashboard.json @@ -52,71 +52,6 @@ "title": "Web application metrics", "type": "row" }, - { - "datasource": { - "type": "prometheus" - }, - "fieldConfig": { - "defaults": { - "color": { - "mode": "continuous-GrYlRd" - }, - "decimals": 0, - "mappings": [], - "min": 0, - "thresholds": { - "mode": "absolute", - "steps": [ - { - "color": "green", - "value": null - } - ] - }, - "unit": "bytes" - }, - "overrides": [] - }, - "gridPos": { - "h": 6, - "w": 4, - "x": 0, - "y": 1 - }, - "id": 2, - "interval": "5s", - "options": { - "colorMode": "value", - "graphMode": "area", - "justifyMode": "auto", - "orientation": "auto", - "reduceOptions": { - "calcs": [ - "lastNotNull" - ], - "fields": "", - "values": false - }, - "textMode": "auto" - }, - "pluginVersion": "9.5.2", - "targets": [ - { - "datasource": { - "type": "prometheus" - }, - "editorMode": "builder", - "exemplar": true, - "expr": "meilisearch_db_size_bytes{job=\"meilisearch\", instance=\"$instance\"}", - "interval": "", - "legendFormat": "", - "range": true, - "refId": "A" - } - ], - "title": "Database Size", - "type": "stat" - }, { "datasource": { "type": "prometheus" @@ -145,7 +80,7 @@ "gridPos": { "h": 6, "w": 4, - "x": 4, + "x": 0, "y": 1 }, "id": 22, @@ -206,7 +141,7 @@ "gridPos": { "h": 6, "w": 4, - "x": 8, + "x": 4, "y": 1 }, "id": 18, @@ -431,10 +366,11 @@ "type": "prometheus", "uid": "c4085c47-f6d3-45dd-b761-6809055bb749" }, + "description": "", "fieldConfig": { "defaults": { "color": { - "mode": "continuous-YlBl" + "mode": "palette-classic" }, "custom": { "axisCenteredZero": false, @@ -443,7 +379,7 @@ "axisPlacement": "auto", "barAlignment": 0, "drawStyle": "line", - "fillOpacity": 15, + "fillOpacity": 25, "gradientMode": "none", "hideFrom": { "legend": false, @@ -456,18 +392,18 @@ "scaleDistribution": { "type": "linear" }, - "showPoints": "never", + "showPoints": "auto", "spanNulls": false, "stacking": { "group": "A", - "mode": "none" + "mode": "normal" }, "thresholdsStyle": { "mode": "off" } }, - "decimals": 2, "mappings": [], + "min": 0, "thresholds": { "mode": "absolute", "steps": [ @@ -480,7 +416,8 @@ "value": 80 } ] - } + }, + "unit": "bytes" }, "overrides": [] }, @@ -490,13 +427,13 @@ "x": 0, "y": 7 }, - "id": 1, + "id": 2, "interval": "5s", "options": { "legend": { "calcs": [], "displayMode": "list", - "placement": "right", + "placement": "bottom", "showLegend": true }, "tooltip": { @@ -504,6 +441,7 @@ "sort": "none" } }, + "pluginVersion": "9.5.2", "targets": [ { "datasource": { @@ -511,14 +449,26 @@ }, "editorMode": "builder", "exemplar": true, - "expr": "rate(meilisearch_http_requests_total{instance=\"$instance\", job=\"meilisearch\"}[5m])", + "expr": "meilisearch_db_size_bytes{job=\"meilisearch\", instance=\"$instance\"}", "interval": "", - "legendFormat": "{{method}} {{path}}", + "legendFormat": "Database size on disk", "range": true, - "refId": "A" + "refId": "DB Size on disk" + }, + { + "datasource": { + "type": "prometheus", + "uid": "c4085c47-f6d3-45dd-b761-6809055bb749" + }, + "editorMode": "builder", + "expr": "meilisearch_used_db_size_bytes{job=\"meilisearch\", instance=\"$instance\"}", + "hide": false, + "legendFormat": "Used bytes", + "range": true, + "refId": "Actual used bytes" } ], - "title": "HTTP requests per second (All Indexes)", + "title": "Database Size in bytes", "type": "timeseries" }, { @@ -616,6 +566,101 @@ "title": "Mean response time (All Indexes)", "type": "timeseries" }, + { + "datasource": { + "type": "prometheus", + "uid": "c4085c47-f6d3-45dd-b761-6809055bb749" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-YlBl" + }, + "custom": { + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 15, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "never", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "decimals": 2, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 11, + "w": 12, + "x": 0, + "y": 18 + }, + "id": 1, + "interval": "5s", + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "right", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "datasource": { + "type": "prometheus" + }, + "editorMode": "builder", + "exemplar": true, + "expr": "rate(meilisearch_http_requests_total{instance=\"$instance\", job=\"meilisearch\"}[5m])", + "interval": "", + "legendFormat": "{{method}} {{path}}", + "range": true, + "refId": "A" + } + ], + "title": "HTTP requests per second (All Indexes)", + "type": "timeseries" + }, { "cards": {}, "color": { @@ -648,7 +693,7 @@ "h": 11, "w": 24, "x": 0, - "y": 18 + "y": 29 }, "heatmap": {}, "hideZeroBuckets": false, @@ -790,7 +835,7 @@ "h": 11, "w": 12, "x": 0, - "y": 29 + "y": 40 }, "id": 23, "interval": "5s", @@ -883,7 +928,7 @@ "h": 11, "w": 12, "x": 12, - "y": 29 + "y": 40 }, "id": 24, "interval": "5s", @@ -976,7 +1021,7 @@ "h": 11, "w": 12, "x": 0, - "y": 40 + "y": 51 }, "id": 25, "interval": "5s", @@ -1020,7 +1065,7 @@ "h": 1, "w": 24, "x": 0, - "y": 51 + "y": 62 }, "id": 12, "panels": [], @@ -1098,7 +1143,7 @@ "h": 11, "w": 12, "x": 0, - "y": 52 + "y": 63 }, "id": 4, "interval": "5s", @@ -1201,7 +1246,7 @@ "h": 11, "w": 12, "x": 12, - "y": 52 + "y": 63 }, "id": 5, "interval": "5s", @@ -1323,6 +1368,6 @@ "timezone": "", "title": "Meilisearch", "uid": "7wcZ94dnz", - "version": 3, + "version": 4, "weekStart": "" } \ No newline at end of file diff --git a/index-scheduler/src/index_mapper/mod.rs b/index-scheduler/src/index_mapper/mod.rs index 2bf6f46ad..86bec2927 100644 --- a/index-scheduler/src/index_mapper/mod.rs +++ b/index-scheduler/src/index_mapper/mod.rs @@ -90,6 +90,8 @@ pub struct IndexStats { pub number_of_documents: u64, /// Size of the index' DB, in bytes. pub database_size: u64, + /// Size of the index' DB, in bytes. + pub used_database_size: u64, /// Association of every field name with the number of times it occurs in the documents. pub field_distribution: FieldDistribution, /// Creation date of the index. @@ -105,10 +107,10 @@ impl IndexStats { /// /// - rtxn: a RO transaction for the index, obtained from `Index::read_txn()`. pub fn new(index: &Index, rtxn: &RoTxn) -> Result { - let database_size = index.on_disk_size()?; Ok(IndexStats { number_of_documents: index.number_of_documents(rtxn)?, - database_size, + database_size: index.on_disk_size()?, + used_database_size: index.used_size()?, field_distribution: index.field_distribution(rtxn)?, created_at: index.created_at(rtxn)?, updated_at: index.updated_at(rtxn)?, diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index a05be8afb..c27546c8e 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -554,10 +554,16 @@ impl IndexScheduler { &self.index_mapper.indexer_config } + /// Return the real database size (i.e.: The size **with** the free pages) pub fn size(&self) -> Result { Ok(self.env.real_disk_size()?) } + /// Return the used database size (i.e.: The size **without** the free pages) + pub fn used_size(&self) -> Result { + Ok(self.env.non_free_pages_size()?) + } + /// Return the index corresponding to the name. /// /// * If the index wasn't opened before, the index will be opened. diff --git a/meilisearch-auth/src/lib.rs b/meilisearch-auth/src/lib.rs index 2a02776bd..e74f1707c 100644 --- a/meilisearch-auth/src/lib.rs +++ b/meilisearch-auth/src/lib.rs @@ -45,6 +45,11 @@ impl AuthController { self.store.size() } + /// Return the used size of the `AuthController` database in bytes. + pub fn used_size(&self) -> Result { + self.store.used_size() + } + pub fn create_key(&self, create_key: CreateApiKey) -> Result { match self.store.get_api_key(create_key.uid)? { Some(_) => Err(AuthControllerError::ApiKeyAlreadyExists(create_key.uid.to_string())), diff --git a/meilisearch-auth/src/store.rs b/meilisearch-auth/src/store.rs index 5c2776154..eb93f5a46 100644 --- a/meilisearch-auth/src/store.rs +++ b/meilisearch-auth/src/store.rs @@ -73,6 +73,11 @@ impl HeedAuthStore { Ok(self.env.real_disk_size()?) } + /// Return the number of bytes actually used in the database + pub fn used_size(&self) -> Result { + Ok(self.env.non_free_pages_size()?) + } + pub fn set_drop_on_close(&mut self, v: bool) { self.should_close_on_drop = v; } diff --git a/meilisearch/src/metrics.rs b/meilisearch/src/metrics.rs index 07c7706bf..79332f360 100644 --- a/meilisearch/src/metrics.rs +++ b/meilisearch/src/metrics.rs @@ -23,8 +23,13 @@ lazy_static! { ) .expect("Can't create a metric"); pub static ref MEILISEARCH_DB_SIZE_BYTES: IntGauge = - register_int_gauge!(opts!("meilisearch_db_size_bytes", "Meilisearch Db Size In Bytes")) + register_int_gauge!(opts!("meilisearch_db_size_bytes", "Meilisearch DB Size In Bytes")) .expect("Can't create a metric"); + pub static ref MEILISEARCH_USED_DB_SIZE_BYTES: IntGauge = register_int_gauge!(opts!( + "meilisearch_used_db_size_bytes", + "Meilisearch Used DB Size In Bytes" + )) + .expect("Can't create a metric"); pub static ref MEILISEARCH_INDEX_COUNT: IntGauge = register_int_gauge!(opts!("meilisearch_index_count", "Meilisearch Index Count")) .expect("Can't create a metric"); diff --git a/meilisearch/src/routes/metrics.rs b/meilisearch/src/routes/metrics.rs index 3c9a52e26..a7d41e33e 100644 --- a/meilisearch/src/routes/metrics.rs +++ b/meilisearch/src/routes/metrics.rs @@ -31,6 +31,7 @@ pub async fn get_metrics( let response = create_all_stats((*index_scheduler).clone(), auth_controller, auth_filters)?; crate::metrics::MEILISEARCH_DB_SIZE_BYTES.set(response.database_size as i64); + crate::metrics::MEILISEARCH_USED_DB_SIZE_BYTES.set(response.used_database_size as i64); crate::metrics::MEILISEARCH_INDEX_COUNT.set(response.indexes.len() as i64); for (index, value) in response.indexes.iter() { diff --git a/meilisearch/src/routes/mod.rs b/meilisearch/src/routes/mod.rs index 51340ac1b..57d670b5f 100644 --- a/meilisearch/src/routes/mod.rs +++ b/meilisearch/src/routes/mod.rs @@ -231,6 +231,8 @@ pub async fn running() -> HttpResponse { #[serde(rename_all = "camelCase")] pub struct Stats { pub database_size: u64, + #[serde(skip)] + pub used_database_size: u64, #[serde(serialize_with = "time::serde::rfc3339::option::serialize")] pub last_update: Option, pub indexes: BTreeMap, @@ -259,6 +261,7 @@ pub fn create_all_stats( let mut last_task: Option = None; let mut indexes = BTreeMap::new(); let mut database_size = 0; + let mut used_database_size = 0; for index_uid in index_scheduler.index_names()? { // Accumulate the size of all indexes, even unauthorized ones, so @@ -266,6 +269,7 @@ pub fn create_all_stats( // See for context. let stats = index_scheduler.index_stats(&index_uid)?; database_size += stats.inner_stats.database_size; + used_database_size += stats.inner_stats.used_database_size; if !filters.is_index_authorized(&index_uid) { continue; @@ -278,10 +282,14 @@ pub fn create_all_stats( } database_size += index_scheduler.size()?; + used_database_size += index_scheduler.used_size()?; database_size += auth_controller.size()?; - database_size += index_scheduler.compute_update_file_size()?; + used_database_size += auth_controller.used_size()?; + let update_file_size = index_scheduler.compute_update_file_size()?; + database_size += update_file_size; + used_database_size += update_file_size; - let stats = Stats { database_size, last_update: last_task, indexes }; + let stats = Stats { database_size, used_database_size, last_update: last_task, indexes }; Ok(stats) } From 51dce9e9d1f6f7a5a67174dd658ac39604737121 Mon Sep 17 00:00:00 2001 From: Tamo Date: Thu, 25 May 2023 18:33:01 +0200 Subject: [PATCH 06/10] improve the dashboard slightly --- grafana-dashboards/dashboard.json | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/grafana-dashboards/dashboard.json b/grafana-dashboards/dashboard.json index b546b4969..19355650b 100644 --- a/grafana-dashboards/dashboard.json +++ b/grafana-dashboards/dashboard.json @@ -387,6 +387,9 @@ "viz": false }, "lineInterpolation": "linear", + "lineStyle": { + "fill": "solid" + }, "lineWidth": 1, "pointSize": 5, "scaleDistribution": { @@ -396,7 +399,7 @@ "spanNulls": false, "stacking": { "group": "A", - "mode": "normal" + "mode": "none" }, "thresholdsStyle": { "mode": "off" @@ -1368,6 +1371,6 @@ "timezone": "", "title": "Meilisearch", "uid": "7wcZ94dnz", - "version": 4, + "version": 5, "weekStart": "" } \ No newline at end of file From 1213ec716467d689bb0699d94cf272cf10acce58 Mon Sep 17 00:00:00 2001 From: Tamo Date: Mon, 29 May 2023 18:37:55 +0200 Subject: [PATCH 07/10] update the dashboard once again --- grafana-dashboards/dashboard.json | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/grafana-dashboards/dashboard.json b/grafana-dashboards/dashboard.json index 19355650b..d00069293 100644 --- a/grafana-dashboards/dashboard.json +++ b/grafana-dashboards/dashboard.json @@ -694,9 +694,9 @@ }, "gridPos": { "h": 11, - "w": 24, - "x": 0, - "y": 29 + "w": 12, + "x": 12, + "y": 18 }, "heatmap": {}, "hideZeroBuckets": false, @@ -711,12 +711,12 @@ "cellGap": 2, "cellValues": {}, "color": { - "exponent": 0.5, + "exponent": 0.4, "fill": "#b4ff00", "mode": "scheme", - "reverse": true, + "reverse": false, "scale": "exponential", - "scheme": "RdYlBu", + "scheme": "Blues", "steps": 128 }, "exemplars": { @@ -838,7 +838,7 @@ "h": 11, "w": 12, "x": 0, - "y": 40 + "y": 29 }, "id": 23, "interval": "5s", @@ -931,7 +931,7 @@ "h": 11, "w": 12, "x": 12, - "y": 40 + "y": 29 }, "id": 24, "interval": "5s", @@ -1024,7 +1024,7 @@ "h": 11, "w": 12, "x": 0, - "y": 51 + "y": 40 }, "id": 25, "interval": "5s", @@ -1068,7 +1068,7 @@ "h": 1, "w": 24, "x": 0, - "y": 62 + "y": 51 }, "id": 12, "panels": [], @@ -1146,7 +1146,7 @@ "h": 11, "w": 12, "x": 0, - "y": 63 + "y": 52 }, "id": 4, "interval": "5s", @@ -1249,7 +1249,7 @@ "h": 11, "w": 12, "x": 12, - "y": 63 + "y": 52 }, "id": 5, "interval": "5s", @@ -1371,6 +1371,6 @@ "timezone": "", "title": "Meilisearch", "uid": "7wcZ94dnz", - "version": 5, + "version": 6, "weekStart": "" } \ No newline at end of file From 85a80f4f4c2003113b70bee54d151b8c59ff5e05 Mon Sep 17 00:00:00 2001 From: Tamo Date: Mon, 29 May 2023 18:39:34 +0200 Subject: [PATCH 08/10] move the grafana dashboard to the assets directory and upload a basic prometheus scraper to help new users --- .../grafana-dashboard.json | 0 assets/prometheus-basic-scraper.yml | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) rename grafana-dashboards/dashboard.json => assets/grafana-dashboard.json (100%) create mode 100644 assets/prometheus-basic-scraper.yml diff --git a/grafana-dashboards/dashboard.json b/assets/grafana-dashboard.json similarity index 100% rename from grafana-dashboards/dashboard.json rename to assets/grafana-dashboard.json diff --git a/assets/prometheus-basic-scraper.yml b/assets/prometheus-basic-scraper.yml new file mode 100644 index 000000000..762f0ad43 --- /dev/null +++ b/assets/prometheus-basic-scraper.yml @@ -0,0 +1,19 @@ +global: + scrape_interval: 15s # By default, scrape targets every 15 seconds. + + # Attach these labels to any time series or alerts when communicating with + # external systems (federation, remote storage, Alertmanager). + external_labels: + monitor: 'codelab-monitor' + +# A scrape configuration containing exactly one endpoint to scrape: +# Here it's Prometheus itself. +scrape_configs: + # The job name is added as a label `job=` to any timeseries scraped from this config. + - job_name: 'meilisearch' + + # Override the global default and scrape targets from this job every 5 seconds. + scrape_interval: 5s + + static_configs: + - targets: ['localhost:7700'] \ No newline at end of file From 3cfd653db1cbed174d6b9d727d38b361db0aac33 Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 6 Jun 2023 11:38:41 +0200 Subject: [PATCH 09/10] Apply suggestions from code review Co-authored-by: Louis Dureuil --- index-scheduler/src/index_mapper/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index-scheduler/src/index_mapper/mod.rs b/index-scheduler/src/index_mapper/mod.rs index 86bec2927..e5bac4d30 100644 --- a/index-scheduler/src/index_mapper/mod.rs +++ b/index-scheduler/src/index_mapper/mod.rs @@ -88,9 +88,16 @@ pub enum IndexStatus { pub struct IndexStats { /// Number of documents in the index. pub number_of_documents: u64, - /// Size of the index' DB, in bytes. + /// Size taken up by the index' DB, in bytes. + /// + /// This includes the size taken by both the used and free pages of the DB, and as the free pages + /// are not returned to the disk after a deletion, this number is typically larger than + /// `used_database_size` that only includes the size of the used pages. pub database_size: u64, - /// Size of the index' DB, in bytes. + /// Size taken by the used pages of the index' DB, in bytes. + /// + /// As the DB backend does not return to the disk the pages that are not currently used by the DB, + /// this value is typically smaller than `database_size`. pub used_database_size: u64, /// Association of every field name with the number of times it occurs in the documents. pub field_distribution: FieldDistribution, From 4a3405afec696b2a947b1ac45e6fdd8dc6e46cea Mon Sep 17 00:00:00 2001 From: Tamo Date: Tue, 6 Jun 2023 12:28:27 +0200 Subject: [PATCH 10/10] comment the stats method --- index-scheduler/src/index_mapper/mod.rs | 2 +- index-scheduler/src/lib.rs | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/index-scheduler/src/index_mapper/mod.rs b/index-scheduler/src/index_mapper/mod.rs index e5bac4d30..8754e7168 100644 --- a/index-scheduler/src/index_mapper/mod.rs +++ b/index-scheduler/src/index_mapper/mod.rs @@ -91,7 +91,7 @@ pub struct IndexStats { /// Size taken up by the index' DB, in bytes. /// /// This includes the size taken by both the used and free pages of the DB, and as the free pages - /// are not returned to the disk after a deletion, this number is typically larger than + /// are not returned to the disk after a deletion, this number is typically larger than /// `used_database_size` that only includes the size of the used pages. pub database_size: u64, /// Size taken by the used pages of the index' DB, in bytes. diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index c27546c8e..40570c668 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -743,6 +743,10 @@ impl IndexScheduler { Ok(tasks) } + /// The returned structure contains: + /// 1. The name of the property being observed can be `statuses`, `types`, or `indexes`. + /// 2. The name of the specific data related to the property can be `enqueued` for the `statuses`, `settingsUpdate` for the `types`, or the name of the index for the `indexes`, for example. + /// 3. The number of times the properties appeared. pub fn get_stats(&self) -> Result>> { let rtxn = self.read_txn()?;