Open brantian opened 2 weeks ago
Hey there, @brantian! I'm a bot here to help you with bugs, questions, and becoming a contributor. I'm here to assist you while you wait for a human maintainer.
The issue you're encountering with different cache keys for chart thumbnails versus dashboard thumbnails likely stems from a discrepancy in how the cache keys are generated and used in the code.
For dashboards, the cache keys are consistent, but for charts, it seems there is a mismatch. This can be due to differences in the key prefix or the way the keys are constructed in the code.
Here are a few steps to troubleshoot and potentially resolve this issue:
Check Cache Key Prefixes:
Ensure that the cache key prefixes for charts and dashboards are consistent. In your superset_config.py
, you have:
THUMBNAIL_CACHE_CONFIG: CacheConfig = {
'CACHE_TYPE': 'RedisCache',
'CACHE_DEFAULT_TIMEOUT': 7 * 86400, # 7 days
'CACHE_KEY_PREFIX': 'thumbnail_',
'CACHE_REDIS_HOST': REDIS_HOST,
'CACHE_REDIS_PORT': REDIS_PORT,
'CACHE_REDIS_DB': REDIS_CELERY_DB
}
Verify that the CACHE_KEY_PREFIX
is correctly used in both the web app and Celery worker for chart thumbnails.
Review Thumbnail Cache Code:
Check the code in superset/tasks/thumbnails.py
where the cache keys are generated and used. Ensure that the same logic is applied for both charts and dashboards.
For example, in the cache_chart_thumbnail
task, ensure the cache key is generated consistently:
@celery_app.task(name="cache_chart_thumbnail", soft_time_limit=300)
def cache_chart_thumbnail(current_user, chart_id, force=False, thumb_size=None):
from superset.models.slice import Slice
if not thumbnail_cache:
logging.warning("No cache set, refusing to compute")
return
chart = Slice.get(chart_id)
url = get_url_path("Superset.slice", slice_id=chart.id)
logger.info("Caching chart: %s", url)
_, username = get_executor(
executor_types=current_app.config["THUMBNAIL_EXECUTE_AS"],
model=chart,
current_user=current_user,
)
user = security_manager.find_user(username)
with override_user(user):
screenshot = ChartScreenshot(url, chart.digest)
screenshot.compute_and_cache(
user=user,
cache=thumbnail_cache,
force=force,
thumb_size=thumb_size,
)
Debug Cache Key Generation: Add debug logs to print out the cache keys being generated in both the web app and Celery worker. This will help you identify where the discrepancy occurs.
Ensure Consistent Cache Configuration:
Make sure that the THUMBNAIL_CACHE_CONFIG
is correctly applied in both the web app and Celery worker. Sometimes, configuration might not be correctly propagated to all parts of the application.
By following these steps, you should be able to identify and resolve the issue with inconsistent cache keys for chart thumbnails. If the problem persists, you might need to dive deeper into the specific implementation details of the thumbnail caching logic in the Superset codebase [1][2].
To continue talking to Dosu, mention @dosu.
Bug description
Hello!
I was able to successfully make the Thumbnails feature work, but for some reason it works only for Dashboard thumbnails, not for Charts. I'm using Redis for cache
Based on the logs for the Web App and the Celery Worker, it seems they are generating different cache keys. So when the thumbnail is requested, I can see that the screenshot is taken and cached successfully, but the
cache_key
generated to save the image in the Redis server by the Celery worker is different than thecache_key
used by the web to retrieve the screenshot:When the thumbnail is the requested by calling
/api/v1/chart/93/thumbnail/8a61c658366e2896618441f3f43d34ec/
, this is what I see in the Web App logs:And the Celery Worker logs:
Notice that both the Web App and Celery are working with thumbnail for chart 93, but the thumbail keys are different. For dashboards, which work sucessfully, the keys are the same.
How to reproduce the bug
Screenshots/recordings
No response
Superset version
4.0.1
Python version
3.9
Node version
16
Browser
Chrome
Additional context
No response
Checklist