Skip to content

Commit

Permalink
Merge pull request #26 from ties/feature/v0.5.0
Browse files Browse the repository at this point in the history
rename modem_upstream_timeouts to modem_upstream_timeout_count
  • Loading branch information
ties authored Mar 9, 2024
2 parents ffa6db2 + 50c94ed commit 2409e41
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@

## 2024-03-09 (v0.5.0)

* Enable dependabot dependency management
* Add `modem_upstream_timeout_count` metric that will replace
`modem_upstream_timeouts` metric (clearer name).
* **deprecated** `modem_upstream_timeouts` metric. Will be removed on or after 1-5-20204.

## 2024-02-17 (v0.4.1)

* fix: `modem_upstream_ofdm` metric is now called `modem_upstream_ofdma`
Expand Down
34 changes: 29 additions & 5 deletions sagemcom_f3896_client/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
)


class MetricUpdateFailedError(Exception):
class MetricUpdateFailedException(Exception):
pass


Expand Down Expand Up @@ -111,7 +111,7 @@ async def metrics(self, _: web.Request) -> web.Response:
LOG.info("Timeout when updating metrics - using old values")
MODEM_UPDATE_COUNT.labels(status="timeout").inc()
MODEM_LAST_UPDATE.labels(status="timeout").set_to_current_time()
except MetricUpdateFailedError:
except MetricUpdateFailedException:
pass

# from aiohttp support in prometheus-async
Expand All @@ -130,7 +130,7 @@ async def update_metrics(self) -> None:
if self.__metrics_updating_lock.locked():
MODEM_UPDATE_COUNT.labels(status="locked").inc()
MODEM_LAST_UPDATE.labels(status="locked").set_to_current_time()
raise MetricUpdateFailedError("Metrics are already being updated")
raise MetricUpdateFailedException("Metrics are already being updated")

async with self.__metrics_updating_lock:
registry = CollectorRegistry()
Expand Down Expand Up @@ -172,12 +172,12 @@ async def update_metrics(self) -> None:
MODEM_UPDATE_COUNT.labels(status="failed").inc()
MODEM_LAST_UPDATE.labels(status="failed").set_to_current_time()

raise MetricUpdateFailedError() from e
raise MetricUpdateFailedException() from e
except LoginFailedException as e:
MODEM_UPDATE_COUNT.labels(status="login_failed").inc()
MODEM_LAST_UPDATE.labels(status="login_failed").set_to_current_time()

raise MetricUpdateFailedError() from e
raise MetricUpdateFailedException() from e
finally:
# async logout so we do not block the web interface
# keep strong reference to task to prevent GC before it runs/finishes:
Expand Down Expand Up @@ -207,6 +207,12 @@ async def __update_upstream_channel_metrics(self, registry: CollectorRegistry):

# Technically a counter, but value of a counter can not be set
metric_upstream_timeouts = Gauge(
"modem_upstream_timeout_total",
"Upstream timeouts by type",
["channel", "channel_type", "timeout_type"],
registry=registry,
)
metric_upstream_timeouts_legacy = Gauge(
"modem_upstream_timeouts",
"Upstream timeouts by type",
["channel", "channel_type", "timeout_type"],
Expand Down Expand Up @@ -244,6 +250,13 @@ async def __update_upstream_channel_metrics(self, registry: CollectorRegistry):
metric_upstream_timeouts.labels(
channel=ch.channel_id, channel_type=ch.channel_type, timeout_type="t4"
).set(ch.t4_timeouts)
# legacy metric (deprecated, removal after 1-5-2024)
metric_upstream_timeouts_legacy.labels(
channel=ch.channel_id, channel_type=ch.channel_type, timeout_type="t3"
).set(ch.t3_timeouts)
metric_upstream_timeouts_legacy.labels(
channel=ch.channel_id, channel_type=ch.channel_type, timeout_type="t4"
).set(ch.t4_timeouts)

match ch.channel_type:
case "atdma":
Expand All @@ -265,6 +278,17 @@ async def __update_upstream_channel_metrics(self, registry: CollectorRegistry):
channel_type=ch.channel_type,
timeout_type="t2",
).set(ch.t2_timeouts)
# legacy metric (deprecated, removal after 1-5-2024)
metric_upstream_timeouts_legacy.labels(
channel=ch.channel_id,
channel_type=ch.channel_type,
timeout_type="t1",
).set(ch.t1_timeouts)
metric_upstream_timeouts_legacy.labels(
channel=ch.channel_id,
channel_type=ch.channel_type,
timeout_type="t2",
).set(ch.t2_timeouts)
case "ofdma":
metric_upstream_ofdma_info.labels(
channel=ch.channel_id, channel_type=ch.channel_type
Expand Down

0 comments on commit 2409e41

Please sign in to comment.