Skip to content

Commit

Permalink
Format with Fantomas v6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Mar 31, 2023
1 parent 098c447 commit 2e677bf
Show file tree
Hide file tree
Showing 178 changed files with 29,374 additions and 31,522 deletions.
156 changes: 75 additions & 81 deletions src/Farmer/Arm/Alert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,31 @@ type MetricAggregation =
// E.g. if average of VM CPU is going over 80% for 15 minutes -> alert
/// See the MetricNames and their Aggregations:
/// https://docs.microsoft.com/en-us/azure/azure-monitor/essentials/metrics-supported
type ResourceCriteria =
{
/// Resource type name
MetricNamespace: ResourceType
/// Name of the metric
MetricName: MetricsName
/// Threshold to exceed to hit the alert
Threshold: int
/// Equals, GreaterThan, GreaterThanOrEqual, LessThan or LessThanOrEqual
Comparison: MetricComparison
/// Average, Count, Total, Maximum, Minimum
Aggregation: MetricAggregation
}

type CustomMetricCriteria =
{
/// Resource type name. Default value is "Azure.ApplicationInsights"
MetricNamespace: ResourceType option
/// Name of the metric
MetricName: MetricsName
/// Threshold to exceed to hit the alert
Threshold: int
/// Equals, GreaterThan, GreaterThanOrEqual, LessThan or LessThanOrEqual
Comparison: MetricComparison
/// Average, Count, Total, Maximum, Minimum
Aggregation: MetricAggregation
}
type ResourceCriteria = {
/// Resource type name
MetricNamespace: ResourceType
/// Name of the metric
MetricName: MetricsName
/// Threshold to exceed to hit the alert
Threshold: int
/// Equals, GreaterThan, GreaterThanOrEqual, LessThan or LessThanOrEqual
Comparison: MetricComparison
/// Average, Count, Total, Maximum, Minimum
Aggregation: MetricAggregation
}

type CustomMetricCriteria = {
/// Resource type name. Default value is "Azure.ApplicationInsights"
MetricNamespace: ResourceType option
/// Name of the metric
MetricName: MetricsName
/// Threshold to exceed to hit the alert
Threshold: int
/// Equals, GreaterThan, GreaterThanOrEqual, LessThan or LessThanOrEqual
Comparison: MetricComparison
/// Average, Count, Total, Maximum, Minimum
Aggregation: MetricAggregation
}

/// Metric criterias
/// https://docs.microsoft.com/en-us/azure/templates/microsoft.insights/metricalerts?tabs=json#metricalertcriteria
Expand All @@ -79,11 +77,10 @@ type MetricAlertCriteria =
WebTestId: Farmer.ResourceId *
FailedLocationCount: int

type AlertAction =
{
actionGroupId: string
webHookProperties: obj
}
type AlertAction = {
actionGroupId: string
webHookProperties: obj
}

let mapResourceCriteriaOperator (comparison: MetricComparison) =
match comparison with
Expand All @@ -103,7 +100,7 @@ let mapResourceCriteriaTimeAggregation (aggregation: MetricAggregation) =

let createCriteria (criteria: MetricAlertCriteria) =
match criteria with
| MultipleResourceMultipleMetricCriteria (multicriteria: obj list) ->
| MultipleResourceMultipleMetricCriteria(multicriteria: obj list) ->
{|
allOf = multicriteria
``odata.type`` = "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria"
Expand All @@ -113,47 +110,45 @@ let createCriteria (criteria: MetricAlertCriteria) =
{|
allOf =
criterias
|> List.map (fun resourcecriteria ->
{|
threshold = resourcecriteria.Threshold
name = "Metric1"
metricNamespace = resourcecriteria.MetricNamespace.Type
metricName =
resourcecriteria.MetricName
|> (function
| MetricsName n -> n)
operator = resourcecriteria.Comparison |> mapResourceCriteriaOperator
timeAggregation = resourcecriteria.Aggregation |> mapResourceCriteriaTimeAggregation
criterionType = "StaticThresholdCriterion"
|})
|> List.map (fun resourcecriteria -> {|
threshold = resourcecriteria.Threshold
name = "Metric1"
metricNamespace = resourcecriteria.MetricNamespace.Type
metricName =
resourcecriteria.MetricName
|> (function
| MetricsName n -> n)
operator = resourcecriteria.Comparison |> mapResourceCriteriaOperator
timeAggregation = resourcecriteria.Aggregation |> mapResourceCriteriaTimeAggregation
criterionType = "StaticThresholdCriterion"
|})
``odata.type`` = "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria"
|}
:> obj
| SingleResourceMultipleCustomMetricCriteria criterias ->
{|
allOf =
criterias
|> List.map (fun resourcecriteria ->
{|
threshold = resourcecriteria.Threshold
name = "Metric1"
metricNamespace =
resourcecriteria.MetricNamespace
|> Option.defaultValue (ResourceType("Azure.ApplicationInsights", ""))
|> (fun resourceType -> resourceType.Type)
metricName =
resourcecriteria.MetricName
|> (function
| MetricsName n -> n)
operator = resourcecriteria.Comparison |> mapResourceCriteriaOperator
timeAggregation = resourcecriteria.Aggregation |> mapResourceCriteriaTimeAggregation
criterionType = "StaticThresholdCriterion"
skipMetricValidation = true
|})
|> List.map (fun resourcecriteria -> {|
threshold = resourcecriteria.Threshold
name = "Metric1"
metricNamespace =
resourcecriteria.MetricNamespace
|> Option.defaultValue (ResourceType("Azure.ApplicationInsights", ""))
|> (fun resourceType -> resourceType.Type)
metricName =
resourcecriteria.MetricName
|> (function
| MetricsName n -> n)
operator = resourcecriteria.Comparison |> mapResourceCriteriaOperator
timeAggregation = resourcecriteria.Aggregation |> mapResourceCriteriaTimeAggregation
criterionType = "StaticThresholdCriterion"
skipMetricValidation = true
|})
``odata.type`` = "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria"
|}
:> obj
| WebtestLocationAvailabilityCriteria (componentId, webTestId, failedLocationCount) ->
| WebtestLocationAvailabilityCriteria(componentId, webTestId, failedLocationCount) ->
{|
webTestId = webTestId.Eval()
componentId = componentId.Eval()
Expand All @@ -162,17 +157,16 @@ let createCriteria (criteria: MetricAlertCriteria) =
|}
:> obj

type AlertData =
{
Name: Farmer.ResourceName
Description: string
Severity: AlertSeverity
Frequency: IsoDateTime
Window: IsoDateTime
Actions: List<AlertAction>
LinkedResources: ResourceId list
Criteria: MetricAlertCriteria
}
type AlertData = {
Name: Farmer.ResourceName
Description: string
Severity: AlertSeverity
Frequency: IsoDateTime
Window: IsoDateTime
Actions: List<AlertAction>
LinkedResources: ResourceId list
Criteria: MetricAlertCriteria
} with

interface Farmer.IArmResource with
member this.ResourceId = metricAlert.resourceId this.Name
Expand All @@ -185,12 +179,12 @@ type AlertData =

let scopes = this.LinkedResources |> List.rev |> List.map (fun r -> r.Eval())

{| metricAlert.Create(this.Name) with
tags = tags
location = "global"
dependsOn = this.LinkedResources |> List.map (fun r -> r.Eval())
properties =
{|
{|
metricAlert.Create(this.Name) with
tags = tags
location = "global"
dependsOn = this.LinkedResources |> List.map (fun r -> r.Eval())
properties = {|
description = this.Description
severity =
match this.Severity with
Expand Down
Loading

0 comments on commit 2e677bf

Please sign in to comment.