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] Ip reconciler alerting #218

Closed
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
57 changes: 56 additions & 1 deletion cmd/controlloop/main.go → cmd/controlloop/controlloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"time"

corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -21,8 +24,11 @@ import (

wbclient "github.com/k8snetworkplumbingwg/whereabouts/pkg/client/clientset/versioned"
wbinformers "github.com/k8snetworkplumbingwg/whereabouts/pkg/client/informers/externalversions"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/controlloop"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/logging"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/reconciler/controlloop"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/reconciler"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

const (
Expand All @@ -46,7 +52,9 @@ func main() {
logging.SetLogStderr(true)

stopChan := make(chan struct{})
returnErr := make(chan error)
defer close(stopChan)
defer close(returnErr)
handleSignals(stopChan, os.Interrupt)

networkController, err := newPodController(stopChan)
Expand All @@ -56,6 +64,53 @@ func main() {
}

networkController.Start(stopChan)

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

prometheus.MustRegister(totalReconcilerSuccess)

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

// TODO: i want to generalize this - use random ip address instead of a specific one
go func() {
log.Fatal(http.ListenAndServe(":1984", nil)) // I might need to be using port 8443? Not sure
}()

// here's where my for { select {} } loop should go - and use tickers
// https://gobyexample.com/tickers
// general logic - loop indefinitely, with the following conditions:
// a. stopChan sends a value: quit out of the loop and return function
// b. ticker ticks: start a goroutine to run ip-reconciler
// c. default: continue to spin
ticker := time.NewTicker(10 * time.Second) // temp value, will eventually be days/weeks duration

i := 0
for /*i := 0; i < 5; i++*/ {
i++
logging.Verbosef("iteration #%d", i)
select {
case <-stopChan:
return
case t := <-ticker.C:
fmt.Println("Running ip-reconciler, tick at ", t)
go reconciler.InvokeIPReconciler(returnErr)
case err := <-returnErr: // why is this case only reached one time?
logging.Verbosef("reached counter decision")
if err == nil {
totalReconcilerSuccess.Inc()
logging.Verbosef("ip reconciler success!")
} else {
logging.Verbosef("ip reconciler failure: %s", err)
}
}
}

logging.Verbosef("loop ended...you have one minute to curl for counter results.")
time.Sleep(1 * time.Minute)
return
}

func handleSignals(stopChannel chan struct{}, signals ...os.Signal) {
Expand Down
48 changes: 0 additions & 48 deletions cmd/reconciler/ip.go

This file was deleted.

7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ require (
github.com/coreos/etcd v3.3.13+incompatible
github.com/grpc-ecosystem/grpc-gateway v1.11.1 // indirect
github.com/imdario/mergo v0.3.10
github.com/json-iterator/go v1.1.12 // indirect
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.1.1-0.20210510153419-66a699ae3b05
github.com/onsi/ginkgo v1.14.1
github.com/onsi/gomega v1.10.2
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.12.1
golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
golang.org/x/tools v0.1.9 // indirect
Expand All @@ -28,4 +28,7 @@ require (
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
replace (
github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2
google.golang.org/grpc => google.golang.org/grpc v1.29.0
)
Loading