Skip to content

Commit bd37755

Browse files
authored
Revert "move metrics to service port, add healthz, pprof (#1318)" (#1362)
This reverts commit 5ec6a3f.
1 parent d7a5b9e commit bd37755

File tree

3 files changed

+13
-37
lines changed

3 files changed

+13
-37
lines changed

cns/configuration/configuration.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type CNSConfig struct {
2222
ChannelMode string
2323
InitializeFromCNI bool
2424
ManagedSettings ManagedSettings
25-
Debug bool
25+
MetricsBindAddress string
2626
SyncHostNCTimeoutMs int
2727
SyncHostNCVersionIntervalMs int
2828
TLSCertificatePath string
@@ -150,6 +150,9 @@ func SetCNSConfigDefaults(config *CNSConfig) {
150150
if config.ChannelMode == "" {
151151
config.ChannelMode = cns.Direct
152152
}
153+
if config.MetricsBindAddress == "" {
154+
config.MetricsBindAddress = ":9090"
155+
}
153156
if config.SyncHostNCVersionIntervalMs == 0 {
154157
config.SyncHostNCVersionIntervalMs = 1000 //nolint:gomnd // default times
155158
}

cns/configuration/configuration_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func TestReadConfigFromFile(t *testing.T) {
6161
NodeID: "abc",
6262
NodeSyncIntervalInSeconds: 30,
6363
},
64+
MetricsBindAddress: ":9091",
6465
SyncHostNCTimeoutMs: 5,
6566
SyncHostNCVersionIntervalMs: 5,
6667
TLSCertificatePath: "/test",
@@ -190,7 +191,7 @@ func TestSetCNSConfigDefaults(t *testing.T) {
190191
ManagedSettings: ManagedSettings{
191192
NodeSyncIntervalInSeconds: 30,
192193
},
193-
Debug: false,
194+
MetricsBindAddress: ":9090",
194195
SyncHostNCTimeoutMs: 500,
195196
SyncHostNCVersionIntervalMs: 1000,
196197
TelemetrySettings: TelemetrySettings{
@@ -209,6 +210,7 @@ func TestSetCNSConfigDefaults(t *testing.T) {
209210
ManagedSettings: ManagedSettings{
210211
NodeSyncIntervalInSeconds: 1,
211212
},
213+
MetricsBindAddress: ":9091",
212214
SyncHostNCTimeoutMs: 5,
213215
SyncHostNCVersionIntervalMs: 1,
214216
TelemetrySettings: TelemetrySettings{
@@ -224,6 +226,7 @@ func TestSetCNSConfigDefaults(t *testing.T) {
224226
ManagedSettings: ManagedSettings{
225227
NodeSyncIntervalInSeconds: 1,
226228
},
229+
MetricsBindAddress: ":9091",
227230
SyncHostNCTimeoutMs: 5,
228231
SyncHostNCVersionIntervalMs: 1,
229232
TelemetrySettings: TelemetrySettings{

cns/service/main.go

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"encoding/json"
1010
"fmt"
1111
"net/http"
12-
"net/http/pprof"
1312
"os"
1413
"os/signal"
1514
"runtime"
@@ -47,16 +46,13 @@ import (
4746
"github.com/Azure/azure-container-networking/store"
4847
"github.com/avast/retry-go/v3"
4948
"github.com/pkg/errors"
50-
"github.com/prometheus/client_golang/prometheus/promhttp"
5149
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5250
"k8s.io/apimachinery/pkg/fields"
5351
"k8s.io/apimachinery/pkg/types"
5452
"k8s.io/client-go/kubernetes"
5553
ctrl "sigs.k8s.io/controller-runtime"
5654
"sigs.k8s.io/controller-runtime/pkg/cache"
5755
"sigs.k8s.io/controller-runtime/pkg/client"
58-
"sigs.k8s.io/controller-runtime/pkg/healthz"
59-
"sigs.k8s.io/controller-runtime/pkg/metrics"
6056
)
6157

6258
const (
@@ -334,12 +330,7 @@ func registerNode(httpc *http.Client, httpRestService cns.HTTPService, dncEP, in
334330
}
335331

336332
// sendRegisterNodeRequest func helps in registering the node until there is an error.
337-
func sendRegisterNodeRequest(
338-
httpc *http.Client,
339-
httpRestService cns.HTTPService,
340-
nodeRegisterRequest cns.NodeRegisterRequest,
341-
registerURL string,
342-
) error {
333+
func sendRegisterNodeRequest(httpc *http.Client, httpRestService cns.HTTPService, nodeRegisterRequest cns.NodeRegisterRequest, registerURL string) error {
343334
var body bytes.Buffer
344335
err := json.NewEncoder(&body).Encode(nodeRegisterRequest)
345336
if err != nil {
@@ -999,9 +990,10 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
999990
})
1000991

1001992
manager, err := ctrl.NewManager(kubeConfig, ctrl.Options{
1002-
Scheme: nodenetworkconfig.Scheme,
1003-
Namespace: "kube-system", // TODO(rbtr): namespace should be in the cns config
1004-
NewCache: nodeScopedCache,
993+
Scheme: nodenetworkconfig.Scheme,
994+
MetricsBindAddress: cnsconfig.MetricsBindAddress,
995+
Namespace: "kube-system", // TODO(rbtr): namespace should be in the cns config
996+
NewCache: nodeScopedCache,
1005997
})
1006998
if err != nil {
1007999
return errors.Wrap(err, "failed to create manager")
@@ -1020,27 +1012,6 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
10201012
return errors.Wrapf(err, "failed to setup reconciler with manager")
10211013
}
10221014

1023-
// adding some routes to the root serve mux
1024-
mux := httpRestServiceImplementation.Listener.GetMux()
1025-
1026-
if cnsconfig.Debug {
1027-
// add pprof endpoints
1028-
mux.HandleFunc("/debug/pprof/", pprof.Index)
1029-
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
1030-
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
1031-
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
1032-
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
1033-
}
1034-
1035-
// add metrics endpoints
1036-
mux.Handle("/metrics", promhttp.HandlerFor(metrics.Registry, promhttp.HandlerOpts{
1037-
ErrorHandling: promhttp.HTTPErrorOnError,
1038-
}))
1039-
1040-
// add healthz endpoints
1041-
healthzhandler := healthz.Handler{}
1042-
mux.Handle("/healthz", http.StripPrefix("/healthz", &healthzhandler))
1043-
10441015
// Start the Manager which starts the reconcile loop.
10451016
// The Reconciler will send an initial NodeNetworkConfig update to the PoolMonitor, starting the
10461017
// Monitor's internal loop.
@@ -1085,7 +1056,6 @@ func InitializeCRDState(ctx context.Context, httpRestService cns.HTTPService, cn
10851056
}
10861057
}
10871058
}()
1088-
10891059
logger.Printf("initialized and started SyncHostNCVersion loop")
10901060

10911061
return nil

0 commit comments

Comments
 (0)