Skip to content

Commit d60b424

Browse files
authored
[UI] use only one logger adapter and update Dockerfile (#2646)
* [UI] use only one logger adapter and update Dockerfile * remove setLevel on logger
1 parent 1210cec commit d60b424

File tree

7 files changed

+64
-65
lines changed

7 files changed

+64
-65
lines changed

ui/Dockerfile

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,22 @@
1-
ARG BASE_IMAGE=registry.opensource.zalan.do/library/alpine-3.15:latest
2-
ARG NODE_IMAGE=node:14.21.2-alpine
3-
4-
FROM $NODE_IMAGE AS build
5-
6-
COPY . /workdir
7-
WORKDIR /workdir/app
8-
9-
RUN npm install &&\
10-
npm run build
11-
12-
FROM $BASE_IMAGE
13-
1+
FROM registry.opensource.zalan.do/library/python-3.11-slim:latest
142
LABEL maintainer="Team ACID @ Zalando <team-acid@zalando.de>"
153

164
EXPOSE 8081
5+
WORKDIR /app
6+
7+
RUN apt-get -qq -y update \
8+
# https://www.psycopg.org/docs/install.html#psycopg-vs-psycopg-binary
9+
&& apt-get -qq -y install --no-install-recommends g++ libpq-dev python3-dev python3-distutils \
10+
&& apt-get -qq -y clean \
11+
&& rm -rf /var/lib/apt/lists/*
1712

18-
RUN \
19-
apk add --no-cache \
20-
alpine-sdk \
21-
autoconf \
22-
automake \
23-
ca-certificates \
24-
libffi-dev \
25-
libtool \
26-
python3 \
27-
python3-dev \
28-
zlib-dev \
29-
&& \
30-
python3 -m ensurepip && \
31-
rm -r /usr/lib/python*/ensurepip && \
32-
pip3 install --upgrade \
33-
gevent \
34-
jq \
35-
pip \
36-
setuptools \
37-
&& \
38-
rm -rf \
39-
/root/.cache \
40-
/tmp/* \
41-
/var/cache/apk/*
13+
COPY requirements.txt .
14+
COPY start_server.sh .
15+
RUN pip install -r requirements.txt
4216

43-
COPY requirements.txt /
44-
COPY start_server.sh /
45-
RUN pip3 install -r /requirements.txt
17+
COPY operator_ui operator_ui/
4618

47-
COPY operator_ui /operator_ui
48-
COPY --from=build /workdir/operator_ui/static/build /operator_ui/static/build
4919
ARG VERSION=dev
50-
RUN sed -i "s/__version__ = .*/__version__ = '${VERSION}'/" /operator_ui/__init__.py
20+
RUN sed -i "s/__version__ = .*/__version__ = '${VERSION}'/" operator_ui/__init__.py
5121

52-
WORKDIR /
53-
CMD ["/usr/bin/python3", "-m", "operator_ui"]
22+
CMD ["python", "-m", "operator_ui"]

ui/app/src/postgresql.tag.pug

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ postgresql
8787
.alert.alert-info(if='{ progress.statefulSet && !progress.containerFirst }') Waiting for 1st container to spawn
8888
.alert.alert-success(if='{ progress.containerFirst }') First PostgreSQL cluster container spawned
8989

90-
.alert.alert-info(if='{ !progress.postgresql }') PostgreSQL cluster manifest pending
91-
.alert.alert-success(if='{ progress.postgresql }') PostgreSQL cluster manifest created
92-
9390
.alert.alert-info(if='{ progress.containerFirst && !progress.masterLabel }') Waiting for master to become available
9491
.alert.alert-success(if='{ progress.masterLabel }') PostgreSQL master available, label is attached
9592
.alert.alert-success(if='{ progress.masterLabel && progress.dnsName }') PostgreSQL ready: <strong>{ progress.dnsName }</strong>

ui/operator_ui/adapters/__init__ .py

Whitespace-only changes.

ui/operator_ui/adapters/logger.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import logging
2+
from logging.config import dictConfig
3+
4+
dictConfig(
5+
{
6+
"version": 1,
7+
"disable_existing_loggers": True,
8+
"formatters": {
9+
"json": {
10+
"class": "pythonjsonlogger.jsonlogger.JsonFormatter",
11+
"format": "%(asctime)s %(levelname)s: %(message)s",
12+
}
13+
},
14+
"handlers": {
15+
"stream_handler": {
16+
"class": "logging.StreamHandler",
17+
"formatter": "json",
18+
"stream": "ext://flask.logging.wsgi_errors_stream",
19+
}
20+
},
21+
"root": {
22+
"level": "INFO",
23+
"handlers": ["stream_handler"]
24+
}
25+
}
26+
)
27+
28+
29+
class Logger:
30+
def __init__(self):
31+
self.logger = logging.getLogger(__name__)
32+
33+
def debug(self, msg: str, *args, **kwargs):
34+
self.logger.debug(msg, *args, **kwargs)
35+
36+
def info(self, msg: str, *args, **kwargs):
37+
self.logger.info(msg, *args, **kwargs)
38+
39+
def error(self, msg: str, *args, **kwargs):
40+
self.logger.error(msg, *args, **kwargs)
41+
42+
def exception(self, msg: str, *args, **kwargs):
43+
self.logger.exception(msg, *args, **kwargs)
44+
45+
46+
logger = Logger()

ui/operator_ui/main.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
#!/usr/bin/env python3
22
# pylama:ignore=E402
33

4-
import gevent.monkey
5-
6-
gevent.monkey.patch_all()
7-
84
import requests
95
import tokens
10-
import sys
116

127
from backoff import expo, on_exception
138
from click import ParamType, command, echo, option
@@ -25,7 +20,6 @@
2520
from gevent.pywsgi import WSGIServer
2621
from jq import jq
2722
from json import dumps, loads
28-
from logging import DEBUG, ERROR, INFO, basicConfig, exception, getLogger
2923
from os import getenv
3024
from re import X, compile
3125
from requests.exceptions import RequestException
@@ -56,11 +50,7 @@
5650
these,
5751
)
5852

59-
60-
# Disable access logs from Flask
61-
getLogger('gevent').setLevel(ERROR)
62-
63-
logger = getLogger(__name__)
53+
from operator_ui.adapters.logger import logger
6454

6555
SERVER_STATUS = {'shutdown': False}
6656

@@ -77,7 +67,7 @@
7767
SUPERUSER_TEAM = getenv('SUPERUSER_TEAM', 'acid')
7868
TARGET_NAMESPACE = getenv('TARGET_NAMESPACE')
7969
GOOGLE_ANALYTICS = getenv('GOOGLE_ANALYTICS', False)
80-
MIN_PODS= getenv('MIN_PODS', 2)
70+
MIN_PODS = getenv('MIN_PODS', 2)
8171
RESOURCES_VISIBLE = getenv('RESOURCES_VISIBLE', True)
8272
CUSTOM_MESSAGE_RED = getenv('CUSTOM_MESSAGE_RED', '')
8373

@@ -984,8 +974,6 @@ def init_cluster():
984974
def main(port, debug, clusters: list):
985975
global TARGET_NAMESPACE
986976

987-
basicConfig(stream=sys.stdout, level=(DEBUG if debug else INFO), format='%(asctime)s %(levelname)s: %(message)s',)
988-
989977
init_cluster()
990978

991979
logger.info(f'App URL: {APP_URL}')

ui/operator_ui/spiloutils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from datetime import datetime, timezone
33
from furl import furl
44
from json import dumps, loads
5-
from logging import getLogger
65
from os import environ, getenv
76
from requests import Session
87
from urllib.parse import urljoin
@@ -11,8 +10,7 @@
1110

1211
from .utils import Attrs, defaulting, these
1312

14-
15-
logger = getLogger(__name__)
13+
from operator_ui.adapters.logger import logger
1614

1715
session = Session()
1816

ui/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ gevent==24.2.1
88
jq==1.7.0
99
json_delta>=2.0.2
1010
kubernetes==11.0.0
11+
python-json-logger==2.0.7
1112
requests==2.32.2
1213
stups-tokens>=1.1.19
1314
wal_e==1.1.1

0 commit comments

Comments
 (0)