Git Product home page Git Product logo

csaappservicedeployments's Introduction

AppService Deployments

This repo will contain several examples of deploying an App Services. All of these deployments use nested deployments that are located in the CSA Nested Template Repo

Table of Content

Function Apps

Below we'll walk through some depoloyments that involve a Function Apps being deployed in Azure

Function App to Ingest Azure Cost Data into Log Analytics

Many customers would like to see Cost Anamolies that occcure in their Azure Environment. Currently that functionality isn't available in Azure Cost Management but if we were to ingest this data into Log Analytics we could use the build in Anamoly detection in the product. The below deployment will setup a function to ingest Azure Cost data into Log Analytics each day.

This architecture is made of of the following resources:

  • Azure Function App with System Managed Identity
  • Azure Log Analytics
  • Azure Application Insights
  • Azure Storage Account

Environment

Deploy to Azure

Post Deployment Steps

After deploying this solution you have to give the App Service System Assigned Managed Identity "Read" permissons at the scope or scopes that you are quering. The system assigned managed identity will have the same name as your function app.

If you want to load historical data into Log Analytics you can utilize the function named PreLoadLogAnalytics.

  1. Get the function url by opening the Function and clicking on Get Function URL. Note that it may take a little bit to light up.
  2. Use a tool like PostMan or Curl to send the request. Below is an example using curl.

curl 'https://poccostingestionfadhr2puxbmgliy.azurewebsites.net/api/PreLoadLogAnalytics?code=ichangedthisstring'

Deploying Solution

Use the below link to deploy this solution to Azure. Note Make sure you follow the Post Deployment Steps after completing the deployment.

Note There are two parameters that you need to supply:

  1. deploymentPrefix: this will prefix the name of all the resources created.
  2. scope: this defines the scope or scopes for the Cost Management API.
    • ex: subscriptions/5f1c1322-cebc-4ea3-8779-fac7d666e18f
    • ex: subscriptions/5f1c1322-cebc-4ea3-8779-fac7d666e18f, subscriptions/718c1322-cebc-4ea3-8779-fac7d666e18f

Deploy

Deployment Details

Below are the details on the ARM Template used to deploy this solution.

Log Analytics Workspace

The data from Azure Cost API will be stored in this Log Analytics Workspace. So the first step in the template is to deploy the workspace.

You can deploy Log Analytics using the following parameters:

        "workspaceName": {
          "value": "[variables('laName')]"
        }

Application Insights

We want to be able to monitor the Azure Function using Application Insights. So before we deploy our Azure Function we deploy Application Insights using the following properties:

        "name": {
          "value": "[variables('appInsightsName')]"
        }  

Storage Account

Azure Function store data on a storage account. So before we deploy our Azure Function we deploy a Storage Accoung using the following properties:

        "saName": {
          "value": "[variables('saName')]"
        },
        "skuName": {
            "value": "Standard_LRS"
        },
        "skuTier": {
            "value": "Standard"
        }  

Azure Function

Now that we have all the pre-reqs deployed we can deploy the Azure Function. The most important part of this deployment is configuring the Application Settings.

We pass in the Application Settings for the Function using an array formated like this:

[
    "name|value",
    "name|value"
]  

Below are the most important settings for our Function:
- AzureWebJobsStorage = connection string to the storage account
- AzureWebJobDashboard = connection string to the storage account
- WEBSITE_CONTENTAZUREFILECONNECTIONSTRING = connection string to the storage account
- WEBSITE_CONTENTSHARE = connection string to the storage account
- logName = Name of the log to be created in Log Analytics - scope = Comma seperated list of scope you want to query for Cost Data
- workspaceid = Log Analytics workspaceid to store the data
- workspacekey = Key for the log analytics workspace
- APPINSIGHTS_INSTRUMENTATIONKEY = Application Insights instrumentation key

Below are the values we provide in the template:

        "appName": {
          "value": "[variables('appName')]"
        },
        "appSettings": {
            "value": [
                "[concat('AzureWebJobsStorage|',reference('deployStorageAccount').outputs.saConnectionString.value,'')]",
                "[concat('AzureWebJobsDashboard|',reference('deployStorageAccount').outputs.saConnectionString.value,'')]",
                "[concat('WEBSITE_CONTENTAZUREFILECONNECTIONSTRING|',reference('deployStorageAccount').outputs.saConnectionString.value,'')]",
                "[concat('WEBSITE_CONTENTSHARE|', toLower(variables('appName')),'')]","FUNCTIONS_EXTENSION_VERSION|~3",
                "WEBSITE_NODE_DEFAULT_VERSION|~10",
                "FUNCTIONS_WORKER_RUNTIME|dotnet",
                "WEBSITE_RUN_FROM_PACKAGE|0",
                "logName|AzureCostAnamolies",
                "scope|subscriptions/5f1c1322-cebc-4ea3-8779-fac7d666e18f",
                "[concat('workspaceid|',reference('deployLogAnalytics').outputs.customerId.value,'')]",
                "[concat('workspacekey|',reference('deployLogAnalytics').outputs.workspaceKey.value,'')]",
                "[concat('APPINSIGHTS_INSTRUMENTATIONKEY|',reference('deployAppInsights').outputs.aiKey.value,'')]"
            ]
        }  

Deploy Code from GitHub

The last step is to actually deploy our Azure Function. The code for this is sitting in this repo under the AzureCost_to_LogAnalytics folder. We can utilize the WebAppSourceControl.json template to deploy this using the below properties:

        "appName": {
          "value": "[variables('appName')]"
        },
        "packageUri": {
            "value": "https://github.com/microsoft/CSAAppServiceDeployments.git"
        },
        "packageBranch": {
          "value": "main"
        }

csaappservicedeployments's People

Contributors

bwatts64 avatar microsoftopensource avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

csaappservicedeployments's Issues

'extend' operator: Failed to resolve table or column expression named 'AzureCostAnamolies_CL'...

@bwatts64

Getting the following error while loading the costworkbook.json.

https://raw.githubusercontent.com/microsoft/CSACostAnomalies/main/CostWorkbook.json

Error:

extend' operator: Failed to resolve table or column expression named 'AzureCostAnamolies_CL

Followed the below KB Article :

https://techcommunity.microsoft.com/t5/core-infrastructure-and-security/detecting-azure-cost-anomalies/ba-p/2020591

Managed identity role

Hi,

can the system assigned managed identity created in this deployment have cost management reader role instead of reader on the subscription level?

Workbook only showing data for one Resource Group

Hello,

we deployed this service and in scope we added multiple Subscriptions with multiple resource groups, but we noticed that in Workbook and Log Analytics we only see data for first Resource Group in first Subscription.
When we run code manually for test, we see that it pulls info from Cost API for all resources in way that first line of logs contains only data for first RG in first Subscription and each new line adds one new RG until last line where all RGs are listed, but in Log Analytics and Workbook we only see data from first RG.

Is this intentional because we don't have any anomaly and it will show any RG when it has anomaly, or it's a bug when only first line gets sent to Log Analytics?

Also is there recommended way to artificially test for anomaly without waiting for anomaly to appear?

PreLoadLogAnalytics - error

When trying to run the PreLoadLogAnalytics function I get an error

2021-02-03T10:43:48.438 [Error] Executed 'PreLoadLogAnalytics' (Failed, Id=c4e16c20-da6c-45d3-a186-cd6ddd4672e4, Duration=1663ms)Object reference not set to an instance of an object.

Application Insights doesn't show any valuable information to resolve the issue.

Any pointers?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.