github-actions[bot] commited on
Commit
0ae19f1
·
1 Parent(s): 82e122c

Sync from GitHub main

Browse files
Files changed (2) hide show
  1. app/cache.py +4 -7
  2. app/routers/nl2sql.py +0 -7
app/cache.py CHANGED
@@ -3,10 +3,7 @@ from __future__ import annotations
3
  import time
4
  from typing import Any, Dict, Optional, Tuple
5
 
6
- from prometheus_client import Counter
7
-
8
- cache_hits_total = Counter("nl2sql_cache_hits", "NL2SQL cache hits")
9
- cache_misses_total = Counter("nl2sql_cache_misses", "NL2SQL cache misses")
10
 
11
 
12
  class NL2SQLCache:
@@ -37,17 +34,17 @@ class NL2SQLCache:
37
 
38
  entry = self._store.get(key)
39
  if entry is None:
40
- cache_misses_total.inc()
41
  return None
42
 
43
  ts, payload = entry
44
  if now - ts <= self.ttl:
45
- cache_hits_total.inc()
46
  return payload
47
 
48
  # Entry is expired
49
  del self._store[key]
50
- cache_misses_total.inc()
51
  return None
52
 
53
  def set(self, key: str, payload: Dict[str, Any]) -> None:
 
3
  import time
4
  from typing import Any, Dict, Optional, Tuple
5
 
6
+ from nl2sql.metrics import cache_events_total
 
 
 
7
 
8
 
9
  class NL2SQLCache:
 
34
 
35
  entry = self._store.get(key)
36
  if entry is None:
37
+ cache_events_total.labels(hit="false").inc()
38
  return None
39
 
40
  ts, payload = entry
41
  if now - ts <= self.ttl:
42
+ cache_events_total.labels(hit="true").inc()
43
  return payload
44
 
45
  # Entry is expired
46
  del self._store[key]
47
+ cache_events_total.labels(hit="false").inc()
48
  return None
49
 
50
  def set(self, key: str, payload: Dict[str, Any]) -> None:
app/routers/nl2sql.py CHANGED
@@ -12,13 +12,11 @@ import logging
12
  # --- Third-party ---
13
  from fastapi import APIRouter, Depends, HTTPException, Security, UploadFile, File
14
  from fastapi.security import APIKeyHeader
15
- from prometheus_client import Counter
16
 
17
  # --- Local ---
18
  from app.schemas import NL2SQLRequest, NL2SQLResponse, ClarifyResponse
19
  from app.state import register_db
20
  from nl2sql.pipeline import FinalResult
21
- from nl2sql.prom import REGISTRY
22
  from app.dependencies import get_cache, get_nl2sql_service
23
  from app.cache import NL2SQLCache
24
  from app.services.nl2sql_service import NL2SQLService
@@ -52,11 +50,6 @@ def require_api_key(key: Optional[str] = Security(api_key_header)):
52
  ####################################
53
  # ---- Simple in-memory cache for NL→SQL responses ----
54
 
55
- cache_hits_total = Counter("cache_hits_total", "NL2SQL cache hits", registry=REGISTRY)
56
- cache_misses_total = Counter(
57
- "cache_misses_total", "NL2SQL cache misses", registry=REGISTRY
58
- )
59
-
60
  # Cache TTL and max size from centralized settings
61
  _CACHE_TTL = settings.cache_ttl_sec
62
  _CACHE_MAX = settings.cache_max_entries
 
12
  # --- Third-party ---
13
  from fastapi import APIRouter, Depends, HTTPException, Security, UploadFile, File
14
  from fastapi.security import APIKeyHeader
 
15
 
16
  # --- Local ---
17
  from app.schemas import NL2SQLRequest, NL2SQLResponse, ClarifyResponse
18
  from app.state import register_db
19
  from nl2sql.pipeline import FinalResult
 
20
  from app.dependencies import get_cache, get_nl2sql_service
21
  from app.cache import NL2SQLCache
22
  from app.services.nl2sql_service import NL2SQLService
 
50
  ####################################
51
  # ---- Simple in-memory cache for NL→SQL responses ----
52
 
 
 
 
 
 
53
  # Cache TTL and max size from centralized settings
54
  _CACHE_TTL = settings.cache_ttl_sec
55
  _CACHE_MAX = settings.cache_max_entries