[UI] use only one logger adapter and update Dockerfile (#2646)

* [UI] use only one logger adapter and update Dockerfile
* remove setLevel on logger
This commit is contained in:
Felix Kunde 2024-05-31 11:24:31 +02:00 committed by GitHub
parent 1210ceca72
commit d60b424d79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 64 additions and 65 deletions

View File

@ -1,53 +1,22 @@
ARG BASE_IMAGE=registry.opensource.zalan.do/library/alpine-3.15:latest FROM registry.opensource.zalan.do/library/python-3.11-slim:latest
ARG NODE_IMAGE=node:14.21.2-alpine
FROM $NODE_IMAGE AS build
COPY . /workdir
WORKDIR /workdir/app
RUN npm install &&\
npm run build
FROM $BASE_IMAGE
LABEL maintainer="Team ACID @ Zalando <team-acid@zalando.de>" LABEL maintainer="Team ACID @ Zalando <team-acid@zalando.de>"
EXPOSE 8081 EXPOSE 8081
WORKDIR /app
RUN \ RUN apt-get -qq -y update \
apk add --no-cache \ # https://www.psycopg.org/docs/install.html#psycopg-vs-psycopg-binary
alpine-sdk \ && apt-get -qq -y install --no-install-recommends g++ libpq-dev python3-dev python3-distutils \
autoconf \ && apt-get -qq -y clean \
automake \ && rm -rf /var/lib/apt/lists/*
ca-certificates \
libffi-dev \
libtool \
python3 \
python3-dev \
zlib-dev \
&& \
python3 -m ensurepip && \
rm -r /usr/lib/python*/ensurepip && \
pip3 install --upgrade \
gevent \
jq \
pip \
setuptools \
&& \
rm -rf \
/root/.cache \
/tmp/* \
/var/cache/apk/*
COPY requirements.txt / COPY requirements.txt .
COPY start_server.sh / COPY start_server.sh .
RUN pip3 install -r /requirements.txt RUN pip install -r requirements.txt
COPY operator_ui operator_ui/
COPY operator_ui /operator_ui
COPY --from=build /workdir/operator_ui/static/build /operator_ui/static/build
ARG VERSION=dev ARG VERSION=dev
RUN sed -i "s/__version__ = .*/__version__ = '${VERSION}'/" /operator_ui/__init__.py RUN sed -i "s/__version__ = .*/__version__ = '${VERSION}'/" operator_ui/__init__.py
WORKDIR / CMD ["python", "-m", "operator_ui"]
CMD ["/usr/bin/python3", "-m", "operator_ui"]

View File

@ -87,9 +87,6 @@ postgresql
.alert.alert-info(if='{ progress.statefulSet && !progress.containerFirst }') Waiting for 1st container to spawn .alert.alert-info(if='{ progress.statefulSet && !progress.containerFirst }') Waiting for 1st container to spawn
.alert.alert-success(if='{ progress.containerFirst }') First PostgreSQL cluster container spawned .alert.alert-success(if='{ progress.containerFirst }') First PostgreSQL cluster container spawned
.alert.alert-info(if='{ !progress.postgresql }') PostgreSQL cluster manifest pending
.alert.alert-success(if='{ progress.postgresql }') PostgreSQL cluster manifest created
.alert.alert-info(if='{ progress.containerFirst && !progress.masterLabel }') Waiting for master to become available .alert.alert-info(if='{ progress.containerFirst && !progress.masterLabel }') Waiting for master to become available
.alert.alert-success(if='{ progress.masterLabel }') PostgreSQL master available, label is attached .alert.alert-success(if='{ progress.masterLabel }') PostgreSQL master available, label is attached
.alert.alert-success(if='{ progress.masterLabel && progress.dnsName }') PostgreSQL ready: <strong>{ progress.dnsName }</strong> .alert.alert-success(if='{ progress.masterLabel && progress.dnsName }') PostgreSQL ready: <strong>{ progress.dnsName }</strong>

View File

View File

@ -0,0 +1,46 @@
import logging
from logging.config import dictConfig
dictConfig(
{
"version": 1,
"disable_existing_loggers": True,
"formatters": {
"json": {
"class": "pythonjsonlogger.jsonlogger.JsonFormatter",
"format": "%(asctime)s %(levelname)s: %(message)s",
}
},
"handlers": {
"stream_handler": {
"class": "logging.StreamHandler",
"formatter": "json",
"stream": "ext://flask.logging.wsgi_errors_stream",
}
},
"root": {
"level": "INFO",
"handlers": ["stream_handler"]
}
}
)
class Logger:
def __init__(self):
self.logger = logging.getLogger(__name__)
def debug(self, msg: str, *args, **kwargs):
self.logger.debug(msg, *args, **kwargs)
def info(self, msg: str, *args, **kwargs):
self.logger.info(msg, *args, **kwargs)
def error(self, msg: str, *args, **kwargs):
self.logger.error(msg, *args, **kwargs)
def exception(self, msg: str, *args, **kwargs):
self.logger.exception(msg, *args, **kwargs)
logger = Logger()

View File

@ -1,13 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# pylama:ignore=E402 # pylama:ignore=E402
import gevent.monkey
gevent.monkey.patch_all()
import requests import requests
import tokens import tokens
import sys
from backoff import expo, on_exception from backoff import expo, on_exception
from click import ParamType, command, echo, option from click import ParamType, command, echo, option
@ -25,7 +20,6 @@ from gevent import sleep, spawn
from gevent.pywsgi import WSGIServer from gevent.pywsgi import WSGIServer
from jq import jq from jq import jq
from json import dumps, loads from json import dumps, loads
from logging import DEBUG, ERROR, INFO, basicConfig, exception, getLogger
from os import getenv from os import getenv
from re import X, compile from re import X, compile
from requests.exceptions import RequestException from requests.exceptions import RequestException
@ -56,11 +50,7 @@ from .utils import (
these, these,
) )
from operator_ui.adapters.logger import logger
# Disable access logs from Flask
getLogger('gevent').setLevel(ERROR)
logger = getLogger(__name__)
SERVER_STATUS = {'shutdown': False} SERVER_STATUS = {'shutdown': False}
@ -984,8 +974,6 @@ def init_cluster():
def main(port, debug, clusters: list): def main(port, debug, clusters: list):
global TARGET_NAMESPACE global TARGET_NAMESPACE
basicConfig(stream=sys.stdout, level=(DEBUG if debug else INFO), format='%(asctime)s %(levelname)s: %(message)s',)
init_cluster() init_cluster()
logger.info(f'App URL: {APP_URL}') logger.info(f'App URL: {APP_URL}')

View File

@ -2,7 +2,6 @@ from boto3 import client
from datetime import datetime, timezone from datetime import datetime, timezone
from furl import furl from furl import furl
from json import dumps, loads from json import dumps, loads
from logging import getLogger
from os import environ, getenv from os import environ, getenv
from requests import Session from requests import Session
from urllib.parse import urljoin from urllib.parse import urljoin
@ -11,8 +10,7 @@ from wal_e.cmd import configure_backup_cxt
from .utils import Attrs, defaulting, these from .utils import Attrs, defaulting, these
from operator_ui.adapters.logger import logger
logger = getLogger(__name__)
session = Session() session = Session()

View File

@ -8,6 +8,7 @@ gevent==24.2.1
jq==1.7.0 jq==1.7.0
json_delta>=2.0.2 json_delta>=2.0.2
kubernetes==11.0.0 kubernetes==11.0.0
python-json-logger==2.0.7
requests==2.32.2 requests==2.32.2
stups-tokens>=1.1.19 stups-tokens>=1.1.19
wal_e==1.1.1 wal_e==1.1.1