Skip to content

Commit

Permalink
fix: collectors ignore watches with missing title (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
schaermu authored Apr 16, 2024
1 parent 8ac0b80 commit 0547a71
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/collectors/watch_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,16 @@ func TestWatchCollector(t *testing.T) {
//testutil.ExpectMetricCount(t, c, 2, expectedWatchMetrics...)
testutil.ExpectMetrics(t, c, "watch_metrics.prom", expectedWatchMetrics...)
}

func TestWatchCollector_IgnoresWatchesWithoutTitle(t *testing.T) {
_, watchDb := testutil.NewCollectorTestDb()
server := testutil.CreateTestApiServer(t, watchDb)
emptyUuid, emptyTitleItem := testutil.NewTestItem("", 100, "CHF", 20, 15, 10)
watchDb[emptyUuid] = emptyTitleItem
defer server.Close()

client := cdio.NewTestApiClient(server.URL())
c := NewWatchCollector(client)

testutil.ExpectMetrics(t, c, "watch_metrics.prom", expectedWatchMetrics...)
}
4 changes: 4 additions & 0 deletions pkg/data/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package data

import (
"fmt"
"net/url"
)

Expand Down Expand Up @@ -38,5 +39,8 @@ func (w *WatchItem) GetMetrics() ([]string, error) {
if err != nil {
return nil, err
}
if w.Title == "" {
return nil, fmt.Errorf("title is empty")
}
return []string{w.Title, url.Host}, nil
}

0 comments on commit 0547a71

Please sign in to comment.