Skip to content

Commit 0b12481

Browse files
chore: bug fixes
Signed-off-by: deepak-linux <[email protected]>
1 parent 73bd067 commit 0b12481

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

src/models/user_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class UserProfile(db.Model, UserMixin):
1818
__tablename__ = 'users'
1919

2020
id = db.Column(db.Integer, primary_key=True)
21-
username = db.Column(db.String(50), unique=True, nullable=False)
21+
username = db.Column(db.String(50), index=True, unique=True, nullable=False)
2222
email = db.Column(db.String(100), unique=True, nullable=False)
2323
password = db.Column(db.String(100), nullable=False)
2424
user_level = db.Column(db.String(10), nullable=False, default='user')

src/routes/prometheus.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from collections import OrderedDict
66
from werkzeug.security import check_password_hash
77

8+
from functools import lru_cache
9+
from flask import g # 'g' is a request-specific object
810
from src.config import app, db
911
from src.models import ExternalMonitornig, UserProfile
1012
from src.utils import ROOT_DIR
@@ -18,14 +20,21 @@
1820
update_prometheus_container,
1921
update_prometheus_config)
2022

21-
2223
# Define the Prometheus Blueprint
2324
prometheus_bp = Blueprint('prometheus', __name__)
2425

26+
# Cache user queries with LRU cache (memory-based, not ideal for distributed apps)
27+
@lru_cache(maxsize=128)
28+
def get_user_by_username(username):
29+
print('Querying the database...')
30+
return UserProfile.query.filter_by(username=username).first()
31+
32+
# Verify user login information
2533
def verify_user(username, password):
26-
user = UserProfile.query.filter_by(username=username).first()
34+
user = get_user_by_username(username)
2735
if user and check_password_hash(user.password, password):
2836
return True
37+
return False
2938

3039
# Define a route to serve Prometheus metrics
3140
@app.route('/metrics')

src/scripts/prometheus.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ run_output=$(docker run -d \
8989
-p "$PROMETHEUS_PORT:$PROMETHEUS_PORT" \
9090
--restart always \
9191
-v "$PROMETHEUS_CONFIG_FILE:/etc/prometheus/prometheus.yml" \
92-
-v "PROMETHEUS_DATA_DIR:/prometheus" \
93-
"$PROMETHEUS_IMAGE" 2>&1) # Capture both stdout and stderr
92+
-v "$PROMETHEUS_DATA_DIR:/prometheus" \
93+
"$PROMETHEUS_IMAGE" 2>&1)
9494

9595
# Check if Prometheus started successfully
9696
if [ $? -eq 0 ]; then

src/scripts/update_prometheus.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ else
5151
-p "$PROMETHEUS_PORT:$PROMETHEUS_PORT" \
5252
--restart always \
5353
-v "$PROMETHEUS_CONFIG:/etc/prometheus/prometheus.yml" \
54-
-v "PROMETHEUS_DATA_DIR:/prometheus" \
54+
-v "$PROMETHEUS_DATA_DIR:/prometheus" \
5555
"$PROMETHEUS_IMAGE" &> /dev/null
5656

5757
log "Prometheus container started successfully."

0 commit comments

Comments
 (0)