Skip to content

Commit

Permalink
Merge pull request #1148 from CompositionalIT/modern-app-insights
Browse files Browse the repository at this point in the history
Add support to Log Analytics for Web App and Functions.
  • Loading branch information
isaacabraham authored Nov 3, 2024
2 parents 52d23a0 + ec0bad2 commit aee1086
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 91 deletions.
9 changes: 8 additions & 1 deletion Farmer.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29201.188
Expand Down Expand Up @@ -67,6 +67,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tutorials", "tutorials", "{
samples\scripts\tutorials\webapp-keyvault.fsx = samples\scripts\tutorials\webapp-keyvault.fsx
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SampleApp", "samples\SampleApp\SampleApp.fsproj", "{4FA93ACF-25E8-4469-A2AC-4B339675EAF7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -81,13 +83,18 @@ Global
{D68F5B81-6F18-4FC7-B9FD-2113EE7614CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D68F5B81-6F18-4FC7-B9FD-2113EE7614CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D68F5B81-6F18-4FC7-B9FD-2113EE7614CE}.Release|Any CPU.Build.0 = Release|Any CPU
{4FA93ACF-25E8-4469-A2AC-4B339675EAF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FA93ACF-25E8-4469-A2AC-4B339675EAF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FA93ACF-25E8-4469-A2AC-4B339675EAF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FA93ACF-25E8-4469-A2AC-4B339675EAF7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C3991DD2-B728-4EDD-ACD1-2C1470309481} = {47438D72-1C5F-49EB-B7E5-B597F565B14B}
{0053093F-A18C-4FAC-A138-9F5D60CFA24F} = {C3991DD2-B728-4EDD-ACD1-2C1470309481}
{4FA93ACF-25E8-4469-A2AC-4B339675EAF7} = {47438D72-1C5F-49EB-B7E5-B597F565B14B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {63B0361D-FC8A-40CF-B988-5BE797ADD2CE}
Expand Down
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ Release Notes
=============
## vNext
* SQL Azure: Clean up Entra ID authentication support.
* Web App: Support automatic creation of Workspace Based App Insights & Log Analytics.
* Functions: Support automatic creation of Workspace Based App Insights & Log Analytics.
* Az: Update `ad` commands to work with latest (breaking) structure.
* PostgreSQL: Fix a number of issues around the introduction of Flexible Servers.

Expand Down
3 changes: 2 additions & 1 deletion docs/content/api-overview/resources/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The Functions builder is used to create Azure Functions accounts. It abstracts t
| link_to_unmanaged_storage_account | Do not create an automatic storage account; instead, link to an existing storage account that was created external to Farmer. |
| https_only | Disables http for this functions app so that only HTTPS is used. |
| ftp_state | Allows to enable or disable FTP and FTPS. |
| Web App | use_workspace_based_app_insights | Instructs Farmer to use Workspace Based App Insights, which automatically comes with a Log Analytics instance. Both resources will be automatically created. |
| app_insights_name | Sets the name of the automatically-created app insights instance. |
| app_insights_off | Removes any automatic app insights creation, configuration and settings for this webapp. |
| link_to_app_insights | Instead of creating a new AI instance, configure this webapp to point to another AI instance that you are managing yourself. |
Expand Down Expand Up @@ -52,7 +53,7 @@ The Functions builder is used to create Azure Functions accounts. It abstracts t
| add_denied_ip_restriction | Adds an 'deny' rule for an ip |
| link_to_vnet | Enable the VNET integration feature in azure where all outbound traffic from the function with be sent via the specified subnet. Use this operator when the given VNET is in the same deployment |
| link_to_unmanaged_vnet | Enable the VNET integration feature in azure where all outbound traffic from the function with be sent via the specified subnet. Use this operator when the given VNET is *not* in the same deployment |
| max_scale_out_limit | Maximum number of workers that a site can scale out to. This setting only applies to the Consumption and Elastic Premium Plans |
| max_scale_out_limit | Maximum number of workers that a site can scale out to. This setting only applies to the Consumption and Elastic Premium Plans |
#### Post-deployment Builder Keywords
The Functions builder contains special commands that are executed *after* the ARM deployment is completed.

Expand Down
1 change: 1 addition & 0 deletions docs/content/api-overview/resources/web-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The Web App builder is used to create Azure App Service accounts. It abstracts t
| Web App | name | Sets the name of the web app. |
| Web App | link_to_service_plan | Instructs Farmer to link this webapp to a Farmer service plan configuration defined elsewhere in your application, rather than creating a new one. |
| Web App | link_to_unmanaged_service_plan | Instructs Farmer to link this webapp to an existing service plan that is externally managed, rather than creating a new one. |
| Web App | use_workspace_based_app_insights | Instructs Farmer to use Workspace Based App Insights, which automatically comes with a Log Analytics instance. Both resources will be automatically created. |
| Web App | app_insights_name | Sets the name of the automatically-created app insights instance. |
| Web App | app_insights_off | Removes any automatic app insights creation, configuration and settings for this webapp. |
| Web App | link_to_app_insights | Instructs Farmer to link this webapp to a Farmer App Insights configuration defined elsewhere in your application, rather than creating a new one. |
Expand Down
1 change: 0 additions & 1 deletion src/Farmer/Arm/Databricks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Farmer.Arm.Databricks

open Farmer
open Farmer.Databricks
open Farmer.Arm.Network
open System

let workspaces = ResourceType("Microsoft.Databricks/workspaces", "2018-04-01")
Expand Down
2 changes: 1 addition & 1 deletion src/Farmer/Arm/Insights.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let componentsWorkspace = createComponents "2020-02-02"
/// The type of AI instance to create.
type InstanceKind =
| Classic
| Workspace of ResourceId
| Workspace of workspace: ResourceId

member this.ResourceType =
match this with
Expand Down
60 changes: 41 additions & 19 deletions src/Farmer/Builders/Builders.Functions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type FunctionsConfig = {
[<Obsolete("Prefer AppInsightsId instead as this property ignores resource groups")>]
member this.AppInsightsName: ResourceName option =
this.CommonWebConfig.AppInsights
|> Option.map (fun ai -> ai.resourceId(this.Name.ResourceName).Name)
|> Option.map (fun cfg -> cfg.AppInsights.resourceId(this.Name.ResourceName).Name)

/// Gets the Storage Account name for this functions app.
[<Obsolete("Prefer StorageAccountId instead as this property ignores resource groups")>]
Expand All @@ -128,7 +128,7 @@ type FunctionsConfig = {
/// Gets the App Insights resourceId for this functions app, if it exists.
member this.AppInsightsId: ResourceId option =
this.CommonWebConfig.AppInsights
|> Option.map (fun ai -> ai.resourceId (this.Name.ResourceName))
|> Option.map (fun cfg -> cfg.AppInsights.resourceId (this.Name.ResourceName))

/// Gets the Storage Account resourceId for this functions app.
member this.StorageAccountId: ResourceId = this.StorageAccount.resourceId (this)
Expand Down Expand Up @@ -279,9 +279,10 @@ type FunctionsConfig = {
Set [
yield! this.Dependencies

match this.CommonWebConfig.AppInsights with
match this.CommonWebConfig.AppInsights |> Option.map _.AppInsights with
| Some(DependableResource this.Name.ResourceName resourceId) -> resourceId
| _ -> ()
| Some _
| None -> ()

for setting in this.CommonWebConfig.Settings do
match setting.Value with
Expand Down Expand Up @@ -388,22 +389,43 @@ type FunctionsConfig = {
| _ -> ()

match this.CommonWebConfig.AppInsights with
| Some(DeployableResource this.Name.ResourceName resourceId) -> {
Name = resourceId.Name
Location = location
DisableIpMasking = false
SamplingPercentage = 100
Dependencies = Set.empty
InstanceKind = Classic
LinkedWebsite =
match this.CommonWebConfig.OperatingSystem with
| Windows -> Some this.Name.ResourceName
| Linux -> None
Tags = this.Tags
}
| Some _
| Some appInsights ->
match appInsights.AppInsights with
| DeployableResource this.Name.ResourceName resourceId -> {
Name = resourceId.Name
Location = location
DisableIpMasking = false
SamplingPercentage = 100
InstanceKind =
match appInsights with
| ClassicAi _ -> Classic
| WorkspaceAi cfg -> Workspace(cfg.LogAnalytics.resourceId this.Name.ResourceName)
Dependencies =
match appInsights with
| ClassicAi _ -> Set.empty
| WorkspaceAi cfg -> Set [ cfg.LogAnalytics.resourceId this.Name.ResourceName ]
LinkedWebsite = Some this.Name.ResourceName
Tags = this.Tags
}
| _ -> ()

match appInsights with
| ClassicAi _ -> ()
| WorkspaceAi cfg ->
match cfg.LogAnalytics with
| DeployableResource this.Name.ResourceName resourceId -> {
Name = resourceId.Name
Location = location
RetentionPeriod = None
IngestionSupport = None
QuerySupport = None
DailyCap = None
Tags = this.Tags
}
| _ -> ()
| None -> ()


match this.CommonWebConfig.IntegratedSubnet with
| None -> ()
| Some subnetRef -> {
Expand Down Expand Up @@ -432,7 +454,7 @@ type FunctionsBuilder() =
FunctionsConfig.CommonWebConfig = {
Name = WebAppName.Empty
AlwaysOn = false
AppInsights = Some(derived (fun name -> components.resourceId (name - "ai")))
AppInsights = Some(ClassicAi(derived (fun name -> components.resourceId (name - "ai"))))
ConnectionStrings = Map.empty
Cors = None
FTPState = None
Expand Down
Loading

0 comments on commit aee1086

Please sign in to comment.