mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-04 08:09:27 +00:00
fix: use result cache env for metrics (#9281)
This commit is contained in:
@@ -1170,12 +1170,6 @@ pub struct Common {
|
||||
help = "Strategy to use for result cache, default is both, possible value - both, overlap, duration"
|
||||
)]
|
||||
pub result_cache_selection_strategy: String,
|
||||
#[env_config(
|
||||
name = "ZO_METRICS_CACHE_ENABLED",
|
||||
default = true,
|
||||
help = "Enable result cache for PromQL metrics queries"
|
||||
)]
|
||||
pub metrics_cache_enabled: bool,
|
||||
#[env_config(name = "ZO_SWAGGER_ENABLED", default = true)]
|
||||
pub swagger_enabled: bool,
|
||||
#[env_config(
|
||||
@@ -2812,16 +2806,14 @@ fn check_disk_cache_config(cfg: &mut Config) -> Result<(), anyhow::Error> {
|
||||
// disable disk cache for local disk storage
|
||||
if cfg.common.is_local_storage
|
||||
&& !cfg.common.result_cache_enabled
|
||||
&& !cfg.common.metrics_cache_enabled
|
||||
&& !cfg.common.feature_query_streaming_aggs
|
||||
{
|
||||
cfg.disk_cache.enabled = false;
|
||||
}
|
||||
|
||||
// disable result cache and metrics cache if disk cache is disabled
|
||||
// disable result cache if disk cache is disabled
|
||||
if !cfg.disk_cache.enabled {
|
||||
cfg.common.result_cache_enabled = false;
|
||||
cfg.common.metrics_cache_enabled = false;
|
||||
cfg.common.feature_query_streaming_aggs = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -179,9 +179,7 @@ async fn dispatch(
|
||||
}
|
||||
|
||||
// check if the request need to be proxied by body
|
||||
if (cfg.common.result_cache_enabled || cfg.common.metrics_cache_enabled)
|
||||
&& is_querier_route_by_body(&path)
|
||||
{
|
||||
if cfg.common.result_cache_enabled && is_querier_route_by_body(&path) {
|
||||
return proxy_querier_by_body(req, payload, client, new_url, start).await;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -55,7 +55,7 @@ static GLOBAL_CACHE: Lazy<Vec<RwLock<MetricsIndex>>> = Lazy::new(|| {
|
||||
|
||||
pub async fn init() -> Result<()> {
|
||||
let cfg = get_config();
|
||||
if !cfg.common.metrics_cache_enabled {
|
||||
if !cfg.common.result_cache_enabled {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ pub async fn set(
|
||||
/// load the cache item from the secondary storage
|
||||
pub async fn load(cache_key: &str) -> Result<()> {
|
||||
let cfg = get_config();
|
||||
if !cfg.common.metrics_cache_enabled {
|
||||
if !cfg.common.result_cache_enabled {
|
||||
return Ok(());
|
||||
}
|
||||
let Some((key, start, end)) = parse_cache_item_key(cache_key) else {
|
||||
|
||||
@@ -100,7 +100,7 @@ async fn search_in_cluster(
|
||||
|
||||
// cache disabled if result cache is disabled or use_cache is false or start == end or step == 0
|
||||
let cache_disabled =
|
||||
!cfg.common.metrics_cache_enabled || !req.use_cache || start == end || step == 0;
|
||||
!cfg.common.result_cache_enabled || !req.use_cache || start == end || step == 0;
|
||||
// adjust start and end time
|
||||
let (start, end) = adjust_start_end(start, end, step);
|
||||
|
||||
@@ -144,11 +144,13 @@ async fn search_in_cluster(
|
||||
match cache::get(query, start, end, step).await {
|
||||
Ok(Some((new_start, values))) => {
|
||||
let took = start_time.elapsed().as_millis() as i32;
|
||||
let cache_ratio = (new_start - start) as f64 / (end - start) as f64;
|
||||
config::metrics::QUERY_METRICS_CACHE_RATIO
|
||||
.with_label_values(&[&req.org_id])
|
||||
.observe((new_start - start) as f64 / (end - start) as f64);
|
||||
.observe(cache_ratio);
|
||||
log::info!(
|
||||
"[trace_id {trace_id}] promql->search->cache: hit cache, took: {took} ms"
|
||||
"[trace_id {trace_id}] promql->search->cache: hit cache, cache ratio: {:.2}%, took: {took} ms",
|
||||
cache_ratio * 100.0,
|
||||
);
|
||||
(new_start, values)
|
||||
}
|
||||
@@ -348,7 +350,7 @@ async fn search_in_cluster(
|
||||
.await;
|
||||
|
||||
// cache the result
|
||||
if cfg.common.metrics_cache_enabled
|
||||
if cfg.common.result_cache_enabled
|
||||
&& let Some(matrix) = values.get_ref_matrix_values()
|
||||
&& let Err(err) = cache::set(
|
||||
trace_id,
|
||||
|
||||
Reference in New Issue
Block a user