Krish Shah-Nathwani commited on
Commit
a43adb2
·
2 Parent(s): 6a1edf3 a3dcce3

awesome sauce with ports

Browse files
Files changed (2) hide show
  1. app.py +5 -0
  2. metrics.py +1 -15
app.py CHANGED
@@ -12,6 +12,11 @@ CHORDS = {
12
  frozenset(["F", "A", "C"]): "F Major",
13
  }
14
 
 
 
 
 
 
15
  def identify_chord(notes):
16
  """
17
  Identify chord name from a list of notes using dictionary lookup.
 
12
  frozenset(["F", "A", "C"]): "F Major",
13
  }
14
 
15
+ init_metrics(
16
+ port=int(os.getenv("METRICS_PORT", "8000")),
17
+ service_name=os.getenv("SERVICE_NAME", "chord-bot-api"),
18
+ )
19
+
20
  def identify_chord(notes):
21
  """
22
  Identify chord name from a list of notes using dictionary lookup.
metrics.py CHANGED
@@ -57,11 +57,6 @@ ACTIVE_REQUESTS = Gauge(
57
 
58
 
59
  def init_metrics(port: int = 8000, service_name: str | None = None) -> None:
60
- """
61
- Start the Prometheus metrics HTTP server on `port`.
62
-
63
- Call this once at app startup (before serving requests).
64
- """
65
  global SERVICE_NAME
66
 
67
  if service_name is not None:
@@ -73,16 +68,7 @@ def init_metrics(port: int = 8000, service_name: str | None = None) -> None:
73
 
74
 
75
  def instrument_chord_request(endpoint: str, note_tokens, chord_label: str | None, status: str, elapsed_seconds: float) -> None:
76
- """
77
- Helper you can call from your endpoint / handler *after* processing a request.
78
-
79
- Parameters:
80
- endpoint - logical endpoint name, e.g. "analyze" or "predict"
81
- note_tokens - list of parsed notes (e.g., ["C", "E", "G"]) or None
82
- chord_label - predicted chord label (e.g., "Cmaj") or None if invalid/failed
83
- status - "success", "invalid_input", or "error"
84
- elapsed_seconds - wall-clock latency for the request
85
- """
86
 
87
  REQUEST_COUNT.labels(
88
  service=SERVICE_NAME,
 
57
 
58
 
59
  def init_metrics(port: int = 8000, service_name: str | None = None) -> None:
 
 
 
 
 
60
  global SERVICE_NAME
61
 
62
  if service_name is not None:
 
68
 
69
 
70
  def instrument_chord_request(endpoint: str, note_tokens, chord_label: str | None, status: str, elapsed_seconds: float) -> None:
71
+
 
 
 
 
 
 
 
 
 
72
 
73
  REQUEST_COUNT.labels(
74
  service=SERVICE_NAME,