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

Deploy to vmss #32

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 38 additions & 8 deletions azure-vote/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,50 @@
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=69e80301-f0a4-4298-b85b-348f68b2d04e;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/'))
logger.addHandler(AzureEventHandler(connection_string='InstrumentationKey=69e80301-f0a4-4298-b85b-348f68b2d04e;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/'))
logger.setLevel(logging.INFO)

# Metrics
exporter = # TODO: Setup exporter
exporter = metrics_exporter.new_metrics_exporter(
enable_standard_metrics=True,
connection_string='InstrumentationKey=69e80301-f0a4-4298-b85b-348f68b2d04e;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/')
# TODO: Setup exporter


# Tracing
tracer = # TODO: Setup tracer
tracer = Tracer(
exporter=AzureExporter(
connection_string='InstrumentationKey=69e80301-f0a4-4298-b85b-348f68b2d04e;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/'),
sampler=ProbabilitySampler(1.0),
)
# TODO: Setup tracer

app = Flask(__name__)

# Requests
middleware = # TODO: Setup flask middleware
middleware = FlaskMiddleware(
app,
exporter=AzureExporter(connection_string="InstrumentationKey=69e80301-f0a4-4298-b85b-348f68b2d04e;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/"),
sampler=ProbabilitySampler(rate=1.0),
)

# Load configurations from environment or config file
app.config.from_pyfile('config_file.cfg')
Expand Down Expand Up @@ -60,9 +87,12 @@ def index():

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

vote2 = r.get(button2).decode('utf-8')
# TODO: use tracer object to trace dog vote
with tracer.span(name="Total {} Voted: {}".format(button1, vote1)) as span:
print("Dogs Vote")

# Return index with values
return render_template("index.html", value1=int(vote1), value2=int(vote2), button1=button1, button2=button2, title=title)
Expand All @@ -76,11 +106,11 @@ def index():
r.set(button2,0)
vote1 = r.get(button1).decode('utf-8')
properties = {'custom_dimensions': {'Cats Vote': vote1}}
# TODO: use logger object to log cat vote
logger.info("{} voted".format(button1), extra=properties)

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

return render_template("index.html", value1=int(vote1), value2=int(vote2), button1=button1, button2=button2, title=title)

Expand Down
4 changes: 2 additions & 2 deletions setup-script.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

# Variables
resourceGroup="acdnd-c4-project"
location="westus"
resourceGroup="finalproject1209"
location="eastasia"
osType="Ubuntu2204"
vmssName="udacity-vmss"
adminName="udacityadmin"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.