move prometheus behind a feature flag

This commit is contained in:
Tamo 2022-08-29 12:36:54 +02:00 committed by Kerollmops
parent 47a1aa69f0
commit 6aa3ad6b6c
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
7 changed files with 79 additions and 47 deletions

View file

@ -1,4 +1,3 @@
use actix_web::http::header::{self};
use actix_web::{web, HttpRequest, HttpResponse};
use log::debug;
use serde::{Deserialize, Serialize};
@ -13,7 +12,6 @@ use meilisearch_types::star_or::StarOr;
use crate::analytics::Analytics;
use crate::extractors::authentication::{policies::*, GuardedData};
use prometheus::{Encoder, TextEncoder};
mod api_key;
mod dump;
@ -280,31 +278,3 @@ struct KeysResponse {
pub async fn get_health() -> Result<HttpResponse, ResponseError> {
Ok(HttpResponse::Ok().json(serde_json::json!({ "status": "available" })))
}
pub async fn get_metrics(
meilisearch: GuardedData<ActionPolicy<{ actions::METRICS_GET }>, MeiliSearch>,
) -> Result<HttpResponse, ResponseError> {
let search_rules = &meilisearch.filters().search_rules;
let response = meilisearch.get_all_stats(search_rules).await?;
crate::metrics::MEILISEARCH_DB_SIZE_BYTES.set(response.database_size as i64);
crate::metrics::MEILISEARCH_INDEX_COUNT.set(response.indexes.len() as i64);
for (index, value) in response.indexes.iter() {
crate::metrics::MEILISEARCH_INDEX_DOCS_COUNT
.with_label_values(&[index])
.set(value.number_of_documents as i64);
}
let encoder = TextEncoder::new();
let mut buffer = vec![];
encoder
.encode(&prometheus::gather(), &mut buffer)
.expect("Failed to encode metrics");
let response = String::from_utf8(buffer).expect("Failed to convert bytes to string");
Ok(HttpResponse::Ok()
.insert_header(header::ContentType(mime::TEXT_PLAIN))
.body(response))
}