villebro opened a new pull request, #32506:
URL: https://github.com/apache/superset/pull/32506

   ### SUMMARY
   Many db engine specs support defining a custom user agent id to queries to 
distinguish those coming from Superset. In the case of Trino, it makes it easy 
to assign a custom [resource 
group](https://trino.io/docs/current/admin/resource-groups.html) based on the 
source property.
   
   This PR adds a property `USER_AGENT_FUNC` to `config.py` that makes it 
possible to customize the user agent based on the database and source of the 
query. For instance, to pass along information about the source of the query in 
the agent identifier, the following config can be added:
   
   ```python
   from superset.constants import DEFAULT_USER_AGENT
   from superset.constants.utils import QuerySource
   
   
   def USER_AGENT_FUNC(database, source):
       user_agent = DEFAULT_USER_AGENT
       if database.db_engine_spec.engine == "trino" and source:
           user_agent = f"{user_agent} ({source.name})"
   
       return user_agent
   ```
   
   This would yield the following agent for Trino connections:
   - Unknown: `Apache Superset`
   - SQL Lab: `Apache Superset (SQL_LAB)`
   - Dashboard: `Apache Superset (DASHBOARD)`
   - Explore: `Apache Superset (CHART)`
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <!--- Skip this if not applicable -->
   
   ### TESTING INSTRUCTIONS
   <!--- Required! What steps can be taken to manually verify the changes? -->
   
   ### ADDITIONAL INFORMATION
   <!--- Check any relevant boxes with "x" -->
   <!--- HINT: Include "Fixes #nnn" if you are fixing an existing issue -->
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to