Skip to content
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

merge to masster #30

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion azure-vote-all-in-one-redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ spec:
containers:
- name: azure-vote-front
#image: mcr.microsoft.com/azuredocs/azure-vote-front:v1
image: myacr202106.azurecr.io/azure-vote-front:v1
image: myacr261139.azurecr.io/azure-vote-front:v1
ports:
- containerPort: 80
resources:
Expand Down
1 change: 1 addition & 0 deletions azure-vote/config_file.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ TITLE = 'Azure Voting App'
VOTE1VALUE = 'Cats'
VOTE2VALUE = 'Dogs'
SHOWHOST = 'false'
REDIS = '127.0.0.1'
60 changes: 51 additions & 9 deletions azure-vote/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,48 @@
import sys
import logging
from datetime import datetime

from opencensus.ext.azure.log_exporter import AzureLogHandler, AzureEventHandler
from opencensus.ext.azure import metrics_exporter
from opencensus.stats import aggregation as aggregation_module
from opencensus.stats import measure as measure_module
from opencensus.stats import stats as stats_module
from opencensus.stats import view as view_module
from opencensus.tags import tag_map as tag_map_module
from opencensus.ext.azure.trace_exporter import AzureExporter
from opencensus.trace.samplers import ProbabilitySampler
from opencensus.trace.tracer import Tracer
from opencensus.ext.flask.flask_middleware import FlaskMiddleware
# App Insights
# TODO: Import required libraries for App Insights

# Logging
logger = # TODO: Setup logger
logger = logging.getLogger(__name__)# TODO: Setup logger
logger.addHandler(AzureLogHandler(connection_string='InstrumentationKey=aec9a0f1-477f-4bf5-a4f7-94f73e6320b0;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus.livediagnostics.monitor.azure.com/;ApplicationId=2baee3ff-ed21-44c4-9026-4bdc35b25b8d'))
logger.addHandler(AzureEventHandler(connection_string='InstrumentationKey=aec9a0f1-477f-4bf5-a4f7-94f73e6320b0;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus.livediagnostics.monitor.azure.com/;ApplicationId=2baee3ff-ed21-44c4-9026-4bdc35b25b8d'))

# Metrics
exporter = # TODO: Setup exporter
exporter = metrics_exporter.new_metrics_exporter(
enable_standard_metrics=True,
connection_string='InstrumentationKey=aec9a0f1-477f-4bf5-a4f7-94f73e6320b0;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus.livediagnostics.monitor.azure.com/;ApplicationId=2baee3ff-ed21-44c4-9026-4bdc35b25b8d')
# TODO: Setup exporter

# Tracing
tracer = # TODO: Setup tracer
tracer = Tracer(
exporter=AzureExporter(
connection_string='InstrumentationKey=aec9a0f1-477f-4bf5-a4f7-94f73e6320b0;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus.livediagnostics.monitor.azure.com/;ApplicationId=2baee3ff-ed21-44c4-9026-4bdc35b25b8d'),
sampler=ProbabilitySampler(1.0),
)
# TODO: Setup tracer

app = Flask(__name__)

# Requests
middleware = # TODO: Setup flask middleware
middleware = FlaskMiddleware(
app,
exporter=AzureExporter(connection_string="InstrumentationKey=aec9a0f1-477f-4bf5-a4f7-94f73e6320b0;IngestionEndpoint=https://westus-0.in.applicationinsights.azure.com/;LiveEndpoint=https://westus.livediagnostics.monitor.azure.com/;ApplicationId=2baee3ff-ed21-44c4-9026-4bdc35b25b8d"),
sampler=ProbabilitySampler(rate=1.0),
)
# TODO: Setup flask middleware

# Load configurations from environment or config file
app.config.from_pyfile('config_file.cfg')
Expand All @@ -43,7 +68,20 @@
title = app.config['TITLE']

# Redis Connection
r = redis.Redis()
if ("REDIS" in os.environ and os.environ['REDIS']):
redis_server = os.environ['REDIS']
else:
redis_server = app.config['REDIS']
try:
if "REDIS_PWD" in os.environ:
r = redis.StrictRedis(host=redis_server,
port=6379,
password=os.environ['REDIS_PWD'])
else:
r = redis.Redis(redis_server)
r.ping()
except redis.ConnectionError:
exit('Failed to connect to Redis, terminating.')

# Change title to host name to demo NLB
if app.config['SHOWHOST'] == "true":
Expand All @@ -60,8 +98,10 @@ def index():

# Get current values
vote1 = r.get(button1).decode('utf-8')
tracer.span(name="Total {} Voted: {}".format(button1, vote1))
# TODO: use tracer object to trace cat vote
vote2 = r.get(button2).decode('utf-8')
tracer.span(name="Total {} Voted: {}".format(button2, vote2))
# TODO: use tracer object to trace dog vote

# Return index with values
Expand All @@ -76,10 +116,12 @@ def index():
r.set(button2,0)
vote1 = r.get(button1).decode('utf-8')
properties = {'custom_dimensions': {'Cats Vote': vote1}}
logger.warning("{} voted".format(button1), extra=properties)
# TODO: use logger object to log cat vote

vote2 = r.get(button2).decode('utf-8')
properties = {'custom_dimensions': {'Dogs Vote': vote2}}
logger.warning("{} voted".format(button2), extra=properties)
# TODO: use logger object to log dog vote

return render_template("index.html", value1=int(vote1), value2=int(vote2), button1=button1, button2=button2, title=title)
Expand All @@ -99,6 +141,6 @@ def index():

if __name__ == "__main__":
# TODO: Use the statement below when running locally
app.run()
# app.run()
# TODO: Use the statement below before deployment to VMSS
# app.run(host='0.0.0.0', threaded=True, debug=True) # remote
app.run(host='0.0.0.0', threaded=True, debug=True) # remote
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright 2010 Pallets

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
137 changes: 137 additions & 0 deletions azure-vote/venv/Lib/site-packages/Flask-1.1.2.dist-info/METADATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
Metadata-Version: 2.1
Name: Flask
Version: 1.1.2
Summary: A simple framework for building complex web applications.
Home-page: https://palletsprojects.com/p/flask/
Author: Armin Ronacher
Author-email: [email protected]
Maintainer: Pallets
Maintainer-email: [email protected]
License: BSD-3-Clause
Project-URL: Documentation, https://flask.palletsprojects.com/
Project-URL: Code, https://github.com/pallets/flask
Project-URL: Issue tracker, https://github.com/pallets/flask/issues
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Flask
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*
Requires-Dist: Werkzeug (>=0.15)
Requires-Dist: Jinja2 (>=2.10.1)
Requires-Dist: itsdangerous (>=0.24)
Requires-Dist: click (>=5.1)
Provides-Extra: dev
Requires-Dist: pytest ; extra == 'dev'
Requires-Dist: coverage ; extra == 'dev'
Requires-Dist: tox ; extra == 'dev'
Requires-Dist: sphinx ; extra == 'dev'
Requires-Dist: pallets-sphinx-themes ; extra == 'dev'
Requires-Dist: sphinxcontrib-log-cabinet ; extra == 'dev'
Requires-Dist: sphinx-issues ; extra == 'dev'
Provides-Extra: docs
Requires-Dist: sphinx ; extra == 'docs'
Requires-Dist: pallets-sphinx-themes ; extra == 'docs'
Requires-Dist: sphinxcontrib-log-cabinet ; extra == 'docs'
Requires-Dist: sphinx-issues ; extra == 'docs'
Provides-Extra: dotenv
Requires-Dist: python-dotenv ; extra == 'dotenv'

Flask
=====

Flask is a lightweight `WSGI`_ web application framework. It is designed
to make getting started quick and easy, with the ability to scale up to
complex applications. It began as a simple wrapper around `Werkzeug`_
and `Jinja`_ and has become one of the most popular Python web
application frameworks.

Flask offers suggestions, but doesn't enforce any dependencies or
project layout. It is up to the developer to choose the tools and
libraries they want to use. There are many extensions provided by the
community that make adding new functionality easy.


Installing
----------

Install and update using `pip`_:

.. code-block:: text

pip install -U Flask


A Simple Example
----------------

.. code-block:: python

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
return "Hello, World!"

.. code-block:: text

$ env FLASK_APP=hello.py flask run
* Serving Flask app "hello"
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)


Contributing
------------

For guidance on setting up a development environment and how to make a
contribution to Flask, see the `contributing guidelines`_.

.. _contributing guidelines: https://github.com/pallets/flask/blob/master/CONTRIBUTING.rst


Donate
------

The Pallets organization develops and supports Flask and the libraries
it uses. In order to grow the community of contributors and users, and
allow the maintainers to devote more time to the projects, `please
donate today`_.

.. _please donate today: https://psfmember.org/civicrm/contribute/transact?reset=1&id=20


Links
-----

* Website: https://palletsprojects.com/p/flask/
* Documentation: https://flask.palletsprojects.com/
* Releases: https://pypi.org/project/Flask/
* Code: https://github.com/pallets/flask
* Issue tracker: https://github.com/pallets/flask/issues
* Test status: https://dev.azure.com/pallets/flask/_build
* Official chat: https://discord.gg/t6rrQZH

.. _WSGI: https://wsgi.readthedocs.io
.. _Werkzeug: https://www.palletsprojects.com/p/werkzeug/
.. _Jinja: https://www.palletsprojects.com/p/jinja/
.. _pip: https://pip.pypa.io/en/stable/quickstart/


49 changes: 49 additions & 0 deletions azure-vote/venv/Lib/site-packages/Flask-1.1.2.dist-info/RECORD
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
../../Scripts/flask.exe,sha256=UEqQ6bjjeGtzVM5lSe1CLKxMEeRZk3lAdGAOZ2BKCcI,106413
Flask-1.1.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
Flask-1.1.2.dist-info/LICENSE.rst,sha256=SJqOEQhQntmKN7uYPhHg9-HTHwvY-Zp5yESOf_N9B-o,1475
Flask-1.1.2.dist-info/METADATA,sha256=3INpPWH6nKfZ33R2N-bQZy4TOe1wQCMweZc9mwcNrtc,4591
Flask-1.1.2.dist-info/RECORD,,
Flask-1.1.2.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
Flask-1.1.2.dist-info/WHEEL,sha256=8zNYZbwQSXoB9IfXOjPfeNwvAsALAjffgk27FqvCWbo,110
Flask-1.1.2.dist-info/entry_points.txt,sha256=gBLA1aKg0OYR8AhbAfg8lnburHtKcgJLDU52BBctN0k,42
Flask-1.1.2.dist-info/top_level.txt,sha256=dvi65F6AeGWVU0TBpYiC04yM60-FX1gJFkK31IKQr5c,6
flask/__init__.py,sha256=YnA9wkwbJcnb_jTT-nMsMFeFE_UWt33khKzdHmMSuyI,1894
flask/__main__.py,sha256=fjVtt3QTANXlpJCOv3Ha7d5H-76MwzSIOab7SFD9TEk,254
flask/__pycache__/__init__.cpython-39.pyc,,
flask/__pycache__/__main__.cpython-39.pyc,,
flask/__pycache__/_compat.cpython-39.pyc,,
flask/__pycache__/app.cpython-39.pyc,,
flask/__pycache__/blueprints.cpython-39.pyc,,
flask/__pycache__/cli.cpython-39.pyc,,
flask/__pycache__/config.cpython-39.pyc,,
flask/__pycache__/ctx.cpython-39.pyc,,
flask/__pycache__/debughelpers.cpython-39.pyc,,
flask/__pycache__/globals.cpython-39.pyc,,
flask/__pycache__/helpers.cpython-39.pyc,,
flask/__pycache__/logging.cpython-39.pyc,,
flask/__pycache__/sessions.cpython-39.pyc,,
flask/__pycache__/signals.cpython-39.pyc,,
flask/__pycache__/templating.cpython-39.pyc,,
flask/__pycache__/testing.cpython-39.pyc,,
flask/__pycache__/views.cpython-39.pyc,,
flask/__pycache__/wrappers.cpython-39.pyc,,
flask/_compat.py,sha256=8KPT54Iig96TuLipdogLRHNYToIcg-xPhnSV5VRERnw,4099
flask/app.py,sha256=tmEhx_XrIRP24vZg39dHMWFzJ2jj-YxIcd51LaIT5cE,98059
flask/blueprints.py,sha256=vkdm8NusGsfZUeIfPdCluj733QFmiQcT4Sk1tuZLUjw,21400
flask/cli.py,sha256=SIb22uq9wYBeB2tKMl0pYdhtZ1MAQyZtPL-3m6es4G0,31035
flask/config.py,sha256=3dejvQRYfNHw_V7dCLMxU8UNFpL34xIKemN7gHZIZ8Y,10052
flask/ctx.py,sha256=cks-omGedkxawHFo6bKIrdOHsJCAgg1i_NWw_htxb5U,16724
flask/debughelpers.py,sha256=-whvPKuAoU8AZ9c1z_INuOeBgfYDqE1J2xNBsoriugU,6475
flask/globals.py,sha256=OgcHb6_NCyX6-TldciOdKcyj4PNfyQwClxdMhvov6aA,1637
flask/helpers.py,sha256=IHa578HU_3XAAo1wpXQv24MYRYO5TzaiDQQwvUIcE6Q,43074
flask/json/__init__.py,sha256=6nITbZYiYOPB8Qfi1-dvsblwn01KRz8VOsMBIZyaYek,11988
flask/json/__pycache__/__init__.cpython-39.pyc,,
flask/json/__pycache__/tag.cpython-39.pyc,,
flask/json/tag.py,sha256=vq9GOllg_0kTWKuVFrwmkeOQzR-jdBD23x-89JyCCQI,8306
flask/logging.py,sha256=WcY5UkqTysGfmosyygSlXyZYGwOp3y-VsE6ehoJ48dk,3250
flask/sessions.py,sha256=G0KsEkr_i1LG_wOINwFSOW3ts7Xbv4bNgEZKc7TRloc,14360
flask/signals.py,sha256=yYLOed2x8WnQ7pirGalQYfpYpCILJ0LJhmNSrnWvjqw,2212
flask/templating.py,sha256=F8E_IZXn9BGsjMzUJ5N_ACMyZdiFBp_SSEaUunvfZ7g,4939
flask/testing.py,sha256=WXsciCQbHBP7xjHqNvOA4bT0k86GvSNpgzncfXLDEEg,10146
flask/views.py,sha256=eeWnadLAj0QdQPLtjKipDetRZyG62CT2y7fNOFDJz0g,5802
flask/wrappers.py,sha256=kgsvtZuMM6RQaDqhRbc5Pcj9vqTnaERl2pmXcdGL7LU,4736
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Wheel-Version: 1.0
Generator: bdist_wheel (0.33.6)
Root-Is-Purelib: true
Tag: py2-none-any
Tag: py3-none-any

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[console_scripts]
flask = flask.cli:main

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Copyright 2007 Pallets

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Loading
Loading