-
Notifications
You must be signed in to change notification settings - Fork 83
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
Migrate Place Page Functionality to Flask Service #4627
Conversation
…to new-place-page-api
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.
sorry for the late review!
we actually started with these as separate calls processed in flask, then we combined it in flask, then we moved it to mixer -- each move was driven by page latency improvements.
would we make both api calls concurrently from the client? the results from both calls would be needed to start rendering charts so i wonder what would improve page performance (since it's flask, maybe it's better to keep it split like this).
thanks also for adding types & tests!
server/lib/util.py
Outdated
return wrapper | ||
|
||
|
||
from flask import jsonify |
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.
super nit: this should be added to the list of includes above.
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.
Whoops, fixed
@@ -922,3 +923,44 @@ def post_body_cache_key(): | |||
else: | |||
cache_key = full_path | |||
return cache_key | |||
|
|||
|
|||
def log_execution_time(func): |
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.
this is nice!
server/routes/dev_place/api.py
Outdated
} | ||
|
||
# Define blueprint | ||
bp = Blueprint("dev_place_api", __name__, url_prefix='/api/place') |
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.
any issues with shared_api/place.py also registering the same url_prefix?
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.
Good callout- it looks like blueprint allows for this, but it's a little confusing. Changing to /api/dev-place temporarily, and ill migrate it to /api/place before this makes it to production
server/routes/dev_place/types.py
Outdated
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
Dev Place API dataclass types |
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.
nit: we can drop the "dev" prefix in the files so we don't forget to remove when these pages become the default place page.
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.
Done
|
||
|
||
@dataclass | ||
class Chart: |
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.
this is nice - thanks for adding types
server/routes/dev_place/utils.py
Outdated
""" | ||
charts = [] | ||
for page_config_item in chart_config: | ||
denominator = next(iter(page_config_item.get("denominator", [])), None) |
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.
if i'm reading this right, this gets the first denominator from the list.
could you make sure it works in cases like this
the sv and denominator should come from the same index where the denominator.size() > 1
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.
Good catch! fixed
server/routes/dev_place/utils.py
Outdated
Builds a dictionary of translated category strings for each unique category found in | ||
the chart configuration. |
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.
update the comment?
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.
Fixed
server/routes/dev_place/api.py
Outdated
place = place_utils.fetch_place(place_dcid, locale=g.locale) | ||
|
||
# Retrieve available place page charts | ||
chart_config = current_app.config['CHART_CONFIG'] |
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.
don't forget to make a deep copy of the chart_config before passing it along to functions that alter the config. in prod, the config will get permanently updated across requests
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.
Good call-done!
"scale": | ||
True, | ||
"denominator": | ||
"Count_Person_25OrMoreYears", |
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.
consider adding another test with more denominators, and one without translations
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.
done!
server/routes/dev_place/utils.py
Outdated
@@ -13,10 +13,18 @@ | |||
# limitations under the License. | |||
"""Helper functions for development place page routes""" |
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.
we can drop "development" here too
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.
Done
Good to know! I've been paying attention to the latency, and i'll put together some metrics about how this performs vs the mixer version. Yes im thinking we can make both calls concurrently from the client, and we can have some logic to render the page after both calls return. |
Migrate Place Page Functionality to Flask Service with
place_charts
andrelated_places
EndpointsThis PR migrates place page functionality from the Mixer service's /v1/internal/page/place endpoint to the Flask service by introducing two new endpoints: place_charts and related_places. This change centralizes application-specific logic within the Flask service and optimizes payload sizes by adjusting how observational data is handled.
TODO / Next steps:
New Endpoints
/api/dev-place/charts/<place_dcid>
/api/dev-place/related_places/<place_dcid>
Rationale
Testing