-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
chore(async): Making create app configurable #25346
Merged
craig-rueda
merged 10 commits into
apache:master
from
preset-io:craig/making-create-app-configurable
Sep 20, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4991c49
First cut at refacoring create_app
craig-rueda 1db9881
Merge remote-tracking branch 'origin/master' into craig/making-create…
craig-rueda edd494d
Making AsyncQueryManager configurable
craig-rueda 47ba697
Fixing up gitignore
craig-rueda a9b618e
Linting
craig-rueda 2c94a8b
Linting
craig-rueda e592979
Linting again
craig-rueda 195cd89
Fixing tests
craig-rueda 273485d
Refactoring
craig-rueda b4e4cc6
Linting
craig-rueda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
user nginx; | ||
worker_processes 1; | ||
|
||
error_log /var/log/nginx/error.log warn; | ||
pid /var/run/nginx.pid; | ||
|
||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
|
||
http { | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
'$status $body_bytes_sent [$connection_requests] "$http_referer" ' | ||
'"$http_user_agent" "$http_x_forwarded_for"'; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
|
||
sendfile on; | ||
#tcp_nopush on; | ||
|
||
keepalive_timeout 30; | ||
keepalive_requests 2; | ||
|
||
###### Compression Stuff | ||
|
||
# Enable Gzip compressed. | ||
gzip on; | ||
|
||
# Compression level (1-9). | ||
# 5 is a perfect compromise between size and cpu usage, offering about | ||
# 75% reduction for most ascii files (almost identical to level 9). | ||
gzip_comp_level 5; | ||
|
||
# Don't compress anything that's already small and unlikely to shrink much | ||
# if at all (the default is 20 bytes, which is bad as that usually leads to | ||
# larger files after gzipping). | ||
gzip_min_length 256; | ||
|
||
# Compress data even for clients that are connecting to us via proxies, | ||
# identified by the "Via" header (required for CloudFront). | ||
gzip_proxied any; | ||
|
||
# Tell proxies to cache both the gzipped and regular version of a resource | ||
# whenever the client's Accept-Encoding capabilities header varies; | ||
# Avoids the issue where a non-gzip capable client (which is extremely rare | ||
# today) would display gibberish if their proxy gave them the gzipped version. | ||
gzip_vary on; | ||
|
||
# Compress all output labeled with one of the following MIME-types. | ||
gzip_types | ||
application/atom+xml | ||
application/javascript | ||
application/json | ||
application/rss+xml | ||
application/vnd.ms-fontobject | ||
application/x-font-ttf | ||
application/x-web-app-manifest+json | ||
application/xhtml+xml | ||
application/xml | ||
font/opentype | ||
image/svg+xml | ||
image/x-icon | ||
text/css | ||
text/plain | ||
text/x-component; | ||
# text/html is always compressed by HttpGzipModule | ||
|
||
output_buffers 20 10m; | ||
|
||
client_max_body_size 10m; | ||
|
||
upstream superset_app { | ||
server host.docker.internal:8088; | ||
keepalive 100; | ||
} | ||
|
||
upstream superset_websocket { | ||
server host.docker.internal:8080; | ||
keepalive 100; | ||
} | ||
|
||
server { | ||
listen 80 default_server; | ||
server_name _; | ||
|
||
location /ws { | ||
proxy_pass http://superset_websocket; | ||
proxy_http_version 1.1; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "Upgrade"; | ||
proxy_set_header Host $host; | ||
} | ||
|
||
location / { | ||
proxy_pass http://superset_app; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $remote_addr; | ||
proxy_set_header X-Forwarded-Host $host; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
proxy_http_version 1.1; | ||
port_in_redirect off; | ||
proxy_connect_timeout 300; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
import logging | ||
import os | ||
from typing import Optional | ||
|
||
from flask import Flask | ||
|
||
|
@@ -25,12 +26,14 @@ | |
logger = logging.getLogger(__name__) | ||
|
||
|
||
def create_app() -> Flask: | ||
def create_app(superset_config_module: Optional[str] = None) -> Flask: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding optional override module for test configs |
||
app = SupersetApp(__name__) | ||
|
||
try: | ||
# Allow user to override our config completely | ||
config_module = os.environ.get("SUPERSET_CONFIG", "superset.config") | ||
config_module = superset_config_module or os.environ.get( | ||
"SUPERSET_CONFIG", "superset.config" | ||
) | ||
app.config.from_object(config_module) | ||
|
||
app_initializer = app.config.get("APP_INITIALIZER", SupersetAppInitializer)(app) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from flask import Flask | ||
|
||
from superset.async_events.async_query_manager import AsyncQueryManager | ||
from superset.utils.class_utils import load_class_from_name | ||
|
||
|
||
class AsyncQueryManagerFactory: | ||
def __init__(self) -> None: | ||
self._async_query_manager: AsyncQueryManager = None # type: ignore | ||
|
||
def init_app(self, app: Flask) -> None: | ||
self._async_query_manager = load_class_from_name( | ||
app.config["GLOBAL_ASYNC_QUERY_MANAGER_CLASS"] | ||
)() | ||
self._async_query_manager.init_app(app) | ||
|
||
def instance(self) -> AsyncQueryManager: | ||
return self._async_query_manager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import importlib | ||
import logging | ||
from io import StringIO | ||
from typing import TYPE_CHECKING | ||
|
@@ -25,6 +24,7 @@ | |
from paramiko import RSAKey | ||
|
||
from superset.databases.utils import make_url_safe | ||
from superset.utils.class_utils import load_class_from_name | ||
|
||
if TYPE_CHECKING: | ||
from superset.databases.ssh_tunnel.models import SSHTunnel | ||
|
@@ -78,18 +78,9 @@ def __init__(self) -> None: | |
self._ssh_manager = None | ||
|
||
def init_app(self, app: Flask) -> None: | ||
ssh_manager_fqclass = app.config["SSH_TUNNEL_MANAGER_CLASS"] | ||
ssh_manager_classname = ssh_manager_fqclass[ | ||
ssh_manager_fqclass.rfind(".") + 1 : | ||
] | ||
ssh_manager_module_name = ssh_manager_fqclass[ | ||
0 : ssh_manager_fqclass.rfind(".") | ||
] | ||
ssh_manager_class = getattr( | ||
importlib.import_module(ssh_manager_module_name), ssh_manager_classname | ||
) | ||
|
||
self._ssh_manager = ssh_manager_class(app) | ||
self._ssh_manager = load_class_from_name( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drying this up |
||
app.config["SSH_TUNNEL_MANAGER_CLASS"] | ||
)(app) | ||
|
||
@property | ||
def instance(self) -> SSHManager: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
from importlib import import_module | ||
from typing import Any | ||
|
||
|
||
def load_class_from_name(fq_class_name: str) -> Any: | ||
""" | ||
Given a string representing a fully qualified class name, attempts to load | ||
the class and return it. | ||
|
||
:param fq_class_name: The fully qualified name of the class to load | ||
:return: The class object | ||
:raises Exception: if the class cannot be loaded | ||
""" | ||
if not fq_class_name: | ||
raise ValueError(f"Invalid class name {fq_class_name}") | ||
|
||
parts = fq_class_name.split(".") | ||
module_name = ".".join(parts[:-1]) | ||
class_name = parts[-1] | ||
|
||
module = import_module(module_name) | ||
return getattr(module, class_name) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this config for local testing