onedr0p / exportarr

AIO Prometheus Exporter for Sabnzbd, Bazarr, Prowlarr, Lidarr, Readarr, Radarr, and Sonarr
MIT License
575 stars 43 forks source link

Bazarr: error when there are no series #244

Open RobReus opened 1 year ago

RobReus commented 1 year ago

When bazarr contains no series, it will still try to fetch the episodes. This results in the episodes api endpoint returning a 404, and as a result, exportarr returns a 500 to prometheus when prometheus tries to scrape the metrics. I believe this is a bug, as it would be a perfectly acceptable scenario to have no series in bazarr at all.

The culprit is in this part: https://github.com/onedr0p/exportarr/blob/e732d200a9a7cac6f84e9e1f8f1faee74dcb5d58/internal/arr/collector/bazarr.go#L389

When no series are returned, the collector should not attempt to fetch the episodes (as there is nothing to fetch).

This is the error returned by exportarr /metrics when there are no series:

< HTTP/1.1 500 Internal Server Error

An error has occurred while serving metrics:

error collecting metric Desc{fqName: "bazarr_collector_error", help: "Error while collecting metrics", constLabels: {url="http://bazarr:6767"}, variableLabels: {}}: Failed to execute HTTP Request(http://bazarr:6767/api/episodes): Get "http://bazarr:6767/api/episodes": Received Client Error Status Code: 404

And from the exportarr logs:

2023-11-20T12:12:47.147+0100    INFO    Sending HTTP request    {"url": "http://bazarr:6767/api/system/health"}
2023-11-20T12:12:47.150+0100    INFO    Sending HTTP request    {"url": "http://bazarr:6767/api/system/status"}
2023-11-20T12:13:02.137+0100    INFO    Sending HTTP request    {"url": "http://bazarr:6767/api/series"}
2023-11-20T12:13:02.141+0100    INFO    Sending HTTP request    {"url": "http://bazarr:6767/api/episodes"}
2023-11-20T12:13:02.142+0100    ERROR   Error getting episodes subtitles    {"collector": "bazarr", "error": "Failed to execute HTTP Request(http://bazarr:6767/api/episodes): Get \"http://bazarr:6767/api/episodes\": Received Client Error Status Code: 404"}

As soon as you add sonarr to bazarr and it synced the series, it starts to work without problems.

Let me know if any other details are required.

phyzical commented 9 months ago

while minor, easily avoided. will look at adding in a check at some point after https://github.com/onedr0p/exportarr/pull/238 is merged

phyzical commented 9 months ago

i adjusted the tests to take a bunch of empty json payloads, kept a series list so it would try for episodes and it didnt throw any errors. i don't think this is a reproducible as it seems.

Given how short the window for this to be an issue is id argue we just close (unless theres more info for reproduce?)

rtrox commented 8 months ago

There's really two situations that would lead to this state:

  1. As was reported, exportarr turning up while there are no series added to bazarr.
  2. The Series call fails for some other reason.

In the latter case, a 5XX response is the expected handling in prometheus, as this indicates to prometheus that the scrape failed (A 5XX actually flops the up metrics to 0). For the former case, we can just return if the response to the seriesId call is empty.