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

replace structlog with containerlog #448

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
max-line-length = 100
exclude = bin/,.tox/,examples/,.github/,dist/,build/,htmlcov/
exclude = bin/,.tox/,examples/,.github/,dist/,build/,htmlcov/,.venv/
ignore = W605,F401
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN mkdir packages \
#
# RELEASE STAGE
#
FROM vaporio/python:3.9-slim
FROM vaporio/python:3.9

LABEL org.opencontainers.image.title="Synse Server" \
org.opencontainers.image.source="https://github.com/vapor-ware/synse-server" \
Expand All @@ -32,12 +32,16 @@ RUN groupadd -g 51453 synse \
&& useradd -u 51453 -g 51453 synse

RUN apt-get update && apt-get install -y --no-install-recommends \
tini curl \
curl \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p /synse \
&& mkdir -p /etc/synse \
&& chown -R synse:synse /synse \
&& chown -R synse:synse /etc/synse
&& chown -R synse:synse /synse /etc/synse

# PYTHONUNBUFFERED: allow stdin, stdout, and stderr to be totally unbuffered.
# This is required so that the container logs are rendered as they are logged into
# `docker logs`.
ENV PYTHONUNBUFFERED=1

COPY --from=builder /build/dist/synse-server-*.tar.gz /synse/synse-server.tar.gz
COPY --from=builder /build/packages /pip-packages
Expand All @@ -51,4 +55,4 @@ RUN pip install --no-index --find-links=/pip-packages /pip-packages/* \

USER synse

ENTRYPOINT ["/usr/bin/tini", "--", "synse_server"]
ENTRYPOINT ["synse_server"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ lint: ## Run linting checks on the project source code (isort, flake8, twine)
poetry check

test: ## Run the unit tests
poetry run pytest -s -vv --cov-report html --cov-report term-missing --cov synse_server
poetry run pytest --disable-warnings -s -vv --cov-report html --cov-report term-missing --cov synse_server

version: ## Print the version of Synse Server
@echo "${PKG_VERSION}"
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ services:
ports:
- '5000:5000'
environment:
SYNSE_LOGGING: debug
SYNSE_PLUGIN_TCP: emulator-plugin:5001
SYNSE_METRICS_ENABLED: 'true'
links:
Expand Down
36 changes: 14 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ PyYAML = "^5.4.1"
sanic = "^21.6.2"
prometheus-client = "^0.11.0"
shortuuid = "^1.0.1"
structlog = "^21.1.0"
websockets = "^9.1"
synse-grpc = "3.1.0"
containerlog = "^0.4.2"

[tool.poetry.dev-dependencies]
aiohttp = "^3.7.4"
Expand Down
2 changes: 1 addition & 1 deletion synse_server/api/http.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Synse Server HTTP API."""

import ujson
from containerlog import get_logger
from sanic import Blueprint
from sanic.request import Request
from sanic.response import HTTPResponse, StreamingHTTPResponse, stream
from structlog import get_logger

from synse_server import cmd, errors, plugin, utils

Expand Down
2 changes: 1 addition & 1 deletion synse_server/api/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import time
from typing import Any, Dict, List, Union

from containerlog import get_logger
from sanic import Blueprint
from sanic.request import Request
from sanic.websocket import ConnectionClosed
from structlog import get_logger
from websockets import WebSocketCommonProtocol

from synse_server import cmd, errors, utils
Expand Down
12 changes: 6 additions & 6 deletions synse_server/app.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
"""Factory for creating Synse Server Sanic application instances."""

import shortuuid
import structlog
from containerlog import contextvars, get_logger
from sanic import Sanic
from sanic.request import Request
from sanic.response import HTTPResponse
from structlog import contextvars

from synse_server import errors
from synse_server.api import http, websocket

logger = structlog.get_logger()
logger = get_logger()


def on_request(request: Request) -> None:
"""Middleware function that runs prior to processing a request via Sanic."""

# Generate a unique request ID and use it as a field in any logging that
# takes place during the request handling.
req_id = shortuuid.uuid()
request.ctx.uuid = req_id

contextvars.clear_contextvars()
contextvars.bind_contextvars(
contextvars.clear()
contextvars.bind(
request_id=req_id,
)

Expand Down Expand Up @@ -53,7 +53,7 @@ def on_response(request: Request, response: HTTPResponse) -> None:
)

# Unbind the request ID from the logger.
contextvars.unbind_contextvars(
contextvars.unbind(
'request_id',
)

Expand Down
2 changes: 1 addition & 1 deletion synse_server/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import aiocache
import grpc
import synse_grpc.utils
from structlog import get_logger
from containerlog import get_logger
from synse_grpc import api

from synse_server import loop, plugin
Expand Down
2 changes: 1 addition & 1 deletion synse_server/cmd/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from typing import Any, Dict

from structlog import get_logger
from containerlog import get_logger

from synse_server.config import options

Expand Down
2 changes: 1 addition & 1 deletion synse_server/cmd/info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from typing import Any, Dict

from structlog import get_logger
from containerlog import get_logger
from synse_grpc import utils

from synse_server import cache, errors
Expand Down
2 changes: 1 addition & 1 deletion synse_server/cmd/plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from typing import Any, Dict, List

from structlog import get_logger
from containerlog import get_logger
from synse_grpc import api, utils

import synse_server.utils
Expand Down
2 changes: 1 addition & 1 deletion synse_server/cmd/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import synse_grpc.utils
import websockets
from structlog import get_logger
from containerlog import get_logger
from synse_grpc import api

from synse_server import cache, errors, plugin
Expand Down
4 changes: 2 additions & 2 deletions synse_server/cmd/scan.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from typing import Any, Dict, List

from structlog import get_logger
from containerlog import get_logger
from synse_grpc import utils

from synse_server import cache, errors
Expand Down Expand Up @@ -68,7 +68,7 @@ async def scan(
try:
device_group = await cache.get_devices(*group)
except Exception as e:
logger.exception(e)
logger.exception(str(e))
raise errors.ServerError('failed to get devices from cache') from e

for device in device_group:
Expand Down
2 changes: 1 addition & 1 deletion synse_server/cmd/tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from typing import List

from structlog import get_logger
from containerlog import get_logger

from synse_server import cache

Expand Down
2 changes: 1 addition & 1 deletion synse_server/cmd/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from typing import Dict

from structlog import get_logger
from containerlog import get_logger

from synse_server import utils

Expand Down
2 changes: 1 addition & 1 deletion synse_server/cmd/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any, Dict, List

import synse_grpc.utils
from structlog import get_logger
from containerlog import get_logger

from synse_server import cache, errors, plugin, utils

Expand Down
2 changes: 1 addition & 1 deletion synse_server/cmd/version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from typing import Dict

from structlog import get_logger
from containerlog import get_logger

import synse_server

Expand Down
2 changes: 1 addition & 1 deletion synse_server/cmd/write.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from typing import Any, Dict, List, Union

from structlog import get_logger
from containerlog import get_logger
from synse_grpc import utils as grpc_utils

from synse_server import cache, errors, utils
Expand Down
4 changes: 4 additions & 0 deletions synse_server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

# The Synse Server configuration scheme
scheme = Scheme(
# DEPRECATED: no longer supporting logging in this format. This will
# be removed by upcoming release.
Option('logging', default='debug', choices=['debug', 'info', 'warning', 'error', 'critical']),

Option('debug', default=True, field_type=bool),
Option('pretty_json', default=True, field_type=bool),
DictOption('plugin', default={}, scheme=Scheme(
ListOption('tcp', default=[], member_type=str, bind_env=True),
Expand Down
2 changes: 1 addition & 1 deletion synse_server/discovery/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import kubernetes.client
import kubernetes.config
from structlog import get_logger
from containerlog import get_logger

from synse_server import config

Expand Down
2 changes: 1 addition & 1 deletion synse_server/errors.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Error definitions for Synse Server."""

from containerlog import get_logger
from sanic.exceptions import SanicException
from sanic.handlers import ErrorHandler
from sanic.request import Request
from sanic.response import HTTPResponse
from structlog import get_logger

from synse_server import utils

Expand Down
Loading