Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/350 Fix ConfigParser Error for New Teams Workflow URL (#350) #356

Open
wants to merge 16 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.8-alpine AS builder
FROM python:3.8.20-alpine3.20 AS builder
WORKDIR /prom2teams
COPY LICENSE \
MANIFEST.in \
Expand All @@ -8,19 +8,28 @@ COPY LICENSE \
./
COPY prom2teams/ prom2teams
COPY bin/ bin
RUN apk add --no-cache gcc musl-dev libffi-dev pcre-dev
RUN pip install --upgrade pip && \
pip install --upgrade setuptools==65.5.1 && \
pip install Flask==2.2.5 Werkzeug==2.2.3 uWSGI==2.0.22
RUN apk add gcc libc-dev yaml-dev linux-headers --no-cache \
&& python setup.py bdist_wheel

FROM python:3.8-alpine
FROM python:3.8.20-alpine3.20
LABEL maintainer="[email protected]"
EXPOSE 8089
EXPOSE 9090
WORKDIR /opt/prom2teams
COPY docker/rootfs .
COPY --from=builder /prom2teams/dist .
COPY bin/wsgi.py ./wsgi.py
RUN apk add --no-cache gcc musl-dev libffi-dev pcre-dev && \
pip install --upgrade pip && \
pip install --upgrade setuptools==70.0.0 && \
pip install Flask==2.2.5 Werkzeug==2.2.3 uWSGI==2.0.22
RUN apk add gcc libc-dev yaml-dev linux-headers pcre pcre-dev --no-cache \
&& pip install prom2teams*.whl
&& pip install prom2teams*.whl
RUN apk del gcc musl-dev libffi-dev
RUN addgroup -g "101" -S prom2teams && \
adduser -S prom2teams -G prom2teams -u "101" && \
mkdir -p /var/log/prom2teams && \
Expand Down
8 changes: 6 additions & 2 deletions bin/prom2teams
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
#!/usr/bin/env python3
import sys
import os
from werkzeug.serving import run_simple
from functools import cached_property
from flask import Flask

app = Flask(__name__)

try:
from prom2teams.app.api import app as application
except ImportError:
sys.path.append(os.path.abspath('./'))
from prom2teams.app.api import app as application


if __name__ == "__main__":
application.config['ENV'] = "werkzeug"
host = application.config['HOST']
port = int(application.config['PORT'])
run_simple(hostname=host, port=port, application=application, use_reloader=True,
app.run(hostname=host, port=port, application=application, use_reloader=True,
reloader_type='stat', reloader_interval=5, extra_files=[application.config['APP_CONFIG_FILE']])

3 changes: 2 additions & 1 deletion prom2teams/app/configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse
from configparser import RawConfigParser
import configparser
import logging.config

Expand Down Expand Up @@ -60,7 +61,7 @@ def _update_application_configuration(application, configuration):


def _config_provided(filepath):
config = configparser.ConfigParser()
config = RawConfigParser()
try:
with open(filepath) as f_prov:
config.read_file(f_prov)
Expand Down
2 changes: 1 addition & 1 deletion prom2teams/app/versions/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from flask_restplus import Api
from flask_restx import Api

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion prom2teams/app/versions/v1/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask_restplus import fields
from flask_restx import fields
from . import api_v1

annotations = api_v1.model('annotations', {
Expand Down
2 changes: 1 addition & 1 deletion prom2teams/app/versions/v1/namespace.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings

from flask import request, current_app as app
from flask_restplus import Resource
from flask_restx import Resource

from prom2teams.app.sender import AlertSender
from prom2teams.prometheus.message_schema import MessageSchema
Expand Down
27 changes: 24 additions & 3 deletions prom2teams/app/versions/v2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from flask_restplus import Api
from flask_restx import Api
from werkzeug.exceptions import HTTPException

log = logging.getLogger(__name__)

Expand All @@ -9,6 +10,26 @@

@api_v2.errorhandler
def default_error_handler(e):
# Define a default error message at the start
msg = 'An unhandled exception occurred.'
log.exception(msg + e)
return {'message': msg}, 500

# Log the full stack trace for debugging
# log.exception(f"{msg}: {str(e)}\n{traceback.format_exc()}")

# Customize the response based on the type of exception
if isinstance(e, HTTPException):
# Set a specific message for HTTPException
msg = e.description
# Return a dictionary for the HTTPException's description and code
return {'message': msg}, e.code
elif isinstance(e, ValueError):
# For ValueError, set a specific message and return a 400 Bad Request code
msg = 'Invalid value provided.'
return {'message': msg}, 400
elif isinstance(e, KeyError):
# For KeyError, set a specific message and return a 400 Bad Request code
msg = 'Missing required data or missing Connector.'
return {'message': msg}, 400
else:
# Generic response for other unhandled exceptions
return {'message': msg}, 500
2 changes: 1 addition & 1 deletion prom2teams/app/versions/v2/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask_restplus import fields
from flask_restx import fields
from . import api_v2

annotations = api_v2.model('annotations', {
Expand Down
2 changes: 1 addition & 1 deletion prom2teams/app/versions/v2/namespace.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import request, current_app as app
from flask_restplus import Resource
from flask_restx import Resource

from prom2teams.app.sender import AlertSender
from prom2teams.prometheus.message_schema import MessageSchema
Expand Down
18 changes: 9 additions & 9 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
requests==2.20.1
flask-restplus==0.12.1
requests==2.32.0
flask-restx==1.3.0
marshmallow==3.0.0rc6
jinja2==2.11.3
Flask==1.0.2
jinja2==3.1.4
Flask==2.2.5
pyyaml==6.0.1
uwsgi==2.0.20
prometheus_flask_exporter==0.9.0
werkzeug==0.16.1
uwsgi==2.0.22
prometheus_flask_exporter==0.23.1
werkzeug==3.0.3
DeepDiff==4.3.0
zipp==3.1.0
MarkupSafe==1.1.1
zipp==3.19.1
MarkupSafe==2.1.5
pyrsistent==0.16.0
tenacity==6.2.0
itsdangerous==2.0.1