Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DoNotMerge] Prometheus metrics #239

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion cmd/controlloop/controlloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"time"
Expand All @@ -28,6 +30,8 @@ import (
"github.com/k8snetworkplumbingwg/whereabouts/pkg/logging"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/reconciler"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/types"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

const (
Expand Down Expand Up @@ -68,19 +72,44 @@ func main() {
networkController.Start(stopChan)
defer networkController.Shutdown()

logging.Verbosef("test logging 1")
s := gocron.NewScheduler(time.UTC)
schedule := cronExpressionFromFlatFile()

_, err = s.Cron(schedule).Do(func() { // user configurable cron expression in install-cni.sh
logging.Verbosef("test logging 2, schedule is: %s", schedule)
_, err = s.Cron("* * * * *").Do(func() { // user configurable cron expression in install-cni.sh
reconciler.ReconcileIPs(errorChan)
})
if err != nil {
_ = logging.Errorf("error with cron expression schedule: %v", err)
os.Exit(cronExpressionError)
}
logging.Verbosef("test logging 3")

s.StartAsync()

reconcilerSuccessTotal := prometheus.NewCounter(prometheus.CounterOpts{
Name: "reconciler_success_total",
Help: "Increments upon successful run of IP reconciler",
})

reconcilerAttempted := prometheus.NewCounter(prometheus.CounterOpts{
Name: "reconciler_attempted",
Help: "Increments after each attempt of an IP reconciler run",
})

prometheus.MustRegister(reconcilerSuccessTotal, reconcilerAttempted)

http.Handle("/metrics", promhttp.Handler())

logging.Verbosef("test logging 4")

go func() {
log.Fatal(http.ListenAndServe(":1984", nil))
}()

logging.Verbosef("test logging 5")

for {
select {
case <-stopChan:
Expand All @@ -90,8 +119,11 @@ func main() {
case err := <-errorChan:
if err == nil {
logging.Verbosef("reconciler success")
reconcilerSuccessTotal.Inc()
reconcilerAttempted.Inc()
} else {
logging.Verbosef("reconciler failure: %s", err)
reconcilerAttempted.Inc()
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ require (
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
Expand Down Expand Up @@ -55,7 +60,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/common v0.34.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ var _ = Describe("Allocation operations", func() {
"range_start": "00192.00168.1.44",
"range_end": "00192.00168.01.209",
"gateway": "192.168.10.1",
"reconciler_cron_expression": "30 4 * * *"
"reconciler_cron_expression": "* * * * *"
}
}`

Expand All @@ -269,6 +269,6 @@ var _ = Describe("Allocation operations", func() {
Expect(ipamConfig.RangeStart).To(Equal(net.ParseIP("192.168.1.44")))
Expect(ipamConfig.RangeEnd).To(Equal(net.ParseIP("192.168.1.209")))
Expect(ipamConfig.RangeEnd).To(Equal(net.ParseIP("192.168.1.209")))
Expect(ipamConfig.ReconcilerCronExpression).To(Equal("30 4 * * *"))
Expect(ipamConfig.ReconcilerCronExpression).To(Equal("* * * * *"))
})
})
2 changes: 1 addition & 1 deletion script/install-cni.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ EOF
"kubernetes": {
"kubeconfig": "${WHEREABOUTS_KUBECONFIG_LITERAL}"
},
"reconciler_cron_expression": "30 4 * * *"
"reconciler_cron_expression": "* * * * *"
}
EOF

Expand Down
20 changes: 20 additions & 0 deletions vendor/github.com/beorn7/perks/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading