feat: make head pull failure warning toggleable (#912)

* feat: make head pull failure warning toggleable

* expect prometheus tests to go through EVENTUALLY

* wait for queue to be empty before checking test conditions

* clean up new head failure toggle

* fixup! clean up new head failure toggle

* test: add registry tests

* test: add warn on head failure tests

* fix client interface and make tests hit more lines

* make all tests use NewClient instead of creating a struct pointer

* fix lint issues

Co-authored-by: Simon Aronsson <simme@arcticbit.se>
This commit is contained in:
nils måsén 2021-04-23 16:34:21 +02:00 committed by GitHub
parent 23572add74
commit b4cf17d33f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 148 additions and 647 deletions

View file

@ -37,12 +37,10 @@ func getWithToken(c http.Client, url string) (*http.Response, error) {
var _ = Describe("the metrics", func() {
httpAPI := api.New(Token)
m := metricsAPI.New()
httpAPI.RegisterHandler(m.Path, m.Handle)
httpAPI.Start(false)
// We should likely split this into multiple tests, but as prometheus requires a restart of the binary
// to reset the metrics and gauges, we'll just do it all at once.
It("should serve metrics", func() {
metric := &metrics.Metric{
Scanned: 4,
@ -50,12 +48,15 @@ var _ = Describe("the metrics", func() {
Failed: 1,
}
metrics.RegisterScan(metric)
Eventually(metrics.Default().QueueIsEmpty).Should(BeTrue())
c := http.Client{}
res, err := getWithToken(c, "http://localhost:8080/v1/metrics")
Expect(err).ToNot(HaveOccurred())
Expect(err).NotTo(HaveOccurred())
contents, err := ioutil.ReadAll(res.Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(contents)).To(ContainSubstring("watchtower_containers_updated 3"))
Expect(string(contents)).To(ContainSubstring("watchtower_containers_failed 1"))
Expect(string(contents)).To(ContainSubstring("watchtower_containers_scanned 4"))
@ -65,11 +66,13 @@ var _ = Describe("the metrics", func() {
for i := 0; i < 3; i++ {
metrics.RegisterScan(nil)
}
Eventually(metrics.Default().QueueIsEmpty).Should(BeTrue())
res, err = getWithToken(c, "http://localhost:8080/v1/metrics")
Expect(err).NotTo(HaveOccurred())
contents, err = ioutil.ReadAll(res.Body)
Expect(err).ToNot(HaveOccurred())
contents, err = ioutil.ReadAll(res.Body)
Expect(err).ToNot(HaveOccurred())
Expect(string(contents)).To(ContainSubstring("watchtower_scans_total 4"))
Expect(string(contents)).To(ContainSubstring("watchtower_scans_skipped 3"))
})