Skip to content

Commit

Permalink
use config for pixel density
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Nov 13, 2021
1 parent 80974e7 commit 42027f1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
34 changes: 15 additions & 19 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ def _try_json_readsha(filepath: str, length: int) -> Optional[str]:
# Use all X-Forwarded headers when ENABLE_PROXY_FIX is True.
# When proxying to a different port, set "x_port" to 0 to avoid downstream issues.
ENABLE_PROXY_FIX = False
PROXY_FIX_CONFIG = {"x_for": 1, "x_proto": 1,
"x_host": 1, "x_port": 1, "x_prefix": 1}
PROXY_FIX_CONFIG = {"x_for": 1, "x_proto": 1, "x_host": 1, "x_port": 1, "x_prefix": 1}

# ------------------------------
# GLOBALS FOR APP Builder
Expand Down Expand Up @@ -411,13 +410,12 @@ def _try_json_readsha(filepath: str, length: int) -> Optional[str]:
# This could cause the server to run out of memory or compute.
"ALLOW_FULL_CSV_EXPORT": False,
"UX_BETA": False,
"SCREENSHOTS_USE_RETINA_HIRES": False
}

# Feature flags may also be set via 'SUPERSET_FEATURE_' prefixed environment vars.
DEFAULT_FEATURE_FLAGS.update(
{
k[len("SUPERSET_FEATURE_"):]: parse_boolean_string(v)
k[len("SUPERSET_FEATURE_") :]: parse_boolean_string(v)
for k, v in os.environ.items()
if re.search(r"^SUPERSET_FEATURE_\w+", k)
}
Expand All @@ -440,8 +438,7 @@ def _try_json_readsha(filepath: str, length: int) -> Optional[str]:
# if hasattr(g, "user") and g.user.is_active:
# feature_flags_dict['some_feature'] = g.user and g.user.get_id() == 5
# return feature_flags_dict
GET_FEATURE_FLAGS_FUNC: Optional[Callable[[
Dict[str, bool]], Dict[str, bool]]] = None
GET_FEATURE_FLAGS_FUNC: Optional[Callable[[Dict[str, bool]], Dict[str, bool]]] = None
# A function that receives a feature flag name and an optional default value.
# Has a similar utility to GET_FEATURE_FLAGS_FUNC but it's useful to not force the
# evaluation of all feature flags when just evaluating a single one.
Expand Down Expand Up @@ -956,9 +953,8 @@ def CSV_TO_HIVE_UPLOAD_DIRECTORY_FUNC( # pylint: disable=invalid-name
# Provide a callable that receives a tracking_url and returns another
# URL. This is used to translate internal Hadoop job tracker URL
# into a proxied one


def TRACKING_URL_TRANSFORMER(x): return x
def TRACKING_URL_TRANSFORMER(x): # pylint: disable=invalid-name
return x


# Interval between consecutive polls when using Hive Engine
Expand Down Expand Up @@ -1001,8 +997,6 @@ def TRACKING_URL_TRANSFORMER(x): return x
# def SQL_QUERY_MUTATOR(sql, user_name, security_manager, database):
# dttm = datetime.now().isoformat()
# return f"-- [SQL LAB] {username} {dttm}\n{sql}"


def SQL_QUERY_MUTATOR( # pylint: disable=invalid-name,unused-argument
sql: str,
user_name: Optional[str],
Expand Down Expand Up @@ -1036,8 +1030,7 @@ def SQL_QUERY_MUTATOR( # pylint: disable=invalid-name,unused-argument
ALERT_REPORTS_WORKING_TIME_OUT_LAG = int(timedelta(seconds=10).total_seconds())
# if ALERT_REPORTS_WORKING_TIME_OUT_KILL is True, set a celery hard timeout
# Equal to working timeout + ALERT_REPORTS_WORKING_SOFT_TIME_OUT_LAG
ALERT_REPORTS_WORKING_SOFT_TIME_OUT_LAG = int(
timedelta(seconds=1).total_seconds())
ALERT_REPORTS_WORKING_SOFT_TIME_OUT_LAG = int(timedelta(seconds=1).total_seconds())
# If set to true no notification is sent, the worker will just log a message.
# Useful for debugging
ALERT_REPORTS_NOTIFICATION_DRY_RUN = False
Expand Down Expand Up @@ -1096,7 +1089,11 @@ def SQL_QUERY_MUTATOR( # pylint: disable=invalid-name,unused-argument
WEBDRIVER_TYPE = "firefox"

# Window size - this will impact the rendering of the data
WEBDRIVER_WINDOW = {"dashboard": (1600, 2000), "slice": (3000, 1200)}
WEBDRIVER_WINDOW = {
"dashboard": (1600, 2000),
"slice": (3000, 1200),
"pixel_density": 1,
}

# An optional override to the default auth hook used to provide auth to the
# offline webdriver
Expand Down Expand Up @@ -1226,9 +1223,8 @@ def SQL_QUERY_MUTATOR( # pylint: disable=invalid-name,unused-argument
# to allow mutating the object with this callback.
# This can be used to set any properties of the object based on naming
# conventions and such. You can find examples in the tests.


def SQLA_TABLE_MUTATOR(table): return table
def SQLA_TABLE_MUTATOR(table): # pylint: disable=invalid-name
return table


# Global async query config options.
Expand Down Expand Up @@ -1316,11 +1312,11 @@ def SQLA_TABLE_MUTATOR(table): return table
elif importlib.util.find_spec("superset_config") and not is_test():
try:
import superset_config # pylint: disable=import-error

# type: ignore # pylint: disable=import-error,wildcard-import,unused-wildcard-import
from superset_config import *

print(
f"Loaded your LOCAL configuration at [{superset_config.__file__}]")
print(f"Loaded your LOCAL configuration at [{superset_config.__file__}]")
except Exception:
logger.exception("Found but failed to import local superset_config")
raise
25 changes: 16 additions & 9 deletions superset/utils/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

import logging
from enum import Enum
from superset.extensions import feature_flag_manager
from superset import config
from time import sleep
from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING

Expand Down Expand Up @@ -54,30 +52,36 @@ class DashboardStandaloneMode(Enum):

class WebDriverProxy:
def __init__(
self, driver_type: str, window: Optional[WindowSize] = None,
self,
driver_type: str,
window: Optional[WindowSize] = None,
):
self._driver_type = driver_type
self._window: WindowSize = window or (800, 600)
self._screenshot_locate_wait = current_app.config["SCREENSHOT_LOCATE_WAIT"]
self._screenshot_load_wait = current_app.config["SCREENSHOT_LOAD_WAIT"]

def create(self) -> WebDriver:
pixel_density = current_app.config["WEBDRIVER_WINDOW"].get(
"pixel_density", 1)
if self._driver_type == "firefox":
driver_class = firefox.webdriver.WebDriver
options = firefox.options.Options()
profile = FirefoxProfile()
if feature_flag_manager.is_feature_enabled("SCREENSHOTS_USE_RETINA_HIRES"):
profile.set_preference("layout.css.devPixelsPerPx", "2")
profile.set_preference(
"layout.css.devPixelsPerPx",
str(pixel_density),
)
kwargs: Dict[Any, Any] = dict(
options=options, firefox_profile=profile)
elif self._driver_type == "chrome":
driver_class = chrome.webdriver.WebDriver
options = chrome.options.Options()
if feature_flag_manager.is_feature_enabled("SCREENSHOTS_USE_RETINA_HIRES"):
options.add_argument("--force-device-scale-factor=2")
options.add_argument(
f"--force-device-scale-factor={pixel_density}")
options.add_argument(
f"--window-size={self._window[0]},{self._window[1]}")
kwargs: Dict[Any, Any] = dict(options=options)
kwargs = dict(options=options)
else:
raise Exception(
f"Webdriver name ({self._driver_type}) not supported")
Expand Down Expand Up @@ -113,7 +117,10 @@ def destroy(driver: WebDriver, tries: int = 2) -> None:
pass

def get_screenshot(
self, url: str, element_name: str, user: "User",
self,
url: str,
element_name: str,
user: "User",
) -> Optional[bytes]:
params = {"standalone": DashboardStandaloneMode.REPORT.value}
req = PreparedRequest()
Expand Down

0 comments on commit 42027f1

Please sign in to comment.