Skip to content

Commit

Permalink
Revert "Remove sampling_percentage until SDK issue fixed"
Browse files Browse the repository at this point in the history
This reverts commit a6ede6c.
  • Loading branch information
sirlatrom committed Nov 13, 2020
1 parent a6ede6c commit 41c7158
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ func resourceArmApiManagementApiDiagnostic() *schema.Resource {
ValidateFunc: validate.ApiManagementLoggerID,
},

"sampling_percentage": {
Type: schema.TypeFloat,
Optional: true,
Computed: true,
ValidateFunc: validation.FloatBetween(0.0, 100.0),
},

"always_log_errors": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -161,6 +168,15 @@ func resourceArmApiManagementApiDiagnosticCreateUpdate(d *schema.ResourceData, m
},
}

if samplingPercentage, ok := d.GetOk("sampling_percentage"); ok {
parameters.Sampling = &apimanagement.SamplingSettings{
SamplingType: apimanagement.Fixed,
Percentage: utils.Float(samplingPercentage.(float64)),
}
} else {
parameters.Sampling = nil
}

if alwaysLogErrors, ok := d.GetOk("always_log_errors"); ok && alwaysLogErrors.(bool) {
parameters.AlwaysLog = apimanagement.AllErrors
}
Expand Down Expand Up @@ -258,6 +274,9 @@ func resourceArmApiManagementApiDiagnosticRead(d *schema.ResourceData, meta inte
d.Set("api_management_name", diagnosticId.ServiceName)
if props := resp.DiagnosticContractProperties; props != nil {
d.Set("api_management_logger_id", props.LoggerID)
if props.Sampling != nil && props.Sampling.Percentage != nil {
d.Set("sampling_percentage", props.Sampling.Percentage)
}
d.Set("always_log_errors", props.AlwaysLog == apimanagement.AllErrors)
d.Set("verbosity", props.Verbosity)
d.Set("log_client_ip", props.LogClientIP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ resource "azurerm_api_management_api_diagnostic" "test" {
api_management_name = azurerm_api_management.test.name
api_name = azurerm_api_management_api.test.name
api_management_logger_id = azurerm_api_management_logger.test.id
sampling_percentage = 10
always_log_errors = true
log_client_ip = true
http_correlation_protocol = "W3C"
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/api_management_api_diagnostic.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ resource "azurerm_api_management_api_diagnostic" "example" {
api_name = azurerm_api_management_api.example.name
api_management_logger_id = azurerm_api_management_logger.example.id
sampling_percentage = 5.0
always_log_errors = true
log_client_ip = true
verbosity = "Verbose"
Expand Down Expand Up @@ -142,6 +143,8 @@ The following arguments are supported:

* `log_client_ip` - (Optional) Log client IP address.

* `sampling_percentage` - (Optional) Sampling (%). For high traffic APIs, please read this [documentation](https://docs.microsoft.com/azure/api-management/api-management-howto-app-insights#performance-implications-and-log-sampling) to understand performance implications and log sampling. Valid values are between `0.0` and `100.0`.

* `verbosity` - (Optional) Logging verbosity. Possible values are `verbose`, `information` or `error`.

---
Expand Down

0 comments on commit 41c7158

Please sign in to comment.