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 Jan 20, 2021
1 parent f864eef commit fbac625
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 @@ -129,6 +129,13 @@ func resourceApiManagementApiDiagnosticAdditionalContentSchema() *schema.Schema
},
},

"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 @@ -229,6 +236,15 @@ func resourceApiManagementApiDiagnosticCreateUpdate(d *schema.ResourceData, meta
},
}

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 @@ -326,6 +342,9 @@ func resourceApiManagementApiDiagnosticRead(d *schema.ResourceData, meta interfa
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 @@ -260,6 +260,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 fbac625

Please sign in to comment.