-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse unavailable indexer health messages and emit metric (#162)
Signed-off-by: Russell Troxel <[email protected]>
- Loading branch information
Showing
5 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package collector | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/onedr0p/exportarr/internal/arr/model" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
type testCollector struct { | ||
emitter ExtraHealthMetricEmitter | ||
msg model.SystemHealthMessage | ||
} | ||
|
||
func (c *testCollector) Describe(ch chan<- *prometheus.Desc) { | ||
ch <- c.emitter.Describe() | ||
} | ||
|
||
func (c *testCollector) Collect(ch chan<- prometheus.Metric) { | ||
for _, metric := range c.emitter.Emit(c.msg) { | ||
ch <- metric | ||
} | ||
} | ||
|
||
func TestUnavailableIndexerEmitter(t *testing.T) { | ||
emitter := UnavailableIndexerEmitter{ | ||
url: "http://localhost:9117", | ||
} | ||
|
||
require := require.New(t) | ||
require.NotNil(emitter.Describe()) | ||
|
||
msg := model.SystemHealthMessage{ | ||
Source: "IndexerLongTermStatusCheck", | ||
Type: "warning", | ||
WikiURL: "https://wiki.servarr.com/prowlarr/system#indexers-are-unavailable-due-to-failures", | ||
Message: "Indexers unavailable due to failures for more than 6 hours: Server1, ServerTwo, ServerTHREE, Server.four", | ||
} | ||
metrics := emitter.Emit(msg) | ||
require.Len(metrics, 4) | ||
|
||
testCol := &testCollector{ | ||
emitter: &emitter, | ||
msg: msg, | ||
} | ||
|
||
expected := strings.NewReader( | ||
`# HELP prowlarr_indexer_unavailable Indexers marked unavailable due to repeated errors | ||
# TYPE prowlarr_indexer_unavailable gauge | ||
prowlarr_indexer_unavailable{indexer="Server.four",url="http://localhost:9117"} 1 | ||
prowlarr_indexer_unavailable{indexer="Server1",url="http://localhost:9117"} 1 | ||
prowlarr_indexer_unavailable{indexer="ServerTHREE",url="http://localhost:9117"} 1 | ||
prowlarr_indexer_unavailable{indexer="ServerTwo",url="http://localhost:9117"} 1 | ||
`) | ||
err := testutil.CollectAndCompare(testCol, expected) | ||
require.NoError(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters