Skip to content

Commit

Permalink
Add validation for include_aggregated_endpoint (#13793)
Browse files Browse the repository at this point in the history
* Add validation for include_aggregated_endpoint

* Use stronger language

* Use  rather than  for validation error
  • Loading branch information
yzhan289 authored Jan 24, 2023
1 parent c329441 commit ad8b9d9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rabbitmq/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ files:
- name: include_aggregated_endpoint
description: |
Whether or not to include metrics from the aggregated endpoint (/metrics).
Note: This option must be set to true when 'unaggregated_endpoint' is unspecified.
value:
type: boolean
example: true
Expand Down
5 changes: 5 additions & 0 deletions rabbitmq/datadog_checks/rabbitmq/config_models/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,10 @@ def initialize_instance(values, **kwargs):
agg_ep = plugin_settings['include_aggregated_endpoint']
if not isinstance(agg_ep, bool):
raise TypeError("'prometheus_plugin.include_aggregated_endpoint' must be a boolean.")
if not agg_ep and 'unaggregated_endpoint' not in plugin_settings:
raise ValueError(
"'prometheus_plugin.include_aggregated_endpoint' field must "
+ "be set to 'true' when 'prometheus_plugin.unaggregated_endpoint' is not collected."
)

return values
2 changes: 2 additions & 0 deletions rabbitmq/datadog_checks/rabbitmq/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ instances:

## @param include_aggregated_endpoint - boolean - optional - default: true
## Whether or not to include metrics from the aggregated endpoint (/metrics).
##
## Note: This option must be set to true when 'unaggregated_endpoint' is unspecified.
#
# include_aggregated_endpoint: true

Expand Down
6 changes: 6 additions & 0 deletions rabbitmq/tests/test_openmetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ def test_aggregated_and_unaggregated_endpoints(endpoint, metrics, aggregator, dd
r"'prometheus_plugin\.include_aggregated_endpoint' must be a boolean\.",
id="Aggregated_endpoint must be a boolean.",
),
pytest.param(
{'url': "http://localhost", "include_aggregated_endpoint": False},
r"'prometheus_plugin\.include_aggregated_endpoint' field must be set to 'true' "
+ r"when 'prometheus_plugin\.unaggregated_endpoint' is not collected\.",
id="include_aggregated_endpoint must be true when unaggregated_endpoint is missing.",
),
],
)
def test_config(prom_plugin_settings, err):
Expand Down

0 comments on commit ad8b9d9

Please sign in to comment.