Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Demo webserver for managed instances tutorial #2077

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

Merged
merged 10 commits into from
May 1, 2019

Conversation

djmailhot
Copy link
Contributor

A simple demo web server used in a new interactive tutorial: Highly Available Deployments with Autohealing

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 29, 2019
@djmailhot
Copy link
Contributor Author

djmailhot commented Apr 1, 2019

The linter fails on a few lines over the line limit that are part of a multi-line HTML template string:

'''IN-LINE
HTML
TEMPLATE
WITH-A-REALLY-REALLY-REALLY-LONG-LINE-LIKE-THIS
AND-SOME-IF-STATEMENTS
WHICH-IS-WHY-THIS-IS-IN-LINE
'''

Let me know if this is, in fact, an ugly way to define an index.html page for a python HTTP server, and I'll find a way to refactor.

@djmailhot
Copy link
Contributor Author

djmailhot commented Apr 3, 2019

I've updated the server to use Flask.

compute/managed-instances/demo/main.py Outdated Show resolved Hide resolved
compute/managed-instances/demo/main.py Outdated Show resolved Hide resolved
if r.status_code == 200:
return sub(r'.+zones/(.+)', r'\1', r.text)
else:
return ''
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any failure cases here that we should be throwing errors on instead of returning the empty string? This seems like unexpected behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsuccessfully getting the zone is not a critical failure. The zone (and the template) are fetched simply for informational purposes on the UI. The demo still works perfectly fine if both fetches fail. If I were to put something in the failure case, it would be an error message along the lines of 'zone not found'/'template not found'.

compute/managed-instances/demo/main.py Outdated Show resolved Hide resolved

PORT_NUMBER = 80
HTML_TEMPLATES_PATH = path.dirname(path.realpath(__file__)) + '/templates'
HEALTHY = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this sample ever have multiple instances behind a load balancer, or is it intended to run on one machine at a time only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, I intend to run this sample with a load balancer.

The global 'healthy' is meant to simply hold state for each individual server. It is expected that a user might be redirected to different servers by the load balancer. Please let me know if there is a more idiomatic way of hosting a simple boolean state variable on a flask server (all I can find are examples using databases which seems too overcomplicated for this task).

compute/managed-instances/demo/main.py Outdated Show resolved Hide resolved
Copy link
Member

@andrewsg andrewsg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Please take a look at adding comments but otherwise LGTM

compute/managed-instances/demo/app.py Show resolved Hide resolved
@andrewsg
Copy link
Member

andrewsg commented Apr 30, 2019

Looks like there's a linting error with the new comments... sorry it's so nitpicky. If that's resolved I can merge right away. Thanks for your work on this.

./app.py:47:1: W293 blank line contains whitespace
    """Returns the simulated 'healthy'/'unhealthy' status of the server.
    
    Returns:
        HTTP status 200 if 'healthy', HTTP status 500 if 'unhealthy'
    """
^

@djmailhot
Copy link
Contributor Author

Comments fixed, all checks passed!

@andrewsg
Copy link
Member

andrewsg commented May 1, 2019

Thanks, I'll merge now.

@andrewsg andrewsg merged commit fd3ab2f into GoogleCloudPlatform:master May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.