Skip to content

Commit

Permalink
16867 FIX azure: Remove unnecessary 'metric not found' errors
Browse files Browse the repository at this point in the history
When querying metrics, Azure agent was reporting each missing metric in the
details of the 'Azure Agent Info' service. This didn't influence the status
of the service but still implied an error.

It was misleading because some metrics aren't defined in some types
of resources. Now, those metrics are optional and won't cause an error.

SUP-19726

Change-Id: If8f370610c32252f0f9499c4bfed4a60a4910203
  • Loading branch information
scolakovic committed Aug 16, 2024
1 parent e2a96ff commit 418c120
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
19 changes: 19 additions & 0 deletions .werks/16867.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[//]: # (werk v2)
# azure: Remove unnecessary 'metric not found' errors

key | value
---------- | ---
compatible | yes
version | 2.3.0p13
date | 2024-08-08T15:40:36+00:00
level | 1
class | fix
component | checks
edition | cre

When querying metrics, Azure agent was reporting each missing metric in the
details of the 'Azure Agent Info' service. This didn't influence the status
of the service but still implied an error.

It was misleading because some metrics aren't defined in some types
of resources. Now, those metrics are optional and won't cause an error.
30 changes: 27 additions & 3 deletions cmk/special_agents/agent_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,22 @@
],
}

OPTIONAL_METRICS: Mapping[str, Sequence[str]] = {
"Microsoft.Sql/servers/databases": [
"storage_percent",
"deadlock",
"dtu_consumption_percent",
],
"Microsoft.DBforMySQL/servers": ["seconds_behind_master"],
"Microsoft.DBforMySQL/flexibleServers": ["replication_lag"],
"Microsoft.DBforPostgreSQL/servers": ["pg_replica_log_delay_in_seconds"],
"Microsoft.Network/loadBalancers": ["AllocatedSnatPorts", "UsedSnatPorts"],
"Microsoft.Compute/virtualMachines": [
"CPU Credits Consumed",
"CPU Credits Remaining",
],
}


class TagsImportPatternOption(enum.Enum):
ignore_all = "IGNORE_ALL"
Expand Down Expand Up @@ -1340,7 +1356,7 @@ def get_validity_from_args(self, *args: Any) -> bool:
return True

def get_live_data(self, *args: Any) -> Any:
mgmt_client, resource_id, err = args
mgmt_client, resource_id, resource_type, err = args
metricnames, interval, aggregation, filter_ = self.metric_definition

raw_metrics = mgmt_client.metrics(
Expand All @@ -1358,7 +1374,11 @@ def get_live_data(self, *args: Any) -> Any:
if parsed_metric is not None:
metrics.append(parsed_metric)
else:
msg = "metric not found: {} ({})".format(raw_metric["name"]["value"], aggregation)
metric_name = raw_metric["name"]["value"]
if metric_name in OPTIONAL_METRICS.get(resource_type, []):
continue

msg = "metric not found: {} ({})".format(metric_name, aggregation)
err.add("info", resource_id, msg)
LOGGER.info(msg)

Expand Down Expand Up @@ -1408,7 +1428,11 @@ def gather_metrics(mgmt_client, resource, debug=False):
cache = MetricCache(resource, metric_def, NOW, debug=debug)
try:
resource.metrics += cache.get_data(
mgmt_client, resource.info["id"], err, use_cache=cache.cache_interval > 60
mgmt_client,
resource.info["id"],
resource.info["type"],
err,
use_cache=cache.cache_interval > 60,
)
except ApiError as exc:
if debug:
Expand Down

0 comments on commit 418c120

Please sign in to comment.