Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit ec42ee9

Browse files
committed
add flag to disable stackdriver
Tested: Replaced existing installation of hnc v0.8.0 and continued to see errors. Added --enable-stackdriver=false and didn't observe any errors.
1 parent 394d655 commit ec42ee9

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

cmd/manager/main.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ var (
5454

5555
var (
5656
metricsAddr string
57+
enableStackdriver bool
5758
maxReconciles int
5859
enableLeaderElection bool
5960
leaderElectionId string
@@ -82,6 +83,7 @@ func init() {
8283
func main() {
8384
setupLog.Info("Parsing flags")
8485
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
86+
flag.BoolVar(&enableStackdriver, "enable-stackdriver", true, "If true, export metrics to stackdriver")
8587
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
8688
"Enable leader election for controller manager. Enabling this will ensure there is only one active controller manager.")
8789
flag.StringVar(&leaderElectionId, "leader-election-id", "controller-leader-election-helper",
@@ -110,22 +112,24 @@ func main() {
110112
// Exporters use Application Default Credentials to authenticate.
111113
// See https://developers.google.com/identity/protocols/application-default-credentials
112114
// for more details.
113-
setupLog.Info("Creating OpenCensus->Stackdriver exporter")
114-
sd, err := stackdriver.NewExporter(stackdriver.Options{
115-
// Stackdriver’s minimum stats reporting period must be >= 60 seconds.
116-
// https://opencensus.io/exporters/supported-exporters/go/stackdriver/
117-
ReportingInterval: stats.ReportingInterval,
118-
})
119-
if err == nil {
120-
// Flush must be called before main() exits to ensure metrics are recorded.
121-
defer sd.Flush()
122-
err = sd.StartMetricsExporter()
115+
if enableStackdriver {
116+
setupLog.Info("Creating OpenCensus->Stackdriver exporter")
117+
sd, err := stackdriver.NewExporter(stackdriver.Options{
118+
// Stackdriver’s minimum stats reporting period must be >= 60 seconds.
119+
// https://opencensus.io/exporters/supported-exporters/go/stackdriver/
120+
ReportingInterval: stats.ReportingInterval,
121+
})
123122
if err == nil {
124-
defer sd.StopMetricsExporter()
123+
// Flush must be called before main() exits to ensure metrics are recorded.
124+
defer sd.Flush()
125+
err = sd.StartMetricsExporter()
126+
if err == nil {
127+
defer sd.StopMetricsExporter()
128+
}
129+
}
130+
if err != nil {
131+
setupLog.Error(err, "Could not create Stackdriver exporter")
125132
}
126-
}
127-
if err != nil {
128-
setupLog.Error(err, "Could not create Stackdriver exporter")
129133
}
130134

131135
// Hook up OpenCensus to Prometheus.
@@ -134,7 +138,7 @@ func main() {
134138
// the returned value since it doesn't do anything anyway. See:
135139
// (https://github.com/census-ecosystem/opencensus-go-exporter-prometheus/blob/2b9ada237b532c09fcb0a1242469827bdb89df41/prometheus.go#L103)
136140
setupLog.Info("Creating Prometheus exporter")
137-
_, err = prometheus.NewExporter(prometheus.Options{
141+
_, err := prometheus.NewExporter(prometheus.Options{
138142
Registerer: metrics.Registry, // use the controller-runtime registry to merge with all other metrics
139143
})
140144
if err != nil {

0 commit comments

Comments
 (0)