This release is a pre-release and may not be stable for production use.
Modern Flask
性能基准
以 gunicorn 为服务器,以 --workers 1 --threads 1 为性能基准
目的是为了在容器环境下,以 1 CPU 为基准进行调度
配置
Flask.config
使用环境变量 CONFIG_SOURCE 来判断配置来源,只支持 Python 类型
- 本地文件
xxxx.py
- Kubernetes 资源
kubernetes://[NAMESPACE]/configmaps/[NAME]/[KEY]kubernetes://[NAMESPACE]/secrets/[NAME]/[KEY]kubernetes://configmaps/[NAME]/[KEY]kubernetes://secrets/[NAME]/[KEY]
- HTTP 资源
http://xxxxx.xxxx/xxxx.pyhttps://xxxxx.xxxx/xxxx.py
默认为本地文件 config.py
可观测性
可观测性框架基于 OpenTelemetry,使用 Zipkin 或者 Jaeger 作为导出格式, 默认启用了对以下组件的观测
- logging
- flask
- sqlalchemy
- redis
切换导出格式
使用 环境变量 OTEL_EXPORTER 切换 zipkin 和 jaeger
设置 Kubernetes 相关环境变量
[
{
name: 'OTEL_EXPORTER',
value: 'zipkin',
},
{
name: 'OTEL_EXPORTER_ZIPKIN_ENDPOINT',
value: 'http://zipkin.observability:9411/api/v2/spans',
},
{
name: 'NODE_NAME',
valueFrom: {
fieldRef: {
fieldPath: 'spec.nodeName',
},
},
},
{
name: 'POD_NAME',
valueFrom: {
fieldRef: {
fieldPath: 'metadata.name',
},
},
},
{
name: 'POD_NAMESPACE',
valueFrom: {
fieldRef: {
fieldPath: 'metadata.namespace',
},
},
},
{
name: 'SERVICE_NAME',
value: name,
},
{
name: 'CONFIG_SOURCE',
value: 'kubernetes://secrets/' + name + '-cfg/config.py',
},
{
name: 'WORKLOAD_TYPE',
value: type,
}
]
设置其他参数
所有 Flask.config 中,以 OTEL_ 开头的配置会自动写入环境变量,用以配置 OpenTelemetry 的其他组件
详细参考:
- https://opentelemetry-python.readthedocs.io/en/latest/exporter/zipkin/zipkin.html
- https://opentelemetry-python.readthedocs.io/en/latest/exporter/jaeger/jaeger.html
- https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/logging/logging.html
指标
使用标准 Prometheus 库,暴露于 /metrics 路径下
数据库
使用 SQLAlchemy 库
Engine 配置来自于 Flask.config, 前缀 DATABASE_ENGINE_, 参考配置如下:
DATABASE_ENGINE_URL = "sqlite+pysqlite:///:memory:"
DATABASE_ENGINE_ECHO = True
DATABASE_ENGINE_FUTURE = True
Session 配置来自于 Flask.config, 前缀 DATABASE_SESSION_, 参考配置如下:
DATABASE_SESSION_AUTOFLUSH = False
Redis
使用 Redis 库, 配置来自于 Flask.config, 前缀 REDIS_, 参考配置如下:
REDIS_HOST = "127.0.0.1"
详细参考 https://github.com/redis/redis-py/blob/12c17bfc436ea6784bbc8b2d327d981520858eb7/redis/client.py#L853
存储
目前只支持 腾讯云 COS 和 阿里云 OSS
配置来自于 Flask.config,前缀 STORAGE_,参考配置如下
腾讯云 COS
STORAGE_VENDOR = "cos"
STORAGE_SECRET_ID = "xxxxxxxxx"
STORAGE_SECRET_KEY = "xxxxxxxxx"
STORAGE_REGION = "ap-guangzhou"
STORAGE_ENDPOINT = "xxx.xxx.com"
阿里云 OSS
STORAGE_VENDOR = "oss"
STORAGE_ACCESS_KEY_ID = ""
STORAGE_ACCESS_KEY_SECRET = ""
STORAGE_ENDPOINT = ""
STORAGE_BUCKET = ""
详细参考 https://pypi.org/project/oss2/
Celery
使用 Flask.config 配置 CELERY_ 前缀参数
许可证
Guo Y.K., MIT License
Metadata
Release files for modern-flask 202207b1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| modern-flask-202207b1.tar.gz | 9.6 kB | Without provenance | Details for modern-flask-202207b1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| modern_flask-202207b1-py3-none-any.whl | Python 3 | none | any | Details for modern_flask-202207b1-py3-none-any.whl |
Total release size: 19.6 kB
Release files / modern-flask-202207b1.tar.gz
| Download URL | modern-flask-202207b1.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30103bb223bb74bc18612d533e654d8cfe1bcd65508cb82d4d9c9de62b477b9e
|
|
BLAKE2b-256 checksum How to use checksums |
f9be65122feb40a036d8daa7a56cee9e38bf8dfaf836d60fbb0fd8d65f8ceff3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Release files / modern_flask-202207b1-py3-none-any.whl
| Download URL | modern_flask-202207b1-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d49161af56c366892704968ca015b1c393d2287e00d280deac48625a25397e3f
|
|
BLAKE2b-256 checksum How to use checksums |
51d8a2ac26f43e96a0718eb541283f1bf430950dcdd8d99d36ab68c9af98459e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.8.10
|
Security for modern-flask 202207b1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.