Skip to content

Commit

Permalink
Add accesslog control flag for seldon-core python module
Browse files Browse the repository at this point in the history
  • Loading branch information
anggao authored and seldondev committed Dec 1, 2020
1 parent db251e0 commit bead279
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
11 changes: 5 additions & 6 deletions python/seldon_core/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ def post_worker_init(worker):
atexit.unregister(_exit_function)


def accesslog(log_level: str) -> Union[str, None]:
def accesslog(flag: bool) -> Union[str, None]:
"""
Enable / disable access log in Gunicorn depending on the log level.
Enable / disable access log in Gunicorn depending on the flag.
"""

if log_level in ["WARNING", "ERROR", "CRITICAL"]:
return None

return "-"
if flag:
return "-"
return None


def threads(threads: int, single_threaded: bool) -> int:
Expand Down
14 changes: 12 additions & 2 deletions python/seldon_core/microservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
DEFAULT_METRICS_PORT = 6000

DEBUG_ENV = "SELDON_DEBUG"
GUNICORN_ACCESS_LOG_ENV = "SELDON_GUNICORN_ACCESS_LOG"


def start_servers(
Expand Down Expand Up @@ -299,6 +300,15 @@ def main():
"--pidfile", type=str, default=None, help="A file path to use for the PID file"
)

parser.add_argument(
"--accesslog",
nargs="?",
type=bool,
default=getenv_as_bool(GUNICORN_ACCESS_LOG_ENV, default=False),
const=True,
help="Enable gunicorn access log.",
)

args = parser.parse_args()
parameters = parse_parameters(json.loads(args.parameters))

Expand Down Expand Up @@ -379,7 +389,7 @@ def rest_prediction_server():
def rest_prediction_server():
options = {
"bind": "%s:%s" % ("0.0.0.0", http_port),
"accesslog": accesslog(args.log_level),
"accesslog": accesslog(args.accesslog),
"loglevel": args.log_level.lower(),
"timeout": 5000,
"threads": threads(args.threads, args.single_threaded),
Expand Down Expand Up @@ -443,7 +453,7 @@ def rest_metrics_server():
else:
options = {
"bind": "%s:%s" % ("0.0.0.0", metrics_port),
"accesslog": accesslog(args.log_level),
"accesslog": accesslog(args.accesslog),
"loglevel": args.log_level.lower(),
"timeout": 5000,
"max_requests": args.max_requests,
Expand Down

0 comments on commit bead279

Please sign in to comment.